diff options
Diffstat (limited to 'test-line-buffer.c')
-rw-r--r-- | test-line-buffer.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/test-line-buffer.c b/test-line-buffer.c index da0bc6502c..ec19b13ee2 100644 --- a/test-line-buffer.c +++ b/test-line-buffer.c @@ -49,15 +49,31 @@ static void handle_line(const char *line, struct line_buffer *stdin_buf) int main(int argc, char *argv[]) { struct line_buffer stdin_buf = LINE_BUFFER_INIT; + struct line_buffer file_buf = LINE_BUFFER_INIT; + struct line_buffer *input = &stdin_buf; + const char *filename; char *s; - if (argc != 1) - usage("test-line-buffer < script"); + if (argc == 1) + filename = NULL; + else if (argc == 2) + filename = argv[1]; + else + usage("test-line-buffer [file] < script"); if (buffer_init(&stdin_buf, NULL)) die_errno("open error"); + if (filename) { + if (buffer_init(&file_buf, filename)) + die_errno("error opening %s", filename); + input = &file_buf; + } + while ((s = buffer_read_line(&stdin_buf))) - handle_line(s, &stdin_buf); + handle_line(s, input); + + if (filename && buffer_deinit(&file_buf)) + die("error reading from %s", filename); if (buffer_deinit(&stdin_buf)) die("input error"); if (ferror(stdout)) |