diff files.c @ 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 980ed7cb620a
children 60184aa42604
line wrap: on
line diff
--- 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;
 		}