Browse code

shared/optparser.c, sigtool: use the new option parser (bb#1215)

git-svn: trunk@4587

Tomasz Kojm authored on 2009/01/02 20:54:08
Showing 6 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Jan  2 13:08:09 CET 2009 (tk)
2
+---------------------------------
3
+ * shared/optparser.c, sigtool: use the new option parser (bb#1215)
4
+
1 5
 Thu Jan  1 22:56:40 EET 2009 (edwin)
2 6
 ------------------------------------
3 7
  * Makefile.am, Makefile.in: add -Wformat-security to 'make
... ...
@@ -75,16 +75,16 @@ static const struct clam_option {
75 75
     /* name,   longopt, sopt, argtype, regex, num, str, mul, owner, description, suggested */
76 76
 
77 77
     /* cmdline only */
78
-    { NULL, "help", 'h', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
78
+    { NULL, "help", 'h', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
79 79
     { NULL, "config-file", 'c', TYPE_STRING, NULL, 0, CONFDIR"/clamd.conf", FLAG_REQUIRED, OPT_CLAMD | OPT_CLAMDSCAN, "", "" },
80 80
     { NULL, "config-file", 0, TYPE_STRING, NULL, 0, CONFDIR"/freshclam.conf", FLAG_REQUIRED, OPT_FRESHCLAM, "", "" },
81
-    { NULL, "version", 'V', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
82
-    { NULL, "debug", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN, "", "" },
83
-    { NULL, "verbose", 'v', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
84
-    { NULL, "quiet", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
81
+    { NULL, "version", 'V', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
82
+    { NULL, "debug", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_SIGTOOL, "", "" },
83
+    { NULL, "verbose", 'v', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
84
+    { NULL, "quiet", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
85 85
     { NULL, "leave-temps", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMSCAN, "", "" },
86 86
     { NULL, "no-warnings", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
87
-    { NULL, "stdout", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
87
+    { NULL, "stdout", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
88 88
     { NULL, "daemon", 'd', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
89 89
     { NULL, "no-dns", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
90 90
     { NULL, "list-mirrors", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
... ...
@@ -105,6 +105,22 @@ static const struct clam_option {
105 105
     { NULL, "include", 0, TYPE_STRING, NULL, -1, NULL, FLAG_MULTIPLE, OPT_CLAMSCAN, "", "" },
106 106
     { NULL, "include-dir", 0, TYPE_STRING, NULL, -1, NULL, FLAG_MULTIPLE, OPT_CLAMSCAN, "", "" },
107 107
     { NULL, "structured-ssn-format", 0, TYPE_NUMBER, MATCH_NUMBER, 0, NULL, 0, OPT_CLAMSCAN, "", "" },
108
+    { NULL, "hex-dump", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_SIGTOOL, "", "" },
109
+    { NULL, "md5", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_SIGTOOL, "", "" },
110
+    { NULL, "mdb", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_SIGTOOL, "", "" },
111
+    { NULL, "html-normalise", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
112
+    { NULL, "utf16-decode", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
113
+    { NULL, "build", 'b', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
114
+    { NULL, "server", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
115
+    { NULL, "unpack", 'u', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
116
+    { NULL, "unpack-current", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
117
+    { NULL, "info", 'i', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
118
+    { NULL, "list-sigs", 'l', TYPE_STRING, NULL, -1, DATADIR, 0, OPT_SIGTOOL, "", "" },
119
+    { NULL, "vba", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
120
+    { NULL, "vba-hex", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
121
+    { NULL, "diff", 'd', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
122
+    { NULL, "run-cdiff", 'r', TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
123
+    { NULL, "verify-cdiff", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_SIGTOOL, "", "" },
108 124
 
109 125
     /* cmdline only - deprecated */
110 126
     { NULL, "http-proxy", 0, TYPE_STRING, NULL, 0, NULL, 0, OPT_FRESHCLAM | OPT_DEPRECATED, "", "" },
... ...
@@ -155,7 +171,7 @@ static const struct clam_option {
155 155
 
156 156
     { "PidFile", "pid", 'p', TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER, "Save the process ID to a file.", "/var/run/clamd.pid" },
157 157
 
158
-    { "TemporaryDirectory", "tempdir", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_MILTER | OPT_CLAMSCAN, "This option allows you to change the default temporary directory.", "/tmp" },
158
+    { "TemporaryDirectory", "tempdir", 0, TYPE_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_MILTER | OPT_CLAMSCAN | OPT_SIGTOOL, "This option allows you to change the default temporary directory.", "/tmp" },
159 159
 
160 160
     { "DatabaseDirectory", "datadir", 0, TYPE_STRING, NULL, -1, DATADIR, 0, OPT_CLAMD | OPT_FRESHCLAM, "This option allows you to change the default database directory.\nIf you enable it, please make sure it points to the same directory in\nboth clamd and freshclam.", "/var/lib/clamav" },
161 161
 
... ...
@@ -627,16 +643,14 @@ struct optstruct *optparse(const char *cfgfile, int argc, char * const *argv, in
627 627
 		    longopts[lc++].val = optentry->shortopt;
628 628
 		}
629 629
 		if(optentry->shortopt) {
630
-		    if(sc + 1 >= MAXCMDOPTS) {
630
+		    if(sc + 2 >= MAXCMDOPTS) {
631 631
 			fprintf(stderr, "ERROR: optparse: shortopts[] is too small\n");
632 632
 			optfree(opts);
633 633
 			return NULL;
634 634
 		    }
635 635
 		    shortopts[sc++] = optentry->shortopt;
636
-		    /* FIXME: we may need to handle optional args for short
637
-		     * BOOL opts
638
-		     */
639
-		    if(optentry->argtype != TYPE_BOOL)
636
+		    shortopts[sc++] = ':';
637
+		    if(!(optentry->flags & FLAG_REQUIRED) && (optentry->argtype == TYPE_BOOL || optentry->strarg))
640 638
 			shortopts[sc++] = ':';
641 639
 		}
642 640
 	    }
... ...
@@ -27,7 +27,8 @@
27 27
 #define OPT_MILTER	4
28 28
 #define OPT_CLAMSCAN	8
29 29
 #define OPT_CLAMDSCAN	16
30
-#define OPT_DEPRECATED	32
30
+#define OPT_SIGTOOL	32
31
+#define OPT_DEPRECATED	64
31 32
 
32 33
 struct optstruct {
33 34
     char *name;
... ...
@@ -23,12 +23,10 @@ sigtool_SOURCES = \
23 23
     $(top_srcdir)/shared/output.h \
24 24
     $(top_srcdir)/shared/getopt.c \
25 25
     $(top_srcdir)/shared/getopt.h \
26
-    $(top_srcdir)/shared/cfgparser.c \
27
-    $(top_srcdir)/shared/cfgparser.h \
26
+    $(top_srcdir)/shared/optparser.c \
27
+    $(top_srcdir)/shared/optparser.h \
28 28
     $(top_srcdir)/shared/misc.c \
29 29
     $(top_srcdir)/shared/misc.h \
30
-    $(top_srcdir)/shared/options.c \
31
-    $(top_srcdir)/shared/options.h \
32 30
     $(top_srcdir)/shared/sha256.c \
33 31
     $(top_srcdir)/shared/cdiff.c \
34 32
     $(top_srcdir)/shared/cdiff.h \
... ...
@@ -38,8 +36,6 @@ sigtool_SOURCES = \
38 38
     vba.h \
39 39
     sigtool.c
40 40
 
41
-#sigtool_LDADD = $(top_builddir)/clamscan/others.o 
42
-
43 41
 DEFS = @DEFS@ -DCL_NOTHREADS
44 42
 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
45 43
 LIBS = $(top_builddir)/libclamav/libclamav.la @FRESHCLAM_LIBS@ @THREAD_LIBS@
... ...
@@ -72,9 +72,8 @@ am__installdirs = "$(DESTDIR)$(bindir)"
72 72
 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
73 73
 PROGRAMS = $(bin_PROGRAMS)
74 74
 am_sigtool_OBJECTS = output.$(OBJEXT) getopt.$(OBJEXT) \
75
-	cfgparser.$(OBJEXT) misc.$(OBJEXT) options.$(OBJEXT) \
76
-	sha256.$(OBJEXT) cdiff.$(OBJEXT) tar.$(OBJEXT) vba.$(OBJEXT) \
77
-	sigtool.$(OBJEXT)
75
+	optparser.$(OBJEXT) misc.$(OBJEXT) sha256.$(OBJEXT) \
76
+	cdiff.$(OBJEXT) tar.$(OBJEXT) vba.$(OBJEXT) sigtool.$(OBJEXT)
78 77
 sigtool_OBJECTS = $(am_sigtool_OBJECTS)
79 78
 sigtool_LDADD = $(LDADD)
80 79
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
... ...
@@ -116,8 +115,6 @@ CPP = @CPP@
116 116
 CPPFLAGS = @CPPFLAGS@
117 117
 CYGPATH_W = @CYGPATH_W@
118 118
 DBDIR = @DBDIR@
119
-
120
-#sigtool_LDADD = $(top_builddir)/clamscan/others.o 
121 119
 DEFS = @DEFS@ -DCL_NOTHREADS
122 120
 DEPDIR = @DEPDIR@
123 121
 DSYMUTIL = @DSYMUTIL@
... ...
@@ -257,12 +254,10 @@ sigtool_SOURCES = \
257 257
     $(top_srcdir)/shared/output.h \
258 258
     $(top_srcdir)/shared/getopt.c \
259 259
     $(top_srcdir)/shared/getopt.h \
260
-    $(top_srcdir)/shared/cfgparser.c \
261
-    $(top_srcdir)/shared/cfgparser.h \
260
+    $(top_srcdir)/shared/optparser.c \
261
+    $(top_srcdir)/shared/optparser.h \
262 262
     $(top_srcdir)/shared/misc.c \
263 263
     $(top_srcdir)/shared/misc.h \
264
-    $(top_srcdir)/shared/options.c \
265
-    $(top_srcdir)/shared/options.h \
266 264
     $(top_srcdir)/shared/sha256.c \
267 265
     $(top_srcdir)/shared/cdiff.c \
268 266
     $(top_srcdir)/shared/cdiff.h \
... ...
@@ -362,10 +357,9 @@ distclean-compile:
362 362
 	-rm -f *.tab.c
363 363
 
364 364
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdiff.Po@am__quote@
365
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgparser.Po@am__quote@
366 365
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
367 366
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@
368
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@
367
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/optparser.Po@am__quote@
369 368
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/output.Po@am__quote@
370 369
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sha256.Po@am__quote@
371 370
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sigtool.Po@am__quote@
... ...
@@ -421,19 +415,19 @@ getopt.obj: $(top_srcdir)/shared/getopt.c
421 421
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
422 422
 @am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.obj `if test -f '$(top_srcdir)/shared/getopt.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/getopt.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/getopt.c'; fi`
423 423
 
424
-cfgparser.o: $(top_srcdir)/shared/cfgparser.c
425
-@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cfgparser.o -MD -MP -MF $(DEPDIR)/cfgparser.Tpo -c -o cfgparser.o `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c
426
-@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/cfgparser.Tpo $(DEPDIR)/cfgparser.Po
427
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.o' libtool=no @AMDEPBACKSLASH@
424
+optparser.o: $(top_srcdir)/shared/optparser.c
425
+@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT optparser.o -MD -MP -MF $(DEPDIR)/optparser.Tpo -c -o optparser.o `test -f '$(top_srcdir)/shared/optparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/optparser.c
426
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/optparser.Tpo $(DEPDIR)/optparser.Po
427
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/optparser.c' object='optparser.o' libtool=no @AMDEPBACKSLASH@
428 428
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
429
-@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.o `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c
429
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o optparser.o `test -f '$(top_srcdir)/shared/optparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/optparser.c
430 430
 
431
-cfgparser.obj: $(top_srcdir)/shared/cfgparser.c
432
-@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cfgparser.obj -MD -MP -MF $(DEPDIR)/cfgparser.Tpo -c -o cfgparser.obj `if test -f '$(top_srcdir)/shared/cfgparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/cfgparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/cfgparser.c'; fi`
433
-@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/cfgparser.Tpo $(DEPDIR)/cfgparser.Po
434
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.obj' libtool=no @AMDEPBACKSLASH@
431
+optparser.obj: $(top_srcdir)/shared/optparser.c
432
+@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT optparser.obj -MD -MP -MF $(DEPDIR)/optparser.Tpo -c -o optparser.obj `if test -f '$(top_srcdir)/shared/optparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/optparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/optparser.c'; fi`
433
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/optparser.Tpo $(DEPDIR)/optparser.Po
434
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/optparser.c' object='optparser.obj' libtool=no @AMDEPBACKSLASH@
435 435
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
436
-@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.obj `if test -f '$(top_srcdir)/shared/cfgparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/cfgparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/cfgparser.c'; fi`
436
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o optparser.obj `if test -f '$(top_srcdir)/shared/optparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/optparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/optparser.c'; fi`
437 437
 
438 438
 misc.o: $(top_srcdir)/shared/misc.c
439 439
 @am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT misc.o -MD -MP -MF $(DEPDIR)/misc.Tpo -c -o misc.o `test -f '$(top_srcdir)/shared/misc.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/misc.c
... ...
@@ -449,20 +443,6 @@ misc.obj: $(top_srcdir)/shared/misc.c
449 449
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
450 450
 @am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.obj `if test -f '$(top_srcdir)/shared/misc.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/misc.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/misc.c'; fi`
451 451
 
452
-options.o: $(top_srcdir)/shared/options.c
453
-@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.o -MD -MP -MF $(DEPDIR)/options.Tpo -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c
454
-@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/options.Tpo $(DEPDIR)/options.Po
455
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/options.c' object='options.o' libtool=no @AMDEPBACKSLASH@
456
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
457
-@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c
458
-
459
-options.obj: $(top_srcdir)/shared/options.c
460
-@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.obj -MD -MP -MF $(DEPDIR)/options.Tpo -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi`
461
-@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/options.Tpo $(DEPDIR)/options.Po
462
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/options.c' object='options.obj' libtool=no @AMDEPBACKSLASH@
463
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
464
-@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi`
465
-
466 452
 sha256.o: $(top_srcdir)/shared/sha256.c
467 453
 @am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sha256.o -MD -MP -MF $(DEPDIR)/sha256.Tpo -c -o sha256.o `test -f '$(top_srcdir)/shared/sha256.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/sha256.c
468 454
 @am__fastdepCC_TRUE@	mv -f $(DEPDIR)/sha256.Tpo $(DEPDIR)/sha256.Po
... ...
@@ -47,9 +47,8 @@
47 47
 
48 48
 #include "vba.h"
49 49
 
50
-#include "shared/options.h"
51 50
 #include "shared/output.h"
52
-#include "shared/cfgparser.h"
51
+#include "shared/optparser.h"
53 52
 #include "shared/misc.h"
54 53
 #include "shared/cdiff.h"
55 54
 #include "shared/sha256.h"
... ...
@@ -118,15 +117,15 @@ static int hexdump(void)
118 118
     return 0;
119 119
 }
120 120
 
121
-static int md5sig(struct optstruct *opt, unsigned int mdb)
121
+static int md5sig(const struct optstruct *opts, unsigned int mdb)
122 122
 {
123 123
 	char *md5, *filename;
124 124
 	unsigned int i;
125 125
 	struct stat sb;
126 126
 
127 127
 
128
-    if(opt->filename) {
129
-	for(i = 0; (filename = cli_strtok(opt->filename, i, "\t")); i++) {
128
+    if(opts->filename) {
129
+	for(i = 0; (filename = cli_strtok(opts->filename, i, "\t")); i++) {
130 130
 	    if(stat(filename, &sb) == -1) {
131 131
 		mprintf("!md5sig: Can't access file %s\n", filename);
132 132
 		perror("md5sig");
... ...
@@ -163,13 +162,13 @@ static int md5sig(struct optstruct *opt, unsigned int mdb)
163 163
     return 0;
164 164
 }
165 165
 
166
-static int htmlnorm(struct optstruct *opt)
166
+static int htmlnorm(const struct optstruct *opts)
167 167
 {
168 168
 	int fd;
169 169
 
170 170
 
171
-    if((fd = open(opt_arg(opt, "html-normalise"), O_RDONLY)) == -1) {
172
-	mprintf("!htmlnorm: Can't open file %s\n", opt_arg(opt, "html-normalise"));
171
+    if((fd = open(optget(opts, "html-normalise")->strarg, O_RDONLY)) == -1) {
172
+	mprintf("!htmlnorm: Can't open file %s\n", optget(opts, "html-normalise")->strarg);
173 173
 	return -1;
174 174
     }
175 175
 
... ...
@@ -179,14 +178,14 @@ static int htmlnorm(struct optstruct *opt)
179 179
     return 0;
180 180
 }
181 181
 
182
-static int utf16decode(struct optstruct *opt)
182
+static int utf16decode(const struct optstruct *opts)
183 183
 {
184 184
 	const char *fname;
185 185
 	char *newname, buff[512], *decoded;
186 186
 	int fd1, fd2, bytes;
187 187
 
188 188
 
189
-    fname = opt_arg(opt, "utf16-decode");
189
+    fname = optget(opts, "utf16-decode")->strarg;
190 190
     if((fd1 = open(fname, O_RDONLY)) == -1) {
191 191
 	mprintf("!utf16decode: Can't open file %s\n", fname);
192 192
 	return -1;
... ...
@@ -411,7 +410,7 @@ static int writeinfo(const char *dbname, const char *header)
411 411
 static int diffdirs(const char *old, const char *new, const char *patch);
412 412
 static int verifydiff(const char *diff, const char *cvd, const char *incdir);
413 413
 
414
-static int script2cdiff(const char *script, const char *builder, struct optstruct *opt)
414
+static int script2cdiff(const char *script, const char *builder, const struct optstruct *opts)
415 415
 {
416 416
 	char *cdiff, *pt, buffer[FILEBUFF];
417 417
 	unsigned char digest[32];
... ...
@@ -508,7 +507,7 @@ static int script2cdiff(const char *script, const char *builder, struct optstruc
508 508
     sha256_final(&ctx);
509 509
     sha256_digest(&ctx, digest);
510 510
 
511
-    if(!(pt = getdsig(opt_arg(opt, "server"), builder, digest, 32, 1))) {
511
+    if(!(pt = getdsig(optget(opts, "server")->strarg, builder, digest, 32, 1))) {
512 512
 	mprintf("!script2cdiff: Can't get digital signature from remote server\n");
513 513
 	unlink(cdiff);
514 514
 	free(cdiff);
... ...
@@ -531,7 +530,7 @@ static int script2cdiff(const char *script, const char *builder, struct optstruc
531 531
     return 0;
532 532
 }
533 533
 
534
-static int build(struct optstruct *opt)
534
+static int build(const struct optstruct *opts)
535 535
 {
536 536
 	int ret;
537 537
 	size_t bytes;
... ...
@@ -548,7 +547,7 @@ static int build(struct optstruct *opt)
548 548
 	struct cl_cvd *oldcvd;
549 549
 
550 550
 
551
-    if(!opt_check(opt, "server")) {
551
+    if(!optget(opts, "server")->enabled) {
552 552
 	mprintf("!build: --server is required for --build\n");
553 553
 	return -1;
554 554
     }
... ...
@@ -558,7 +557,7 @@ static int build(struct optstruct *opt)
558 558
 	return -1;
559 559
     }
560 560
 
561
-    dbname = strstr(opt_arg(opt, "build"), "main") ? "main" : "daily";
561
+    dbname = strstr(optget(opts, "build")->strarg, "main") ? "main" : "daily";
562 562
 
563 563
     if(!(engine = cl_engine_new())) {
564 564
 	mprintf("!build: Can't initialize antivirus engine\n");
... ...
@@ -589,9 +588,9 @@ static int build(struct optstruct *opt)
589 589
     }
590 590
 
591 591
     /* try to read cvd header of current database */
592
-    if(opt->filename) {
593
-	if(cli_strbcasestr(opt->filename, ".cvd") || cli_strbcasestr(opt->filename, ".cld")) {
594
-	    strncpy(olddb, opt->filename, sizeof(olddb));
592
+    if(opts->filename) {
593
+	if(cli_strbcasestr(opts->filename, ".cvd") || cli_strbcasestr(opts->filename, ".cld")) {
594
+	    strncpy(olddb, opts->filename, sizeof(olddb));
595 595
 	    olddb[sizeof(olddb)-1]='\0';
596 596
 	} else {
597 597
 	    mprintf("!build: Not a CVD/CLD file\n");
... ...
@@ -736,7 +735,7 @@ static int build(struct optstruct *opt)
736 736
     sprintf(header + strlen(header), "%s:", pt);
737 737
     free(pt);
738 738
 
739
-    if(!(pt = getdsig(opt_arg(opt, "server"), builder, buffer, 16, 0))) {
739
+    if(!(pt = getdsig(optget(opts, "server")->strarg, builder, buffer, 16, 0))) {
740 740
 	mprintf("!build: Can't get digital signature from remote server\n");
741 741
 	fclose(fh);
742 742
 	unlink(tarfile);
... ...
@@ -757,7 +756,7 @@ static int build(struct optstruct *opt)
757 757
 	strcat(header, " ");
758 758
 
759 759
     /* build the final database */
760
-    newcvd = opt_arg(opt, "build");
760
+    newcvd = optget(opts, "build")->strarg;
761 761
     if(!(cvd = fopen(newcvd, "wb"))) {
762 762
 	mprintf("!build: Can't create final database %s\n", newcvd);
763 763
 	fclose(fh);
... ...
@@ -879,24 +878,24 @@ static int build(struct optstruct *opt)
879 879
 	    mprintf("!Generated file is incorrect, renamed to %s\n", broken);
880 880
 	}
881 881
     } else {
882
-	ret = script2cdiff(patch, builder, opt);
882
+	ret = script2cdiff(patch, builder, opts);
883 883
     }
884 884
 
885 885
     return ret;
886 886
 }
887 887
 
888
-static int unpack(struct optstruct *opt)
888
+static int unpack(const struct optstruct *opts)
889 889
 {
890 890
 	char name[512], *dbdir;
891 891
 
892 892
 
893
-    if(opt_check(opt, "unpack-current")) {
893
+    if(optget(opts, "unpack-current")->enabled) {
894 894
 	dbdir = freshdbdir();
895
-	snprintf(name, sizeof(name), "%s/%s.cvd", dbdir, opt_arg(opt, "unpack-current"));
895
+	snprintf(name, sizeof(name), "%s/%s.cvd", dbdir, optget(opts, "unpack-current")->strarg);
896 896
 	if(access(name, R_OK)) {
897
-	    snprintf(name, sizeof(name), "%s/%s.cld", dbdir, opt_arg(opt, "unpack-current"));
897
+	    snprintf(name, sizeof(name), "%s/%s.cld", dbdir, optget(opts, "unpack-current")->strarg);
898 898
 	    if(access(name, R_OK)) {
899
-		mprintf("!unpack: Couldn't find %s CLD/CVD database\n", opt_arg(opt, "unpack-current"));
899
+		mprintf("!unpack: Couldn't find %s CLD/CVD database\n", optget(opts, "unpack-current")->strarg);
900 900
 		free(dbdir);
901 901
 		return -1;
902 902
 	    }
... ...
@@ -904,7 +903,7 @@ static int unpack(struct optstruct *opt)
904 904
 	free(dbdir);
905 905
 
906 906
     } else {
907
-	strncpy(name, opt_arg(opt, "unpack"), sizeof(name));
907
+	strncpy(name, optget(opts, "unpack")->strarg, sizeof(name));
908 908
 	name[sizeof(name)-1]='\0';
909 909
     }
910 910
 
... ...
@@ -916,14 +915,14 @@ static int unpack(struct optstruct *opt)
916 916
     return 0;
917 917
 }
918 918
 
919
-static int cvdinfo(struct optstruct *opt)
919
+static int cvdinfo(const struct optstruct *opts)
920 920
 {
921 921
 	struct cl_cvd *cvd;
922 922
 	char *pt;
923 923
 	int ret;
924 924
 
925 925
 
926
-    pt = opt_arg(opt, "info");
926
+    pt = optget(opts, "info")->strarg;
927 927
     if((cvd = cl_cvdhead(pt)) == NULL) {
928 928
 	mprintf("!cvdinfo: Can't read/parse CVD header of %s\n", pt);
929 929
 	return -1;
... ...
@@ -938,7 +937,7 @@ static int cvdinfo(struct optstruct *opt)
938 938
     mprintf("Functionality level: %u\n", cvd->fl);
939 939
     mprintf("Builder: %s\n", cvd->builder);
940 940
 
941
-    pt = opt_arg(opt, "info");
941
+    pt = optget(opts, "info")->strarg;
942 942
     if(cli_strbcasestr(pt, ".cvd")) {
943 943
 	mprintf("MD5: %s\n", cvd->md5);
944 944
 	mprintf("Digital signature: %s\n", cvd->dsig);
... ...
@@ -1162,27 +1161,37 @@ static int listdb(const char *filename)
1162 1162
     return 0;
1163 1163
 }
1164 1164
 
1165
-static int listsigs(struct optstruct *opt)
1165
+static int listsigs(const struct optstruct *opts)
1166 1166
 {
1167 1167
 	int ret;
1168 1168
 	const char *name;
1169 1169
 	char *dbdir;
1170
+	struct stat sb;
1170 1171
 
1171 1172
 
1172
-    mprintf_stdout = 1;
1173
+    name = optget(opts, "list-sigs")->strarg;
1174
+    if(stat(name, &sb) == -1) {
1175
+	mprintf("--list-sigs: Can't get status of %s\n", name);
1176
+	return -1;
1177
+    }
1173 1178
 
1174
-    if((name = opt_arg(opt, "list-sigs"))) {
1175
-	ret = listdb(name);
1179
+    mprintf_stdout = 1;
1180
+    if(S_ISDIR(sb.st_mode)) {
1181
+	if(!strcmp(name, DATADIR)) {
1182
+	    dbdir = freshdbdir();
1183
+	    ret = listdir(dbdir);
1184
+	    free(dbdir);
1185
+	} else {
1186
+	    ret = listdir(name);
1187
+	}
1176 1188
     } else {
1177
-	dbdir = freshdbdir();
1178
-	ret = listdir(dbdir);
1179
-	free(dbdir);
1189
+	ret = listdb(name);
1180 1190
     }
1181 1191
 
1182 1192
     return ret;
1183 1193
 }
1184 1194
 
1185
-static int vbadump(struct optstruct *opt)
1195
+static int vbadump(const struct optstruct *opts)
1186 1196
 {
1187 1197
 	int fd, hex_output;
1188 1198
 	char *dir;
... ...
@@ -1190,12 +1199,12 @@ static int vbadump(struct optstruct *opt)
1190 1190
 	struct uniq *vba = NULL;
1191 1191
 
1192 1192
 
1193
-    if(opt_check(opt, "vba-hex")) {
1193
+    if(optget(opts, "vba-hex")->enabled) {
1194 1194
 	hex_output = 1;
1195
-	pt = opt_arg(opt, "vba-hex");
1195
+	pt = optget(opts, "vba-hex")->strarg;
1196 1196
     } else {
1197 1197
 	hex_output = 0;
1198
-	pt = opt_arg(opt, "vba");
1198
+	pt = optget(opts, "vba")->strarg;
1199 1199
     }
1200 1200
  
1201 1201
     if((fd = open(pt, O_RDONLY)) == -1) {
... ...
@@ -1281,14 +1290,14 @@ static int comparemd5(const char *dbname)
1281 1281
 }
1282 1282
 
1283 1283
 
1284
-static int rundiff(struct optstruct *opt)
1284
+static int rundiff(const struct optstruct *opts)
1285 1285
 {
1286 1286
 	int fd, ret;
1287 1287
 	unsigned short mode;
1288 1288
 	const char *diff;
1289 1289
 
1290 1290
 
1291
-    diff = opt_arg(opt, "run-cdiff");
1291
+    diff = optget(opts, "run-cdiff")->strarg;
1292 1292
     if(strstr(diff, ".cdiff")) {
1293 1293
 	mode = 1;
1294 1294
     } else if(strstr(diff, ".script")) {
... ...
@@ -1589,7 +1598,7 @@ static int diffdirs(const char *old, const char *new, const char *patch)
1589 1589
     return 0;
1590 1590
 }
1591 1591
 
1592
-static int makediff(struct optstruct *opt)
1592
+static int makediff(const struct optstruct *opts)
1593 1593
 {
1594 1594
 	char *odir, *ndir, name[32], broken[32];
1595 1595
 	struct cl_cvd *cvd;
... ...
@@ -1597,20 +1606,20 @@ static int makediff(struct optstruct *opt)
1597 1597
 	int ret;
1598 1598
 
1599 1599
 
1600
-    if(!opt->filename) {
1600
+    if(!opts->filename) {
1601 1601
 	mprintf("!makediff: --diff requires two arguments\n");
1602 1602
 	return -1;
1603 1603
     }
1604 1604
 
1605
-    if(!(cvd = cl_cvdhead(opt->filename))) {
1606
-	mprintf("!makediff: Can't read CVD header from %s\n", opt->filename);
1605
+    if(!(cvd = cl_cvdhead(opts->filename))) {
1606
+	mprintf("!makediff: Can't read CVD header from %s\n", opts->filename);
1607 1607
 	return -1;
1608 1608
     }
1609 1609
     newver = cvd->version;
1610 1610
     free(cvd);
1611 1611
 
1612
-    if(!(cvd = cl_cvdhead(opt_arg(opt, "diff")))) {
1613
-	mprintf("!makediff: Can't read CVD header from %s\n", opt_arg(opt, "diff"));
1612
+    if(!(cvd = cl_cvdhead(optget(opts, "diff")->strarg))) {
1613
+	mprintf("!makediff: Can't read CVD header from %s\n", optget(opts, "diff")->strarg);
1614 1614
 	return -1;
1615 1615
     }
1616 1616
     oldver = cvd->version;
... ...
@@ -1633,8 +1642,8 @@ static int makediff(struct optstruct *opt)
1633 1633
 	return -1;
1634 1634
     }
1635 1635
 
1636
-    if(cvd_unpack(opt_arg(opt, "diff"), odir) == -1) {
1637
-	mprintf("!makediff: Can't unpack CVD file %s\n", opt_arg(opt, "diff"));
1636
+    if(cvd_unpack(optget(opts, "diff")->strarg, odir) == -1) {
1637
+	mprintf("!makediff: Can't unpack CVD file %s\n", optget(opts, "diff")->strarg);
1638 1638
 	cli_rmdirs(odir);
1639 1639
 	free(odir);
1640 1640
 	return -1;
... ...
@@ -1656,8 +1665,8 @@ static int makediff(struct optstruct *opt)
1656 1656
 	return -1;
1657 1657
     }
1658 1658
 
1659
-    if(cvd_unpack(opt->filename, ndir) == -1) {
1660
-	mprintf("!makediff: Can't unpack CVD file %s\n", opt->filename);
1659
+    if(cvd_unpack(opts->filename, ndir) == -1) {
1660
+	mprintf("!makediff: Can't unpack CVD file %s\n", opts->filename);
1661 1661
 	cli_rmdirs(odir);
1662 1662
 	cli_rmdirs(ndir);
1663 1663
 	free(odir);
... ...
@@ -1665,7 +1674,7 @@ static int makediff(struct optstruct *opt)
1665 1665
 	return -1;
1666 1666
     }
1667 1667
 
1668
-    if(strstr(opt->filename, "main"))
1668
+    if(strstr(opts->filename, "main"))
1669 1669
 	snprintf(name, sizeof(name), "main-%u.script", newver);
1670 1670
     else
1671 1671
 	snprintf(name, sizeof(name), "daily-%u.script", newver);
... ...
@@ -1680,7 +1689,7 @@ static int makediff(struct optstruct *opt)
1680 1680
     if(ret == -1)
1681 1681
 	return -1;
1682 1682
 
1683
-    if(verifydiff(name, opt_arg(opt, "diff"), NULL) == -1) {
1683
+    if(verifydiff(name, optget(opts, "diff")->strarg, NULL) == -1) {
1684 1684
 	snprintf(broken, sizeof(broken), "%s.broken", name);
1685 1685
 	if(rename(name, broken)) {
1686 1686
 	    unlink(name);
... ...
@@ -1731,107 +1740,80 @@ static void help(void)
1731 1731
 int main(int argc, char **argv)
1732 1732
 {
1733 1733
 	int ret = 1;
1734
-        struct optstruct *opt;
1734
+        struct optstruct *opts;
1735 1735
 	struct stat sb;
1736
-	const char *short_options = "hvVb:i:u:l::r:d:";
1737
-	static struct option long_options[] = {
1738
-	    {"help", 0, 0, 'h'},
1739
-	    {"quiet", 0, 0, 0},
1740
-	    {"debug", 0, 0, 0},
1741
-	    {"verbose", 0, 0, 'v'},
1742
-	    {"stdout", 0, 0, 0},
1743
-	    {"version", 0, 0, 'V'},
1744
-	    {"tempdir", 1, 0, 0},
1745
-	    {"hex-dump", 0, 0, 0},
1746
-	    {"md5", 0, 0, 0},
1747
-	    {"mdb", 0, 0, 0},
1748
-	    {"html-normalise", 1, 0, 0},
1749
-	    {"utf16-decode", 1, 0, 0},
1750
-	    {"build", 1, 0, 'b'},
1751
-	    {"server", 1, 0, 0},
1752
-	    {"unpack", 1, 0, 'u'},
1753
-	    {"unpack-current", 1, 0, 0},
1754
-	    {"info", 1, 0, 'i'},
1755
-	    {"list-sigs", 2, 0, 'l'},
1756
-	    {"vba", 1, 0 ,0},
1757
-	    {"vba-hex", 1, 0, 0},
1758
-	    {"diff", 1, 0, 'd'},
1759
-	    {"run-cdiff", 1, 0, 'r'},
1760
-	    {"verify-cdiff", 1, 0, 0},
1761
-	    {0, 0, 0, 0}
1762
-    	};
1763
-
1764
-    opt = opt_parse(argc, argv, short_options, long_options, NULL, NULL);
1765
-    if(!opt) {
1766
-	mprintf("!Can't parse the command line\n");
1736
+
1737
+    opts = optparse(NULL, argc, argv, 1, OPT_SIGTOOL, 0, NULL);
1738
+    if(!opts) {
1739
+	mprintf("!Can't parse command line options\n");
1767 1740
 	return 1;
1768 1741
     }
1769 1742
 
1770
-    if(opt_check(opt, "quiet"))
1743
+    if(optget(opts, "quiet")->enabled)
1771 1744
 	mprintf_quiet = 1;
1772 1745
 
1773
-    if(opt_check(opt, "stdout"))
1746
+    if(optget(opts, "stdout")->enabled)
1774 1747
 	mprintf_stdout = 1;
1775 1748
 
1776
-    if(opt_check(opt, "debug"))
1749
+    if(optget(opts, "debug")->enabled)
1777 1750
 	cl_debug();
1778 1751
 
1779
-    if(opt_check(opt, "version")) {
1752
+    if(optget(opts, "version")->enabled) {
1780 1753
 	print_version(NULL);
1781
-	opt_free(opt);
1754
+	optfree(opts);
1782 1755
 	return 0;
1783 1756
     }
1784 1757
 
1785
-    if(opt_check(opt, "help")) {
1786
-	opt_free(opt);
1758
+    if(optget(opts, "help")->enabled) {
1759
+	optfree(opts);
1787 1760
     	help();
1788 1761
 	return 0;
1789 1762
     }
1790 1763
 
1791
-    if(opt_check(opt, "hex-dump"))
1764
+    if(optget(opts, "hex-dump")->enabled)
1792 1765
 	ret = hexdump();
1793
-    else if(opt_check(opt, "md5"))
1794
-	ret = md5sig(opt, 0);
1795
-    else if(opt_check(opt, "mdb"))
1796
-	ret = md5sig(opt, 1);
1797
-    else if(opt_check(opt, "html-normalise"))
1798
-	ret = htmlnorm(opt);
1799
-    else if(opt_check(opt, "utf16-decode"))
1800
-	ret = utf16decode(opt);
1801
-    else if(opt_check(opt, "build"))
1802
-	ret = build(opt);
1803
-    else if(opt_check(opt, "unpack"))
1804
-	ret = unpack(opt);
1805
-    else if(opt_check(opt, "unpack-current"))
1806
-	ret = unpack(opt);
1807
-    else if(opt_check(opt, "info"))
1808
-	ret = cvdinfo(opt);
1809
-    else if(opt_check(opt, "list-sigs"))
1810
-	ret = listsigs(opt);
1811
-    else if(opt_check(opt, "vba") || opt_check(opt, "vba-hex"))
1812
-	ret = vbadump(opt);
1813
-    else if(opt_check(opt, "diff"))
1814
-	ret = makediff(opt);
1815
-    else if(opt_check(opt, "run-cdiff"))
1816
-	ret = rundiff(opt);
1817
-    else if(opt_check(opt, "verify-cdiff")) {
1818
-	if(!opt->filename) {
1766
+    else if(optget(opts, "md5")->enabled)
1767
+	ret = md5sig(opts, 0);
1768
+    else if(optget(opts, "mdb")->enabled)
1769
+	ret = md5sig(opts, 1);
1770
+    else if(optget(opts, "html-normalise")->enabled)
1771
+	ret = htmlnorm(opts);
1772
+    else if(optget(opts, "utf16-decode")->enabled)
1773
+	ret = utf16decode(opts);
1774
+    else if(optget(opts, "build")->enabled)
1775
+	ret = build(opts);
1776
+    else if(optget(opts, "unpack")->enabled)
1777
+	ret = unpack(opts);
1778
+    else if(optget(opts, "unpack-current")->enabled)
1779
+	ret = unpack(opts);
1780
+    else if(optget(opts, "info")->enabled)
1781
+	ret = cvdinfo(opts);
1782
+    else if(optget(opts, "list-sigs")->active)
1783
+	ret = listsigs(opts);
1784
+    else if(optget(opts, "vba")->enabled || optget(opts, "vba-hex")->enabled)
1785
+	ret = vbadump(opts);
1786
+    else if(optget(opts, "diff")->enabled)
1787
+	ret = makediff(opts);
1788
+    else if(optget(opts, "run-cdiff")->enabled)
1789
+	ret = rundiff(opts);
1790
+    else if(optget(opts, "verify-cdiff")->enabled) {
1791
+	if(!opts->filename) {
1819 1792
 	    mprintf("!--verify-cdiff requires two arguments\n");
1820 1793
 	    ret = -1;
1821 1794
 	} else {
1822
-	    if(stat(opt->filename, &sb) == -1) {
1823
-		mprintf("--verify-cdiff: Can't get status of %s\n", opt->filename);
1795
+	    if(stat(opts->filename, &sb) == -1) {
1796
+		mprintf("--verify-cdiff: Can't get status of %s\n", opts->filename);
1824 1797
 		ret = -1;
1825 1798
 	    } else {
1826 1799
 		if(S_ISDIR(sb.st_mode))
1827
-		    ret = verifydiff(opt_arg(opt, "verify-cdiff"), NULL, opt->filename);
1800
+		    ret = verifydiff(optget(opts, "verify-cdiff")->strarg, NULL, opts->filename);
1828 1801
 		else
1829
-		    ret = verifydiff(opt_arg(opt, "verify-cdiff"), opt->filename, NULL);
1802
+		    ret = verifydiff(optget(opts, "verify-cdiff")->strarg, opts->filename, NULL);
1830 1803
 	    }
1831 1804
 	}
1832 1805
     } else
1833 1806
 	help();
1834 1807
 
1835
-    opt_free(opt);
1808
+    optfree(opts);
1836 1809
     return ret ? 1 : 0;
1837 1810
 }