# HG changeset patch # User David A. Holland # Date 1370908615 14400 # Node ID 980ed7cb620a3634554373c3ab4f8bed71155aad # Parent bbbf71859a21400364018727709b543b968f67be More multiline comment fixes. It looks like the only rational way to handle multiline comments is to treat the newlines as fully part of the comment text. diff -r bbbf71859a21 -r 980ed7cb620a files.c --- a/files.c Mon Jun 10 18:49:36 2013 -0400 +++ b/files.c Mon Jun 10 19:56:55 2013 -0400 @@ -115,18 +115,52 @@ //////////////////////////////////////////////////////////// // parsing +/* + * Find the end of the logical line. End of line characters that are + * commented out do not count. + */ static size_t -findnl(const char *buf, size_t start, size_t limit) +findeol(const char *buf, size_t start, size_t limit) { size_t i; + int incomment = 0; + + for (i=start; i= bufend) { /* do not have a whole line in the buffer; read more */ + assert(bufend >= linestart); if (linestart > 0 && bufend > linestart) { /* slide to beginning of buffer */ memmove(buf, buf+linestart, bufend-linestart); @@ -194,7 +229,7 @@ } else { tmp = bufend; bufend += (size_t)result; - lineend = findnl(buf, tmp, bufend); + lineend = findeol(buf, tmp, bufend); } /* loop in case we still don't have a whole line */ continue; @@ -222,20 +257,25 @@ } bufend -= tmp; nextlinestart -= tmp; - lineend = findnl(buf, lineend, bufend); + lineend = findeol(buf, lineend, bufend); /* might not have a whole line, so loop */ continue; } /* line now goes from linestart to lineend */ assert(buf[lineend] == '\0'); + + /* count how many commented-out newlines we swallowed */ + nextlinestartplace.line += countnls(buf, linestart, lineend); + + /* if the line isn't empty, process it */ if (lineend > linestart) { directive_gotline(&linestartplace, buf+linestart, lineend-linestart); } linestart = nextlinestart; - lineend = findnl(buf, linestart, bufend); + lineend = findeol(buf, linestart, bufend); linestartplace = nextlinestartplace; }