From 5aaff8260abdaefdbf7a64d3e66b1928dfe5d726 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 11 Mar 2009 01:44:12 +0100 Subject: Add fz_catch function, and cause the throw/rethrow/catch functions to print the errors immediately. --- apps/common/pdfapp.c | 15 +++++---------- apps/pdfclean.c | 9 ++------- apps/pdfdraw.c | 11 +++-------- apps/pdfinfo.c | 17 ++++++----------- apps/pdfshow.c | 9 ++------- apps/unix/x11pdf.c | 2 +- 6 files changed, 19 insertions(+), 44 deletions(-) (limited to 'apps') diff --git a/apps/common/pdfapp.c b/apps/common/pdfapp.c index b01bd485..b3507097 100644 --- a/apps/common/pdfapp.c +++ b/apps/common/pdfapp.c @@ -83,16 +83,11 @@ void pdfapp_open(pdfapp_t *app, char *filename) error = pdf_loadxref(app->xref, filename); if (error) { - if (!strncmp(error->msg, "ioerror", 7)) - pdfapp_error(app, error); - pdfapp_warn(app, - "There was a problem with file \"%s\".\n" - "It may be corrupted or generated by faulty software.\n\n" - "%s\n\nTrying to continue anyway...", - filename, error->msg); - error = pdf_repairxref(app->xref, filename); - if (error) - pdfapp_error(app, error); + fz_catch(error, "trying to repair"); + pdfapp_warn(app, "There was a problem with file \"%s\".\nIt may be corrupted or generated by faulty software.\nTrying to repair the file.", filename); + error = pdf_repairxref(app->xref, filename); + if (error) + pdfapp_error(app, error); } /* diff --git a/apps/pdfclean.c b/apps/pdfclean.c index 7a8cc0fc..58fc9b68 100644 --- a/apps/pdfclean.c +++ b/apps/pdfclean.c @@ -26,10 +26,7 @@ int doexpand = 0; void die(fz_error *eo) { - fflush(stdout); - fz_printerror(eo); - fz_droperror(eo); - fflush(stderr); + fz_catch(eo, "aborting"); exit(1); } @@ -45,9 +42,7 @@ void openxref(char *filename, char *password) error = pdf_loadxref(xref, filename); if (error) { - fz_printerror(error); - fz_droperror(error); - fz_warn("trying to repair"); + fz_catch(error, "trying to repair"); error = pdf_repairxref(xref, filename); if (error) die(error); diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index 53df42c8..cc7ce53e 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -23,13 +23,10 @@ pdf_pagetree *pagetree = nil; void die(fz_error *eo) { - fflush(stdout); - fz_printerror(eo); - fz_droperror(eo); - fflush(stderr); + fz_catch(eo, "aborting"); if (drawgc) fz_droprenderer(drawgc); - abort(); + exit(1); } void openxref(char *filename, char *password) @@ -50,9 +47,7 @@ void openxref(char *filename, char *password) error = pdf_loadxref(xref, filename); if (error) { - fz_printerror(error); - fz_droperror(error); - fz_warn("trying to repair"); + fz_catch(error, "trying to repair"); error = pdf_repairxref(xref, filename); if (error) die(error); diff --git a/apps/pdfinfo.c b/apps/pdfinfo.c index 374b39c6..c785391d 100644 --- a/apps/pdfinfo.c +++ b/apps/pdfinfo.c @@ -30,14 +30,11 @@ pdf_pagetree *srcpages = nil; void die(fz_error *eo) { - fflush(stdout); - fz_printerror(eo); - fz_droperror(eo); - fflush(stderr); - if (drawgc) - fz_droprenderer(drawgc); - closesrc(); - abort(); + fz_catch(eo, "aborting"); + if (drawgc) + fz_droprenderer(drawgc); + closesrc(); + exit(-1); } void closesrc(void) @@ -78,9 +75,7 @@ void opensrc(char *filename, char *password, int loadpages) error = pdf_loadxref(src, filename); if (error) { - fz_printerror(error); - fz_droperror(error); - fz_warn("trying to repair"); + fz_catch(error, "trying to repair"); error = pdf_repairxref(src, filename); if (error) die(error); diff --git a/apps/pdfshow.c b/apps/pdfshow.c index b3239978..4d59c590 100644 --- a/apps/pdfshow.c +++ b/apps/pdfshow.c @@ -9,10 +9,7 @@ pdf_xref *xref = NULL; void die(fz_error *eo) { - fflush(stdout); - fz_printerror(eo); - fz_droperror(eo); - fflush(stderr); + fz_catch(eo, "aborting"); exit(1); } @@ -28,9 +25,7 @@ void openxref(char *filename, char *password) error = pdf_loadxref(xref, filename); if (error) { - fz_printerror(error); - fz_droperror(error); - fz_warn("trying to repair"); + fz_catch(error, "trying to repair"); error = pdf_repairxref(xref, filename); if (error) die(error); diff --git a/apps/unix/x11pdf.c b/apps/unix/x11pdf.c index 0b1ff37c..18507f62 100644 --- a/apps/unix/x11pdf.c +++ b/apps/unix/x11pdf.c @@ -84,7 +84,7 @@ void winwarn(pdfapp_t *app, char *msg) void winerror(pdfapp_t *app, fz_error *error) { - fz_printerror(error); + fz_catch(error, "aborting"); exit(1); } -- cgit v1.2.3