summaryrefslogtreecommitdiff
path: root/apps/pdfdebug.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2005-08-09 18:16:23 +0200
committerTor Andersson <tor@ghostscript.com>2005-08-09 18:16:23 +0200
commit559ada6a8fe16b5dded7acebffd0d46cd272867f (patch)
tree9c5efffdc03fc32c52911c75ac0f7be260de709b /apps/pdfdebug.c
parent4a10060a92a91e7a3897cb7224d204be5e372364 (diff)
downloadmupdf-559ada6a8fe16b5dded7acebffd0d46cd272867f.tar.xz
new unified pdf tool
Diffstat (limited to 'apps/pdfdebug.c')
-rw-r--r--apps/pdfdebug.c190
1 files changed, 0 insertions, 190 deletions
diff --git a/apps/pdfdebug.c b/apps/pdfdebug.c
deleted file mode 100644
index 3a3f8321..00000000
--- a/apps/pdfdebug.c
+++ /dev/null
@@ -1,190 +0,0 @@
-#include <fitz.h>
-#include <mupdf.h>
-
-static char *password = "";
-static int dodecode = 0;
-static int doprintxref = 0;
-
-void usage()
-{
- fprintf(stderr, "usage: pdfdebug [-dx] [-u password] file.pdf [oid ...]\n");
- exit(1);
-}
-
-/*
- * Debug-print stream contents
- */
-
-static int safecol = 0;
-
-void printsafe(unsigned char *buf, int n)
-{
- int i;
- for (i = 0; i < n; i++) {
- if (buf[i] == '\r' || buf[i] == '\n') {
- printf("\n");
- safecol = 0;
- }
- else if (buf[i] < 32 || buf[i] > 126) {
- printf(".");
- safecol ++;
- }
- else {
- printf("%c", buf[i]);
- safecol ++;
- }
- if (safecol == 79) {
- printf("\n");
- safecol = 0;
- }
- }
-}
-
-void decodestream(pdf_xref *xref, int oid, int gid)
-{
- fz_error *error;
- fz_stream *stm;
- unsigned char buf[512];
-
- safecol = 0;
-
- error = pdf_openstream(&stm, xref, oid, gid);
- if (error) fz_abort(error);
-
- while (1)
- {
- int n = fz_read(stm, buf, sizeof buf);
- if (n == 0)
- break;
- if (n < 0)
- fz_abort(fz_ioerror(stm));
- printsafe(buf, n);
- }
-
- fz_dropstream(stm);
-}
-
-void copystream(pdf_xref *xref, int oid, int gid)
-{
- fz_error *error;
- fz_stream *stm;
- unsigned char buf[512];
-
- safecol = 0;
-
- error = pdf_openrawstream(&stm, xref, oid, gid);
- if (error) fz_abort(error);
-
- while (1)
- {
- int n = fz_read(stm, buf, sizeof buf);
- if (n == 0)
- break;
- if (n < 0)
- fz_abort(fz_ioerror(stm));
- printsafe(buf, n);
- }
-
- fz_dropstream(stm);
-}
-
-void printobject(pdf_xref *xref, int oid, int gid)
-{
- fz_error *error;
- fz_obj *obj;
-
- error = pdf_loadobject(&obj, xref, oid, gid);
- if (error) fz_abort(error);
-
- printf("%d %d obj\n", oid, gid);
- fz_debugobj(obj);
- printf("\n");
-
- if (xref->table[oid].stmofs) {
- printf("stream\n");
- if (dodecode)
- decodestream(xref, oid, gid);
- else
- copystream(xref, oid, gid);
- printf("endstream\n");
- }
-
- printf("endobj\n");
-
- fz_dropobj(obj);
-}
-
-int main(int argc, char **argv)
-{
- fz_error *error;
- char *filename;
- pdf_xref *xref;
- int c;
-
- while ((c = getopt(argc, argv, "dxu:")) != -1)
- {
- switch (c)
- {
- case 'd':
- dodecode ++;
- break;
- case 'x':
- doprintxref ++;
- break;
- case 'u':
- password = optarg;
- break;
- default:
- usage();
- }
- }
-
- if (argc - optind == 0)
- usage();
-
- filename = argv[optind++];
-
- error = pdf_newxref(&xref);
- if (error)
- fz_abort(error);
-
- error = pdf_loadxref(xref, filename);
- if (error)
- {
- fz_warn("trying to repair");
- error = pdf_repairxref(xref, filename);
- if (error)
- fz_abort(error);
- }
-
- error = pdf_decryptxref(xref);
- if (error)
- fz_abort(error);
-
- if (xref->crypt)
- {
- error = pdf_setpassword(xref->crypt, password);
- if (error) fz_abort(error);
- }
-
- if (optind == argc)
- {
- printf("trailer\n");
- fz_debugobj(xref->trailer);
- printf("\n");
- }
-
- for ( ; optind < argc; optind++)
- {
- printobject(xref, atoi(argv[optind]), 0);
- printf("\n");
- }
-
- if (doprintxref)
- pdf_debugxref(xref);
-
- pdf_closexref(xref);
-
- return 0;
-}
-