summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorragge <ragge>2008-08-16 15:27:27 +0000
committerragge <ragge>2008-08-16 15:27:27 +0000
commit536515b0de0b07646c37827c0ed3f6ef5ee6f702 (patch)
tree5a191948565a54646049448f5401b938321eb157
parentd430c9dd10dae93fd9d0cb4d25596c2b7f173c93 (diff)
Must delay _Pragma -> #pragma conversion until printout, otherwise
the pragma stmt may end up at the wrong place. Spotted by gmcgarry.
-rw-r--r--cpp.c53
-rw-r--r--scanner.l19
2 files changed, 58 insertions, 14 deletions
diff --git a/cpp.c b/cpp.c
index 7ec242f..cebba6a 100644
--- a/cpp.c
+++ b/cpp.c
@@ -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;
+}
diff --git a/scanner.l b/scanner.l
index 283921e..fc4b26c 100644
--- a/scanner.l
+++ b/scanner.l
@@ -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);
}