Mercurial > ~dholland > hg > tradcpp > index.cgi
diff files.c @ 154:a2c2fe8dbea3
Wrap up the current and next line position when invoking directives.
(in preparation for implementing #line)
author | David A. Holland |
---|---|
date | Fri, 12 Jun 2015 00:56:12 -0400 (2015-06-12) |
parents | ed45f2d8d3bc |
children | f14f5352956c |
line wrap: on
line diff
--- a/files.c Fri Jun 12 00:35:46 2015 -0400 +++ b/files.c Fri Jun 12 00:56:12 2015 -0400 @@ -172,14 +172,15 @@ void file_read(const struct placefile *pf, int fd, const char *name, bool toplevel) { - struct place linestartplace, nextlinestartplace, ptmp; + struct lineplace places; + struct place ptmp; size_t bufend, bufmax, linestart, lineend, nextlinestart, tmp; ssize_t result; bool ateof = false; char *buf; - place_setfilestart(&linestartplace, pf); - nextlinestartplace = linestartplace; + place_setfilestart(&places.current, pf); + places.nextline = places.current; bufmax = 128; bufend = 0; @@ -223,7 +224,7 @@ } else if (result == 0) { /* eof in middle of line */ ateof = true; - ptmp = linestartplace; + ptmp = places.current; ptmp.column += bufend - linestart; complain(&ptmp, "No newline at end of file"); if (mode.werror) { @@ -244,7 +245,7 @@ assert(buf[lineend] == '\n'); buf[lineend] = '\0'; nextlinestart = lineend+1; - nextlinestartplace.line++; + places.nextline.line++; /* check for CR/NL */ if (lineend > 0 && buf[lineend-1] == '\r') { @@ -271,21 +272,21 @@ assert(buf[lineend] == '\0'); /* count how many commented-out newlines we swallowed */ - nextlinestartplace.line += countnls(buf, linestart, lineend); + places.nextline.line += countnls(buf, linestart, lineend); /* if the line isn't empty, process it */ if (lineend > linestart) { - directive_gotline(&linestartplace, + directive_gotline(&places, buf+linestart, lineend-linestart); } linestart = nextlinestart; lineend = findeol(buf, linestart, bufend); - linestartplace = nextlinestartplace; + places.current = places.nextline; } if (toplevel) { - directive_goteof(&linestartplace); + directive_goteof(&places.current); } dofree(buf, bufmax); }