From 7e91f87c55e4910ab71852fdf9de424492f2d493 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 6 Sep 2013 10:18:54 -0500 Subject: Add '-' as a option for stdout to mudraw --- source/tools/mudraw.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'source/tools') diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index 34801f51..81222993 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -531,10 +531,16 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) FILE *file; fz_output *out; - sprintf(buf, output, pagenum); - file = fopen(buf, "wb"); - if (file == NULL) - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", buf, strerror(errno)); + if (!strcmp(output, "-")) + file = stdout; + else + { + sprintf(buf, output, pagenum); + file = fopen(buf, "wb"); + if (file == NULL) + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", buf, strerror(errno)); + } + out = fz_new_output_with_file(ctx, file); fz_bound_page(doc, page, &bounds); @@ -558,7 +564,8 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) fz_free_device(dev); dev = NULL; fz_close_output(out); - fclose(file); + if (file != stdout) + fclose(file); } fz_catch(ctx) { @@ -667,8 +674,14 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) if (output) { - sprintf(filename_buf, output, pagenum); - output_file = fz_new_output_to_filename(ctx, filename_buf); + if (!strcmp(output, "-")) + output_file = fz_new_output_with_file(ctx, stdout); + else + { + sprintf(filename_buf, output, pagenum); + output_file = fz_new_output_to_filename(ctx, filename_buf); + } + if (output_format == OUT_PGM || output_format == OUT_PPM || output_format == OUT_PNM) fz_output_pnm_header(output_file, pix->w, totalheight, pix->n); else if (output_format == OUT_PAM) -- cgit v1.2.3