# HG changeset patch # User David A. Holland # Date 1371257964 14400 # Node ID 1cda505ddc78fdab303496e4be4e9aa66ba12f71 # Parent a0a86380456ea41199266debcf1726ec44e8ffc5 Don't expand macros within character constants. diff -r a0a86380456e -r 1cda505ddc78 CHANGES --- 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 diff -r a0a86380456e -r 1cda505ddc78 directive.c --- 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) { diff -r a0a86380456e -r 1cda505ddc78 files.c --- 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 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); diff -r a0a86380456e -r 1cda505ddc78 output.c --- 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++;