Mercurial > ~dholland > hg > tradcpp > index.cgi
changeset 128:1cda505ddc78
Don't expand macros within character constants.
author | David A. Holland |
---|---|
date | Fri, 14 Jun 2013 20:59:24 -0400 |
parents | a0a86380456e |
children | 2e1496dd96c4 |
files | CHANGES directive.c files.c macro.c output.c |
diffstat | 5 files changed, 30 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES Wed Jun 12 10:52:56 2013 -0400 +++ b/CHANGES Fri Jun 14 20:59:24 2013 -0400 @@ -1,7 +1,8 @@ pending - - don't eval the control expression of the first #if of a block when + - Don't eval the control expression of the first #if of a block when already in a false block; it might not be valid. Reported by Baptiste Daroussin. + - Don't recognize comments within character constants. release 0.2 (20130611) - auto-recognize more builtin PowerPC and mips macros
--- a/directive.c Wed Jun 12 10:52:56 2013 -0400 +++ b/directive.c Fri Jun 14 20:59:24 2013 -0400 @@ -62,6 +62,7 @@ bool incomment = false; bool inesc = false; bool inquote = false; + char quote = '\0'; for (s = t = buf; *s; s++) { if (incomment) { @@ -77,8 +78,12 @@ inesc = false; } else if (s[0] == '\\') { inesc = true; - } else if (s[0] == '"') { - inquote = !inquote; + } else if (!inquote && + (s[0] == '"' || s[0] == '\'')) { + inquote = true; + quote = s[0]; + } else if (inquote && s[0] == quote) { + inquote = false; } if (t != s) {
--- a/files.c Wed Jun 12 10:52:56 2013 -0400 +++ b/files.c Fri Jun 14 20:59:24 2013 -0400 @@ -127,6 +127,7 @@ size_t i; int incomment = 0; bool inquote = false; + char quote = '\0'; for (i=start; i<limit; i++) { if (incomment) { @@ -139,10 +140,13 @@ i++; incomment = 1; } else if (i+1 < limit && - buf[i] == '\\' && buf[i+1] == '"') { + buf[i] == '\\' && buf[i+1] != '\n') { i++; - } else if (buf[i] == '"') { - inquote = !inquote; + } else if (!inquote && (buf[i] == '"' || buf[i] == '\'')) { + inquote = true; + quote = buf[i]; + } else if (inquote && buf[i] == quote) { + inquote = false; } else if (buf[i] == '\n') { return i; }
--- a/macro.c Wed Jun 12 10:52:56 2013 -0400 +++ b/macro.c Fri Jun 14 20:59:24 2013 -0400 @@ -1066,6 +1066,7 @@ char *s; size_t x; bool inquote = false; + char quote = '\0'; while (len > 0) { x = strspn(buf, ws); @@ -1128,14 +1129,18 @@ continue; } - if (len > 1 && buf[0] == '\\' && buf[1] == '"') { + if (len > 1 && buf[0] == '\\' && + (buf[1] == '"' || buf[1] == '\'')) { expand_got_other(es, p, buf, 2); buf += 2; len -= 2; continue; } - if (buf[0] == '"') { - inquote = !inquote; + if (!inquote && (buf[0] == '"' || buf[0] == '\'')) { + inquote = true; + quote = buf[0]; + } else if (inquote && buf[0] == quote) { + inquote = false; } expand_got_other(es, p, buf, 1);
--- a/output.c Wed Jun 12 10:52:56 2013 -0400 +++ b/output.c Fri Jun 14 20:59:24 2013 -0400 @@ -101,6 +101,7 @@ size_t pos, start; bool inesc = false; bool inquote = false; + char quote = '\0'; start = 0; for (pos = 0; pos < len - 1; pos++) { @@ -136,8 +137,11 @@ inesc = false; } else if (buf[pos] == '\\') { inesc = true; - } else if (buf[pos] == '"') { - inquote = !inquote; + } else if (!inquote && (buf[pos] == '"' || buf[pos] == '\'')) { + inquote = true; + quote = buf[pos]; + } else if (inquote && buf[pos] == quote) { + inquote = false; } } pos++;