diff options
author | Robin Watts <robin.watts@artifex.com> | 2015-09-25 18:26:57 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2015-09-28 13:28:49 +0100 |
commit | 75f6057a294db286856965e32685032b9f07118c (patch) | |
tree | 1038ba66f6d927bc64be00c95c5051dc6648a057 /source/tools | |
parent | eaa8bfedd2bff50400254f9d4240cccce16614a5 (diff) | |
download | mupdf-75f6057a294db286856965e32685032b9f07118c.tar.xz |
Fix mudraw text outputting to respect given filename.
When we are asked to output a text file, the current code would
correctly guess the file format from the name, but would then
output to stdout anyway. Fixed here.
Diffstat (limited to 'source/tools')
-rw-r--r-- | source/tools/mudraw.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index 00f71cf0..4614d4bc 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -860,6 +860,7 @@ int mudraw_main(int argc, char **argv) int c; fz_context *ctx; fz_alloc_context alloc_ctx = { NULL, trace_malloc, trace_realloc, trace_free }; + FILE *my_output = NULL; fz_var(doc); @@ -1042,7 +1043,20 @@ int mudraw_main(int argc, char **argv) timing.maxfilename = ""; if (output_format == OUT_TEXT || output_format == OUT_HTML || output_format == OUT_STEXT || output_format == OUT_TRACE) - out = fz_new_output_with_file(ctx, stdout, 0); + { + if (output && output[0] != '-' && *output != 0) + { + my_output = fopen(output, "w"); + if (my_output == NULL) + { + fprintf(stderr, "Failed to open file '%s' for output\n", output); + exit(1); + } + } + else + my_output = stdout; + out = fz_new_output_with_file(ctx, my_output, 0); + } if (output_format == OUT_STEXT || output_format == OUT_TRACE) fz_printf(ctx, out, "<?xml version=\"1.0\"?>\n"); @@ -1150,6 +1164,9 @@ int mudraw_main(int argc, char **argv) fz_drop_output(ctx, out); out = NULL; + if (my_output != NULL && my_output != stdout) + fclose(my_output); + if (showtime && timing.count > 0) { if (files == 1) |