Mercurial > ~dholland > hg > tradcpp > index.cgi
changeset 24:daa801fe719e
fix some bugs
author | David A. Holland |
---|---|
date | Mon, 20 Dec 2010 04:30:02 -0500 |
parents | fb83c2df2268 |
children | 18681e5ae6e4 |
files | files.c output.c |
diffstat | 2 files changed, 32 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/files.c Mon Dec 20 04:21:51 2010 -0500 +++ b/files.c Mon Dec 20 04:30:02 2010 -0500 @@ -307,12 +307,21 @@ assert(place != NULL); - fd = file_tryopen(name); - if (fd < 0) { - warn("%s", name); - die(); + if (name == NULL) { + fd = STDIN_FILENO; + pf = place_addfile(place, "<standard-input>", false); + } else { + fd = file_tryopen(name); + if (fd < 0) { + warn("%s", name); + die(); + } + pf = place_addfile(place, name, false); } - pf = place_addfile(place, name, false); + file_read(pf, fd, name); - close(fd); + + if (name != NULL) { + close(fd); + } }
--- a/output.c Mon Dec 20 04:21:51 2010 -0500 +++ b/output.c Mon Dec 20 04:30:02 2010 -0500 @@ -14,10 +14,15 @@ void output_open(void) { - outputfd = open(mode.output_file, O_WRONLY|O_CREAT|O_TRUNC, 0664); - if (outputfd < 0) { - warn("%s", mode.output_file); - die(); + if (mode.output_file == NULL) { + outputfd = STDOUT_FILENO; + } else { + outputfd = open(mode.output_file, O_WRONLY|O_CREAT|O_TRUNC, + 0664); + if (outputfd < 0) { + warn("%s", mode.output_file); + die(); + } } } @@ -100,12 +105,19 @@ } } } + pos++; + + if (pos > start) { + if (!incomment || mode.output_retain_comments) { + dowrite(buf + start, pos - start); + } + } } void output_eof(void) { - if (outputfd >= 0) { + if (mode.output_file != NULL && outputfd >= 0) { close(outputfd); } outputfd = -1;