Fixes: #define S "//foo" #define S "/*foo" bug where comments are interpreted inside strings. The fix assumes strings and char literals are essentially the same. Screwups will be caught by the compiler on macro expansion. This decision was made to simplify the implementation and to avoid duplication of code. Notes: Thu Feb 10 18:11:36 EST 2005 rsc This fix breaks the following program: #include #include #define x(y) "y\n" void main(void) { print(x(hello world)); } Replacing within quotes is occasionally useful for "stringizing", especially since Ken doesn't support the ANSI preprocessor # foo syntax. I think the comment problem is still fixable without breaking the above program, just not this way. Reference: /n/sources/patch/sorry/macbody Date: Thu Feb 10 21:10:49 CET 2005 Reviewed-by: rsc --- /sys/src/cmd/cc/macbody Thu Feb 10 21:06:58 2005 +++ /sys/src/cmd/cc/macbody Thu Feb 10 21:06:57 2005 @@ -234,6 +234,34 @@ base[len++] = 'a' + i; continue; } + if (c == '\'' || c == '"') { + int e; + + base = allocn(base, len, 1); + base[len++] = c; + e = c; + + for (;;) { + int p; + + p = c; + if ((c = getc()) == '\n') + break; + + base = allocn(base, len, 1); + base[len++] = c; + + if (p == '\\' && c == e) + continue; + + if (c == e) { + c = getc(); + break; + } + } + + continue; + } if(c == '/') { c = getc(); if(c == '/'){