diff options
-rw-r--r-- | cpp.c | 53 | ||||
-rw-r--r-- | scanner.l | 19 |
2 files changed, 58 insertions, 14 deletions
@@ -160,6 +160,8 @@ usch *stringbuf = sbf; #define SNUFF 3 /* ETX, not legal char */ #define NOEXP 4 /* EOT, not legal char */ #define EXPAND 5 /* ENQ, not legal char */ +#define PRAGS 6 /* start of converted pragma */ +#define PRAGE 14 /* end of converted pragma */ /* args for lookup() */ #define FIND 0 @@ -173,6 +175,7 @@ void line(void); void flbuf(void); void usage(void); usch *xstrdup(char *str); +usch *prtprag(usch *opb); int @@ -914,8 +917,7 @@ pragoper(void) usch *opb; int t, plev; - slow = 1; - putstr((usch *)"\n#pragma "); + slow++; if ((t = yylex()) == WSPACE) t = yylex(); if (t != '(') @@ -941,23 +943,19 @@ pragoper(void) cunput('\n'); while (stringbuf > opb) cunput(*--stringbuf); + savch(PRAGS); while ((t = yylex()) != '\n') { if (t == WSPACE) continue; if (t != STRING) goto bad; - opb = (usch *)yytext; - if (*opb++ == 'L') - opb++; - while ((t = *opb++) != '\"') { - if (t == '\\' && (*opb == '\"' || *opb == '\\')) - t = *opb++; - putch(t); - } + savstr((usch *)yytext); } - putch('\n'); - prtline(); + savch(PRAGE); + while (stringbuf > opb) + cunput(*--stringbuf); + slow--; return; bad: error("bad pragma operator"); } @@ -1461,6 +1459,10 @@ void putstr(usch *s) { for (; *s; s++) { + if (*s == PRAGS) { + s = prtprag(s); + continue; + } outbuf[obufp++] = *s; if (obufp == CPPBUF || (istty && *s == '\n')) flbuf(); @@ -1697,3 +1699,30 @@ xstrdup(char *str) strlcpy((char *)rv, str, len); return rv; } + +usch * +prtprag(usch *s) +{ + int ch; + + s++; + putstr((usch *)"\n#pragma "); + while (*s != PRAGE) { + if (*s == 'L') + s++; + if (*s == '\"') { + s++; + while ((ch = *s++) != '\"') { + if (ch == '\\' && (*s == '\"' || *s == '\\')) + ch = *s++; + putch(ch); + } + } else { + s++; + putch(*s); + } + } + putstr((usch *)"\n"); + prtline(); + return ++s; +} @@ -317,7 +317,22 @@ L?\"(\\.|[^\\"])*\" { PRTOUT(STRING); } xx: ; } -. { PRTOUT(yytext[0]); } +. { + if (YYSTATE || slow) + return yytext[0]; + if (yytext[0] == 6) { /* PRAGS */ + usch *obp = stringbuf; + extern usch *prtprag(usch *); + *stringbuf++ = yytext[0]; + do { + *stringbuf = input(); + } while (*stringbuf++ != 14); + prtprag(obp); + stringbuf = obp; + } else { + PRTOUT(yytext[0]); + } + } %% @@ -507,7 +522,7 @@ cunput(int c) { #ifdef CPP_DEBUG extern int dflag; - if (dflag)printf(": '%c'(%d)", c, c); + if (dflag)printf(": '%c'(%d)", c > 31 ? c : ' ', c); #endif unput(c); } |