summaryrefslogtreecommitdiff
path: root/apps/pdfshow.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/pdfshow.c')
-rw-r--r--apps/pdfshow.c87
1 files changed, 56 insertions, 31 deletions
diff --git a/apps/pdfshow.c b/apps/pdfshow.c
index 5e74042b..fee20d2f 100644
--- a/apps/pdfshow.c
+++ b/apps/pdfshow.c
@@ -6,13 +6,14 @@
#include "mupdf.h"
static pdf_xref *xref = NULL;
+static fz_context *ctx = NULL;
static int showbinary = 0;
static int showdecode = 1;
static int showcolumn;
void die(fz_error error)
{
- fz_catch(error, "aborting");
+ fz_error_handle(error, "aborting");
if (xref)
pdf_free_xref(xref);
exit(1);
@@ -30,7 +31,7 @@ static void usage(void)
static void showtrailer(void)
{
if (!xref)
- die(fz_throw("no file specified"));
+ die(fz_error_make("no file specified"));
printf("trailer\n");
fz_debug_obj(xref->trailer);
printf("\n");
@@ -39,26 +40,30 @@ static void showtrailer(void)
static void showxref(void)
{
if (!xref)
- die(fz_throw("no file specified"));
+ die(fz_error_make("no file specified"));
pdf_debug_xref(xref);
printf("\n");
}
static void showpagetree(void)
{
- fz_error error;
fz_obj *ref;
int count;
int i;
if (!xref)
- die(fz_throw("no file specified"));
+ die(fz_error_make("no file specified"));
if (!xref->page_len)
{
- error = pdf_load_page_tree(xref);
- if (error)
- die(fz_rethrow(error, "cannot load page tree"));
+ fz_try(xref->ctx)
+ {
+ pdf_load_page_tree(xref);
+ }
+ fz_catch(xref->ctx)
+ {
+ die(fz_error_note(1, "cannot load page tree"));
+ }
}
count = pdf_count_pages(xref);
@@ -95,19 +100,23 @@ static void showsafe(unsigned char *buf, int n)
static void showstream(int num, int gen)
{
- fz_error error;
fz_stream *stm;
unsigned char buf[2048];
int n;
showcolumn = 0;
- if (showdecode)
- error = pdf_open_stream(&stm, xref, num, gen);
- else
- error = pdf_open_raw_stream(&stm, xref, num, gen);
- if (error)
- die(error);
+ fz_try(xref->ctx)
+ {
+ if (showdecode)
+ stm = pdf_open_stream(xref, num, gen);
+ else
+ stm = pdf_open_raw_stream(xref, num, gen);
+ }
+ fz_catch(xref->ctx)
+ {
+ die(1);
+ }
while (1)
{
@@ -127,15 +136,19 @@ static void showstream(int num, int gen)
static void showobject(int num, int gen)
{
- fz_error error;
fz_obj *obj;
if (!xref)
- die(fz_throw("no file specified"));
+ die(fz_error_make("no file specified"));
- error = pdf_load_object(&obj, xref, num, gen);
- if (error)
- die(error);
+ fz_try(ctx)
+ {
+ obj = pdf_load_object(xref, num, gen);
+ }
+ fz_catch(ctx)
+ {
+ die(1);
+ }
if (pdf_is_stream(xref, num, gen))
{
@@ -165,7 +178,6 @@ static void showobject(int num, int gen)
static void showgrep(char *filename)
{
- fz_error error;
fz_obj *obj;
int i;
@@ -173,9 +185,14 @@ static void showgrep(char *filename)
{
if (xref->table[i].type == 'n' || xref->table[i].type == 'o')
{
- error = pdf_load_object(&obj, xref, i, 0);
- if (error)
- die(error);
+ fz_try(ctx)
+ {
+ obj = pdf_load_object(xref, i, 0);
+ }
+ fz_catch(ctx)
+ {
+ die(1);
+ }
fz_sort_dict(obj);
@@ -194,7 +211,6 @@ int main(int argc, char **argv)
{
char *password = NULL; /* don't throw errors if encrypted */
char *filename;
- fz_error error;
int c;
while ((c = fz_getopt(argc, argv, "p:be")) != -1)
@@ -212,9 +228,19 @@ int main(int argc, char **argv)
usage();
filename = argv[fz_optind++];
- error = pdf_open_xref(&xref, filename, password);
- if (error)
- die(fz_rethrow(error, "cannot open document: %s", filename));
+
+ ctx = fz_new_context(&fz_alloc_default);
+ if (ctx == NULL)
+ die(fz_error_note(1, "failed to initialise context"));
+
+ fz_try(ctx)
+ {
+ xref = pdf_open_xref(ctx, filename, password);
+ }
+ fz_catch(ctx)
+ {
+ die(fz_error_note(1, "cannot open document: %s", filename));
+ }
if (fz_optind == argc)
showtrailer();
@@ -233,8 +259,7 @@ int main(int argc, char **argv)
}
pdf_free_xref(xref);
-
- fz_flush_warnings();
-
+ fz_flush_warnings(ctx);
+ fz_free_context(ctx);
return 0;
}