diff options
author | Robin Watts <robin.watts@artifex.com> | 2012-06-12 15:01:15 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-06-12 15:11:03 +0100 |
commit | 75d09fdbb8dce46719d74fa9079f4ac55a4515b0 (patch) | |
tree | c8ca57de91303a21ab50962267047a4df6fe70ac /apps | |
parent | 14f4205130757c534d4da8b310fa0a3cdeabdd96 (diff) | |
download | mupdf-75d09fdbb8dce46719d74fa9079f4ac55a4515b0.tar.xz |
Change mudraw to set the error code if rendering errors present.
Make mudraw pass a cookie in to the rendering procedures. If any errors
are reported for any page, remember this, and set the return code to 1
on exit.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/mudraw.c | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c index 6a90398f..359b102f 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -30,6 +30,7 @@ static int invert = 0; static int width = 0; static int height = 0; static int fit = 0; +static int errored = 0; static fz_text_sheet *sheet = NULL; static fz_colorspace *colorspace; @@ -102,6 +103,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) fz_display_list *list = NULL; fz_device *dev = NULL; int start; + fz_cookie cookie = { 0 }; fz_var(list); fz_var(dev); @@ -126,7 +128,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) { list = fz_new_display_list(ctx); dev = fz_new_list_device(ctx, list); - fz_run_page(doc, page, dev, fz_identity, NULL); + fz_run_page(doc, page, dev, fz_identity, &cookie); } fz_catch(ctx) { @@ -146,20 +148,22 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) dev = fz_new_trace_device(ctx); printf("<page number=\"%d\">\n", pagenum); if (list) - fz_run_display_list(list, dev, fz_identity, fz_infinite_bbox, NULL); + fz_run_display_list(list, dev, fz_identity, fz_infinite_bbox, &cookie); else - fz_run_page(doc, page, dev, fz_identity, NULL); + fz_run_page(doc, page, dev, fz_identity, &cookie); printf("</page>\n"); } - fz_catch(ctx) + fz_always(ctx) { fz_free_device(dev); + dev = NULL; + } + fz_catch(ctx) + { fz_free_display_list(ctx, list); fz_free_page(doc, page); fz_rethrow(ctx); } - fz_free_device(dev); - dev = NULL; } if (showtext) @@ -173,9 +177,9 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) text = fz_new_text_page(ctx, fz_bound_page(doc, page)); dev = fz_new_text_device(ctx, sheet, text); if (list) - fz_run_display_list(list, dev, fz_identity, fz_infinite_bbox, NULL); + fz_run_display_list(list, dev, fz_identity, fz_infinite_bbox, &cookie); else - fz_run_page(doc, page, dev, fz_identity, NULL); + fz_run_page(doc, page, dev, fz_identity, &cookie); fz_free_device(dev); dev = NULL; if (showtext == TEXT_XML) @@ -192,15 +196,18 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) printf("\f\n"); } } - fz_catch(ctx) + fz_always(ctx) { fz_free_device(dev); + dev = NULL; fz_free_text_page(ctx, text); + } + fz_catch(ctx) + { fz_free_display_list(ctx, list); fz_free_page(doc, page); fz_rethrow(ctx); } - fz_free_text_page(ctx, text); } if (showmd5 || showtime) @@ -283,9 +290,9 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) dev = fz_new_draw_device(ctx, pix); if (list) - fz_run_display_list(list, dev, ctm, bbox, NULL); + fz_run_display_list(list, dev, ctm, bbox, &cookie); else - fz_run_page(doc, page, dev, ctm, NULL); + fz_run_page(doc, page, dev, ctm, &cookie); fz_free_device(dev); dev = NULL; @@ -324,13 +331,15 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) for (i = 0; i < 16; i++) printf("%02x", digest[i]); } - - fz_drop_pixmap(ctx, pix); } - fz_catch(ctx) + fz_always(ctx) { fz_free_device(dev); + dev = NULL; fz_drop_pixmap(ctx, pix); + } + fz_catch(ctx) + { fz_free_display_list(ctx, list); fz_free_page(doc, page); fz_rethrow(ctx); @@ -368,6 +377,9 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) printf("\n"); fz_flush_warnings(ctx); + + if (cookie.errors) + errored = 1; } static void drawrange(fz_context *ctx, fz_document *doc, char *range) @@ -557,6 +569,7 @@ int main(int argc, char **argv) { fz_close_document(doc); fprintf(stderr, "error: cannot draw '%s'\n", filename); + errored = 1; } if (showtext == TEXT_HTML) @@ -589,5 +602,5 @@ int main(int argc, char **argv) } fz_free_context(ctx); - return 0; + return (errored != 0); } |