diff options
author | Tor Andersson <tor@ghostscript.com> | 2010-12-05 00:08:35 +0000 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2010-12-05 00:08:35 +0000 |
commit | 7940cee7f4ecfa7cca755396a235615bdbbee2d7 (patch) | |
tree | ca679d9f59ecb1a789d3a2331dcb1b75fb9f55dc | |
parent | bdfb216f7fa59be87b0300e7d6d1c53a751b796c (diff) | |
download | mupdf-7940cee7f4ecfa7cca755396a235615bdbbee2d7.tar.xz |
Add "grepable" command to pdfshow to print all objects on one line each.
-rw-r--r-- | apps/pdfshow.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/apps/pdfshow.c b/apps/pdfshow.c index b05f6013..22891e05 100644 --- a/apps/pdfshow.c +++ b/apps/pdfshow.c @@ -20,7 +20,7 @@ void die(fz_error error) static void usage(void) { - fprintf(stderr, "usage: pdfshow [options] file.pdf [xref] [trailer] [pagetree] [object numbers]\n"); + fprintf(stderr, "usage: pdfshow [options] file.pdf [grepable] [xref] [trailer] [pagetree] [object numbers]\n"); fprintf(stderr, "\t-b\tprint streams as binary data\n"); fprintf(stderr, "\t-e\tprint encoded streams (don't decode)\n"); fprintf(stderr, "\t-p\tpassword\n"); @@ -163,11 +163,33 @@ static void showobject(int num, int gen) fz_dropobj(obj); } +static void showgrep(char *filename) +{ + fz_error error; + fz_obj *obj; + int i; + + for (i = 0; i < xref->len; i++) + { + if (xref->table[i].type == 'n' || xref->table[i].type == 'o') + { + error = pdf_loadobject(&obj, xref, i, 0); + if (error) + die(error); + + printf("%s:%d: ", filename, i); + fz_fprintobj(stdout, obj, 1); + + fz_dropobj(obj); + } + } +} + int main(int argc, char **argv) { char *password = NULL; /* don't throw errors if encrypted */ - fz_error error; char *filename; + fz_error error; int c; while ((c = fz_getopt(argc, argv, "p:be")) != -1) @@ -199,6 +221,7 @@ int main(int argc, char **argv) case 't': showtrailer(); break; case 'x': showxref(); break; case 'p': showpagetree(); break; + case 'g': showgrep(filename); break; default: showobject(atoi(argv[fz_optind]), 0); break; } fz_optind++; |