Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.115
 
1.116
 
MAIN:ragge:20110116115554
 
cpp.c
_>115115  * WARN is used:
 116116  *      - in stored replacement lists to tell that an argument comes
 117117  *      - When expanding replacement lists to tell that the list ended.
<> 118+ *
  119+ * To ensure that an already expanded identifier won't get expanded
  120+ * again a EBLOCK char + its number is stored directly before any
  121+ * expanded identifier.
118122  */
 119123 
 120124 /* args for lookup() */
     
 !
124128 static int readargs(struct symtab *sp, const usch **args);
 125129 void prline(const usch *s);
 126130 static void prrep(const usch *s);
<>127 -static void exparg(const usch *bp, int);
  131+static void exparg(int);
128132 static void subarg(struct symtab *sp, const usch **args, int);
 129133 void define(void);
 130134 void include(void);
 131135 void include_next(void);
 132136 void line(void);
 133137 void flbuf(void);
 134138 void usage(void);
<>135 -usch *xstrdup(const char *str);
  139+usch *xstrdup(const usch *str);
136140 static void addidir(char *idir, struct incs **ww);
 137141 void imp(const char *);
 138142 #define IMP(x) if (dflag>1) imp(x)
     
 !
439443         } else {
 440444                 usch *nm = stringbuf;
 441445 
<>442 -                yytext[strlen(yytext)-1] = 0;
  446+                yytext[strlen((char *)yytext)-1] = 0;
443447                 fn = (usch *)&yytext[1];
 444448                 /* first try to open file relative to previous file */
 445449                 /* but only if it is not an absolute path */
     
 !
646650                         if (c == IDENT) {
 647651                                 /* make sure there is no arg of same name */
 648652                                 for (i = 0; i < narg; i++)
<>649 -                                        if (!strcmp((char *) args[i], yytext))
  653+                                        if (!strcmp((char *) args[i], (char *)yytext))
650654                                                 error("Duplicate macro "
 651655                                                   "parameter \"%s\"", yytext);
 652656                                 if (narg == MAXARGS)
     
 !
746750                         if (c == WSPACE)
 747751                                 c = sloscan(); /* whitespace, ignore */
 748752                         mkstr = 1;
<>749 -                        if (c == IDENT && strcmp(yytext, "__VA_ARGS__") == 0)
  753+                        if (c == IDENT && strcmp((char *)yytext, "__VA_ARGS__") == 0)
750754                                 continue;
 751755 
 752756                         /* FALLTHROUGH */
 753757                 case IDENT:
<>754 -                        if (strcmp(yytext, "__VA_ARGS__") == 0) {
  758+                        if (strcmp((char *)yytext, "__VA_ARGS__") == 0) {
755759                                 if (ellips == 0)
 756760                                         error("unwanted %s", yytext);
 757761                                 savch(VARG);
     
 !
764768                                 goto id; /* just add it if object */
 765769                         /* check if its an argument */
 766770                         for (i = 0; i < narg; i++)
<>767 -                                if (strcmp(yytext, (char *)args[i]) == 0)
  771+                                if (strcmp((char *)yytext, (char *)args[i]) == 0)
768772                                         break;
 769773                         if (i == narg) {
 770774 #ifdef GCC_VARI
 771775                                 if (gccvari &&
<>772 -                                    strcmp(yytext, (char *)gccvari) == 0) {
  776+                                    strcmp((char *)yytext, (char *)gccvari) == 0) {
773777                                         savch(wascon ? GCCARG : VARG);
 774778                                         savch(WARN);
 775779                                         if (mkstr)
     
 !
905909         return c;
 906910 }
 907911 
<>908 -/* Allow next nr in lex buffer to expand */
 909 -int
 910 -doexp(void)
  912+static void
  913+doblk(void)
911914 {
<>912 -        int i, n = cinput();
 913 -        DDPRINT(("doexp %s(%d) blocking:", norep[n]->namep, n));
 914 -        if (n != bptr[--bidx])
 915 -                error("expansion sync error");
 916 -        if (dflag>1) {
 917 -                for (i = bidx-1; i >= 0; i--)
 918 -                        printf(" '%s'", norep[bptr[i]]->namep);
 919 -                printf("\n");
 920 -        }
 921 -        return n;
  915+        int c;
  916+
  917+        do {
  918+                donex();
  919+        } while ((c = sloscan()) == EBLOCK);
  920+        if (c != IDENT)
  921+                error("EBLOCK sync error");
922922 }
 923923 
 924924 /* Block next nr in lex buffer to expand */
     
 !
929929 
 930930         if (bidx == RECMAX)
 931931                 error("too deep macro recursion");
<>932 -        bptr[bidx++] = n = cinput();
  932+        n = cinput();
  933+        for (i = 0; i < bidx; i++)
  934+                if (bptr[i] == n)
  935+                        return n; /* already blocked */
  936+        bptr[bidx++] = n;
933937         /* XXX - check for sp buffer overflow */
 934938         if (dflag>1) {
 935939                 printf("donex %d (%d) blocking:\n", bidx, n);
     
 !
965969         usch *s;
 966970         int t;
 967971 
<>968 -        while ((t = sloscan()) != '(') {
 969 -                if (t == EXP)
 970 -                        doexp();
 971 -                else if (t == NEX)
 972 -                        donex();
 973 -        }
  972+        while ((t = sloscan()) != '(')
  973+                ;
974974 
 975975         while ((t = sloscan()) == WSPACE)
 976976                 ;
     
 !
10111011 }
 10121012 
 10131013 /*
<> 1014+ * Insert block(s) before each expanded name.
  1015+ * Input is in lex buffer, output on lex buffer.
  1016+ */
  1017+static void
  1018+insblock(int bnr)
  1019+{
  1020+        usch *bp = stringbuf;
  1021+        int c, i;
  1022+ 
  1023+        IMP("IB");
  1024+        while ((c = sloscan()) != WARN) {
  1025+                if (c == EBLOCK) {
  1026+                        savch(EBLOCK), savch(cinput());
  1027+                        continue;
  1028+                }
  1029+                if (c == IDENT) {
  1030+                        savch(EBLOCK), savch(bnr);
  1031+                        for (i = 0; i < bidx; i++)
  1032+                                savch(EBLOCK), savch(bptr[i]);
  1033+                }
  1034+                savstr((const usch *)yytext);
  1035+        }
  1036+        savch(0);
  1037+        cunput(WARN);
  1038+        unpstr(bp);
  1039+        stringbuf = bp;
  1040+        IMP("IBRET");
  1041+}
  1042+
  1043+/* Delete next WARN on the input stream */
  1044+static void
  1045+delwarn(void)
  1046+{
  1047+        usch *bp = stringbuf;
  1048+        int c;
  1049+ 
  1050+        IMP("DELWARN");
  1051+        while ((c = sloscan()) != WARN) {
  1052+                if (c == EBLOCK) {
  1053+                        savch(EBLOCK), savch(cinput());
  1054+                } else
  1055+                        savstr(yytext);
  1056+        }
  1057+        savch(0);
  1058+        unpstr(bp);
  1059+        stringbuf = bp;
  1060+        IMP("DELWRET");
  1061+}
  1062+
  1063+/*
10141064  * Handle defined macro keywords found on input stream.
 10151065  * When finished print out the full expanded line.
<> 1066+ * Everything on lex buffer except for the symtab.
10161067  */
 10171068 int
 10181069 kfind(struct symtab *sp)
 10191070 {
 10201071         struct symtab *nl;
 10211072         const usch *argary[MAXARGS+1];
 10221073         usch *bp, *sbp;
<>1023 -        int c;
  1074+        int c, o;
10241075 
 10251076         DPRINT(("%d:enter kfind(%s)\n",0,sp->namep));
 10261077         IMP("KFIND");
<> 1078+        sbp = stringbuf;
10271079         if (*sp->value == OBJCT) {
<> 1080+                if (sp == filloc) {
  1081+                        unpstr(sheap("\"%s\"", ifiles->fname));
  1082+                        return 1;
  1083+                } else if (sp == linloc) {
  1084+                        unpstr(sheap("%d", ifiles->lineno));
  1085+                        return 1;
  1086+                }
  1087+                IMP("END1");
  1088+                bp = stringbuf;
10281089                 cunput(WARN);
<>1029 -                exparg(sp->namep, 1);
 1030 -upp:            sbp = bp = stringbuf;
 1031 -                unpstr(bp);
  1090+                for (bp = (usch *)sp->value-1; *bp; bp--)
  1091+                        cunput(*bp);
  1092+                insblock(addmac(sp));
10321093                 IMP("ENDX");
<> 1094+                exparg(1);
  1095+
  1096+upp:            sbp = bp = stringbuf;
10331097                 while ((c = sloscan()) != WARN) {
 10341098                         switch (c) {
<>1035 -                        case NEX:
 1036 -                                donex();
 1037 -                                break;
 1038 -                        case EXP:
 1039 -                                doexp();
 1040 -                                break;
10411099                         case STRING:
 10421100                                 /* Remove embedded directives */
 10431101                                 for (bp = (usch *)yytext; *bp; bp++) {
<>1044 -                                        if (*bp == EXP || *bp == NEX)
  1102+                                        if (*bp == EBLOCK)
10451103                                                 bp++;
 10461104                                         else if (*bp != CONC)
 10471105                                                 savch(*bp);
 10481106                                 }
 10491107                                 break;
 10501108 
<> 1109+                        case EBLOCK:
  1110+                                doblk();
  1111+                                /* FALLTHROUGH */
10511112                         case IDENT:
 10521113                                 /*
 10531114                                  * Tricky: if this is the last identifier
     
 !
10561117                                  * back on the input stream and let fastscan
 10571118                                  * handle it as a new macro.
 10581119                                  * BUT: if this macro is blocked then this
<>1059 -                                 * should not me done.
  1120+                                 * should not be done.
10601121                                  */
 10611122                                 nl = lookup((usch *)yytext, FIND);
<> 1123+                                o = okexp(nl);
  1124+                                bidx = 0;
10621125                                 /* Deal with pragmas here */
 10631126                                 if (nl == pragloc) {
 10641127                                         pragoper();
 10651128                                         break;
 10661129                                 }
<>1067 -                                if (nl == NULL || !okexp(nl) ||
 1068 -                                    *nl->value == OBJCT) {
  1130+                                if (nl == NULL || !o || *nl->value == OBJCT) {
10691131                                         /* Not fun-like macro */
<>1070 -                                        savstr((usch *)yytext);
  1132+                                        savstr(yytext);
10711133                                         break;
 10721134                                 }
<>1073 -                                while ((c = cinput()) == NEX || c == EXP)
 1074 -                                        c == EXP ? doexp() : donex();
  1135+                                c = cinput();
10751136                                 if (c == WARN) {
 10761137                                         /* succeeded, push back */
<>1077 -                                        unpstr((usch *)yytext);
  1138+                                        unpstr(yytext);
10781139                                 } else {
<>1079 -                                        savstr((usch *)yytext);
  1140+                                        savstr(yytext);
10801141                                 }
 10811142                                 cunput(c);
 10821143                                 break;
 10831144 
 10841145                         default:
<>1085 -                                savstr((usch *)yytext);
  1146+                                savstr(yytext);
10861147                                 break;
 10871148                         }
 10881149                 }
 10891150                 IMP("END2");
<>1090 -                if (bidx != 0)
 1091 -                        error("exp/noexp sync error");
10921151                 norepptr = 1;
 10931152                 savch(0);
 10941153                 stringbuf = sbp;
     
 !
11211180         c = addmac(sp);
 11221181         bp = stringbuf;
 11231182         cunput(WARN);
<>1124 -        cunput(WARN);
 1125 -        cunput(c);
 1126 -        cunput(EXP);
 1127 -        IMP("KEXP");
11281183 
<> 1184+        IMP("KEXP");
11291185         subarg(sp, argary, 1);
<>1130 -
 1131 -        cunput(c);
 1132 -        cunput(NEX);
11331186         IMP("KNEX");
<> 1187+        insblock(c);
  1188+        IMP("KBLK");
11341189 
 11351190         stringbuf = bp;
 11361191 
<>1137 -        IMP("MID1");
  1192+        exparg(1);
11381193 
<>1139 -        while ((c = cinput()) != WARN) {
 1140 -                savch(c);
 1141 -                if (c == EXP || c == NEX)
 1142 -                        savch(cinput());
 1143 -        }
 1144 -        savch(0);
 1145 -
 1146 -        exparg(bp, 0);
 1147 -
11481194         IMP("END");
 11491195 
 11501196         goto upp;
     
 !
11531199 
 11541200 /*
 11551201  * Replace and push-back on input stream the eventual replaced macro.
<> 1202+ * The check for whether it can expand or not should already have been done.
  1203+ * Blocks for this identifier will be added via insblock() after expansion.
11561204  */
 11571205 int
 11581206 submac(struct symtab *sp, int lvl)
 11591207 {
 11601208         const usch *argary[MAXARGS+1];
<>1161 -        usch savc[100], savn[100];
11621209         const usch *cp;
<>1163 -        usch *obp;
 1164 -        int ch, nl, i, ccnt, bsv, gotnex;
  1210+        usch *bp;
  1211+        int ch;
11651212 
 11661213         DPRINT(("%d:submac1: trying '%s'\n", lvl, sp->namep));
 11671214         if (*sp->value == OBJCT) {
<>1168 -                if (!okexp(sp))
 1169 -                        return 0; /* cannot expand */
 1170 -
11711215                 if (sp == filloc) {
 11721216                         unpstr(sheap("\"%s\"", ifiles->fname));
 11731217                         return 1;
     
 !
11791223                 DPRINT(("submac: exp object macro '%s'\n",sp->namep));
 11801224                 /* expand object-type macros */
 11811225                 ch = addmac(sp);
<> 1226+                cunput(WARN);
11821227 
<>1183 -                cunput(ch);
 1184 -                cunput(EXP);
11851228                 for (cp = sp->value-1; *cp; cp--)
 11861229                         cunput(*cp);
<>1187 -                cunput(ch);
 1188 -                cunput(NEX);
  1230+                insblock(ch);
  1231+                delwarn();
11891232                 return 1;
 11901233         }
 11911234 
     
 !
11971240          * If input is          <NEX><NEX>foo<EXP>()<EXP> then
 11981241          * output should be     <NEX><NEX><EXP>kaka<EXP>.
 11991242          */
<>1200 -        obp = stringbuf;
 1201 -        gotnex = nl = ccnt = 0;
 1202 -        i = bidx;
 1203 -        do {
 1204 -                switch (ch = cinput()) {
 1205 -                case NEX: /* disallow expansion */
 1206 -                        savc[ccnt] = ch;
 1207 -                        savn[ccnt] = cinput();
 1208 -                        gotnex = 1;
 1209 -                        ccnt++;
 1210 -                        break;
 1211 -                case EXP: /* allow expansion */
 1212 -                        savc[ccnt] = ch;
 1213 -                        if (gotnex == 0) {
 1214 -                                savn[ccnt] = doexp();
 1215 -                        } else {
 1216 -                                savn[ccnt] = cinput();
 1217 -                        }
 1218 -                        ccnt++;
 1219 -                        break;
 1220 -
 1221 -                case '\n':
 1222 -                        nl++;
 1223 -                        /* FALLTHROUGH */
 1224 -                default:
 1225 -                        savch(ch);
 1226 -                }
 1227 -        } while (iswsnl(ch) || ch == EXP || ch == NEX);
 1228 -
 1229 -        /*
 1230 -         * Is there any macro to expand?
 1231 -         * The okexp() call must be done here because an EXP may
 1232 -         * have been found.
 1233 -         */
 1234 -        bsv = okexp(sp);
 1235 -        bidx = i;
 1236 -        
 1237 -        if (ch != '(' || !bsv) {
 1238 -                DPRINT(("submac: failed '%s' %s\n",sp->namep,
 1239 -                    ch != '(' ? "no (" : "already expanded"));
  1243+        bp = stringbuf;
  1244+        while (iswsnl(ch = cinput()))
  1245+                savch(ch);
  1246+        savch(0);
  1247+        stringbuf = bp;
  1248+        if (ch != '(') {
12401249                 cunput(ch);
<>1241 -                *--stringbuf = 0; /* remove saved ch */
 1242 -                /* push back exp/noexp first */
 1243 -                for (i = ccnt-1; i >= 0; i--)
 1244 -                        cunput(savn[i]), cunput(savc[i]);
 1245 -                /* push back rest */
 1246 -                unpstr(obp);
 1247 -                stringbuf = obp;
 1248 -                return 0;
  1250+                unpstr(bp);
  1251+                return 0; /* Failed */
12491252         }
 12501253 
<> 1254+        /* no \n should be here */
  1255+
12511256         /*
 12521257          * A function-like macro has been found.  Read in the arguments,
 12531258          * expand them and push-back everything for another scan.
     
 !
12561261         savch(0);
 12571262         if (readargs(sp, argary)) {
 12581263                 /* Bailed out in the middle of arg list */
<>1259 -                /* XXX EXP balance */
 1260 -                unpstr(obp);
  1264+                unpstr(bp);
12611265                 if (dflag>1)printf("%d:noreadargs\n", lvl);
<>1262 -                stringbuf = obp;
  1266+                stringbuf = bp;
12631267                 return 0;
 12641268         }
<>1265 -        ifiles->lineno += nl;
12661269 
 12671270         /* when all args are read from input stream */
 12681271         ch = addmac(sp);
 12691272 
<>1270 -        cunput(ch);
 1271 -        cunput(EXP);
 1272 -        DDPRINT(("%d:cunput(EXP)\n", lvl));
  1273+        DDPRINT(("%d:submac pre\n", lvl));
  1274+        cunput(WARN);
12731275 
 12741276         subarg(sp, argary, lvl+1);
 12751277 
<>1276 -        cunput(ch);
 1277 -        cunput(NEX);
 1278 -        DDPRINT(("%d:cunput(NEX)\n", lvl));
  1278+        DDPRINT(("%d:submac post\n", lvl));
  1279+        insblock(ch);
  1280+        delwarn();
12791281 
<>1280 -        for (i = ccnt-1; i >= 0; i--)
 1281 -                cunput(savn[i]), cunput(savc[i]);
 1282 -
 1283 -        stringbuf = obp; /* Reset heap */
  1282+        stringbuf = bp; /* Reset heap */
12841283         DPRINT(("%d:Return submac\n", lvl));
 12851284         IMP("SM1");
 12861285         return 1;
     
 !
12941293 readargs(struct symtab *sp, const usch **args)
 12951294 {
 12961295         const usch *vp = sp->value;
<>1297 -        usch savn[100];
12981296         int c, i, plev, narg, ellips = 0;
<>1299 -        int gotnex, ccnt, warn;
  1297+        int warn;
13001298 
 13011299         DPRINT(("readargs\n"));
 13021300 
     
 !
13101308         /*
 13111309          * read arguments and store them on heap.
 13121310          */
<>1313 -        gotnex = ccnt = warn = 0;
  1311+        warn = 0;
13141312         c = '(';
 13151313         for (i = 0; i < narg && c != ')'; i++) {
 13161314                 args[i] = stringbuf;
     
 !
13191317                         if (c == '\n')
 13201318                                 putch(cinput());
 13211319                 for (;;) {
<>1322 -                        if (c == NEX) {
 1323 -                                gotnex = 1;
 1324 -                                savch(NEX);
  1320+                        while (c == EBLOCK) {
  1321+                                savch(c);
13251322                                 savch(cinput());
<>1326 -                                goto oho;
  1323+                                c = sloscan();
13271324                         }
<>1328 -                        if (c == EXP) {
 1329 -                                if (gotnex == 0) {
 1330 -                                        savn[ccnt++] = cinput();
 1331 -                                } else {
 1332 -                                        savch(EXP);
 1333 -                                        savch(cinput());
 1334 -                                }
 1335 -                                goto oho;
 1336 -                        }
13371325                         if (c == WARN) {
 13381326                                 warn++;
 13391327                                 goto oho;
     
 !
13471335                         savstr((usch *)yytext);
 13481336 oho:                    while ((c = sloscan()) == '\n') {
 13491337                                 putch(cinput());
<>1350 -                                savch('\n');
  1338+                                savch(' ');
13511339                         }
 13521340                         while (c == CMNT) {
 13531341                                 getcmnt();
     
 !
13571345                                 error("eof in macro");
 13581346                 }
 13591347                 while (args[i] < stringbuf &&
<>1360 -                    (iswsnl(stringbuf[-1]) &&
 1361 -                    !(stringbuf[-2] == EXP || stringbuf[-2] == NEX)))
  1348+                    iswsnl(stringbuf[-1]) && stringbuf[-2] != EBLOCK)
13621349                         stringbuf--;
 13631350                 savch('\0');
 13641351                 if (dflag) {
     
 !
13871374                         savstr((usch *)yytext);
 13881375                         while ((c = sloscan()) == '\n') {
 13891376                                 cinput();
<>1390 -                                savch('\n');
  1377+                                savch(' ');
13911378                         }
 13921379                 }
 13931380                 while (args[i] < stringbuf && iswsnl(stringbuf[-1]))
     
 !
14041391                 error("wrong arg count");
 14051392         while (warn)
 14061393                 cunput(WARN), warn--;
<>1407 -        while (ccnt)
 1408 -                cunput(savn[--ccnt]), cunput(EXP);
14091394         return 0;
 14101395 }
 14111396 
<> 1397+#if 0
14121398 /*
 14131399  * Maybe an indentifier (for macro expansion).
 14141400  */
     
 !
14201406                         return 0;
 14211407         return 1;
 14221408 }
<> 1409+#endif
14231410 
 14241411 /*
 14251412  * expand a function-like macro.
     
 !
14331420         int narg, instr, snuff;
 14341421         const usch *sp, *bp, *ap, *vp;
 14351422 
<>1436 -        DPRINT(("%d:subarg(%s)\n", lvl,nl->namep));
  1423+        DPRINT(("%d:subarg '%s'\n", lvl, nl->namep));
14371424         vp = nl->value;
 14381425         narg = *vp--;
 14391426         if (narg == VARG)
     
 !
14841471                                  *  after all macros contained therein have
 14851472                                  *  been expanded.".
 14861473                                  */
<>1487 -                                exparg(bp, lvl+1);
 1488 -                                unpstr(stringbuf);
  1474+                                cunput(WARN);
  1475+                                unpstr(bp);
  1476+                                exparg(lvl+1);
  1477+                                delwarn();
14891478                         } else {
 14901479                         while (*bp)
 14911480                                 bp++;
     
 !
15171506 }
 15181507 
 15191508 /*
<>1520 - * Do a (correct) expansion of an argument.
 1521 - * Data is read from the string bp, pushed-back and expanded.
 1522 - * When nothing more to expand, return with expanded arg in lex buffer.
  1509+ * Do a (correct) expansion of a WARN-terminated buffer of tokens.
  1510+ * Data is read from the lex buffer, result on lex buffer, WARN-terminated.
  1511+ * Expansion blocking is not altered here unless when tokens are
  1512+ * concatenated, in which case they are removed.
15231513  */
 15241514 void
<>1525 -exparg(const usch *bp, int lvl)
  1515+exparg(int lvl)
15261516 {
 15271517         struct symtab *nl;
<>1528 -        int c, isexp, i, ccnt;
  1518+        int c, i;
15291519         usch *och;
 15301520         usch *osb = stringbuf;
 15311521         int anychange;
<>1532 -        usch savc[100], savn[100];
15331522 
<>1534 -        if (dflag) {
 1535 -                printf("%d:exparg3: Expand '", lvl);
 1536 -                prline(bp);
 1537 -                printf("' block %d: ", bidx);
 1538 -                for (i = 1; i < bidx; i++)
 1539 -                        printf("'%s' ", norep[bptr[i]]->namep);
 1540 -                printf("\n");
 1541 -        }
  1523+        DPRINT(("%d:exparg\n", lvl));
  1524+        IMP("EXPARG");
15421525 
 15431526 rescan:
<>1544 -        cunput(WARN);
 1545 -        unpstr(bp);
 1546 -        if (dflag>1) {
 1547 -                printf("%d:exparg WARN '", lvl);
 1548 -                prline(bp);
 1549 -                printf("'\n");
 1550 -        }
 1551 -
15521527         anychange = 0;
 15531528         readmac++;
 15541529         while ((c = sloscan()) != WARN) {
 15551530                 DDPRINT(("%d:exparg swdata %d\n", lvl, c));
 15561531                 IMP("EA0");
 15571532                 switch (c) {
<>1558 -                case NEX:
 1559 -                        DDPRINT(("%d:exparg donex\n", lvl));
 1560 -                        savch(NEX);
 1561 -                        savch(donex());
 1562 -                        break;
15631533 
<>1564 -                case EXP:
 1565 -                        DDPRINT(("%d:exparg doexp\n", lvl));
 1566 -                        savch(EXP);
 1567 -                        savch(doexp());
 1568 -                        break;
 1569 -
 1570 -                case NUMBER: /* handled as ident if no .+- in it */
 1571 -                        if (!mayid((usch *)yytext))
 1572 -                                goto def;
  1534+                case EBLOCK:
  1535+                        doblk();
15731536                         /* FALLTHROUGH */
 15741537                 case IDENT:
 15751538                         /*
 15761539                          * Handle argument concatenation here.
<> 1540+                         * In case of concatenation, scratch all blockings.
15771541                          */
 15781542                         DDPRINT(("%d:exparg ident %d\n", lvl, c));
 15791543                         och = stringbuf;
<>1580 -                        isexp = ccnt = 0;
 1581 -                        savstr((usch *)yytext);
15821544 
<>1583 -                        /* Must see if ident was expandable before EXP */
 1584 -                        if ((nl = lookup(och, FIND)) && okexp(nl))
 1585 -                                isexp = 1;
  1545+sav:                    savstr(yytext);
15861546 
<>1587 -                        DPRINT(("%d:exparg: '%s' isexp %d\n", lvl, och, isexp));
 1588 -
 1589 -                        while ((c = cinput()) == EXP || c == NEX) {
 1590 -                                savc[ccnt] = c;
 1591 -                                savn[ccnt] = cinput();
 1592 -                                ccnt++;
  1547+                        if ((c = cinput()) == EBLOCK) {
  1548+                                /* yep, are concatenating; forget blocks */
  1549+                                do {
  1550+                                        (void)cinput();
  1551+                                } while ((c = sloscan()) == EBLOCK);
  1552+                                bidx = 0;
  1553+                                goto sav;
15931554                         }
 15941555                         cunput(c);
<>1595 -                        c = sloscan();
15961556 
<>1597 -                        DPRINT(("%d:exparg neoent %d %d\n", lvl, ccnt, c));
 1598 -
 1599 -                        if (c == IDENT ||
 1600 -                            (c == NUMBER && mayid((usch *)yytext))) {
 1601 -                                DPRINT(("id2: str %s\n", yytext));
 1602 -                                /* OK to always expand here? */
 1603 -                                /* push back exp/noexp */
 1604 -                                for (i = ccnt-1; i >= 0; i--)
 1605 -                                        cunput(savn[i]), cunput(savc[i]);
 1606 -                                savstr((usch *)yytext);
 1607 -                                unpstr(och);
 1608 -                                stringbuf = och;
 1609 -                                continue; /* Refetch new longer identifier */
 1610 -                        }
 1611 -
 1612 -                        unpstr((const usch *)yytext);
 1613 -
 1614 -                        /* push back exp/noexp */
 1615 -                        for (i = ccnt-1; i >= 0; i--)
 1616 -                                cunput(savn[i]), cunput(savc[i]);
 1617 -
 1618 -                        DPRINT(("%d:exparg: pb '%s' str '%s'\n", lvl, yytext, och));
  1557+                        DPRINT(("%d:exparg: str '%s'\n", lvl, och));
16191558                         IMP("EA1");
<>1620 -                        /* try to expand the string we have */
 1621 -                        if (isexp) {
 1622 -                                /* expand the previous IDENT */
  1559+                        /* see if ident is expandable */
  1560+                        if ((nl = lookup(och, FIND)) && okexp(nl)) {
16231561                                 if (submac(nl, lvl+1)) {
 16241562                                         /* Could expand, result on lexbuffer */
 16251563                                         stringbuf = och; /* clear saved name */
 16261564                                         anychange = 1;
 16271565                                 }
<>1628 -                                
  1566+                        } else if (bidx) {
  1567+                                /* must restore blocks */
  1568+                                stringbuf = och;
  1569+                                for (i = 0; i < bidx; i++)
  1570+                                        savch(EBLOCK), savch(bptr[i]);
  1571+                                savstr(yytext);
16291572                         }
<> 1573+                        bidx = 0;
16301574                         IMP("EA2");
 16311575                         break;
 16321576 
     
 !
16391583                         savch(' ');
 16401584                         break;
 16411585 
<>1642 -def:            default:
  1586+                default:
16431587                         savstr((usch *)yytext);
 16441588                         break;
 16451589                 }
 16461590         }
 16471591         *stringbuf = 0;
<>1648 -        if (dflag) {
 1649 -                printf("%d:exparg return: change %d final '", lvl, anychange);
 1650 -                prline(osb);
 1651 -                printf("'\n");
 1652 -        }
 1653 -        bp = stringbuf = osb;
  1592+        cunput(WARN);
  1593+        unpstr(osb);
  1594+        DPRINT(("%d:exparg return: change %d\n", lvl, anychange));
  1595+        IMP("EXPRET");
  1596+        stringbuf = osb;
16541597         if (anychange)
 16551598                 goto rescan;
 16561599         readmac--;
     
 !
16721615                 case WARN: printf("<ARG(%d)>", *--s); break;
 16731616                 case CONC: printf("<CONC>"); break;
 16741617                 case SNUFF: printf("<SNUFF>"); break;
<>1675 -                case NEX: printf("<NEX(%d)>",*--s); break;
 1676 -                case EXP: printf("<EXP(%d)>",*--s); break;
  1618+                case EBLOCK: printf("<E(%d)>",*--s); break;
16771619                 default: printf("%c", *s); break;
 16781620                 }
 16791621                 s--;
     
 !
16881630                 case WARN: printf("<WARN>"); break;
 16891631                 case CONC: printf("<CONC>"); break;
 16901632                 case SNUFF: printf("<SNUFF>"); break;
<>1691 -                case NEX: printf("<NEX(%d)>",*++s); break;
 1692 -                case EXP: printf("<EXP(%d)>",*++s); break;
  1633+                case EBLOCK: printf("<E(%d)>",*++s); break;
16931634                 case '\n': printf("<NL>"); break;
 16941635                 default: printf("%c", *s); break;
 16951636                 }
     
 !
17171658 {
 17181659         const usch *d = c;
 17191660 
<> 1661+#if 0
17201662         if (dflag>1) {
 17211663                 printf("Xunpstr: '");
 17221664                 prline(c);
 17231665                 printf("'\n");
 17241666         }
<> 1667+#endif
17251668         while (*d)
 17261669                 d++;
 17271670         while (d > c) {
     
 !
19781921 }
 19791922 
 19801923 usch *
<>1981 -xstrdup(const char *str)
  1924+xstrdup(const usch *str)
19821925 {
<>1983 -        size_t len = strlen(str)+1;
  1926+        size_t len = strlen((char *)str)+1;
19841927         usch *rv;
 19851928 
 19861929         if ((rv = malloc(len)) == NULL)
 19871930                 error("xstrdup: out of mem");
<>1988 -        strlcpy((char *)rv, str, len);
  1931+        strlcpy((char *)rv, (char *)str, len);
<_19891932         return rv;
 19901933 }
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-02 16:31 +0200