changeset 81:27c9aafcaca1

Don't recognize comments within double-quote strings. Blah.
author David A. Holland
date Mon, 10 Jun 2013 21:30:20 -0400
parents 7e64b1dd0a26
children 05a94332f08b
files directive.c files.c output.c
diffstat 3 files changed, 38 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/directive.c	Mon Jun 10 20:19:49 2013 -0400
+++ b/directive.c	Mon Jun 10 21:30:20 2013 -0400
@@ -60,6 +60,8 @@
 {
 	char *s, *t, *u = NULL;
 	bool incomment = false;
+	bool inesc = false;
+	bool inquote = false;
 
 	for (s = t = buf; *s; s++) {
 		if (incomment) {
@@ -68,9 +70,17 @@
 				incomment = false;
 			}
 		} else {
-			if (s[0] == '/' && s[1] == '*') {
+			if (!inquote && s[0] == '/' && s[1] == '*') {
 				incomment = true;
 			} else {
+				if (inesc) {
+					inesc = false;
+				} else if (s[0] == '\\') {
+					inesc = true;
+				} else if (s[0] == '"') {
+					inquote = !inquote;
+				}
+
 				if (t != s) {
 					*t = *s;
 				}
--- a/files.c	Mon Jun 10 20:19:49 2013 -0400
+++ b/files.c	Mon Jun 10 21:30:20 2013 -0400
@@ -125,6 +125,7 @@
 {
 	size_t i;
 	int incomment = 0;
+	bool inquote = false;
 
 	for (i=start; i<limit; i++) {
 		if (incomment) {
@@ -132,17 +133,17 @@
 				i++;
 				incomment = 0;
 			}
-		}
-		else {
-			if (i+1 < limit && buf[i] == '/' && buf[i+1] == '*') {
-				i++;
-				incomment = 1;
-			}
-			else {
-				if (buf[i] == '\n') {
-					return i;
-				}
-			}
+		} else if (!inquote && i+1 < limit &&
+			   buf[i] == '/' && buf[i+1] == '*') {
+			i++;
+			incomment = 1;
+		} else if (i+1 < limit &&
+			   buf[i] == '\\' && buf[i+1] == '"') {
+			i++;
+		} else if (buf[i] == '"') {
+			inquote = !inquote;
+		} else if (buf[i] == '\n') {
+			return i;
 		}
 	}
 	return limit;
@@ -227,9 +228,8 @@
 				lineend = bufend++;
 				buf[lineend] = '\n';
 			} else {
-				tmp = bufend;
 				bufend += (size_t)result;
-				lineend = findeol(buf, tmp, bufend);
+				lineend = findeol(buf, linestart, bufend);
 			}
 			/* loop in case we still don't have a whole line */
 			continue;
@@ -257,7 +257,7 @@
 			}
 			bufend -= tmp;
 			nextlinestart -= tmp;
-			lineend = findeol(buf, lineend, bufend);
+			lineend = findeol(buf, linestart, bufend);
 			/* might not have a whole line, so loop */
 			continue;
 		}
--- a/output.c	Mon Jun 10 20:19:49 2013 -0400
+++ b/output.c	Mon Jun 10 21:30:20 2013 -0400
@@ -99,10 +99,12 @@
 filter_output(const struct place *p, const char *buf, size_t len)
 {
 	size_t pos, start;
+	bool inesc = false;
+	bool inquote = false;
 
 	start = 0;
 	for (pos = 0; pos < len - 1; pos++) {
-		if (buf[pos] == '/' && buf[pos+1] == '*') {
+		if (!inquote && buf[pos] == '/' && buf[pos+1] == '*') {
 			if (!incomment) {
 				if (pos > start) {
 					dowrite(buf + start, pos - start);
@@ -127,6 +129,16 @@
 				continue;
 			}
 		}
+
+		if (incomment) {
+			/* nothing */
+		} else if (inesc) {
+			inesc = false;
+		} else if (buf[pos] == '\\') {
+			inesc = true;
+		} else if (buf[pos] == '"') {
+			inquote = !inquote;
+		}
 	}
 	pos++;