From f6edd178f1d3693dfc392a47c8ac562b82339d3f Mon Sep 17 00:00:00 2001 From: kramm Date: Tue, 23 Oct 2001 17:15:20 +0000 Subject: [PATCH] added enhanced argument parsing --- src/swfstrings.c | 67 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/src/swfstrings.c b/src/swfstrings.c index 2bf1d9a..de967bd 100644 --- a/src/swfstrings.c +++ b/src/swfstrings.c @@ -10,6 +10,42 @@ #include #include #include "../lib/rfxswf.h" +#include "../lib/args.h" + +char * filename = 0; + +struct options_t options[] = +{ + {"v","verbose"}, + {"V","version"}, + {0,0} +}; + +int args_callback_option(char*name,char*val) +{ + if(!strcmp(name, "V")) { + printf("swfstrings - part of %s %s\n", PACKAGE, VERSION); + exit(0); + } +} +int args_callback_longoption(char*name,char*val) +{ + return args_long2shortoption(options, name, val); +} +void args_callback_usage(char*name) +{ + printf("\nreflex SWF Text Scan Utility\n(w) 2000 by Rainer Boehme \n\nUsage: %s filename.swf\n", name); + exit(0); +} +int args_callback_command(char*name,char*val) +{ + if(filename) { + fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n", + filename, name); + } + filename = name; + return 0; +} SWF swf; @@ -33,21 +69,24 @@ void fontcallback(U16 id,U8 * name) int main (int argc,char ** argv) { int f; - if (argc>1) - { f = open(argv[1],O_RDONLY); - if (f>=0) - { if FAILED(ReadSWF(f,&swf)) - { fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",argv[1]); - close(f); - } - else - { close(f); - FontEnumerate(&swf,&fontcallback); - FreeTags(&swf); - } - } else fprintf(stderr,"File not found: %s\n",argv[1]); + processargs(argc, argv); + if(!filename) + exit(0); + + f = open(filename,O_RDONLY); + if (f>=0) + { if FAILED(ReadSWF(f,&swf)) + { fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",filename); + close(f); + } + else + { close(f); + FontEnumerate(&swf,&fontcallback); + FreeTags(&swf); + } + } else { + fprintf(stderr,"File not found: %s\n",argv[1]); } - else fprintf(stderr,"\nreflex SWF Text Scan Utility\n(w) 2000 by Rainer Boehme \n\nUsage: %s filename.swf\n", argv[0]); return 0; } -- 1.7.10.4