|
|
1.1 ! root 1: /* @(#)large.c 1.1 88/10/11 NFS Rev 2 Testsuite */ ! 2: /* ! 3: * cc - front end for C compiler ! 4: */ ! 5: #include <sys/param.h> ! 6: #ifndef major ! 7: #include <sys/types.h> ! 8: #endif ! 9: #include <stdio.h> ! 10: #include <ctype.h> ! 11: #include <signal.h> ! 12: #include <sys/dir.h> ! 13: ! 14: #undef MAXNAMLEN ! 15: #define MAXNAMLEN 256 ! 16: ! 17: char *cpp = "/lib/cpp"; ! 18: char *ccom = "/lib/ccom"; ! 19: char *c2 = "/lib/c2"; ! 20: char *as = "/bin/as"; ! 21: char *ld = "/bin/ld"; ! 22: char *crt0 = "/lib/crt0.o"; ! 23: ! 24: char tmp0[30]; /* big enough for /tmp/ctm%05.5d */ ! 25: char *tmp1, *tmp2, *tmp3, *tmp4, *tmp5; ! 26: char *outfile; ! 27: char *savestr(), *strspl(), *setsuf(); ! 28: int idexit(); ! 29: char **av, **clist, **llist, **plist; ! 30: int cflag, eflag, oflag, pflag, sflag, wflag, Rflag, exflag, proflag; ! 31: int gflag, Gflag; ! 32: char *dflag; ! 33: int exfail; ! 34: char *chpass; ! 35: char *npassname; ! 36: ! 37: int nc, nl, np, nxo, na; ! 38: ! 39: #define cunlink(s) if (s) unlink(s) ! 40: ! 41: main(argc, argv) ! 42: char **argv; ! 43: { ! 44: char *t; ! 45: char *assource; ! 46: int i, j, c; ! 47: ! 48: /* ld currently adds upto 5 args; 10 is room to spare */ ! 49: av = (char **)calloc(argc+10, sizeof (char **)); ! 50: clist = (char **)calloc(argc, sizeof (char **)); ! 51: llist = (char **)calloc(argc, sizeof (char **)); ! 52: plist = (char **)calloc(argc, sizeof (char **)); ! 53: for (i = 1; i < argc; i++) { ! 54: if (*argv[i] == '-') switch (argv[i][1]) { ! 55: ! 56: case 'S': ! 57: sflag++; ! 58: cflag++; ! 59: continue; ! 60: case 'o': ! 61: if (++i < argc) { ! 62: outfile = argv[i]; ! 63: switch (getsuf(outfile)) { ! 64: ! 65: case 'c': ! 66: case 'o': ! 67: error("-o would overwrite %s", ! 68: outfile); ! 69: exit(8); ! 70: } ! 71: } ! 72: continue; ! 73: case 'R': ! 74: Rflag++; ! 75: continue; ! 76: case 'O': ! 77: oflag++; ! 78: continue; ! 79: case 'p': ! 80: proflag++; ! 81: crt0 = "/lib/mcrt0.o"; ! 82: if (argv[i][2] == 'g') ! 83: crt0 = "/usr/lib/gcrt0.o"; ! 84: continue; ! 85: case 'g': ! 86: if (argv[i][2] == 'o') { ! 87: Gflag++; /* old format for -go */ ! 88: } else { ! 89: gflag++; /* new format for -g */ ! 90: } ! 91: continue; ! 92: case 'w': ! 93: wflag++; ! 94: continue; ! 95: case 'E': ! 96: exflag++; ! 97: case 'P': ! 98: pflag++; ! 99: if (argv[i][1]=='P') ! 100: fprintf(stderr, ! 101: "cc: warning: -P option obsolete; you should use -E instead\n"); ! 102: plist[np++] = argv[i]; ! 103: case 'c': ! 104: cflag++; ! 105: continue; ! 106: case 'D': ! 107: case 'I': ! 108: case 'U': ! 109: case 'C': ! 110: plist[np++] = argv[i]; ! 111: continue; ! 112: case 't': ! 113: if (chpass) ! 114: error("-t overwrites earlier option", 0); ! 115: chpass = argv[i]+2; ! 116: if (chpass[0]==0) ! 117: chpass = "012p"; ! 118: continue; ! 119: case 'f': ! 120: fprintf(stderr, ! 121: "cc: warning: -f option obsolete (unnecessary)\n"); ! 122: continue; ! 123: case 'B': ! 124: if (npassname) ! 125: error("-B overwrites earlier option", 0); ! 126: npassname = argv[i]+2; ! 127: if (npassname[0]==0) ! 128: npassname = "/usr/c/o"; ! 129: continue; ! 130: case 'd': ! 131: dflag = argv[i]; ! 132: continue; ! 133: } ! 134: t = argv[i]; ! 135: c = getsuf(t); ! 136: if (c=='c' || c=='s' || exflag) { ! 137: clist[nc++] = t; ! 138: t = setsuf(t, 'o'); ! 139: } ! 140: if (nodup(llist, t)) { ! 141: llist[nl++] = t; ! 142: if (getsuf(t)=='o') ! 143: nxo++; ! 144: } ! 145: } ! 146: if (gflag || Gflag) { ! 147: if (oflag) ! 148: fprintf(stderr, "cc: warning: -g disables -O\n"); ! 149: oflag = 0; ! 150: } ! 151: if (npassname && chpass ==0) ! 152: chpass = "012p"; ! 153: if (chpass && npassname==0) ! 154: npassname = "/usr/new"; ! 155: if (chpass) ! 156: for (t=chpass; *t; t++) { ! 157: switch (*t) { ! 158: ! 159: case '0': ! 160: ccom = strspl(npassname, "ccom"); ! 161: continue; ! 162: case '2': ! 163: c2 = strspl(npassname, "c2"); ! 164: continue; ! 165: case 'p': ! 166: cpp = strspl(npassname, "cpp"); ! 167: continue; ! 168: } ! 169: } ! 170: if (nc==0) ! 171: goto nocom; ! 172: if (signal(SIGINT, SIG_IGN) != SIG_IGN) ! 173: signal(SIGINT, idexit); ! 174: if (signal(SIGTERM, SIG_IGN) != SIG_IGN) ! 175: signal(SIGTERM, idexit); ! 176: if (pflag==0) ! 177: sprintf(tmp0, "/tmp/ctm%05.5d", getpid()); ! 178: tmp1 = strspl(tmp0, "1"); ! 179: tmp2 = strspl(tmp0, "2"); ! 180: tmp3 = strspl(tmp0, "3"); ! 181: if (pflag==0) ! 182: tmp4 = strspl(tmp0, "4"); ! 183: if (oflag) ! 184: tmp5 = strspl(tmp0, "5"); ! 185: for (i=0; i<nc; i++) { ! 186: if (nc > 1) { ! 187: printf("%s:\n", clist[i]); ! 188: fflush(stdout); ! 189: } ! 190: if (getsuf(clist[i]) == 's') { ! 191: assource = clist[i]; ! 192: goto assemble; ! 193: } else ! 194: assource = tmp3; ! 195: if (pflag) ! 196: tmp4 = setsuf(clist[i], 'i'); ! 197: av[0] = "cpp"; av[1] = clist[i]; av[2] = exflag ? "-" : tmp4; ! 198: na = 3; ! 199: for (j = 0; j < np; j++) ! 200: av[na++] = plist[j]; ! 201: av[na++] = 0; ! 202: if (callsys(cpp, av)) { ! 203: exfail++; ! 204: eflag++; ! 205: } ! 206: if (pflag || exfail) { ! 207: cflag++; ! 208: continue; ! 209: } ! 210: if (sflag) ! 211: assource = tmp3 = setsuf(clist[i], 's'); ! 212: av[0] = "ccom"; av[1] = tmp4; av[2] = oflag?tmp5:tmp3; na = 3; ! 213: if (proflag) ! 214: av[na++] = "-XP"; ! 215: if (gflag) { ! 216: av[na++] = "-Xg"; ! 217: } else if (Gflag) { ! 218: av[na++] = "-XG"; ! 219: } ! 220: if (wflag) ! 221: av[na++] = "-w"; ! 222: av[na] = 0; ! 223: if (callsys(ccom, av)) { ! 224: cflag++; ! 225: eflag++; ! 226: continue; ! 227: } ! 228: if (oflag) { ! 229: av[0] = "c2"; av[1] = tmp5; av[2] = tmp3; av[3] = 0; ! 230: if (callsys(c2, av)) { ! 231: unlink(tmp3); ! 232: tmp3 = assource = tmp5; ! 233: } else ! 234: unlink(tmp5); ! 235: } ! 236: if (sflag) ! 237: continue; ! 238: assemble: ! 239: cunlink(tmp1); cunlink(tmp2); cunlink(tmp4); ! 240: av[0] = "as"; av[1] = "-o"; av[2] = setsuf(clist[i], 'o'); ! 241: na = 3; ! 242: if (Rflag) ! 243: av[na++] = "-R"; ! 244: if (dflag) ! 245: av[na++] = dflag; ! 246: av[na++] = assource; ! 247: av[na] = 0; ! 248: if (callsys(as, av) > 1) { ! 249: cflag++; ! 250: eflag++; ! 251: continue; ! 252: } ! 253: } ! 254: nocom: ! 255: if (cflag==0 && nl!=0) { ! 256: i = 0; ! 257: av[0] = "ld"; av[1] = "-X"; av[2] = crt0; na = 3; ! 258: if (outfile) { ! 259: av[na++] = "-o"; ! 260: av[na++] = outfile; ! 261: } ! 262: while (i < nl) ! 263: av[na++] = llist[i++]; ! 264: if (gflag || Gflag) ! 265: av[na++] = "-lg"; ! 266: if (proflag) ! 267: av[na++] = "-lc_p"; ! 268: else ! 269: av[na++] = "-lc"; ! 270: av[na++] = 0; ! 271: eflag |= callsys(ld, av); ! 272: if (nc==1 && nxo==1 && eflag==0) ! 273: unlink(setsuf(clist[0], 'o')); ! 274: } ! 275: dexit(); ! 276: } ! 277: ! 278: idexit() ! 279: { ! 280: ! 281: eflag = 100; ! 282: dexit(); ! 283: } ! 284: ! 285: dexit() ! 286: { ! 287: ! 288: if (!pflag) { ! 289: cunlink(tmp1); ! 290: cunlink(tmp2); ! 291: if (sflag==0) ! 292: cunlink(tmp3); ! 293: cunlink(tmp4); ! 294: cunlink(tmp5); ! 295: } ! 296: exit(eflag); ! 297: } ! 298: ! 299: error(s, x) ! 300: char *s, *x; ! 301: { ! 302: FILE *diag = exflag ? stderr : stdout; ! 303: ! 304: fprintf(diag, "cc: "); ! 305: fprintf(diag, s, x); ! 306: putc('\n', diag); ! 307: exfail++; ! 308: cflag++; ! 309: eflag++; ! 310: } ! 311: ! 312: getsuf(as) ! 313: char as[]; ! 314: { ! 315: register int c; ! 316: register char *s; ! 317: register int t; ! 318: ! 319: s = as; ! 320: c = 0; ! 321: while (t = *s++) ! 322: if (t=='/') ! 323: c = 0; ! 324: else ! 325: c++; ! 326: s -= 3; ! 327: if (c <= MAXNAMLEN && c > 2 && *s++ == '.') ! 328: return (*s); ! 329: return (0); ! 330: } ! 331: ! 332: char * ! 333: setsuf(as, ch) ! 334: char *as; ! 335: { ! 336: register char *s, *s1; ! 337: ! 338: s = s1 = savestr(as); ! 339: while (*s) ! 340: if (*s++ == '/') ! 341: s1 = s; ! 342: s[-1] = ch; ! 343: return (s1); ! 344: } ! 345: ! 346: callsys(f, v) ! 347: char *f, **v; ! 348: { ! 349: int t, status; ! 350: ! 351: t = fork(); ! 352: if (t == -1) { ! 353: printf("No more processes\n"); ! 354: return (100); ! 355: } ! 356: if (t == 0) { ! 357: execv(f, v); ! 358: printf("Can't find %s\n", f); ! 359: fflush(stdout); ! 360: _exit(100); ! 361: } ! 362: while (t != wait(&status)) ! 363: ; ! 364: if ((t=(status&0377)) != 0 && t!=14) { ! 365: if (t!=2) { ! 366: printf("Fatal error in %s\n", f); ! 367: eflag = 8; ! 368: } ! 369: dexit(); ! 370: } ! 371: return ((status>>8) & 0377); ! 372: } ! 373: ! 374: nodup(l, os) ! 375: char **l, *os; ! 376: { ! 377: register char *t, *s; ! 378: register int c; ! 379: ! 380: s = os; ! 381: if (getsuf(s) != 'o') ! 382: return (1); ! 383: while (t = *l++) { ! 384: while (c = *s++) ! 385: if (c != *t++) ! 386: break; ! 387: if (*t==0 && c==0) ! 388: return (0); ! 389: s = os; ! 390: } ! 391: return (1); ! 392: } ! 393: ! 394: #define NSAVETAB 1024 ! 395: char *savetab; ! 396: int saveleft; ! 397: ! 398: char * ! 399: savestr(cp) ! 400: register char *cp; ! 401: { ! 402: register int len; ! 403: ! 404: len = strlen(cp) + 1; ! 405: if (len > saveleft) { ! 406: saveleft = NSAVETAB; ! 407: if (len > saveleft) ! 408: saveleft = len; ! 409: savetab = (char *)malloc(saveleft); ! 410: if (savetab == 0) { ! 411: fprintf(stderr, "ran out of memory (savestr)\n"); ! 412: exit(1); ! 413: } ! 414: } ! 415: strncpy(savetab, cp, len); ! 416: cp = savetab; ! 417: savetab += len; ! 418: saveleft -= len; ! 419: return (cp); ! 420: } ! 421: ! 422: char * ! 423: strspl(left, right) ! 424: char *left, *right; ! 425: { ! 426: char buf[BUFSIZ]; ! 427: ! 428: strcpy(buf, left); ! 429: strcat(buf, right); ! 430: return (savestr(buf)); ! 431: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.