Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.223
 
1.224
 
MAIN:ragge:20120803124205
 
cc.c
_>166166 static int lac;
 167167 static void add_prefix(const char *);
 168168 static char *find_file(const char *, int);
<> 169+static char *find_file2(const char *file, struct strlist *path, int mode);
169170 char *copy(const char *, int);
 170171 char *cat(const char *, const char *);
 171172 char *setsuf(char *, char);
     
 !
193194 char *win32commandline(char *, char *[]);
 194195 #endif
 195196 char    *av[MAXAV];
<>196 -char    *clist[MAXFIL];
 197 -char    *olist[MAXFIL];
198197 char    *llist[MAXLIB];
 199198 char    *aslist[MAXAV];
 200199 char    *xlist[100];
     
 !
377376 struct strlist crtdirs;
 378377 struct strlist libdirs;
 379378 struct strlist progdirs;
<> 379+struct strlist early_linker_flags;
  380+struct strlist middle_linker_flags;
  381+struct strlist late_linker_flags;
  382+struct strlist inputs;
380383 
 381384 int
 382385 main(int argc, char *argv[])
 383386 {
<>384 -        struct string *s;
  387+        struct string *s, *ss;
385388         struct Wflags *Wf;
 386389         char *t, *u, *argp;
 387390         char *assource;
<>388 -        int nc, nl, nas, ncpp, i, j, c, nxo, na;
  391+        int ninput, nl, nas, i, j, c, nxo, na;
389392 
 390393         lav = argv;
 391394         lac = argc;
     
 !
400403         strlist_init(&sysincdirs);
 401404         strlist_init(&dirafterdirs);
 402405         strlist_init(&depflags);
<> 406+        strlist_init(&early_linker_flags);
  407+        strlist_init(&middle_linker_flags);
  408+        strlist_init(&late_linker_flags);
  409+        strlist_init(&inputs);
403410 
 404411         if ((t = strrchr(argv[0], '/')))
 405412                 t = copy(t+1, 0);
     
 !
447454 #endif
 448455 #endif
 449456 
<>450 -        nc = nl = nas = ncpp = nxo = 0;
  457+        nl = nas = nxo = 0;
451458         while (--lac) {
 452459                 ++lav;
 453460                 argp = *lav;
     
 !
457464 
 458465                 switch (argp[1]) {
 459466                 default:
<>460 -                        goto passa;
 461 -#ifdef notyet
 462 -        /* must add library options first (-L/-l/...) */
 463 -                        oerror(argp);
  467+                        owarning(argp);
464468                         break;
<>465 -#endif
466469 
 467470                 case '-': /* double -'s */
 468471                         if (match(argp, "--version")) {
     
 !
478481                         break;
 479482 
 480483                 case 'B': /* other search paths for binaries */
<>481 -                        add_prefix(argp + 2);
  484+                        t = nxtopt("-B");
  485+                        strlist_append(&crtdirs, t);
  486+                        strlist_append(&libdirs, t);
  487+                        strlist_append(&progdirs, t);
  488+                        add_prefix(t);
482489                         break;
 483490 
 484491                 case 'C':
     
 !
614621                         kflag = F_pic;
 615622                         break;
 616623 
<> 624+                case 'l':
  625+                case 'L':
  626+                        strlist_append(&late_linker_flags, argp);
  627+                        break;
  628+
  629+
617630                 case 'm': /* target-dependent options */
 618631 #ifdef mach_amd64
 619632                         /* need to call i386 ccom for this */
     
 !
796809 
 797810         passa:
 798811                 t = argp;
<>799 -                if (*argp == '-' && argp[1] == 'L')
 800 -                        ;
 801 -                else if ((cxxsuf(getsufp(t)) && cxxflag) ||
  812+                if ((cxxsuf(getsufp(t)) && cxxflag) ||
802813                     (c=getsuf(t))=='c' || c=='S' || c=='i' ||
 803814                     c=='s'|| Eflag || xcflag || xasm) {
<>804 -                        clist[nc++] = t;
 805 -                        if (nc>=MAXFIL) {
 806 -                                error("Too many source files");
 807 -                                exit(1);
 808 -                        }
  815+                        strlist_append(&inputs, t);
809816                 }
 810817 
 811818                 /* Check for duplicate .o files. */
     
 !
827834         }
 828835 
 829836         /* Sanity checking */
<> 837+        ninput = 0;
  838+        STRLIST_FOREACH(s, &inputs)
  839+                ninput++;
830840         if (cppflag) {
<>831 -                if (nc == 0)
 832 -                        clist[nc++] = "-";
 833 -                else if (nc > 2 || (nc == 2 && outfile))
  841+                if (ninput == 0) {
  842+                        strlist_append(&inputs, "-");
  843+                } else if (ninput > 2 || (ninput == 2 && outfile)) {
834844                         errorx(8, "too many files");
<>835 -                else if (nc == 2)
  845+#if 0
  846+                } else if (ninput == 2) {
836847                         outfile = clist[--nc];
<> 848+#endif
  849+                }
837850         }
<>838 -        if (nc == 0 && nl == 0)
  851+        if (ninput == 0 && nl == 0)
839852                 errorx(8, "no input files");
<>840 -        if (outfile && (cflag || sflag || Eflag) && nc > 1)
  853+        if (outfile && (cflag || sflag || Eflag) && ninput > 1)
841854                 errorx(8, "-o given with -c || -E || -S and more than one file");
<> 855+#if 0
842856         if (outfile && clist[0] && strcmp(outfile, clist[0]) == 0)
 843857                 errorx(8, "output file will be clobbered");
<> 858+#endif
844859 
 845860         if (needM && !Mflag)
 846861                 errorx(8, "to make dependencies needs -M");
 847862 
 848863 
<>849 -        if (nc==0)
  864+        if (ninput == 0)
850865                 goto nocom;
 851866         if (pflag==0) {
 852867                 if (!sflag)
     
 !
864879                 isysroot = sysroot;
 865880         expand_sysroot();
 866881 
<>867 -        for (i=0; i<nc; i++) {
  882+        STRLIST_FOREACH(ss, &inputs) {
868883                 /*
 869884                  * C preprocessor
 870885                  */
<>871 -                if (nc>1 && !Eflag)
 872 -                        printf("%s:\n", clist[i]);
  886+                if (ninput > 1 && !Eflag)
  887+                        printf("%s:\n", ss->value);
873888                 onlyas = 0;
 874889                 assource = tmp3;
<>875 -                if (getsuf(clist[i])=='S')
  890+                if (getsuf(ss->value)=='S')
876891                         ascpp = 1;
<>877 -                if (getsuf(clist[i])=='i') {
  892+                if (getsuf(ss->value)=='i') {
878893                         if(Eflag)
 879894                                 continue;
 880895                         goto com;
 881896                 } else if (ascpp) {
 882897                         onlyas = 1;
<>883 -                } else if (xasm || getsuf(clist[i])=='s') {
 884 -                        assource = clist[i];
  898+                } else if (xasm || getsuf(ss->value)=='s') {
  899+                        assource = ss->value;
885900                         goto assemble;
 886901                 }
 887902 
 888903 
 889904                 if (pflag)
<>890 -                        tmp4 = setsuf(clist[i], 'i');
  905+                        tmp4 = setsuf(s->value, 'i');
891906                 na = 0;
 892907                 av[na++] = "cpp";
 893908 
     
 !
920935                         av[na++] = s->value;
 921936                 }
 922937 
<>923 -                av[na++] = clist[i];
  938+                av[na++] = ss->value;
924939                 if (!Eflag && !Mflag)
 925940                         av[na++] = tmp4;
 926941                 if ((Eflag || Mflag) && outfile)
     
 !
9921007                         av[na++] = xlist[j];
 9931008                 for (j = 0; j < nm; j++)
 9941009                         av[na++] = mlist[j];
<>995 -                if (getsuf(clist[i])=='i')
 996 -                        av[na++] = clist[i];
  1010+                if (getsuf(ss->value)=='i')
  1011+                        av[na++] = ss->value;
9971012                 else
 9981013                         av[na++] = tmp4; /* created by cpp */
 9991014                 if (pflag || exfail)
     
 !
10051020                         if (outfile)
 10061021                                 tmp3 = outfile;
 10071022                         else
<>1008 -                                tmp3 = setsuf(clist[i], 's');
  1023+                                tmp3 = setsuf(ss->value, 's');
10091024                 }
 10101025                 ermfile = av[na++] = tmp3;
<>1011 -#if 0
 1012 -                if (proflag) {
 1013 -                        av[3] = "-XP";
 1014 -                        av[4] = 0;
 1015 -                } else
 1016 -                        av[3] = 0;
 1017 -#endif
  1026+
10181027                 av[na++] = NULL;
 10191028                 if (callsys(pass0, av)) {
 10201029                         cflag++;
     
 !
10721081 #endif
 10731082                 av[na++] = "-o";
 10741083                 if (outfile && cflag)
<>1075 -                        ermfile = av[na++] = outfile;
  1084+                        ermfile = outfile;
10761085                 else if (cflag)
<>1077 -                        ermfile = av[na++] = olist[i] = setsuf(clist[i], 'o');
  1086+                        ermfile = setsuf(ss->value, 'o');
10781087                 else
<>1079 -                        ermfile = av[na++] = olist[i] = gettmp();
  1088+                        ermfile = ss->value = gettmp();
  1089+
  1090+                av[na++] = ermfile;
10801091                 av[na++] = assource;
 10811092                 av[na++] = 0;
 10821093                 if (callsys(as, av)) {
     
 !
10951106          * Linker
 10961107          */
 10971108 nocom:
<>1098 -        if (cflag==0 && nc+nl != 0) {
  1109+        if (cflag==0 && ninput+nl != 0) {
10991110                 j = 0;
 11001111                 av[j++] = ld;
 11011112 #ifndef MSLINKER
     
 !
11051116 #if !defined(os_sunos) && !defined(os_win32) && !defined(os_darwin)
 11061117                 av[j++] = "-X";
 11071118 #endif
<>1108 -                if (sysroot)
  1119+                if (sysroot && *sysroot)
11091120                         av[j++] = cat("--sysroot=", sysroot);
 11101121                 if (shared) {
 11111122 #ifdef os_darwin
     
 !
11861197                         }
 11871198                 }
 11881199                 i = 0;
<>1189 -                while (i<nc) {
 1190 -                        av[j++] = olist[i++];
 1191 -                        if (j >= MAXAV)
 1192 -                                error("Too many ld options");
 1193 -                }
  1200+                STRLIST_FOREACH(s, &inputs)
  1201+                        av[j++] = s->value;
  1202+                STRLIST_FOREACH(s, &late_linker_flags)
  1203+                        av[j++] = s->value;
  1204+
11941205                 i = 0;
 11951206                 while(i<nl) {
 11961207                         av[j++] = llist[i++];
     
 !
12541265                 }
 12551266                 av[j++] = 0;
 12561267                 eflag |= callsys(ld, av);
<>1257 -                if (nc==1 && nxo==1 && eflag==0)
 1258 -                        cunlink(olist[0]);
 1259 -                else if (nc > 0 && eflag == 0) {
  1268+                if (ninput == 1 && nxo==1 && eflag==0)
  1269+                        cunlink(STRLIST_FIRST(&inputs)->value);
  1270+                else if (ninput > 0 && eflag == 0) {
12601271                         /* remove .o files XXX ugly */
<>1261 -                        for (i = 0; i < nc; i++)
 1262 -                                cunlink(olist[i]);
  1272+                        STRLIST_FOREACH(s, &inputs)
  1273+                                cunlink(s->value);
12631274                 }
 12641275         }
 12651276 #ifdef notdef
     
 !
12731284         strlist_free(&sysincdirs);
 12741285         strlist_free(&dirafterdirs);
 12751286         strlist_free(&depflags);
<> 1287+        strlist_free(&early_linker_flags);
  1288+        strlist_free(&middle_linker_flags);
  1289+        strlist_free(&late_linker_flags);
  1290+        strlist_free(&inputs);
12761291 #endif
 12771292         dexit(eflag);
 12781293         return 0;
     
 !
13421357         dexit(eval);
 13431358 }
 13441359 
<> 1360+static char *
  1361+find_file2(const char *file, struct strlist *path, int mode)
  1362+{
  1363+        struct string *s;
  1364+        char *f;
  1365+        size_t lf, lp;
  1366+        int need_sep;
  1367+
  1368+        lf = strlen(file);
  1369+        STRLIST_FOREACH(s, path) {
  1370+                lp = strlen(s->value);
  1371+                need_sep = (lp && s->value[lp - 1] != '/') ? 1 : 0;
  1372+                f = xmalloc(lp + lf + need_sep + 1);
  1373+                memcpy(f, s->value, lp);
  1374+                if (need_sep)
  1375+                        f[lp] = '/';
  1376+                memcpy(f + lp + need_sep, file, lf + 1);
  1377+                if (access(f, mode) == 0)
  1378+                        return f;
  1379+                free(f);
  1380+        }
  1381+        return xstrdup(file);
  1382+}
  1383+
  1384+
13451385 static size_t file_prefixes_cnt;
 13461386 static char **file_prefixes;
 13471387 
     
 !
15211561 }
 15221562 #endif
 15231563 
<> 1564+#if 0
  1565+static int
  1566+strlist_exec(struct strlist *l)
  1567+{
  1568+        char **argv;
  1569+        size_t argc;
  1570+        int result;
  1571+
  1572+        strlist_make_array(l, &argv, &argc);
  1573+        if (verbose_mode) {
  1574+                printf("Calling ");
  1575+                strlist_print(l, stdout);
  1576+                printf("\n");
  1577+        }
  1578+
  1579+        if (exit_now)
  1580+                return 1;
  1581+
  1582+        switch ((child = fork())) {
  1583+        case 0:
  1584+                execvp(argv[0], argv);
  1585+                result = write(STDERR_FILENO, "Exec of ", 8);
  1586+                result = write(STDERR_FILENO, argv[0], strlen(argv[0]));
  1587+                result = write(STDERR_FILENO, "failed\n", 7);
  1588+                (void)result;
  1589+                _exit(127);
  1590+        case -1:
  1591+                error("fork failed");
  1592+        default:
  1593+                while (waitpid(child, &result, 0) == -1 && errno == EINTR)
  1594+                        /* nothing */(void)0;
  1595+                result = WEXITSTATUS(result);
  1596+                if (result)
  1597+                        error("%s terminated with status %d", argv[0], result);
  1598+                while (argc-- > 0)
  1599+                        free(argv[argc]);
  1600+                free(argv);
  1601+                break;
  1602+        }
  1603+        return exit_now;
  1604+}
  1605+#endif
  1606+
<_15241607 /*
 15251608  * Make a copy of string as, mallocing extra bytes in the string.
 15261609  */
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-08-21 20:01 +0200