#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <signal.h>
Include dependency graph for lcc.c:

Go to the source code of this file.
Data Structures | |
| struct | list |
Defines | |
| #define | _P_WAIT 0 |
| #define | TEMPDIR "/tmp" |
| #define | xx(v) if (s = getenv(#v)) fprintf(stderr, #v "=%s\n", s) |
Typedefs | |
| typedef list * | List |
Functions | |
| int | _spawnvp (int mode, const char *cmdname, char *argv[]) |
| int | access (char *, int) |
| void * | alloc (int) |
| List | append (char *, List) |
| char * | basepath (char *) |
| int | callsys (char **av) |
| int | callsys (char *[]) |
| int | compile (char *, char *) |
| void | compose (char *[], List, List, List) |
| char * | concat (char *, char *) |
| void | error (char *, char *) |
| void | execv (const char *, char *[]) |
| char * | exists (char *) |
| int | filename (char *, char *) |
| List | find (char *, List) |
| char * | first (char *) |
| int | fork (void) |
| int | getpid (void) |
| void | help (void) |
| void | initinputs (void) |
| void | interrupt (int) |
| int | main (int, char *[]) |
| void | opt (char *) |
| int | option (char *) |
| List | path2list (const char *) |
| char * | replace (const char *, int, int) |
| void | rm (List) |
| char * | stringf (const char *,...) |
| char * | strsave (const char *) |
| int | suffix (char *, char *[], int) |
| char * | tempname (char *) |
| int | wait (int *) |
Variables | |
| int | ac |
| List | alist |
| char * | as [] |
| char ** | av |
| int | cflag |
| List | clist |
| char * | com [] |
| char * | cpp [] |
| int | Eflag |
| int | errcnt |
| List | ilist |
| char * | include [] |
| char | inputs [] |
| List | lccinputs |
| char * | ld [] |
| List | llist [2] |
| char * | outfile |
| List | plist |
| char * | progname |
| char | rcsid [] = "Id: dummy rcsid" |
| List | rmlist |
| int | Sflag |
| char * | suffixes [] |
| char * | tempdir = TEMPDIR |
| int | verbose |
|
|
Definition at line 214 of file lcc.c. Referenced by callsys(). |
|
|
|
|
|
|
Definition at line 19 of file lcc.c. Referenced by append(), apply(), attach(), bbfile(), compose(), enumdcl(), exists(), find(), ftype(), initinputs(), length(), ltov(), parameters(), path2list(), printproto(), and rm(). |
|
||||||||||||||||
|
Definition at line 219 of file lcc.c. References argv, exit(), fflush(), fork(), fprintf(), n, perror(), progname, stderr, stdout, and wait(). Referenced by callsys(). 00219 {
00220 int pid, n, status;
00221
00222 switch (pid = fork()) {
00223 case -1:
00224 fprintf(stderr, "%s: no more processes\n", progname);
00225 return 100;
00226 case 0:
00227 // TTimo removing hardcoded paths, searching in $PATH
00228 execvp(cmdname, argv);
00229 fprintf(stderr, "%s: ", progname);
00230 perror(cmdname);
00231 fflush(stdout);
00232 exit(100);
00233 }
00234 while ((n = wait(&status)) != pid && n != -1)
00235 ;
00236 if (n == -1)
00237 status = -1;
00238 if (status&0377) {
00239 fprintf(stderr, "%s: fatal error in %s\n", progname, cmdname);
00240 status |= 0400;
00241 }
00242 return (status>>8)&0377;
00243 }
|
Here is the call graph for this function:

|
||||||||||||
|
|
|
|
Definition at line 169 of file lcc.c. References assert, limit, malloc(), and n. 00169 {
00170 static char *avail, *limit;
00171
00172 n = (n + sizeof(char *) - 1)&~(sizeof(char *) - 1);
00173 if (n >= limit - avail) {
00174 avail = malloc(n + 4*1024);
00175 assert(avail);
00176 limit = avail + n + 4*1024;
00177 }
00178 avail += n;
00179 return avail - n;
00180 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 183 of file lcc.c. References alloc(), list::link, List, p, and list::str. 00183 {
00184 List p = alloc(sizeof *p);
00185
00186 p->str = str;
00187 if (list) {
00188 p->link = list->link;
00189 list->link = p;
00190 } else
00191 p->link = p;
00192 return p;
00193 }
|
Here is the call graph for this function:

|
|
Definition at line 196 of file lcc.c. References b, s, strsave(), and t. Referenced by DefaultPath(), filename(), opt(), and Sys_LoadDll(). 00196 {
00197 char *s, *b, *t = 0;
00198
00199 for (b = s = name; *s; s++)
00200 if (*s == '/' || *s == '\\') {
00201 b = s + 1;
00202 t = 0;
00203 } else if (*s == '.')
00204 t = s;
00205 s = strsave(b);
00206 if (t)
00207 s[t-b] = 0;
00208 return s;
00209 }
|
Here is the call graph for this function:

|
|
Definition at line 247 of file lcc.c. References _P_WAIT, _spawnvp(), argc, argv, assert, av, fprintf(), i, j, k, malloc(), NULL, perror(), progname, realloc(), s, stderr, strchr(), stringf(), and verbose. Referenced by compile(), and filename(). 00247 {
00248 int i, status = 0;
00249 static char **argv;
00250 static int argc;
00251
00252 for (i = 0; av[i] != NULL; i++)
00253 ;
00254 if (i + 1 > argc) {
00255 argc = i + 1;
00256 if (argv == NULL)
00257 argv = malloc(argc*sizeof *argv);
00258 else
00259 argv = realloc(argv, argc*sizeof *argv);
00260 assert(argv);
00261 }
00262 for (i = 0; status == 0 && av[i] != NULL; ) {
00263 int j = 0;
00264 char *s;
00265 for ( ; av[i] != NULL && (s = strchr(av[i], '\n')) == NULL; i++)
00266 argv[j++] = av[i];
00267 if (s != NULL) {
00268 if (s > av[i])
00269 argv[j++] = stringf("%.*s", s - av[i], av[i]);
00270 if (s[1] != '\0')
00271 av[i] = s + 1;
00272 else
00273 i++;
00274 }
00275 argv[j] = NULL;
00276 if (verbose > 0) {
00277 int k;
00278 fprintf(stderr, "%s", argv[0]);
00279 for (k = 1; argv[k] != NULL; k++)
00280 fprintf(stderr, " %s", argv[k]);
00281 fprintf(stderr, "\n");
00282 }
00283 if (verbose < 2)
00284 status = _spawnvp(_P_WAIT, argv[0], argv);
00285 if (status == -1) {
00286 fprintf(stderr, "%s: ", progname);
00287 perror(argv[0]);
00288 }
00289 }
00290 return status;
00291 }
|
Here is the call graph for this function:

|
|
|
|
||||||||||||
|
Definition at line 304 of file lcc.c. References append(), av, callsys(), clist, com, compose(), and src. Referenced by filename(). 00304 {
00305 compose(com, clist, append(src, 0), append(dst, 0));
00306 return callsys(av);
00307 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 310 of file lcc.c. References ac, alloc(), assert, av, b, i, isdigit, j, k, list::link, List, lists, s, list::str, strcat(), strchr(), strlen(), and strncpy(). 00310 {
00311 int i, j;
00312 List lists[3];
00313
00314 lists[0] = a;
00315 lists[1] = b;
00316 lists[2] = c;
00317 for (i = j = 0; cmd[i]; i++) {
00318 char *s = strchr(cmd[i], '$');
00319 if (s && isdigit(s[1])) {
00320 int k = s[1] - '0';
00321 assert(k >=1 && k <= 3);
00322 if (b = lists[k-1]) {
00323 b = b->link;
00324 av[j] = alloc(strlen(cmd[i]) + strlen(b->str) - 1);
00325 strncpy(av[j], cmd[i], s - cmd[i]);
00326 av[j][s-cmd[i]] = '\0';
00327 strcat(av[j], b->str);
00328 strcat(av[j++], s + 2);
00329 while (b != lists[k-1]) {
00330 b = b->link;
00331 assert(j < ac);
00332 av[j++] = b->str;
00333 };
00334 }
00335 } else if (*cmd[i]) {
00336 assert(j < ac);
00337 av[j++] = cmd[i];
00338 }
00339 }
00340 av[j] = NULL;
00341 }
|
Here is the call graph for this function:

|
||||||||||||
|
|
|
||||||||||||
|
Definition at line 344 of file lcc.c. References errcnt, fprintf(), progname, and stderr. 00344 {
00345 fprintf(stderr, "%s: ", progname);
00346 fprintf(stderr, fmt, msg);
00347 fprintf(stderr, "\n");
00348 errcnt++;
00349 }
|
Here is the call graph for this function:

|
||||||||||||
|
|
|
|
Definition at line 352 of file lcc.c. References access(), b, list::link, List, name, sprintf(), list::str, strsave(), and verbose. 00352 {
00353 List b;
00354
00355 if ( (name[0] == '/' || name[0] == '\\' || name[2] == ':')
00356 && access(name, 4) == 0)
00357 return name;
00358 if (!(name[0] == '/' || name[0] == '\\' || name[2] == ':')
00359 && (b = lccinputs))
00360 do {
00361 b = b->link;
00362 if (b->str[0]) {
00363 char buf[1024];
00364 sprintf(buf, "%s/%s", b->str, name);
00365 if (access(buf, 4) == 0)
00366 return strsave(buf);
00367 } else if (access(name, 4) == 0)
00368 return name;
00369 } while (b != lccinputs);
00370 if (verbose > 1)
00371 return name;
00372 return 0;
00373 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 389 of file lcc.c. References alist, append(), as, av, basepath(), callsys(), cflag, compile(), compose(), concat(), cpp, errcnt, find(), first(), llist, name, outfile, plist, suffix(), suffixes, and tempname(). 00389 {
00390 int status = 0;
00391 static char *stemp, *itemp;
00392
00393 if (base == 0)
00394 base = basepath(name);
00395 switch (suffix(name, suffixes, 4)) {
00396 case 0: /* C source files */
00397 compose(cpp, plist, append(name, 0), 0);
00398 if (Eflag) {
00399 status = callsys(av);
00400 break;
00401 }
00402 if (itemp == NULL)
00403 itemp = tempname(first(suffixes[1]));
00404 compose(cpp, plist, append(name, 0), append(itemp, 0));
00405 status = callsys(av);
00406 if (status == 0)
00407 return filename(itemp, base);
00408 break;
00409 case 1: /* preprocessed source files */
00410 if (Eflag)
00411 break;
00412 if (Sflag)
00413 status = compile(name, outfile ? outfile : concat(base, first(suffixes[2])));
00414 else if ((status = compile(name, stemp?stemp:(stemp=tempname(first(suffixes[2]))))) == 0)
00415 return filename(stemp, base);
00416 break;
00417 case 2: /* assembly language files */
00418 if (Eflag)
00419 break;
00420 if (!Sflag) {
00421 char *ofile;
00422 if (cflag && outfile)
00423 ofile = outfile;
00424 else if (cflag)
00425 ofile = concat(base, first(suffixes[3]));
00426 else
00427 ofile = tempname(first(suffixes[3]));
00428 compose(as, alist, append(name, 0), append(ofile, 0));
00429 status = callsys(av);
00430 if (!find(ofile, llist[1]))
00431 llist[1] = append(ofile, llist[1]);
00432 }
00433 break;
00434 case 3: /* object files */
00435 if (!find(name, llist[1]))
00436 llist[1] = append(name, llist[1]);
00437 break;
00438 default:
00439 if (Eflag) {
00440 compose(cpp, plist, append(name, 0), 0);
00441 status = callsys(av);
00442 }
00443 llist[1] = append(name, llist[1]);
00444 break;
00445 }
00446 if (status)
00447 errcnt++;
00448 return status;
00449 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 452 of file lcc.c. References b, list::link, List, list::str, and strcmp(). Referenced by filename(), and path2list(). 00452 {
00453 List b;
00454
00455 if (b = list)
00456 do {
00457 if (strcmp(str, b->str) == 0)
00458 return b;
00459 } while ((b = b->link) != list);
00460 return 0;
00461 }
|
Here is the call graph for this function:

|
|
Referenced by filename(), and opt(). |
|
|
Referenced by _spawnvp(). |
|
|
Referenced by tempname(). |
|
|
Definition at line 464 of file lcc.c. References fprintf(), i, include, LCCDIR, stderr, strncmp(), tempdir, and xx. Referenced by opt(). 00464 {
00465 static char *msgs[] = {
00466 "", " [ option | file ]...\n",
00467 " except for -l, options are processed left-to-right before files\n",
00468 " unrecognized options are taken to be linker options\n",
00469 "-A warn about nonANSI usage; 2nd -A warns more\n",
00470 "-b emit expression-level profiling code; see bprint(1)\n",
00471 #ifdef sparc
00472 "-Bstatic -Bdynamic specify static or dynamic libraries\n",
00473 #endif
00474 "-Bdir/ use the compiler named `dir/rcc'\n",
00475 "-c compile only\n",
00476 "-dn set switch statement density to `n'\n",
00477 "-Dname -Dname=def define the preprocessor symbol `name'\n",
00478 "-E run only the preprocessor on the named C programs and unsuffixed files\n",
00479 "-g produce symbol table information for debuggers\n",
00480 "-help or -? print this message\n",
00481 "-Idir add `dir' to the beginning of the list of #include directories\n",
00482 "-lx search library `x'\n",
00483 "-N do not search the standard directories for #include files\n",
00484 "-n emit code to check for dereferencing zero pointers\n",
00485 "-O is ignored\n",
00486 "-o file leave the output in `file'\n",
00487 "-P print ANSI-style declarations for globals\n",
00488 "-p -pg emit profiling code; see prof(1) and gprof(1)\n",
00489 "-S compile to assembly language\n",
00490 #ifdef linux
00491 "-static specify static libraries (default is dynamic)\n",
00492 #endif
00493 "-t -tname emit function tracing calls to printf or to `name'\n",
00494 "-target name is ignored\n",
00495 "-tempdir=dir place temporary files in `dir/'", "\n"
00496 "-Uname undefine the preprocessor symbol `name'\n",
00497 "-v show commands as they are executed; 2nd -v suppresses execution\n",
00498 "-w suppress warnings\n",
00499 "-Woarg specify system-specific `arg'\n",
00500 "-W[pfal]arg pass `arg' to the preprocessor, compiler, assembler, or linker\n",
00501 0 };
00502 int i;
00503 char *s;
00504
00505 msgs[0] = progname;
00506 for (i = 0; msgs[i]; i++) {
00507 fprintf(stderr, "%s", msgs[i]);
00508 if (strncmp("-tempdir", msgs[i], 8) == 0 && tempdir)
00509 fprintf(stderr, "; default=%s", tempdir);
00510 }
00511 #define xx(v) if (s = getenv(#v)) fprintf(stderr, #v "=%s\n", s)
00512 xx(LCCINPUTS);
00513 xx(LCCDIR);
00514 #ifdef WIN32
00515 xx(include);
00516 xx(lib);
00517 #endif
00518 #undef xx
00519 }
|
Here is the call graph for this function:

|
|
Definition at line 522 of file lcc.c. References append(), b, com, concat(), getenv(), ilist, lccinputs, list::link, List, llist, path2list(), s, list::str, strcmp(), stringf(), and strstr(). 00522 {
00523 char *s = getenv("LCCINPUTS");
00524 List list, b;
00525
00526 if (s == 0 || (s = inputs)[0] == 0)
00527 s = ".";
00528 if (s) {
00529 lccinputs = path2list(s);
00530 if (b = lccinputs)
00531 do {
00532 b = b->link;
00533 if (strcmp(b->str, ".") != 0) {
00534 ilist = append(concat("-I", b->str), ilist);
00535 if (strstr(com[1], "win32") == NULL)
00536 llist[0] = append(concat("-L", b->str), llist[0]);
00537 } else
00538 b->str = "";
00539 } while (b != lccinputs);
00540 }
00541 #ifdef WIN32
00542 if (list = b = path2list(getenv("include")))
00543 do {
00544 b = b->link;
00545 ilist = append(stringf("-I\"%s\"", b->str), ilist);
00546 } while (b != list);
00547 #endif
00548 }
|
Here is the call graph for this function:

|
|
Definition at line 551 of file lcc.c. References exit(), n, rm(), and rmlist.
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1223 of file unix_main.c. 01224 {
01225 // int oldtime, newtime; // bk001204 - unused
01226 int len, i;
01227 char *cmdline;
01228 void Sys_SetDefaultCDPath(const char *path);
01229
01230 // go back to real user for config loads
01231 saved_euid = geteuid();
01232 seteuid(getuid());
01233
01234 Sys_ParseArgs( argc, argv ); // bk010104 - added this for support
01235
01236 Sys_SetDefaultCDPath(argv[0]);
01237
01238 // merge the command line, this is kinda silly
01239 for (len = 1, i = 1; i < argc; i++)
01240 len += strlen(argv[i]) + 1;
01241 cmdline = malloc(len);
01242 *cmdline = 0;
01243 for (i = 1; i < argc; i++)
01244 {
01245 if (i > 1)
01246 strcat(cmdline, " ");
01247 strcat(cmdline, argv[i]);
01248 }
01249
01250 // bk000306 - clear queues
01251 memset( &eventQue[0], 0, MAX_QUED_EVENTS*sizeof(sysEvent_t) );
01252 memset( &sys_packetReceived[0], 0, MAX_MSGLEN*sizeof(byte) );
01253
01254 Com_Init(cmdline);
01255 NET_Init();
01256
01257 Sys_ConsoleInputInit();
01258
01259 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
01260
01261 #ifdef DEDICATED
01262 // init here for dedicated, as we don't have GLimp_Init
01263 InitSig();
01264 #endif
01265
01266 while (1)
01267 {
01268 #ifdef __linux__
01269 Sys_ConfigureFPU();
01270 #endif
01271 Com_Frame ();
01272 }
01273 }
|
|
|
Definition at line 557 of file lcc.c. References alist, append(), basepath(), cflag, clist, com, concat(), cpp, Eflag, error(), first(), fprintf(), help(), ilist, include, llist, option(), plist, printed(), progname, rcsid, replace(), Sflag, stderr, strcmp(), strncmp(), strstr(), suffixes, tempdir, and verbose. 00557 {
00558 switch (arg[1]) { /* multi-character options */
00559 case 'W': /* -Wxarg */
00560 if (arg[2] && arg[3])
00561 switch (arg[2]) {
00562 case 'o':
00563 if (option(&arg[3]))
00564 return;
00565 break;
00566 case 'p':
00567 plist = append(&arg[3], plist);
00568 return;
00569 case 'f':
00570 if (strcmp(&arg[3], "-C") || option("-b")) {
00571 clist = append(&arg[3], clist);
00572 return;
00573 }
00574 break; /* and fall thru */
00575 case 'a':
00576 alist = append(&arg[3], alist);
00577 return;
00578 case 'l':
00579 llist[0] = append(&arg[3], llist[0]);
00580 return;
00581 }
00582 fprintf(stderr, "%s: %s ignored\n", progname, arg);
00583 return;
00584 case 'd': /* -dn */
00585 arg[1] = 's';
00586 clist = append(arg, clist);
00587 return;
00588 case 't': /* -t -tname -tempdir=dir */
00589 if (strncmp(arg, "-tempdir=", 9) == 0)
00590 tempdir = arg + 9;
00591 else
00592 clist = append(arg, clist);
00593 return;
00594 case 'p': /* -p -pg */
00595 if (option(arg))
00596 clist = append(arg, clist);
00597 else
00598 fprintf(stderr, "%s: %s ignored\n", progname, arg);
00599 return;
00600 case 'D': /* -Dname -Dname=def */
00601 case 'U': /* -Uname */
00602 case 'I': /* -Idir */
00603 plist = append(arg, plist);
00604 return;
00605 case 'B': /* -Bdir -Bstatic -Bdynamic */
00606 #ifdef sparc
00607 if (strcmp(arg, "-Bstatic") == 0 || strcmp(arg, "-Bdynamic") == 0)
00608 llist[1] = append(arg, llist[1]);
00609 else
00610 #endif
00611 {
00612 static char *path;
00613 if (path)
00614 error("-B overwrites earlier option", 0);
00615 path = arg + 2;
00616 if (strstr(com[1], "win32") != NULL)
00617 com[0] = concat(replace(path, '/', '\\'), concat("rcc", first(suffixes[4])));
00618 else
00619 com[0] = concat(path, "rcc");
00620 if (path[0] == 0)
00621 error("missing directory in -B option", 0);
00622 }
00623 return;
00624 case 'h':
00625 if (strcmp(arg, "-help") == 0) {
00626 static int printed = 0;
00627 case '?':
00628 if (!printed)
00629 help();
00630 printed = 1;
00631 return;
00632 }
00633 #ifdef linux
00634 case 's':
00635 if (strcmp(arg,"-static") == 0) {
00636 if (!option(arg))
00637 fprintf(stderr, "%s: %s ignored\n", progname, arg);
00638 return;
00639 }
00640 #endif
00641 }
00642 if (arg[2] == 0)
00643 switch (arg[1]) { /* single-character options */
00644 case 'S':
00645 Sflag++;
00646 return;
00647 case 'O':
00648 fprintf(stderr, "%s: %s ignored\n", progname, arg);
00649 return;
00650 case 'A': case 'n': case 'w': case 'P':
00651 clist = append(arg, clist);
00652 return;
00653 case 'g': case 'b':
00654 if (option(arg))
00655 clist = append(arg[1] == 'g' ? "-g2" : arg, clist);
00656 else
00657 fprintf(stderr, "%s: %s ignored\n", progname, arg);
00658 return;
00659 case 'G':
00660 if (option(arg)) {
00661 clist = append("-g3", clist);
00662 llist[0] = append("-N", llist[0]);
00663 } else
00664 fprintf(stderr, "%s: %s ignored\n", progname, arg);
00665 return;
00666 case 'E':
00667 Eflag++;
00668 return;
00669 case 'c':
00670 cflag++;
00671 return;
00672 case 'N':
00673 if (strcmp(basepath(cpp[0]), "gcc-cpp") == 0)
00674 plist = append("-nostdinc", plist);
00675 include[0] = 0;
00676 ilist = 0;
00677 return;
00678 case 'v':
00679 if (verbose++ == 0) {
00680 if (strcmp(basepath(cpp[0]), "gcc-cpp") == 0)
00681 plist = append(arg, plist);
00682 clist = append(arg, clist);
00683 fprintf(stderr, "%s %s\n", progname, rcsid);
00684 }
00685 return;
00686 }
00687 if (cflag || Sflag || Eflag)
00688 fprintf(stderr, "%s: %s ignored\n", progname, arg);
00689 else
00690 llist[1] = append(arg, llist[1]);
00691 }
|
Here is the call graph for this function:

|
|
Definition at line 35 of file gcc-solaris.c. References com, concat(), cpp, GCCLIB, include, ld, replace(), strcmp(), strlen(), and strncmp(). Referenced by opt(). 00035 {
00036 if (strncmp(arg, "-lccdir=", 8) == 0) {
00037 cpp[0] = concat(&arg[8], "/cpp");
00038 include[0] = concat("-I", concat(&arg[8], "/include"));
00039 ld[10] = concat("-L", &arg[8]);
00040 com[0] = concat(&arg[8], "/rcc");
00041 } else if (strcmp(arg, "-g") == 0)
00042 ;
00043 else if (strcmp(arg, "-pg") == 0) {
00044 ld[8] = GCCLIB "gmon.o";
00045 } else if (strcmp(arg, "-b") == 0)
00046 ;
00047 else
00048 return 0;
00049 return 1;
00050 }
|
Here is the call graph for this function:
