Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.8
 
1.9
 
MAIN:ragge:20040826162445
 
cpp.c
_>7373 #include <stdarg.h>
 7474 #include <stdlib.h>
 7575 #include <string.h>
<> 76+#include <time.h>
7677 #include <unistd.h>
 7778 
 7879 #include "cpp.h"
     
 !
8283 #define MAXARG  250     /* # of args to a macro, limited by char value */
 8384 #define SBSIZE  2000
 8485 #define SYMSIZ  200
<>85 -#define MAXREC  200     /* max recursive macros to avoid expansion */
8686 
 8787 static usch     sbf[SBSIZE];
 8888 /* C command */
     
 !
112112 
 113113 static struct symtab *filloc;
 114114 static struct symtab *linloc;
<> 115+static struct symtab *datloc;
  116+static struct symtab *timloc;
115117 static int      trulvl;
 116118 static int      flslvl;
 117119 static usch *stringbuf = sbf;
     
 !
152154 static int canexpand(struct recur *, struct symtab *np);
 153155 static void unpstr(usch *);
 154156 static void include(void);
<> 157+static void line(void);
155158 
 156159 int
 157160 main(int argc, char **argv)
     
 !
228231 
 229232         insym(&filloc, "__FILE__");
 230233         insym(&linloc, "__LINE__");
<> 234+        insym(&datloc, "__DATE__");
  235+        insym(&timloc, "__TIME__");
231236 
 232237         thisnl = NULL;
 233238         while ((c = yylex()) != 0) {
     
 !
345350                         savstr(yytext);
 346351                 savch('\n');
 347352                 error("error: %s", ch);
<>348 -        } else {
 349 -                if (yylex() != WSPACE || yylex() != IDENT)
 350 -                        error("control line syntax error");
 351 -                if (CHECK(define)) {
 352 -                        define();
 353 -                } else if (CHECK(ifdef)) {
 354 -                        if (flslvl == 0 && lookup(yytext, FIND) != 0)
 355 -                                trulvl++;
 356 -                        else
 357 -                                flslvl++;
 358 -                } else if (CHECK(ifndef)) {
 359 -                        if (flslvl == 0 && lookup(yytext, FIND) == 0)
 360 -                                trulvl++;
 361 -                        else
 362 -                                flslvl++;
 363 -                } else if (CHECK(undef)) {
 364 -                        if (flslvl == 0 && (np = lookup(yytext, FIND)))
 365 -                                np->value = 0;
 366 -                } else
 367 -                        error("undefined control '%s'", np->namep);
 368 -        }
  353+#define GETID() if (yylex() != WSPACE || yylex() != IDENT) goto cfail
  354+        } else if (CHECK(define)) {
  355+                GETID();
  356+                define();
  357+        } else if (CHECK(ifdef)) {
  358+                GETID();
  359+                if (flslvl == 0 && lookup(yytext, FIND) != 0)
  360+                        trulvl++;
  361+                else
  362+                        flslvl++;
  363+        } else if (CHECK(ifndef)) {
  364+                GETID();
  365+                if (flslvl == 0 && lookup(yytext, FIND) == 0)
  366+                        trulvl++;
  367+                else
  368+                        flslvl++;
  369+        } else if (CHECK(undef)) {
  370+                GETID();
  371+                if (flslvl == 0 && (np = lookup(yytext, FIND)))
  372+                        np->value = 0;
  373+        } else if (CHECK(line)) {
  374+                line();
  375+        } else
  376+                error("undefined control '%s'", yytext);
369377 
<> 378+        return;
  379+
  380+cfail:
  381+        error("control line syntax error");
  382+
370383 exit:
 371384         while (yylex() != NL)
 372385                 ;
 373386 #undef CHECK
 374387 }
 375388 
 376389 void
<> 390+line()
  391+{
  392+        struct symtab *nl;
  393+        int c;
  394+
  395+        if (yylex() != WSPACE)
  396+                goto bad;
  397+        if ((c = yylex()) == IDENT) {
  398+                /* Do macro preprocessing first */
  399+                usch *osp = stringbuf;
  400+                if ((nl = lookup(yytext, FIND)) == NULL)
  401+                        goto bad;
  402+                if (subst(yytext, nl, NULL) == 0)
  403+                        goto bad;
  404+                while (stringbuf > osp)
  405+                        cunput(*--stringbuf);
  406+                c = yylex();
  407+        }
  408+
  409+        if (c != NUMBER)
  410+                goto bad;
  411+        setline(atoi(yytext));
  412+
  413+        if ((c = yylex()) != NL && c != WSPACE)
  414+                goto bad;
  415+        if (c == NL)
  416+                return setline(curline()+1);
  417+        if (yylex() != STRING)
  418+                goto bad;
  419+        yytext[strlen(yytext)-1] = 0;
  420+        setfile(&yytext[1]);
  421+        return;
  422+
  423+bad:    error("bad line directive");
  424+}
  425+
  426+void
377427 include()
 378428 {
 379429         struct symtab *nl;
     
 !
615665         int c, rv = 0;
 616666 
 617667 if (dflag)printf("subst\n");
<>618 -        if ((vp = sp->value) == 0)
 619 -                return 0;
 620 -        if (sp == filloc) {
 621 -                fprintf(obuf, "\"%s\"", curfile());
  668+        if ((vp = sp->value) == 0) {
  669+                /*
  670+                 * If no value is assigned, it may be a special macro,
  671+                 * otherwise a deleted macro.
  672+                 */
  673+                if (sp == filloc) {
  674+                        savch('"');
  675+                        savstr(curfile());
  676+                        savch('"');
  677+                } else if (sp == linloc) {
  678+                        char buf[12];
  679+                        sprintf(buf, "%d", curline());
  680+                        savstr(buf);
  681+                } else if (sp == datloc) {
  682+                        time_t t = time(NULL);
  683+                        char *n = ctime(&t);
  684+                        savch('"');
  685+                        n[24] = n[11] = 0;
  686+                        savstr(&n[4]);
  687+                        savstr(&n[20]);
  688+                        savch('"');
  689+                } else if (sp == timloc) {
  690+                        time_t t = time(NULL);
  691+                        char *n = ctime(&t);
  692+                        savch('"'); 
  693+                        n[19] = 0;
  694+                        savstr(&n[11]);
  695+                        savch('"');
  696+                } else
  697+                        return 0;
622698                 return 1;
<>623 -        } else if (sp == linloc) {
 624 -                fprintf(obuf, "%d", curline());
 625 -                return 1;
<_626699         }
 627700 
 628701         rp2.next = rp;
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-19 01:33 +0100