# HG changeset patch # User David A. Holland # Date 1292837402 18000 # Node ID daa801fe719e53d79c08bfc481bc052bc45322bf # Parent fb83c2df226891266f784fc4075ffeb1f8f41bec fix some bugs diff -r fb83c2df2268 -r daa801fe719e files.c --- 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, "", 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); + } } diff -r fb83c2df2268 -r daa801fe719e output.c --- 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;