diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2012-05-10 15:32:29 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2012-05-10 15:32:29 +0200 |
commit | 314c9ecaaba711741ecc5bb3e3e1e62655cee8c4 (patch) | |
tree | 21309558223ac886f20a4c3ff2de6d1365d9dfc1 /apps/mubusy.c | |
parent | 35d9b6d47a786b77d8c66925de4ca35bebd172c5 (diff) | |
download | mupdf-314c9ecaaba711741ecc5bb3e3e1e62655cee8c4.tar.xz |
Combine all small tools into mubusy and remove the separate executables.
Diffstat (limited to 'apps/mubusy.c')
-rw-r--r-- | apps/mubusy.c | 94 |
1 files changed, 58 insertions, 36 deletions
diff --git a/apps/mubusy.c b/apps/mubusy.c index a9df26fa..5030f7a0 100644 --- a/apps/mubusy.c +++ b/apps/mubusy.c @@ -1,62 +1,84 @@ /* - * pdfbusy -- combined exe build + * mubusy -- swiss army knife of pdf manipulation tools */ #include <stdio.h> #include <stdlib.h> #include <string.h> +#define nelem(x) (sizeof(x)/sizeof((x)[0])) + int pdfclean_main(int argc, char *argv[]); -int draw_main(int argc, char *argv[]); int pdfextract_main(int argc, char *argv[]); int pdfinfo_main(int argc, char *argv[]); +int pdfposter_main(int argc, char *argv[]); int pdfshow_main(int argc, char *argv[]); +static struct { + int (*func)(int argc, char *argv[]); + char *name; + char *desc; +} tools[] = { + { pdfclean_main, "clean", "rewrite pdf file" }, + { pdfextract_main, "extract", "extract font and image resources" }, + { pdfinfo_main, "info", "show information about pdf resources" }, + { pdfposter_main, "poster", "split large page into many tiles" }, + { pdfshow_main, "show", "show internal pdf objects" }, +}; + static int -namematch(const char *end, const char *start, const char *match, int len) +namematch(const char *end, const char *start, const char *match) { + int len = strlen(match); return ((end-len >= start) && (strncmp(end-len, match, len) == 0)); } int main(int argc, char **argv) { char *start, *end; + char buf[32]; + int i; + if (argc == 0) { fprintf(stderr, "No command name found!\n"); - exit(EXIT_FAILURE); + return 1; + } + + /* Check argv[0] */ + + if (argc > 0) + { + end = start = argv[0]; + while (*end) + end++; + if ((end-4 >= start) && (end[-4] == '.') && (end[-3] == 'e') && (end[-2] == 'x') && (end[-1] == 'e')) + end = end-4; + for (i = 0; i < nelem(tools); i++) + { + strcpy(buf, "mupdf"); + strcat(buf, tools[i].name); + if (namematch(end, start, buf)) + return tools[i].func(argc, argv); + } } - end = start = argv[0]; - while (*end) - end++; - if ((end-4 >= start) && (end[-4] == '.') && (end[-3] == 'e') && (end[-2] == 'x') && (end[-1] == 'e')) - end = end-4; - if (namematch(end, start, "mupdfdraw", 9) || namematch(end, start, "muxpsdraw", 9) || namematch(end, start, "mudraw", 6)) - return draw_main(argc, argv); - if (namematch(end, start, "mupdfclean", 10)) - return pdfclean_main(argc, argv); - if (namematch(end, start, "mupdfextract", 12)) - return pdfextract_main(argc, argv); - if (namematch(end, start, "mupdfshow", 9)) - return pdfshow_main(argc, argv); - if (namematch(end, start, "mupdfinfo", 9)) - return pdfinfo_main(argc, argv); - /* And include old names for backward compatibility */ - if (namematch(end, start, "pdfdraw", 7) || namematch(end, start, "xpsdraw", 7)) - return draw_main(argc, argv); - if (namematch(end, start, "pdfclean", 8)) - return pdfclean_main(argc, argv); - if (namematch(end, start, "pdfextract", 10)) - return pdfextract_main(argc, argv); - if (namematch(end, start, "pdfshow", 7)) - return pdfshow_main(argc, argv); - if (namematch(end, start, "pdfinfo", 7)) - return pdfinfo_main(argc, argv); - - fprintf(stderr, "mubusy: Combined build of mupdf/mudraw tools.\n\n"); - fprintf(stderr, "Invoke as one of the following:\n"); - fprintf(stderr, "\tmupdfclean, mudraw, mupdfextract, mupdfinfo, mupdfshow.\n"); - - return 0; + /* Check argv[1] */ + + if (argc > 1) + { + for (i = 0; i < nelem(tools); i++) + if (!strcmp(tools[i].name, argv[1])) + return tools[i].func(argc - 1, argv + 1); + } + + /* Print usage */ + + fprintf(stderr, "usage: mubusy <command> [options]\n"); + fprintf(stderr, "Available commands:\n"); + + for (i = 0; i < nelem(tools); i++) + fprintf(stderr, "\t%s\t-- %s\n", tools[i].name, tools[i].desc); + + return 1; } |