From 4ebd84900f7f5d0afda14e09c518e614d9fde60d Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 5 Jul 2009 12:01:17 +0200 Subject: Refactor xref opening and closing to a common file for all pdf tools. --- apps/pdfshow.c | 60 ++-------------------------------------------------------- 1 file changed, 2 insertions(+), 58 deletions(-) (limited to 'apps/pdfshow.c') diff --git a/apps/pdfshow.c b/apps/pdfshow.c index 44d50774..164daca0 100644 --- a/apps/pdfshow.c +++ b/apps/pdfshow.c @@ -2,63 +2,7 @@ * pdfshow -- the ultimate pdf debugging tool */ -#include "fitz.h" -#include "mupdf.h" - -pdf_xref *xref = NULL; - -void die(fz_error eo) -{ - fz_catch(eo, "aborting"); - exit(1); -} - -void openxref(char *filename, char *password) -{ - fz_error error; - fz_obj *obj; - - error = pdf_newxref(&xref); - if (error) - die(error); - - error = pdf_loadxref(xref, filename); - if (error) - { - fz_catch(error, "trying to repair"); - error = pdf_repairxref(xref, filename); - if (error) - die(error); - } - - error = pdf_decryptxref(xref); - if (error) - die(error); - - if (xref->crypt) - { - int okay = pdf_setpassword(xref->crypt, password); - if (!okay) - fz_warn("invalid password, attempting to continue."); - } - - /* TODO: move into mupdf lib, see pdfapp_open in pdfapp.c */ - obj = fz_dictgets(xref->trailer, "Root"); - xref->root = fz_resolveindirect(obj); - if (xref->root) - fz_keepobj(xref->root); - - obj = fz_dictgets(xref->trailer, "Info"); - xref->info = fz_resolveindirect(obj); - if (xref->info) - fz_keepobj(xref->info); -} - -void closexref() -{ - pdf_closexref(xref); - xref = nil; -} +#include "pdftool.h" int showbinary = 0; int showdecode = 0; @@ -197,7 +141,7 @@ int main(int argc, char **argv) if (fz_optind == argc) showusage(); - openxref(argv[fz_optind++], password); + openxref(argv[fz_optind++], password, 0); if (fz_optind == argc) showtrailer(); -- cgit v1.2.3