Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.14
 
1.15
 
MAIN:ragge:20040902213333
 
cpp.c
_>7979 #include "cpp.h"
 8080 
 8181 #define MAXARG  250     /* # of args to a macro, limited by char value */
<>82 -#define SBSIZE  20000
  82+#define SBSIZE  40000
8383 #define SYMSIZ  2000
 8484 
 8585 static usch     sbf[SBSIZE];
     
 !
140140 /* args for lookup() */
 141141 #define FIND    0
 142142 #define ENTER   1
<>143 -#define FORGET  3
144143 
 145144 static void expdef(usch *proto, struct recur *, int gotwarn);
 146145 static void savch(int c);
     
 !
155154 int
 156155 main(int argc, char **argv)
 157156 {
<>158 -        struct incs *w, *w2;
  157+        struct incs *w, *w2, incs;
159158         struct symtab *nl, *thisnl;
 160159         register int c, gotspc, ch;
 161160         usch *osp;
 162161 
<> 162+        incs.dir = ".";
  163+        incs.next = NULL;
  164+        incdir[INCINC] = &incs;
  165+
163166         while ((ch = getopt(argc, argv, "D:I:S:U:td")) != -1)
 164167                 switch (ch) {
 165168                 case 'D': /* Define something */
     
 !
196199 
 197200                 case 'U':
 198201                         nl = lookup(optarg, FIND);
<>199 -                        if (nl && nl->value)
  202+                        if ((nl = lookup(optarg, FIND)))
200203                                 nl->value = NULL;
 201204                         break;
 202205 #ifdef CPP_DEBUG
     
 !
237240 
 238241         filloc = lookup("__FILE__", ENTER);
 239242         linloc = lookup("__LINE__", ENTER);
<> 243+        filloc->value = linloc->value = ""; /* Just something */
  244+
240245         if (tflag == 0) {
 241246                 time_t t = time(NULL);
 242247                 char *n = ctime(&t);
     
 !
270275                         if (flslvl)
 271276                                 break;
 272277                         osp = stringbuf;
<>273 -                        nl = lookup(yytext, FIND);
  278+                        nl = lookup(yystr, FIND);
274279                         if (nl == 0 || thisnl == 0)
 275280                                 goto found;
 276281                         if (thisnl == nl) {
     
 !
281286                         if ((c = yylex()) == WSPACE)
 282287                                 gotspc = 1, c = yylex();
 283288                         if (c != EXPAND) {
<>284 -                                unpstr(yytext);
  289+                                unpstr(yystr);
285290                                 if (gotspc)
 286291                                         cunput(' ');
 287292                                 unpstr(nl->namep);
<>288 -                                (void)yylex(); /* get yytext correct */
  293+                                (void)yylex(); /* get yystr correct */
289294                                 nl = 0; /* ignore */
 290295                         } else
 291296                                 thisnl = NULL;
 292297 
<>293 -found:                  if (nl == 0 || subst(yytext, nl, NULL) == 0) {
 294 -                                fputs(yytext, obuf);
  298+found:                  if (nl == 0 || subst(yystr, nl, NULL) == 0) {
  299+                                fputs(yystr, obuf);
295300                         } else if (osp != stringbuf) {
 296301                                 cunput(EXPAND);
 297302                                 while (stringbuf > osp)
     
 !
305310                         thisnl = NULL;
 306311                         break;
 307312 
<> 313+                case NL:
  314+                        if (flslvl == 0)
  315+                                putc('\n', obuf);
  316+                        break;
  317+
308318                 case CHARCON:
 309319                 case NUMBER:
 310320                 case FPOINT:
 311321                 case STRING:
 312322                 case WSPACE:
<>313 -                case NL:
314323                 default:
 315324                         if (flslvl == 0)
<>316 -                                fputs(yytext, obuf);
  325+                                fputs(yystr, obuf);
317326                         break;
 318327                 }
 319328         }
     
 !
330339         struct symtab *np;
 331340         int t;
 332341 
<>333 -#define CHECK(x) (yytext[0] == #x[0]) && strcmp(yytext, #x) == 0
  342+#define CHECK(x) (yystr[0] == #x[0]) && strcmp(yystr, #x) == 0
334343 
 335344         if ((t = yylex()) == WSPACE)
 336345                 t = yylex();
     
 !
340349                 return;
 341350         }
 342351         if (t != IDENT)
<>343 -                return error("bad control '%s'", yytext);
  352+                return error("bad control '%s'", yystr);
344353 
 345354         if (CHECK(include)) {
 346355                 if (flslvl)
     
 !
381390                 if (flslvl)
 382391                         goto exit;
 383392                 while (yylex() != NL)
<>384 -                        savstr(yytext);
  393+                        savstr(yystr);
385394                 savch('\n');
 386395                 error("error: %s", ch);
 387396 #define GETID() if (yylex() != WSPACE || yylex() != IDENT) goto cfail
     
 !
392401                 define();
 393402         } else if (CHECK(ifdef)) {
 394403                 GETID();
<>395 -                if (flslvl == 0 && lookup(yytext, FIND) != 0)
  404+                if (flslvl == 0 && lookup(yystr, FIND) != 0)
396405                         trulvl++;
 397406                 else
 398407                         flslvl++;
 399408         } else if (CHECK(ifndef)) {
 400409                 GETID();
<>401 -                if (flslvl == 0 && lookup(yytext, FIND) == 0)
  410+                if (flslvl == 0 && lookup(yystr, FIND) == 0)
402411                         trulvl++;
 403412                 else
 404413                         flslvl++;
 405414         } else if (CHECK(undef)) {
 406415                 GETID();
<>407 -                if (flslvl == 0 && (np = lookup(yytext, FIND)))
  416+                if (flslvl == 0 && (np = lookup(yystr, FIND)))
408417                         np->value = 0;
 409418         } else if (CHECK(line)) {
 410419                 if (flslvl)
     
 !
436445                 } else
 437446                         error("If-less elif");
 438447         } else
<>439 -                error("undefined control '%s'", yytext);
  448+                error("undefined control '%s'", yystr);
440449 
 441450         return;
 442451 
     
 !
461470         if ((c = yylex()) == IDENT) {
 462471                 /* Do macro preprocessing first */
 463472                 usch *osp = stringbuf;
<>464 -                if ((nl = lookup(yytext, FIND)) == NULL)
  473+                if ((nl = lookup(yystr, FIND)) == NULL)
465474                         goto bad;
<>466 -                if (subst(yytext, nl, NULL) == 0)
  475+                if (subst(yystr, nl, NULL) == 0)
467476                         goto bad;
 468477                 while (stringbuf > osp)
 469478                         cunput(*--stringbuf);
     
 !
472481 
 473482         if (c != NUMBER)
 474483                 goto bad;
<>475 -        setline(atoi(yytext));
  484+        setline(atoi(yystr));
476485 
 477486         if ((c = yylex()) != NL && c != WSPACE)
 478487                 goto bad;
 479488         if (c == NL)
 480489                 return setline(curline()+1);
 481490         if (yylex() != STRING)
 482491                 goto bad;
<>483 -        yytext[strlen(yytext)-1] = 0;
 484 -        setfile(&yytext[1]);
  492+        yystr[strlen(yystr)-1] = 0;
  493+        setfile(&yystr[1]);
485494         return;
 486495 
 487496 bad:    error("bad line directive");
     
 !
509518                 goto bad;
 510519 
 511520         if (c == IDENT) {
<>512 -                if ((nl = lookup(yytext, FIND)) == NULL)
  521+                if ((nl = lookup(yystr, FIND)) == NULL)
513522                         goto bad;
<>514 -                if (subst(yytext, nl, NULL) == 0)
  523+                if (subst(yystr, nl, NULL) == 0)
515524                         goto bad;
 516525                 savch('\0');
 517526                 unpstr(osp);
     
 !
521530                 while ((c = yylex()) != '>' && c != NL) {
 522531                         if (c == NL)
 523532                                 goto bad;
<>524 -                        savstr(yytext);
  533+                        savstr(yystr);
525534                 }
 526535                 savch('\0');
 527536                 it = SYSINC;
 528537         } else {
<>529 -                yytext[strlen(yytext)-1] = 0;
 530 -                fn = &yytext[1];
  538+                yystr[strlen(yystr)-1] = 0;
  539+                fn = &yystr[1];
531540                 it = INCINC;
 532541         }
 533542 
     
 !
556565 define()
 557566 {
 558567         struct symtab *np;
<>559 -        usch *args[MAXARG], *ubuf;
 560 -        int c, i;
  568+        usch *args[MAXARG], *ubuf, *sbeg;
  569+        int c, i, redef;
561570         int mkstr = 0, narg = -1;
 562571 
<>563 -        np = lookup(yytext, ENTER);
 564 -        if (np->value)
 565 -                error("%s redefined", np->namep);
  572+        np = lookup(yystr, ENTER);
  573+        redef = np->value != NULL;
566574 
<> 575+        sbeg = stringbuf;
567576         if ((c = yylex()) == '(') {
 568577                 narg = 0;
 569578                 /* function-like macros, deal with identifiers */
     
 !
573582                         if (c == WSPACE) c = yylex();
 574583                         if (c == ')')
 575584                                 break;
<>576 -                                if (c != IDENT)
 577 -                        error("define error");
 578 -                        args[narg] = alloca(strlen(yytext)+1);
 579 -                        strcpy(args[narg], yytext);
  585+                        if (c != IDENT)
  586+                                error("define error");
  587+                        args[narg] = alloca(strlen(yystr)+1);
  588+                        strcpy(args[narg], yystr);
580589                         narg++;
 581590                 }
 582591         } else if (c == NL) {
     
 !
595604                 case WSPACE:
 596605                         /* remove spaces if it surrounds a ## directive */
 597606                         ubuf = stringbuf;
<>598 -                        savstr(yytext);
  607+                        savstr(yystr);
599608                         c = yylex();
 600609                         if (c == CONCAT) {
 601610                                 stringbuf = ubuf;
     
 !
630639                                 goto id; /* just add it if object */
 631640                         /* check if its an argument */
 632641                         for (i = 0; i < narg; i++)
<>633 -                                if (strcmp(yytext, args[i]) == 0)
  642+                                if (strcmp(yystr, args[i]) == 0)
634643                                         break;
 635644                         if (i == narg) {
 636645                                 if (mkstr)
     
 !
644653                         break;
 645654 
 646655                 default:
<>647 -id:                     savstr(yytext);
  656+id:                     savstr(yystr);
648657                         break;
 649658                 }
 650659                 c = yylex();
 651660         }
 652661         savch(narg < 0 ? OBJCT : narg);
<>653 -        np->value = stringbuf-1;
  662+        if (redef) {
  663+                usch *o = np->value, *n = stringbuf-1;
  664+
  665+                /* Redefinition to identical replacement-list is allowed */
  666+                while (*o && *o == *n)
  667+                        o--, n--;
  668+                if (*o || *o != *n)
  669+                        error("%s redefined", np->namep);
  670+                stringbuf = sbeg;  /* forget this space */
  671+        } else
  672+                np->value = stringbuf-1;
654673         putc('\n', obuf);
 655674 
 656675 #ifdef CPP_DEBUG
     
 !
704723 
 705724 /*
 706725  * Do a symbol lookup.
<>707 - * If enterf == FIND, only lookup.
  726+ * If enterf == ENTER, create a new entry.
  727+ * will return NULL if symbol not found and FIND is given.
708728  */
 709729 struct symtab *
 710730 lookup(namep, enterf)
     
 !
724744 
 725745         while (sp->namep) {
 726746                 if (*sp->namep == *namep && strcmp(sp->namep, namep) == 0)
<>727 -                        return(sp);
  747+                        return sp->value || enterf == ENTER ? sp : NULL;
728748                 if (++sp >= &symtab[SYMSIZ]) {
 729749                         if (around++)
 730750                                 error("too many defines");
 731751                         else
 732752                                 sp = symtab;
 733753                 }
 734754         }
<>735 -        if (enterf == ENTER) {
  755+        if (enterf == ENTER)
736756                 sp->namep = savstr(namep), savch('\0'), sp->value = NULL;
<>737 -        }
  757+
738758         return(sp->namep ? sp : 0);
 739759 }
 740760 
     
 !
789809                         }
 790810                 } while (c == WSPACE || c == NL || c == WARN);
 791811 
<>792 -                cp = yytext;
  812+                cp = yystr;
793813                 while (*cp)
 794814                         cp++;
<>795 -                while (cp > yytext)
  815+                while (cp > (usch *)yystr)
796816                         cunput(*--cp);
 797817 if (dflag)printf("c %d\n", c);
 798818                 if (c == '(' ) {
     
 !
847867                 case IDENT:
 848868                         /* workaround if an arg will be concatenated */
 849869                         och = stringbuf;
<>850 -                        savstr(yytext);
  870+                        savstr(yystr);
851871                         savch('\0');
 852872 //printf("id: str %s\n", och);
 853873                         if ((c = yylex()) == EXPAND) {
 854874 //printf("funnet expand\n");
 855875                                 if ((c = yylex()) == NOEXP) {
 856876 //printf("funnet noexp\n");
 857877                                         if ((c = yylex()) == IDENT) {
<>858 -//printf("funnet ident %s%s\n", och, yytext);
  878+//printf("funnet ident %s%s\n", och, yystr);
859879                                                 stringbuf--;
<>860 -                                                savstr(yytext);
  880+                                                savstr(yystr);
861881                                                 savch('\0');
 862882                                                 cunput(NOEXP);
 863883                                                 unpstr(och);
     
 !
866886                                                 continue;
 867887                                         } else {
 868888 //printf("ofunnet ident\n");
<>869 -                                                unpstr(yytext);
  889+                                                unpstr(yystr);
870890                                                 unpstr(och);
 871891                                                 stringbuf = och;
 872892                                                 continue;
 873893                                         }
 874894                                 } else {
 875895 //printf("ofunnet inoexp\n");
<>876 -                                        unpstr(yytext);
  896+                                        unpstr(yystr);
877897                                         cunput(EXPAND);
 878898                                         unpstr(och);
 879899                                         yylex();
 880900                                 }
 881901                         } else {
<>882 -                                unpstr(yytext);
  902+                                unpstr(yystr);
883903                                 unpstr(och);
 884904                                 yylex();
<>885 -//printf("ofunnet expand: yytext %s\n", yytext);
  905+//printf("ofunnet expand: yystr %s\n", yystr);
886906                         }
 887907                         stringbuf = och;
 888908 
<>889 -                        if ((nl = lookup(yytext, FIND)) == NULL)
  909+                        if ((nl = lookup(yystr, FIND)) == NULL)
890910                                 goto def;
 891911 
 892912                         if (canexpand(rp, nl) == 0)
     
 !
909929                                 if (gotspc)
 910930                                         savch(' ');
 911931                         } else {
<>912 -                                unpstr(yytext);
  932+                                unpstr(yystr);
913933                                 if (gotspc)
 914934                                         cunput(' ');
 915935                                 savstr(nl->namep);
 916936                         }
 917937                         break;
 918938 
<> 939+                case STRING:
  940+                        /* remove EXPAND/NOEXP from strings */
  941+                        if (yystr[1] == NOEXP) {
  942+                                savch('"');
  943+                                och = &yystr[2];
  944+                                while (*och != EXPAND)
  945+                                        savch(*och++);
  946+                                savch('"');
  947+                                break;
  948+                        }
  949+                        /* FALLTHROUGH */
  950+
919951 def:            default:
<>920 -                        savstr(yytext);
  952+                        savstr(yystr);
921953                         break;
 922954                 }
 923955         }
     
 !
962994                                 plev++;
 963995                         if (c == ')')
 964996                                 plev--;
<>965 -                        savstr(yytext);
  997+                        savstr(yystr);
<_966998                         c = yylex();
 967999                 }
 9681000                 while (args[i] < stringbuf &&
FishEye: Open Source License registered to PCC.
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-12-23 04:42 +0100