diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2018-09-02 08:28:06 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2018-09-02 08:28:06 +0000 |
commit | 4c2476d8511b0f7bb17501a58e321d973e039d5f (patch) | |
tree | f1665fec409d3267b3a9880250832e7a4a71ac37 /libexec/tradcpp/files.c | |
parent | 216272ce4a2cdbc9fdfa43c1f4d892c4ae50d05e (diff) |
update tradcpp to 0.5.2
ok miko@ bcallah@ deraadt@
Diffstat (limited to 'libexec/tradcpp/files.c')
-rw-r--r-- | libexec/tradcpp/files.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/libexec/tradcpp/files.c b/libexec/tradcpp/files.c index e5e945581bb..e59388f0abb 100644 --- a/libexec/tradcpp/files.c +++ b/libexec/tradcpp/files.c @@ -27,7 +27,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -35,6 +34,7 @@ #include <fcntl.h> #include <errno.h> +#include "bool.h" #include "array.h" #include "mode.h" #include "place.h" @@ -172,14 +172,21 @@ static 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; + + if (name) { + debuglog(&places.current, "Reading file %s", name); + } else { + debuglog(&places.current, "Reading standard input"); + } bufmax = 128; bufend = 0; @@ -223,9 +230,15 @@ file_read(const struct placefile *pf, int fd, const char *name, bool toplevel) } 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 (buf[bufend - 1] == '\n') { + complain(&ptmp, "Unclosed comment"); + complain_fail(); + } else { + complain(&ptmp, + "No newline at end of file"); + } if (mode.werror) { complain_fail(); } @@ -244,7 +257,7 @@ file_read(const struct placefile *pf, int fd, const char *name, bool toplevel) 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 +284,18 @@ file_read(const struct placefile *pf, int fd, const char *name, bool toplevel) 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, - buf+linestart, lineend-linestart); - } + /* process the line (even if it's empty) */ + 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); } @@ -396,7 +406,7 @@ file_readabsolute(struct place *place, const char *name) assert(place != NULL); - if ((name == NULL) || !strcmp(name, "-")) { + if (name == NULL) { fd = STDIN_FILENO; pf = place_addfile(place, "<standard-input>", false); } else { |