Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.34
 
1.35
 
MAIN:ragge:20060805102429
 
cpp.c
_>7878 #include <string.h>
 7979 #include <time.h>
 8080 #include <unistd.h>
<> 81+#include <ctype.h>
8182 
 8283 #ifdef HAVE_ALLOCA_H
 8384 #include <alloca.h>
     
 !
182183 #define ENTER   1
 183184 
 184185 static void expdef(usch *proto, struct recur *, int gotwarn);
<> 186+#ifdef ragge
  187+static void control(struct includ *);
  188+#else
185189 static void control(void);
<> 190+#endif
186191 static void define(void);
 187192 static void expmac(struct recur *);
 188193 static int canexpand(struct recur *, struct symtab *np);
     
 !
316321         return exfail;
 317322 }
 318323 
<> 324+#ifdef ragge
  325+/*
  326+ * Scan the input file for macros to replace and preprocessor directives.
  327+ */
319328 void
<> 329+scanover(struct includ *ic)
  330+{
  331+        struct symtab *nl;
  332+        usch *sp, *st;
  333+        int c, oc, gnl;
  334+        int wasnl = 1;
  335+
  336+        for (;;) {
  337+                if ((c = inch(ic)) < 0)
  338+                        return;
  339+                if (c != ' ' && c != '\n' && c != '#')
  340+                        wasnl = 0; /* cannot be control */
  341+                switch (c) {
  342+                case '\'': /* charcon */
  343+                case '"': /* string */
  344+                        gnl = 0;
  345+                        oc = c;
  346+                        do {
  347+                                if (c == GOTNL)
  348+                                        gnl++;
  349+                                else
  350+                                        outch(c);
  351+                                if (c == '\\') /* avoid escaped chars */
  352+                                        outch(inch(ic));
  353+                        } while ((c = inch(ic)) != -1 && c != oc);
  354+                        outch(c);
  355+                        while (gnl--)
  356+                                putc('\n', obuf);
  357+                        break;
  358+
  359+                case '0': case '1': case '2': case '3': case '4':
  360+                case '5': case '6': case '7': case '8': case '9':
  361+#define ONEMORE(c, ic)  (outch(c), inch(ic))
  362+                        oc = c;
  363+                        outch(c);
  364+                        c = inch(ic);
  365+                        if (oc == '0' && (c == 'x' || c == 'X')) {
  366+                                do {
  367+                                        c = ONEMORE(c, ic);
  368+                                } while (isxdigit(c));
  369+                        } else {
  370+                                while (isdigit(c)) {
  371+                                        c = ONEMORE(c, ic);
  372+                                }
  373+                        }
  374+                        if (c != '.' && c != 'e' && c != 'E') {
  375+                                /* not floating point number */
  376+                                while (c == 'l' || c == 'L' ||
  377+                                    c == 'u' || c == 'U') {
  378+                                        c = ONEMORE(c, ic);
  379+                                }
  380+                                unch(ic, c);
  381+                                break; /* done here */
  382+                        }
  383+                        /* it's a floating point number here */
  384+                        if (c != '.')
  385+                                goto E;
  386+
  387+                        /* decimal point */
  388+F:                      do { /* may be followed by digits */
  389+                                c = ONEMORE(c, ic);
  390+                        } while (isdigit(c));
  391+                        if (c == 'e' || c == 'E') {
  392+E:                              c = ONEMORE(c, ic);
  393+                                if (c == '-' || c == '+')
  394+                                        c = ONEMORE(c, ic);
  395+                                while (isdigit(c))
  396+                                        c = ONEMORE(c, ic);
  397+                        }
  398+                        if (c == 'f' || c == 'F'||c == 'l' || c == 'L')
  399+                                c = ONEMORE(c, ic);
  400+                        unch(ic, c);
  401+                        break;
  402+
  403+                case '.':
  404+                        c = ONEMORE(c, ic);
  405+                        if (isdigit(c))
  406+                                goto F;
  407+                        unch(ic, c);
  408+                        break;
  409+
  410+                case GOTNL:
  411+                        putch('\n');
  412+                        break;
  413+
  414+                case ' ':
  415+                case '\t': /* whitespace */
  416+                        while (c == ' ' || c == '\t')
  417+                                c = ONEMORE(c, ic);
  418+                        /* FALLTHROUGH */
  419+                case '#':
  420+                        if (wasnl && c == '#')
  421+                                control(ic);
  422+                        else
  423+                                unch(ic, c);
  424+                        break;
  425+
  426+                case '/':
  427+                        if ((c = inch(ic)) == '/') {
  428+                                if (Cflag)
  429+                                        fprintf(obuf, "//");
  430+                                while ((c = inch(ic)) >= 0 && c != '\n')
  431+                                        if (Cflag)
  432+                                                putc(c, obuf);
  433+                                unch(ic, c);
  434+                        } else if (c == '*') {
  435+                                if (Cflag)
  436+                                        fprintf(obuf, "/*");
  437+                                oc = 0;
  438+                                do {
  439+                                        while ((c = inch(ic)) >= 0&& c != '*') {
  440+                                                if (c == '\n') {
  441+                                                        putc(c, obuf);
  442+                                                        ic->lineno++;
  443+                                                } else if (Cflag)
  444+                                                        putc(c, obuf);
  445+                                        }
  446+                                        if (Cflag)
  447+                                                putc(c, obuf);
  448+                                        if ((c = inch(ic)) == '/')
  449+                                                break;
  450+                                        unch(ic, c);
  451+                                } while (c >= 0);
  452+                                if (Cflag)
  453+                                        putc(c, obuf);
  454+                                if (!tflag)
  455+                                        putc(' ', obuf);
  456+                        } else {
  457+                                unch(ic, c);
  458+                                putc('/', obuf);
  459+                        }
  460+                        break;
  461+
  462+                case 'L': /* may be STRING, CHARCON or identifier */
  463+                        if ((c = inch(ic)) == '"' || c == '\'') {
  464+                                /* just print out L and continue */
  465+                                unch(ic, c);
  466+                                putc('L', obuf);
  467+                                break;
  468+                        } else {
  469+                                unch(ic, c);
  470+                                c = 'L';
  471+                        }
  472+                        /* FALLTHROUGH */
  473+                default:
  474+                        if (!isalpha(c) && c != '_') {
  475+                                putc(c, obuf);
  476+                                break;
  477+                        }
  478+                        /*
  479+                         * got an identifier, store it on the heap and
  480+                         * try to find a definition.
  481+                         */
  482+                        sp = stringbuf;
  483+                        while (isalpha(c) || isdigit(c) || c == '_') {
  484+                                *stringbuf++ = c;
  485+                                c = inch(ic);
  486+                        }
  487+                        unch(ic, c);
  488+                        *stringbuf = 0;
  489+                        if ((nl = lookup(sp, FIND)) != NULL &&
  490+                            (st = subst(nl, NULL)) != NULL) {
  491+                                fprintf(obuf, "%s", st);
  492+                        } else
  493+                                fprintf(obuf, "%s", sp);
  494+                        stringbuf = sp;
  495+                }
  496+        }
  497+}
  498+#endif
  499+
  500+#ifndef ragge
  501+void
320502 mainscan()
 321503 {
 322504         struct symtab *nl, *thisnl;
     
 !
416598                 }
 417599         }
 418600 }
<> 601+#endif
419602 
 420603 #if 0
 421604 struct noexp {
     
 !
475658  * do something when a '#' is found.
 476659  */
 477660 void
<> 661+#ifdef ragge
  662+control(struct includ *ic)
  663+#else
478664 control()
<> 665+#endif
479666 {
 480667         struct symtab *np;
 481668         int t;
     
 !
670857         if (c == IDENT) {
 671858                 if ((nl = lookup(yystr, FIND)) == NULL)
 672859                         goto bad;
<> 860+#ifdef ragge
  861+                if (subst(nl, NULL) == 0)
  862+#else
673863                 if (subst(yystr, nl, NULL) == 0)
<> 864+#endif
674865                         goto bad;
 675866                 savch('\0');
 676867                 unpstr(osp);
     
 !
9601151         return(sp->namep ? sp : 0);
 9611152 }
 9621153 
<>963 -#ifdef ragge
  1154+#if 0
9641155 /*
 9651156  * Scan over a string, copying its contents to the heap until
 9661157  * an identifier or an argument is reached. When reached,
     
 !
9691160 static usch *
 9701161 tokenize(usch *s)
 9711162 {
<> 1163+        usch *op = stringbuf;
  1164+        int os;
  1165+
9721166         for (; *s; s++) {
 9731167                 switch (utype[*s] & TOKTYP) {
<>974 -                case S_: /* char or string constant */
 975 -                do {
  1168+                case S_: /* char or string constant to skip over */
  1169+                        os = *s;
  1170+                        do {
  1171+                                savch(*s);
  1172+                                if (*s == 0)
  1173+                                        return op;
  1174+                                if (*s == '\\') {
  1175+                                        s++;
  1176+                                        savch(*s);
  1177+                                        if (*s == 0)
  1178+                                                return op;
  1179+                                }
  1180+                                s++;
  1181+                        } while (*s && *s != os);
9761182                         savch(*s);
<>977 -                }
  1183+                        if (*s == 0)
  1184+                                return op;
  1185+                        break;
  1186+
  1187+                case B_: /* Beginning of an identifier */
  1188+                        
  1189+                        
  1190+
  1191+                default:
  1192+                        savch(*s);
  1193+                        break;
  1194+                }
  1195+        }
  1196+        savch(*s);
  1197+        return op;
9781198 }
 9791199 #endif
 9801200 
     
 !
9991219 {
 10001220         struct recur rp2;
 10011221         register usch *vp, *cp;
<> 1222+#ifdef ragge
  1223+        usch *basesb = stringbuf;
  1224+#endif
10021225         int c, rv = 0;
 10031226 
 10041227 if (dflag)printf("subst: %s\n", sp->namep);
     
 !
10091232                 savch('"');
 10101233                 savstr(curfile());
 10111234                 savch('"');
<> 1235+#ifdef ragge
  1236+                savch('\0');
  1237+                return basesb;
  1238+#else
10121239                 return 1;
<> 1240+#endif
10131241         } else if (sp == linloc) {
 10141242                 char buf[12];
 10151243                 sprintf(buf, "%d", curline());
 10161244                 savstr(buf);
<> 1245+#ifdef ragge
  1246+                return basesb;
  1247+#else
10171248                 return 1;
<> 1249+#endif
10181250         }
 10191251         vp = sp->value;
 10201252 
     
 !
10491281 if (dflag)printf("c %d\n", c);
 10501282                 if (c == '(' ) {
 10511283                         expdef(vp, &rp2, gotwarn);
<>1052 -                        return rv;
  1284+#ifdef ragge
  1285+                        return basesb;
  1286+#else
  1287+                        return 1;
  1288+#endif
10531289                 } else {
 10541290                         /* restore identifier */
 10551291 noid:                   while (gotwarn--)
     
 !
10651301                         return 0;
 10661302                 }
 10671303         } else {
<>1068 -#ifdef ragge
  1304+#if 0
10691305                 while ((*vp
 10701306                         tokenize(
 10711307                 expmac(&rp2);
     
 !
10801316                 expmac(&rp2);
 10811317 #endif
 10821318         }
<> 1319+#ifdef ragge
  1320+        return basesb;
  1321+#else
10831322         return 1;
<> 1323+#endif
10841324 }
 10851325 
 10861326 /*
     
 !
11711411                         if (canexpand(rp, nl) == 0)
 11721412                                 goto def;
 11731413                         if (noexp == 0) {
<> 1414+#ifdef ragge
  1415+                                if (subst(nl, rp) == NULL)
  1416+                                        goto def;
  1417+#else
11741418                                 if ((c = subst(nl->namep, nl, rp)) == 0)
 11751419                                         goto def;
<> 1420+#endif
11761421                                 break;
 11771422                         }
 11781423                         if (noexp != 1)
     
 !
11821427                                 gotspc = 1, c = yylex();
 11831428                         if (c == EXPAND) {
 11841429                                 noexp--;
<> 1430+#ifdef ragge
  1431+                                if (subst(nl, rp))
  1432+                                        break;
  1433+#else
11851434                                 if (subst(nl->namep, nl, rp))
 11861435                                         break;
<> 1436+#endif
<_11871437                                 savstr(nl->namep);
 11881438                                 if (gotspc)
 11891439                                         savch(' ');
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-10-01 18:23 +0200