comparison 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
comparison
equal deleted inserted replaced
80:7e64b1dd0a26 81:27c9aafcaca1
123 size_t 123 size_t
124 findeol(const char *buf, size_t start, size_t limit) 124 findeol(const char *buf, size_t start, size_t limit)
125 { 125 {
126 size_t i; 126 size_t i;
127 int incomment = 0; 127 int incomment = 0;
128 bool inquote = false;
128 129
129 for (i=start; i<limit; i++) { 130 for (i=start; i<limit; i++) {
130 if (incomment) { 131 if (incomment) {
131 if (i+1 < limit && buf[i] == '*' && buf[i+1] == '/') { 132 if (i+1 < limit && buf[i] == '*' && buf[i+1] == '/') {
132 i++; 133 i++;
133 incomment = 0; 134 incomment = 0;
134 } 135 }
135 } 136 } else if (!inquote && i+1 < limit &&
136 else { 137 buf[i] == '/' && buf[i+1] == '*') {
137 if (i+1 < limit && buf[i] == '/' && buf[i+1] == '*') { 138 i++;
138 i++; 139 incomment = 1;
139 incomment = 1; 140 } else if (i+1 < limit &&
140 } 141 buf[i] == '\\' && buf[i+1] == '"') {
141 else { 142 i++;
142 if (buf[i] == '\n') { 143 } else if (buf[i] == '"') {
143 return i; 144 inquote = !inquote;
144 } 145 } else if (buf[i] == '\n') {
145 } 146 return i;
146 } 147 }
147 } 148 }
148 return limit; 149 return limit;
149 } 150 }
150 151
225 } 226 }
226 assert(bufend < bufmax); 227 assert(bufend < bufmax);
227 lineend = bufend++; 228 lineend = bufend++;
228 buf[lineend] = '\n'; 229 buf[lineend] = '\n';
229 } else { 230 } else {
230 tmp = bufend;
231 bufend += (size_t)result; 231 bufend += (size_t)result;
232 lineend = findeol(buf, tmp, bufend); 232 lineend = findeol(buf, linestart, bufend);
233 } 233 }
234 /* loop in case we still don't have a whole line */ 234 /* loop in case we still don't have a whole line */
235 continue; 235 continue;
236 } 236 }
237 237
255 memmove(buf+lineend, buf+nextlinestart, 255 memmove(buf+lineend, buf+nextlinestart,
256 bufend - nextlinestart); 256 bufend - nextlinestart);
257 } 257 }
258 bufend -= tmp; 258 bufend -= tmp;
259 nextlinestart -= tmp; 259 nextlinestart -= tmp;
260 lineend = findeol(buf, lineend, bufend); 260 lineend = findeol(buf, linestart, bufend);
261 /* might not have a whole line, so loop */ 261 /* might not have a whole line, so loop */
262 continue; 262 continue;
263 } 263 }
264 264
265 /* line now goes from linestart to lineend */ 265 /* line now goes from linestart to lineend */