git-svn: trunk@4589
Tomasz Kojm authored on 2009/01/03 02:04:111 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,22 @@ |
0 |
+getopt.c - my re-implementation of getopt. |
|
1 |
+Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler |
|
2 |
+ |
|
3 |
+Permission is hereby granted, free of charge, to any person |
|
4 |
+obtaining a copy of this software and associated documentation |
|
5 |
+files (the "Software"), to deal in the Software without |
|
6 |
+restriction, including without limitation the rights to use, copy, |
|
7 |
+modify, merge, publish, distribute, sublicense, and/or sell copies |
|
8 |
+of the Software, and to permit persons to whom the Software is |
|
9 |
+furnished to do so, subject to the following conditions: |
|
10 |
+ |
|
11 |
+The above copyright notice and this permission notice shall be |
|
12 |
+included in all copies or substantial portions of the Software. |
|
13 |
+ |
|
14 |
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
15 |
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
16 |
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
17 |
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
18 |
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
19 |
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
20 |
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
21 |
+DEALINGS IN THE SOFTWARE. |
... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Fri Jan 2 18:16:45 CET 2009 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * shared, clamconf: drop old stuff; replace getopt.[ch] with my_getopt |
|
4 |
+ |
|
1 | 5 |
Fri Jan 2 13:08:09 CET 2009 (tk) |
2 | 6 |
--------------------------------- |
3 | 7 |
* shared/optparser.c, clamav-milter: use the new option parser (bb#1215) |
... | ... |
@@ -19,7 +19,7 @@ |
19 | 19 |
ACLOCAL_AMFLAGS=-I m4 |
20 | 20 |
|
21 | 21 |
SUBDIRS = libltdl libclamav clamscan clamd clamdscan freshclam sigtool clamconf database docs etc clamav-milter test unit_tests |
22 |
-EXTRA_DIST = FAQ examples BUGS shared libclamav.pc.in UPGRADE COPYING.bzip2 COPYING.lzma COPYING.unrar COPYING.LGPL COPYING.file COPYING.zlib COPYING.BSD |
|
22 |
+EXTRA_DIST = FAQ examples BUGS shared libclamav.pc.in UPGRADE COPYING.bzip2 COPYING.lzma COPYING.unrar COPYING.LGPL COPYING.file COPYING.zlib COPYING.BSD COPYING.getopt |
|
23 | 23 |
|
24 | 24 |
bin_SCRIPTS=clamav-config |
25 | 25 |
|
... | ... |
@@ -282,7 +282,7 @@ top_builddir = @top_builddir@ |
282 | 282 |
top_srcdir = @top_srcdir@ |
283 | 283 |
ACLOCAL_AMFLAGS = -I m4 |
284 | 284 |
SUBDIRS = libltdl libclamav clamscan clamd clamdscan freshclam sigtool clamconf database docs etc clamav-milter test unit_tests |
285 |
-EXTRA_DIST = FAQ examples BUGS shared libclamav.pc.in UPGRADE COPYING.bzip2 COPYING.lzma COPYING.unrar COPYING.LGPL COPYING.file COPYING.zlib COPYING.BSD |
|
285 |
+EXTRA_DIST = FAQ examples BUGS shared libclamav.pc.in UPGRADE COPYING.bzip2 COPYING.lzma COPYING.unrar COPYING.LGPL COPYING.file COPYING.zlib COPYING.BSD COPYING.getopt |
|
286 | 286 |
bin_SCRIPTS = clamav-config |
287 | 287 |
pkgconfigdir = $(libdir)/pkgconfig |
288 | 288 |
pkgconfig_DATA = libclamav.pc |
... | ... |
@@ -16,16 +16,16 @@ |
16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
17 | 17 |
# MA 02110-1301, USA. |
18 | 18 |
|
19 |
-bin_PROGRAMS = clamconf |
|
19 |
+#bin_PROGRAMS = clamconf |
|
20 | 20 |
|
21 |
-clamconf_SOURCES = \ |
|
22 |
- $(top_srcdir)/shared/cfgparser.c \ |
|
23 |
- $(top_srcdir)/shared/cfgparser.h \ |
|
24 |
- $(top_srcdir)/shared/misc.c \ |
|
25 |
- $(top_srcdir)/shared/misc.h \ |
|
26 |
- $(top_srcdir)/shared/getopt.c \ |
|
27 |
- $(top_srcdir)/shared/getopt.h \ |
|
28 |
- clamconf.c |
|
21 |
+#clamconf_SOURCES = \ |
|
22 |
+# $(top_srcdir)/shared/cfgparser.c \ |
|
23 |
+# $(top_srcdir)/shared/cfgparser.h \ |
|
24 |
+# $(top_srcdir)/shared/misc.c \ |
|
25 |
+# $(top_srcdir)/shared/misc.h \ |
|
26 |
+# $(top_srcdir)/shared/getopt.c \ |
|
27 |
+# $(top_srcdir)/shared/getopt.h \ |
|
28 |
+# clamconf.c |
|
29 | 29 |
|
30 | 30 |
DEFS = @DEFS@ -DCL_NOTHREADS |
31 | 31 |
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav |
... | ... |
@@ -32,6 +32,16 @@ |
32 | 32 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
33 | 33 |
# MA 02110-1301, USA. |
34 | 34 |
|
35 |
+#bin_PROGRAMS = clamconf |
|
36 |
+ |
|
37 |
+#clamconf_SOURCES = \ |
|
38 |
+# $(top_srcdir)/shared/cfgparser.c \ |
|
39 |
+# $(top_srcdir)/shared/cfgparser.h \ |
|
40 |
+# $(top_srcdir)/shared/misc.c \ |
|
41 |
+# $(top_srcdir)/shared/misc.h \ |
|
42 |
+# $(top_srcdir)/shared/getopt.c \ |
|
43 |
+# $(top_srcdir)/shared/getopt.h \ |
|
44 |
+# clamconf.c |
|
35 | 45 |
VPATH = @srcdir@ |
36 | 46 |
pkgdatadir = $(datadir)/@PACKAGE@ |
37 | 47 |
pkglibdir = $(libdir)/@PACKAGE@ |
... | ... |
@@ -51,7 +61,6 @@ POST_UNINSTALL = : |
51 | 51 |
build_triplet = @build@ |
52 | 52 |
host_triplet = @host@ |
53 | 53 |
target_triplet = @target@ |
54 |
-bin_PROGRAMS = clamconf$(EXEEXT) |
|
55 | 54 |
subdir = clamconf |
56 | 55 |
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in |
57 | 56 |
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 |
... | ... |
@@ -68,29 +77,8 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ |
68 | 68 |
mkinstalldirs = $(install_sh) -d |
69 | 69 |
CONFIG_HEADER = $(top_builddir)/clamav-config.h |
70 | 70 |
CONFIG_CLEAN_FILES = |
71 |
-am__installdirs = "$(DESTDIR)$(bindir)" |
|
72 |
-binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) |
|
73 |
-PROGRAMS = $(bin_PROGRAMS) |
|
74 |
-am_clamconf_OBJECTS = cfgparser.$(OBJEXT) misc.$(OBJEXT) \ |
|
75 |
- getopt.$(OBJEXT) clamconf.$(OBJEXT) |
|
76 |
-clamconf_OBJECTS = $(am_clamconf_OBJECTS) |
|
77 |
-clamconf_LDADD = $(LDADD) |
|
78 |
-DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) |
|
79 |
-depcomp = $(SHELL) $(top_srcdir)/config/depcomp |
|
80 |
-am__depfiles_maybe = depfiles |
|
81 |
-COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ |
|
82 |
- $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) |
|
83 |
-LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ |
|
84 |
- --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ |
|
85 |
- $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) |
|
86 |
-CCLD = $(CC) |
|
87 |
-LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ |
|
88 |
- --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ |
|
89 |
- $(LDFLAGS) -o $@ |
|
90 |
-SOURCES = $(clamconf_SOURCES) |
|
91 |
-DIST_SOURCES = $(clamconf_SOURCES) |
|
92 |
-ETAGS = etags |
|
93 |
-CTAGS = ctags |
|
71 |
+SOURCES = |
|
72 |
+DIST_SOURCES = |
|
94 | 73 |
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) |
95 | 74 |
ACLOCAL = @ACLOCAL@ |
96 | 75 |
AMTAR = @AMTAR@ |
... | ... |
@@ -248,21 +236,11 @@ target_os = @target_os@ |
248 | 248 |
target_vendor = @target_vendor@ |
249 | 249 |
top_builddir = @top_builddir@ |
250 | 250 |
top_srcdir = @top_srcdir@ |
251 |
-clamconf_SOURCES = \ |
|
252 |
- $(top_srcdir)/shared/cfgparser.c \ |
|
253 |
- $(top_srcdir)/shared/cfgparser.h \ |
|
254 |
- $(top_srcdir)/shared/misc.c \ |
|
255 |
- $(top_srcdir)/shared/misc.h \ |
|
256 |
- $(top_srcdir)/shared/getopt.c \ |
|
257 |
- $(top_srcdir)/shared/getopt.h \ |
|
258 |
- clamconf.c |
|
259 |
- |
|
260 | 251 |
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav |
261 | 252 |
CLEANFILES = *.gcda *.gcno |
262 | 253 |
all: all-am |
263 | 254 |
|
264 | 255 |
.SUFFIXES: |
265 |
-.SUFFIXES: .c .lo .o .obj |
|
266 | 256 |
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) |
267 | 257 |
@for dep in $?; do \ |
268 | 258 |
case '$(am__configure_deps)' in \ |
... | ... |
@@ -292,180 +270,18 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) |
292 | 292 |
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh |
293 | 293 |
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) |
294 | 294 |
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh |
295 |
-install-binPROGRAMS: $(bin_PROGRAMS) |
|
296 |
- @$(NORMAL_INSTALL) |
|
297 |
- test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" |
|
298 |
- @list='$(bin_PROGRAMS)'; for p in $$list; do \ |
|
299 |
- p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ |
|
300 |
- if test -f $$p \ |
|
301 |
- || test -f $$p1 \ |
|
302 |
- ; then \ |
|
303 |
- f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ |
|
304 |
- echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \ |
|
305 |
- $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \ |
|
306 |
- else :; fi; \ |
|
307 |
- done |
|
308 |
- |
|
309 |
-uninstall-binPROGRAMS: |
|
310 |
- @$(NORMAL_UNINSTALL) |
|
311 |
- @list='$(bin_PROGRAMS)'; for p in $$list; do \ |
|
312 |
- f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ |
|
313 |
- echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ |
|
314 |
- rm -f "$(DESTDIR)$(bindir)/$$f"; \ |
|
315 |
- done |
|
316 |
- |
|
317 |
-clean-binPROGRAMS: |
|
318 |
- @list='$(bin_PROGRAMS)'; for p in $$list; do \ |
|
319 |
- f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ |
|
320 |
- echo " rm -f $$p $$f"; \ |
|
321 |
- rm -f $$p $$f ; \ |
|
322 |
- done |
|
323 |
- |
|
324 |
-installcheck-binPROGRAMS: $(bin_PROGRAMS) |
|
325 |
- bad=0; pid=$$$$; list="$(bin_PROGRAMS)"; for p in $$list; do \ |
|
326 |
- case ' $(AM_INSTALLCHECK_STD_OPTIONS_EXEMPT) ' in \ |
|
327 |
- *" $$p "* | *" $(srcdir)/$$p "*) continue;; \ |
|
328 |
- esac; \ |
|
329 |
- f=`echo "$$p" | \ |
|
330 |
- sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ |
|
331 |
- for opt in --help --version; do \ |
|
332 |
- if "$(DESTDIR)$(bindir)/$$f" $$opt >c$${pid}_.out \ |
|
333 |
- 2>c$${pid}_.err </dev/null \ |
|
334 |
- && test -n "`cat c$${pid}_.out`" \ |
|
335 |
- && test -z "`cat c$${pid}_.err`"; then :; \ |
|
336 |
- else echo "$$f does not support $$opt" 1>&2; bad=1; fi; \ |
|
337 |
- done; \ |
|
338 |
- done; rm -f c$${pid}_.???; exit $$bad |
|
339 |
-clamconf$(EXEEXT): $(clamconf_OBJECTS) $(clamconf_DEPENDENCIES) |
|
340 |
- @rm -f clamconf$(EXEEXT) |
|
341 |
- $(LINK) $(clamconf_OBJECTS) $(clamconf_LDADD) $(LIBS) |
|
342 |
- |
|
343 |
-mostlyclean-compile: |
|
344 |
- -rm -f *.$(OBJEXT) |
|
345 |
- |
|
346 |
-distclean-compile: |
|
347 |
- -rm -f *.tab.c |
|
348 |
- |
|
349 |
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgparser.Po@am__quote@ |
|
350 |
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clamconf.Po@am__quote@ |
|
351 |
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@ |
|
352 |
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@ |
|
353 |
- |
|
354 |
-.c.o: |
|
355 |
-@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< |
|
356 |
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po |
|
357 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ |
|
358 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
359 |
-@am__fastdepCC_FALSE@ $(COMPILE) -c $< |
|
360 |
- |
|
361 |
-.c.obj: |
|
362 |
-@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` |
|
363 |
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po |
|
364 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ |
|
365 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
366 |
-@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` |
|
367 |
- |
|
368 |
-.c.lo: |
|
369 |
-@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< |
|
370 |
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo |
|
371 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ |
|
372 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
373 |
-@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< |
|
374 |
- |
|
375 |
-cfgparser.o: $(top_srcdir)/shared/cfgparser.c |
|
376 |
-@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 |
|
377 |
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/cfgparser.Tpo $(DEPDIR)/cfgparser.Po |
|
378 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.o' libtool=no @AMDEPBACKSLASH@ |
|
379 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
380 |
-@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 |
|
381 |
- |
|
382 |
-cfgparser.obj: $(top_srcdir)/shared/cfgparser.c |
|
383 |
-@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` |
|
384 |
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/cfgparser.Tpo $(DEPDIR)/cfgparser.Po |
|
385 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.obj' libtool=no @AMDEPBACKSLASH@ |
|
386 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
387 |
-@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` |
|
388 |
- |
|
389 |
-misc.o: $(top_srcdir)/shared/misc.c |
|
390 |
-@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 |
|
391 |
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/misc.Tpo $(DEPDIR)/misc.Po |
|
392 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/misc.c' object='misc.o' libtool=no @AMDEPBACKSLASH@ |
|
393 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
394 |
-@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.o `test -f '$(top_srcdir)/shared/misc.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/misc.c |
|
395 |
- |
|
396 |
-misc.obj: $(top_srcdir)/shared/misc.c |
|
397 |
-@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT misc.obj -MD -MP -MF $(DEPDIR)/misc.Tpo -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` |
|
398 |
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/misc.Tpo $(DEPDIR)/misc.Po |
|
399 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/misc.c' object='misc.obj' libtool=no @AMDEPBACKSLASH@ |
|
400 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
401 |
-@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` |
|
402 |
- |
|
403 |
-getopt.o: $(top_srcdir)/shared/getopt.c |
|
404 |
-@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT getopt.o -MD -MP -MF $(DEPDIR)/getopt.Tpo -c -o getopt.o `test -f '$(top_srcdir)/shared/getopt.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/getopt.c |
|
405 |
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/getopt.Tpo $(DEPDIR)/getopt.Po |
|
406 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/getopt.c' object='getopt.o' libtool=no @AMDEPBACKSLASH@ |
|
407 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
408 |
-@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.o `test -f '$(top_srcdir)/shared/getopt.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/getopt.c |
|
409 |
- |
|
410 |
-getopt.obj: $(top_srcdir)/shared/getopt.c |
|
411 |
-@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT getopt.obj -MD -MP -MF $(DEPDIR)/getopt.Tpo -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` |
|
412 |
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/getopt.Tpo $(DEPDIR)/getopt.Po |
|
413 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/shared/getopt.c' object='getopt.obj' libtool=no @AMDEPBACKSLASH@ |
|
414 |
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
|
415 |
-@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` |
|
416 | 295 |
|
417 | 296 |
mostlyclean-libtool: |
418 | 297 |
-rm -f *.lo |
419 | 298 |
|
420 | 299 |
clean-libtool: |
421 | 300 |
-rm -rf .libs _libs |
422 |
- |
|
423 |
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) |
|
424 |
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ |
|
425 |
- unique=`for i in $$list; do \ |
|
426 |
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ |
|
427 |
- done | \ |
|
428 |
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ |
|
429 |
- END { if (nonempty) { for (i in files) print i; }; }'`; \ |
|
430 |
- mkid -fID $$unique |
|
431 | 301 |
tags: TAGS |
302 |
+TAGS: |
|
432 | 303 |
|
433 |
-TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ |
|
434 |
- $(TAGS_FILES) $(LISP) |
|
435 |
- tags=; \ |
|
436 |
- here=`pwd`; \ |
|
437 |
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ |
|
438 |
- unique=`for i in $$list; do \ |
|
439 |
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ |
|
440 |
- done | \ |
|
441 |
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ |
|
442 |
- END { if (nonempty) { for (i in files) print i; }; }'`; \ |
|
443 |
- if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ |
|
444 |
- test -n "$$unique" || unique=$$empty_fix; \ |
|
445 |
- $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ |
|
446 |
- $$tags $$unique; \ |
|
447 |
- fi |
|
448 | 304 |
ctags: CTAGS |
449 |
-CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ |
|
450 |
- $(TAGS_FILES) $(LISP) |
|
451 |
- tags=; \ |
|
452 |
- list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ |
|
453 |
- unique=`for i in $$list; do \ |
|
454 |
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ |
|
455 |
- done | \ |
|
456 |
- $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ |
|
457 |
- END { if (nonempty) { for (i in files) print i; }; }'`; \ |
|
458 |
- test -z "$(CTAGS_ARGS)$$tags$$unique" \ |
|
459 |
- || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ |
|
460 |
- $$tags $$unique |
|
461 |
- |
|
462 |
-GTAGS: |
|
463 |
- here=`$(am__cd) $(top_builddir) && pwd` \ |
|
464 |
- && cd $(top_srcdir) \ |
|
465 |
- && gtags -i $(GTAGS_ARGS) $$here |
|
466 |
- |
|
467 |
-distclean-tags: |
|
468 |
- -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags |
|
305 |
+CTAGS: |
|
306 |
+ |
|
469 | 307 |
|
470 | 308 |
distdir: $(DISTFILES) |
471 | 309 |
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ |
... | ... |
@@ -495,11 +311,8 @@ distdir: $(DISTFILES) |
495 | 495 |
done |
496 | 496 |
check-am: all-am |
497 | 497 |
check: check-am |
498 |
-all-am: Makefile $(PROGRAMS) |
|
498 |
+all-am: Makefile |
|
499 | 499 |
installdirs: |
500 |
- for dir in "$(DESTDIR)$(bindir)"; do \ |
|
501 |
- test -z "$$dir" || $(MKDIR_P) "$$dir"; \ |
|
502 |
- done |
|
503 | 500 |
install: install-am |
504 | 501 |
install-exec: install-exec-am |
505 | 502 |
install-data: install-data-am |
... | ... |
@@ -527,13 +340,11 @@ maintainer-clean-generic: |
527 | 527 |
@echo "it deletes files that may require special tools to rebuild." |
528 | 528 |
clean: clean-am |
529 | 529 |
|
530 |
-clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am |
|
530 |
+clean-am: clean-generic clean-libtool mostlyclean-am |
|
531 | 531 |
|
532 | 532 |
distclean: distclean-am |
533 |
- -rm -rf ./$(DEPDIR) |
|
534 | 533 |
-rm -f Makefile |
535 |
-distclean-am: clean-am distclean-compile distclean-generic \ |
|
536 |
- distclean-tags |
|
534 |
+distclean-am: clean-am distclean-generic |
|
537 | 535 |
|
538 | 536 |
dvi: dvi-am |
539 | 537 |
|
... | ... |
@@ -549,7 +360,7 @@ install-data-am: |
549 | 549 |
|
550 | 550 |
install-dvi: install-dvi-am |
551 | 551 |
|
552 |
-install-exec-am: install-binPROGRAMS |
|
552 |
+install-exec-am: |
|
553 | 553 |
|
554 | 554 |
install-html: install-html-am |
555 | 555 |
|
... | ... |
@@ -561,17 +372,15 @@ install-pdf: install-pdf-am |
561 | 561 |
|
562 | 562 |
install-ps: install-ps-am |
563 | 563 |
|
564 |
-installcheck-am: installcheck-binPROGRAMS |
|
564 |
+installcheck-am: |
|
565 | 565 |
|
566 | 566 |
maintainer-clean: maintainer-clean-am |
567 |
- -rm -rf ./$(DEPDIR) |
|
568 | 567 |
-rm -f Makefile |
569 | 568 |
maintainer-clean-am: distclean-am maintainer-clean-generic |
570 | 569 |
|
571 | 570 |
mostlyclean: mostlyclean-am |
572 | 571 |
|
573 |
-mostlyclean-am: mostlyclean-compile mostlyclean-generic \ |
|
574 |
- mostlyclean-libtool |
|
572 |
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool |
|
575 | 573 |
|
576 | 574 |
pdf: pdf-am |
577 | 575 |
|
... | ... |
@@ -581,23 +390,20 @@ ps: ps-am |
581 | 581 |
|
582 | 582 |
ps-am: |
583 | 583 |
|
584 |
-uninstall-am: uninstall-binPROGRAMS |
|
584 |
+uninstall-am: |
|
585 | 585 |
|
586 | 586 |
.MAKE: install-am install-strip |
587 | 587 |
|
588 |
-.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ |
|
589 |
- clean-generic clean-libtool ctags distclean distclean-compile \ |
|
590 |
- distclean-generic distclean-libtool distclean-tags distdir dvi \ |
|
588 |
+.PHONY: all all-am check check-am clean clean-generic clean-libtool \ |
|
589 |
+ distclean distclean-generic distclean-libtool distdir dvi \ |
|
591 | 590 |
dvi-am html html-am info info-am install install-am \ |
592 |
- install-binPROGRAMS install-data install-data-am install-dvi \ |
|
593 |
- install-dvi-am install-exec install-exec-am install-html \ |
|
594 |
- install-html-am install-info install-info-am install-man \ |
|
595 |
- install-pdf install-pdf-am install-ps install-ps-am \ |
|
596 |
- install-strip installcheck installcheck-am \ |
|
597 |
- installcheck-binPROGRAMS installdirs maintainer-clean \ |
|
598 |
- maintainer-clean-generic mostlyclean mostlyclean-compile \ |
|
599 |
- mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ |
|
600 |
- tags uninstall uninstall-am uninstall-binPROGRAMS |
|
591 |
+ install-data install-data-am install-dvi install-dvi-am \ |
|
592 |
+ install-exec install-exec-am install-html install-html-am \ |
|
593 |
+ install-info install-info-am install-man install-pdf \ |
|
594 |
+ install-pdf-am install-ps install-ps-am install-strip \ |
|
595 |
+ installcheck installcheck-am installdirs maintainer-clean \ |
|
596 |
+ maintainer-clean-generic mostlyclean mostlyclean-generic \ |
|
597 |
+ mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am |
|
601 | 598 |
|
602 | 599 |
# Tell versions [3.59,3.63) of GNU make to not export all variables. |
603 | 600 |
# Otherwise a system limit (for SysV at least) may be exceeded. |
604 | 601 |
deleted file mode 100644 |
... | ... |
@@ -1,330 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2006 Sensory Networks, Inc. |
|
3 |
- * (C) 2007 Tomasz Kojm <tkojm@clamav.net> |
|
4 |
- * Written by Tomasz Kojm |
|
5 |
- * |
|
6 |
- * This program is free software; you can redistribute it and/or modify |
|
7 |
- * it under the terms of the GNU General Public License version 2 as |
|
8 |
- * published by the Free Software Foundation. |
|
9 |
- * |
|
10 |
- * This program is distributed in the hope that it will be useful, |
|
11 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
- * GNU General Public License for more details. |
|
14 |
- * |
|
15 |
- * You should have received a copy of the GNU General Public License |
|
16 |
- * along with this program; if not, write to the Free Software |
|
17 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
- * MA 02110-1301, USA. |
|
19 |
- */ |
|
20 |
- |
|
21 |
-#if HAVE_CONFIG_H |
|
22 |
-#include "clamav-config.h" |
|
23 |
-#endif |
|
24 |
- |
|
25 |
-#include <stdio.h> |
|
26 |
-#include <stdlib.h> |
|
27 |
-#include <string.h> |
|
28 |
-#include <sys/types.h> |
|
29 |
-#include <sys/stat.h> |
|
30 |
-#ifdef HAVE_UNISTD_H |
|
31 |
-#include <unistd.h> |
|
32 |
-#endif |
|
33 |
-#include <time.h> |
|
34 |
- |
|
35 |
-#include "shared/misc.h" |
|
36 |
-#include "libclamav/clamav.h" |
|
37 |
-#include "libclamav/version.h" |
|
38 |
- |
|
39 |
-#include "cfgparser.h" |
|
40 |
-#define _GNU_SOURCE |
|
41 |
-#include "getopt.h" |
|
42 |
- |
|
43 |
-static void printopt(const struct cfgoption *opt, const struct cfgstruct *cpt, int nondef) |
|
44 |
-{ |
|
45 |
- |
|
46 |
- if(!cpt->enabled && opt->numarg == -1) { |
|
47 |
- if(!nondef || (opt->numarg != cpt->numarg)) |
|
48 |
- printf("%s not set\n", opt->name); |
|
49 |
- return; |
|
50 |
- } |
|
51 |
- |
|
52 |
- while(cpt) { |
|
53 |
- if(opt->owner & OPT_DEPRECATED) { |
|
54 |
- printf("*** %s is DEPRECATED ***\n", opt->name); |
|
55 |
- } else switch(opt->argtype) { |
|
56 |
- case OPT_STR: |
|
57 |
- case OPT_FULLSTR: |
|
58 |
- case OPT_QUOTESTR: |
|
59 |
- if(!nondef || !opt->strarg || strcmp(opt->strarg, cpt->strarg)) |
|
60 |
- printf("%s = \"%s\"\n", opt->name, cpt->strarg); |
|
61 |
- break; |
|
62 |
- case OPT_NUM: |
|
63 |
- case OPT_COMPSIZE: |
|
64 |
- if(!nondef || (opt->numarg != cpt->numarg)) |
|
65 |
- printf("%s = %u\n", opt->name, cpt->numarg); |
|
66 |
- break; |
|
67 |
- case OPT_BOOL: |
|
68 |
- if(!nondef || (opt->numarg != cpt->numarg)) |
|
69 |
- printf("%s = %s\n", opt->name, cpt->enabled ? "yes" : "no"); |
|
70 |
- break; |
|
71 |
- default: |
|
72 |
- printf("%s: UNKNOWN ARGUMENT TYPE\n", opt->name); |
|
73 |
- } |
|
74 |
- cpt = cpt->nextarg; |
|
75 |
- } |
|
76 |
-} |
|
77 |
- |
|
78 |
-static void printcfg(const char *cfgfile, int nondef) |
|
79 |
-{ |
|
80 |
- const struct cfgoption *opt; |
|
81 |
- const struct cfgstruct *cpt; |
|
82 |
- struct cfgstruct *cfg; |
|
83 |
- int i; |
|
84 |
- unsigned short cfgowner = 0; |
|
85 |
- |
|
86 |
- |
|
87 |
- if(!(cfg = getcfg(cfgfile, 1, OPT_FRESHCLAM|OPT_CLAMD))) { |
|
88 |
- printf("Can't parse %s\n", cfgfile); |
|
89 |
- return; |
|
90 |
- } |
|
91 |
- |
|
92 |
- /* pre loop to detect merged config */ |
|
93 |
- for(i = 0; ; i++) { |
|
94 |
- opt = &cfg_options[i]; |
|
95 |
- |
|
96 |
- if(!opt->name) |
|
97 |
- break; |
|
98 |
- |
|
99 |
- if(!(opt->owner & (OPT_CLAMD|OPT_FRESHCLAM))) |
|
100 |
- continue; |
|
101 |
- |
|
102 |
- cpt = cfgopt(cfg, opt->name); |
|
103 |
- |
|
104 |
- if((cpt->numarg != opt->numarg) || (cpt->strarg && opt->strarg && strcmp(cpt->strarg, opt->strarg))) { |
|
105 |
- if((opt->owner & OPT_CLAMD) && !(opt->owner & OPT_FRESHCLAM)) |
|
106 |
- cfgowner |= OPT_CLAMD; |
|
107 |
- else if((opt->owner & OPT_FRESHCLAM) && !(opt->owner & OPT_CLAMD)) |
|
108 |
- cfgowner |= OPT_FRESHCLAM; |
|
109 |
- } |
|
110 |
- } |
|
111 |
- |
|
112 |
- if((cfgowner & OPT_CLAMD) && (cfgowner & OPT_FRESHCLAM)) { /* merged cfg */ |
|
113 |
- printf("%s: clamd and freshclam directives\n", cfgfile); |
|
114 |
- printf("------------------------------\n"); |
|
115 |
- |
|
116 |
- printf("\n[common]\n"); |
|
117 |
- for(i = 0; ; i++) { |
|
118 |
- opt = &cfg_options[i]; |
|
119 |
- if(!opt->name) |
|
120 |
- break; |
|
121 |
- if((opt->owner & OPT_CLAMD) && (opt->owner & OPT_FRESHCLAM)) { |
|
122 |
- cpt = cfgopt(cfg, opt->name); |
|
123 |
- printopt(opt, cpt, nondef); |
|
124 |
- } |
|
125 |
- } |
|
126 |
- |
|
127 |
- printf("\n[clamd]\n"); |
|
128 |
- for(i = 0; ; i++) { |
|
129 |
- opt = &cfg_options[i]; |
|
130 |
- if(!opt->name) |
|
131 |
- break; |
|
132 |
- if((opt->owner & OPT_CLAMD) && !(opt->owner & OPT_FRESHCLAM)) { |
|
133 |
- cpt = cfgopt(cfg, opt->name); |
|
134 |
- printopt(opt, cpt, nondef); |
|
135 |
- } |
|
136 |
- } |
|
137 |
- |
|
138 |
- printf("\n[freshclam]\n"); |
|
139 |
- for(i = 0; ; i++) { |
|
140 |
- opt = &cfg_options[i]; |
|
141 |
- if(!opt->name) |
|
142 |
- break; |
|
143 |
- if((opt->owner & OPT_FRESHCLAM) && !(opt->owner & OPT_CLAMD)) { |
|
144 |
- cpt = cfgopt(cfg, opt->name); |
|
145 |
- printopt(opt, cpt, nondef); |
|
146 |
- } |
|
147 |
- } |
|
148 |
- |
|
149 |
- } else { /* separate cfg */ |
|
150 |
- |
|
151 |
- if(cfgowner & OPT_CLAMD) { |
|
152 |
- printf("%s: clamd directives\n", cfgfile); |
|
153 |
- printf("------------------------------\n"); |
|
154 |
- |
|
155 |
- for(i = 0; ; i++) { |
|
156 |
- opt = &cfg_options[i]; |
|
157 |
- if(!opt->name) |
|
158 |
- break; |
|
159 |
- if(opt->owner & OPT_CLAMD) { |
|
160 |
- cpt = cfgopt(cfg, opt->name); |
|
161 |
- printopt(opt, cpt, nondef); |
|
162 |
- } |
|
163 |
- } |
|
164 |
- } else { |
|
165 |
- printf("%s: freshclam directives\n", cfgfile); |
|
166 |
- printf("------------------------------\n"); |
|
167 |
- |
|
168 |
- for(i = 0; ; i++) { |
|
169 |
- opt = &cfg_options[i]; |
|
170 |
- if(!opt->name) |
|
171 |
- break; |
|
172 |
- if(opt->owner & OPT_FRESHCLAM) { |
|
173 |
- cpt = cfgopt(cfg, opt->name); |
|
174 |
- printopt(opt, cpt, nondef); |
|
175 |
- } |
|
176 |
- } |
|
177 |
- } |
|
178 |
- } |
|
179 |
- freecfg(cfg); |
|
180 |
- |
|
181 |
-} |
|
182 |
- |
|
183 |
-static void printdb(const char *dir, const char *db) |
|
184 |
-{ |
|
185 |
- struct cl_cvd *cvd; |
|
186 |
- char path[256]; |
|
187 |
- unsigned int cld = 0; |
|
188 |
- time_t t; |
|
189 |
- |
|
190 |
- |
|
191 |
- snprintf(path, sizeof(path), "%s/%s.cvd", dir, db); |
|
192 |
- if(access(path, R_OK) == -1) { |
|
193 |
- snprintf(path, sizeof(path), "%s/%s.cld", dir, db); |
|
194 |
- cld = 1; |
|
195 |
- if(access(path, R_OK) == -1) { |
|
196 |
- printf("%s db: Not found\n", db); |
|
197 |
- return; |
|
198 |
- } |
|
199 |
- } |
|
200 |
- |
|
201 |
- if((cvd = cl_cvdhead(path))) { |
|
202 |
- t = (time_t) cvd->stime; |
|
203 |
- printf("%s db: Format: %s, Version: %u, Build time: %s", db, cld ? ".cld" : ".cvd", cvd->version, ctime(&t)); |
|
204 |
- cl_cvdfree(cvd); |
|
205 |
- } |
|
206 |
-} |
|
207 |
- |
|
208 |
-static void version(void) |
|
209 |
-{ |
|
210 |
- printf("Clam AntiVirus Configuration Tool %s\n", get_version()); |
|
211 |
-} |
|
212 |
- |
|
213 |
-static void help(void) |
|
214 |
-{ |
|
215 |
- printf("\n"); |
|
216 |
- printf(" Clam AntiVirus: Configuration Tool %s\n", get_version()); |
|
217 |
- printf(" (C) 2006 - 2007 ClamAV Team - http://www.clamav.net/team\n\n"); |
|
218 |
- |
|
219 |
- printf(" --help -h show help\n"); |
|
220 |
- printf(" --version -v show version\n"); |
|
221 |
- printf(" --config-dir DIR -c DIR search for config files in DIR\n"); |
|
222 |
- printf(" --non-default -n only print non-default settings\n"); |
|
223 |
- printf("\n"); |
|
224 |
-} |
|
225 |
- |
|
226 |
- |
|
227 |
-#ifndef REPO_VERSION |
|
228 |
-#define REPO_VERSION VERSION |
|
229 |
-#endif |
|
230 |
- |
|
231 |
-int main(int argc, char **argv) |
|
232 |
-{ |
|
233 |
- char path[1024]; |
|
234 |
- struct stat sb; |
|
235 |
- int ret, opt_index, nondef = 0; |
|
236 |
- const char *getopt_parameters = "hVc:n"; |
|
237 |
- static struct option long_options[] = { |
|
238 |
- {"help", 0, 0, 'h'}, |
|
239 |
- {"version", 0, 0, 'V'}, |
|
240 |
- {"config-dir", 1, 0, 'c'}, |
|
241 |
- {"non-default", 0, 0, 'n'}, |
|
242 |
- {0, 0, 0, 0} |
|
243 |
- }; |
|
244 |
- char *confdir = strdup(CONFDIR), *dbdir; |
|
245 |
- int found = 0; |
|
246 |
- |
|
247 |
- |
|
248 |
- while(1) { |
|
249 |
- opt_index = 0; |
|
250 |
- ret = getopt_long(argc, argv, getopt_parameters, long_options, &opt_index); |
|
251 |
- |
|
252 |
- if (ret == -1) |
|
253 |
- break; |
|
254 |
- |
|
255 |
- switch (ret) { |
|
256 |
- case 0: |
|
257 |
- break; |
|
258 |
- |
|
259 |
- case 'c': |
|
260 |
- free(confdir); |
|
261 |
- confdir = strdup(optarg); |
|
262 |
- break; |
|
263 |
- |
|
264 |
- case 'h': |
|
265 |
- help(); |
|
266 |
- free(confdir); |
|
267 |
- exit(0); |
|
268 |
- |
|
269 |
- case 'n': |
|
270 |
- nondef = 1; |
|
271 |
- break; |
|
272 |
- |
|
273 |
- case 'V': |
|
274 |
- version(); |
|
275 |
- free(confdir); |
|
276 |
- exit(0); |
|
277 |
- |
|
278 |
- default: |
|
279 |
- printf("ERROR: Unknown option passed\n"); |
|
280 |
- free(confdir); |
|
281 |
- exit(1); |
|
282 |
- } |
|
283 |
- } |
|
284 |
- |
|
285 |
- snprintf(path, sizeof(path), "%s/clamd.conf", confdir); |
|
286 |
- if(stat(path, &sb) != -1) { |
|
287 |
- printcfg(path, nondef); |
|
288 |
- found = 1; |
|
289 |
- printf("\n"); |
|
290 |
- } |
|
291 |
- |
|
292 |
- snprintf(path, sizeof(path), "%s/freshclam.conf", confdir); |
|
293 |
- if(stat(path, &sb) != -1) { |
|
294 |
- printcfg(path, nondef); |
|
295 |
- found = 1; |
|
296 |
- } |
|
297 |
- |
|
298 |
- if(!found) { |
|
299 |
- printf("No config files found in %s\n", confdir); |
|
300 |
- free(confdir); |
|
301 |
- return 1; |
|
302 |
- } |
|
303 |
- free(confdir); |
|
304 |
- |
|
305 |
- printf("\nEngine and signature databases\n"); |
|
306 |
- printf("------------------------------\n"); |
|
307 |
- |
|
308 |
-#ifdef CL_EXPERIMENTAL |
|
309 |
- printf("Engine version: %s (with experimental code)\n", get_version()); |
|
310 |
-#else |
|
311 |
- printf("Engine version: %s\n", get_version()); |
|
312 |
-#endif |
|
313 |
- |
|
314 |
- if(strcmp(REPO_VERSION, cl_retver())) |
|
315 |
- printf("WARNING: Version mismatch: clamconf: "REPO_VERSION", libclamav: %s\n", cl_retver()); |
|
316 |
- |
|
317 |
- printf("Database directory: "); |
|
318 |
- dbdir = freshdbdir(); |
|
319 |
- if(!dbdir) { |
|
320 |
- printf("Failed to retrieve\n"); |
|
321 |
- return 1; |
|
322 |
- } else printf("%s\n", dbdir); |
|
323 |
- |
|
324 |
- if(dbdir) { |
|
325 |
- printdb(dbdir, "main"); |
|
326 |
- printdb(dbdir, "daily"); |
|
327 |
- free(dbdir); |
|
328 |
- } |
|
329 |
- return 0; |
|
330 |
-} |
331 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,576 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2002 - 2007 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
4 |
- * This program is free software; you can redistribute it and/or modify |
|
5 |
- * it under the terms of the GNU General Public License as published by |
|
6 |
- * the Free Software Foundation; either version 2 of the License, or |
|
7 |
- * (at your option) any later version. |
|
8 |
- * |
|
9 |
- * This program is distributed in the hope that it will be useful, |
|
10 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
- * GNU General Public License for more details. |
|
13 |
- * |
|
14 |
- * You should have received a copy of the GNU General Public License |
|
15 |
- * along with this program; if not, write to the Free Software |
|
16 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
17 |
- * MA 02110-1301, USA. |
|
18 |
- */ |
|
19 |
- |
|
20 |
-#if HAVE_CONFIG_H |
|
21 |
-#include "clamav-config.h" |
|
22 |
-#endif |
|
23 |
- |
|
24 |
-#include <stdio.h> |
|
25 |
-#include <stdlib.h> |
|
26 |
-#include <string.h> |
|
27 |
-#ifdef HAVE_STRINGS_H |
|
28 |
-#include <strings.h> |
|
29 |
-#endif |
|
30 |
-#include <ctype.h> |
|
31 |
- |
|
32 |
-#include "shared/cfgparser.h" |
|
33 |
-#include "shared/misc.h" |
|
34 |
- |
|
35 |
-#include "libclamav/str.h" |
|
36 |
- |
|
37 |
-struct cfgoption cfg_options[] = { |
|
38 |
- {"LogFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER}, |
|
39 |
- {"LogFileUnlock", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_MILTER}, |
|
40 |
- {"LogFileMaxSize", OPT_COMPSIZE, 1048576, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, |
|
41 |
- {"LogTime", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, |
|
42 |
- {"LogClean", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
43 |
- {"LogVerbose", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, |
|
44 |
- {"LogSyslog", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, |
|
45 |
- {"LogFacility", OPT_QUOTESTR, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, |
|
46 |
- {"PidFile", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, |
|
47 |
- {"TemporaryDirectory", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER}, |
|
48 |
- {"ScanPE", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, |
|
49 |
- {"ScanELF", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, |
|
50 |
- {"DetectBrokenExecutables", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
51 |
- {"ScanMail", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, |
|
52 |
- {"MailFollowURLs", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
53 |
- {"ScanPartialMessages", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
54 |
- {"PhishingSignatures", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, |
|
55 |
- {"PhishingScanURLs",OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, |
|
56 |
- /* these are FP prone options, if default isn't used */ |
|
57 |
- {"PhishingAlwaysBlockCloak", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
58 |
- {"PhishingAlwaysBlockSSLMismatch", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
59 |
- {"HeuristicScanPrecedence", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
60 |
- /* end of FP prone options */ |
|
61 |
- {"DetectPUA", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
62 |
- {"ExcludePUA", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD}, |
|
63 |
- {"IncludePUA", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD}, |
|
64 |
- {"StructuredDataDetection", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
65 |
- {"StructuredMinCreditCardCount", OPT_NUM, 3, NULL, 0, OPT_CLAMD}, |
|
66 |
- {"StructuredMinSSNCount", OPT_NUM, 3, NULL, 0, OPT_CLAMD}, |
|
67 |
- {"StructuredSSNFormatNormal", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, |
|
68 |
- {"StructuredSSNFormatStripped", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
69 |
- {"AlgorithmicDetection", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, |
|
70 |
- {"ScanHTML", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, |
|
71 |
- {"ScanOLE2", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, |
|
72 |
- {"ScanPDF", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, |
|
73 |
- {"ScanArchive", OPT_BOOL, 1, NULL, 0, OPT_CLAMD}, |
|
74 |
- {"MaxScanSize", OPT_COMPSIZE, -1, NULL, 0, OPT_CLAMD}, |
|
75 |
- {"MaxFileSize", OPT_COMPSIZE, -1, NULL, 0, OPT_CLAMD | OPT_MILTER}, |
|
76 |
- {"MaxRecursion", OPT_NUM, -1, NULL, 0, OPT_CLAMD}, |
|
77 |
- {"MaxFiles", OPT_NUM, -1, NULL, 0, OPT_CLAMD}, |
|
78 |
- {"ArchiveBlockEncrypted", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
79 |
- {"DatabaseDirectory", OPT_QUOTESTR, -1, DATADIR, 0, OPT_CLAMD | OPT_FRESHCLAM}, |
|
80 |
- {"TCPAddr", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD}, |
|
81 |
- {"TCPSocket", OPT_NUM, -1, NULL, 0, OPT_CLAMD}, |
|
82 |
- {"LocalSocket", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD}, |
|
83 |
- {"MaxConnectionQueueLength", OPT_NUM, 15, NULL, 0, OPT_CLAMD}, |
|
84 |
- {"StreamMaxLength", OPT_COMPSIZE, 10485760, NULL, 0, OPT_CLAMD}, |
|
85 |
- {"StreamMinPort", OPT_NUM, 1024, NULL, 0, OPT_CLAMD}, |
|
86 |
- {"StreamMaxPort", OPT_NUM, 2048, NULL, 0, OPT_CLAMD}, |
|
87 |
- {"MaxThreads", OPT_NUM, 10, NULL, 0, OPT_CLAMD | OPT_MILTER}, |
|
88 |
- {"ReadTimeout", OPT_NUM, 120, NULL, 0, OPT_CLAMD | OPT_MILTER}, |
|
89 |
- {"IdleTimeout", OPT_NUM, 30, NULL, 0, OPT_CLAMD}, |
|
90 |
- {"MaxDirectoryRecursion", OPT_NUM, 15, NULL, 0, OPT_CLAMD}, |
|
91 |
- {"ExcludePath", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD}, |
|
92 |
- {"FollowDirectorySymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
93 |
- {"FollowFileSymlinks", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
94 |
- {"ExitOnOOM", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
95 |
- {"Foreground", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, |
|
96 |
- {"Debug", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM}, |
|
97 |
- {"LeaveTemporaryFiles", OPT_BOOL, 0, NULL, 0, OPT_CLAMD}, |
|
98 |
- {"FixStaleSocket", OPT_BOOL, 1, NULL, 0, OPT_CLAMD | OPT_MILTER}, |
|
99 |
- {"User", OPT_QUOTESTR, -1, NULL, 0, OPT_CLAMD | OPT_MILTER}, |
|
100 |
- {"AllowSupplementaryGroups", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER}, |
|
101 |
- {"SelfCheck", OPT_NUM, 1800, NULL, 0, OPT_CLAMD}, |
|
102 |
- {"VirusEvent", OPT_FULLSTR, -1, NULL, 0, OPT_CLAMD}, |
|
103 |
- {"ClamukoScanOnAccess", OPT_BOOL, -1, NULL, 0, OPT_CLAMD}, |
|
104 |
- {"ClamukoScanOnOpen", OPT_BOOL, -1, NULL, 0, OPT_CLAMD}, |
|
105 |
- {"ClamukoScanOnClose", OPT_BOOL, -1, NULL, 0, OPT_CLAMD}, |
|
106 |
- {"ClamukoScanOnExec", OPT_BOOL, -1, NULL, 0, OPT_CLAMD}, |
|
107 |
- {"ClamukoIncludePath", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD}, |
|
108 |
- {"ClamukoExcludePath", OPT_QUOTESTR, -1, NULL, 1, OPT_CLAMD}, |
|
109 |
- {"ClamukoMaxFileSize", OPT_COMPSIZE, 5242880, NULL, 0, OPT_CLAMD}, |
|
110 |
- {"DatabaseOwner", OPT_QUOTESTR, -1, CLAMAVUSER, 0, OPT_FRESHCLAM}, |
|
111 |
- {"Checks", OPT_NUM, 12, NULL, 0, OPT_FRESHCLAM}, |
|
112 |
- {"UpdateLogFile", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
113 |
- {"DNSDatabaseInfo", OPT_QUOTESTR, -1, "current.cvd.clamav.net", 0, OPT_FRESHCLAM}, |
|
114 |
- {"DatabaseMirror", OPT_QUOTESTR, -1, NULL, 1, OPT_FRESHCLAM}, |
|
115 |
- {"MaxAttempts", OPT_NUM, 3, NULL, 0, OPT_FRESHCLAM}, |
|
116 |
- {"ScriptedUpdates", OPT_BOOL, 1, NULL, 0, OPT_FRESHCLAM}, |
|
117 |
- {"CompressLocalDatabase", OPT_BOOL, 0, NULL, 0, OPT_FRESHCLAM}, |
|
118 |
- {"HTTPProxyServer", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
119 |
- {"HTTPProxyPort", OPT_NUM, -1, NULL, 0, OPT_FRESHCLAM}, |
|
120 |
- {"HTTPProxyUsername", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
121 |
- {"HTTPProxyPassword", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
122 |
- {"HTTPUserAgent", OPT_FULLSTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
123 |
- {"NotifyClamd", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
124 |
- {"OnUpdateExecute", OPT_FULLSTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
125 |
- {"OnErrorExecute", OPT_FULLSTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
126 |
- {"OnOutdatedExecute", OPT_FULLSTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
127 |
- {"LocalIPAddress", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
128 |
- {"ConnectTimeout", OPT_NUM, 30, NULL, 0, OPT_FRESHCLAM}, |
|
129 |
- {"ReceiveTimeout", OPT_NUM, 30, NULL, 0, OPT_FRESHCLAM}, |
|
130 |
- {"SubmitDetectionStats", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
131 |
- {"DetectionStatsCountry", OPT_QUOTESTR, -1, NULL, 0, OPT_FRESHCLAM}, |
|
132 |
- |
|
133 |
- {"DevACOnly", OPT_BOOL, -1, NULL, 0, OPT_CLAMD}, |
|
134 |
- {"DevACDepth", OPT_NUM, -1, NULL, 0, OPT_CLAMD}, |
|
135 |
- |
|
136 |
- /* Deprecated options */ |
|
137 |
- {"MailMaxRecursion", OPT_NUM, 64, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, |
|
138 |
- {"ArchiveMaxScanSize", OPT_COMPSIZE, 10485760, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, |
|
139 |
- {"ArchiveMaxRecursion", OPT_NUM, 8, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, |
|
140 |
- {"ArchiveMaxFiles", OPT_NUM, 1000, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, |
|
141 |
- {"ArchiveMaxCompressionRatio", OPT_NUM, 250, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, |
|
142 |
- {"ArchiveBlockMax", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_DEPRECATED}, |
|
143 |
- {"ArchiveLimitMemoryUsage", OPT_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_DEPRECATED }, |
|
144 |
- |
|
145 |
- /* Milter specific options */ |
|
146 |
- {"ClamdSocket", OPT_QUOTESTR, -1, NULL, 1, OPT_MILTER}, |
|
147 |
- {"MilterSocket", OPT_QUOTESTR, -1, NULL, 1, OPT_MILTER}, |
|
148 |
- {"LocalNet", OPT_QUOTESTR, -1, NULL, 1, OPT_MILTER}, |
|
149 |
- {"OnClean", OPT_QUOTESTR, -1, "Accept", 0, OPT_MILTER}, |
|
150 |
- {"OnInfected", OPT_QUOTESTR, -1, "Quarantine", 0, OPT_MILTER}, |
|
151 |
- {"OnFail", OPT_QUOTESTR, -1, "Defer", 0, OPT_MILTER}, |
|
152 |
- {"AddHeader", OPT_BOOL, 0, NULL, 0, OPT_MILTER}, |
|
153 |
- {"Chroot", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER}, |
|
154 |
- {"Whitelist", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER}, |
|
155 |
- |
|
156 |
- |
|
157 |
- /* Deprecated milter options */ |
|
158 |
- {"ArchiveBlockEncrypted", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
159 |
- {"DatabaseDirectory", OPT_QUOTESTR, -1, DATADIR, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
160 |
- {"Debug", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
161 |
- {"DetectBrokenExecutables", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
162 |
- {"LeaveTemporaryFiles", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
163 |
- {"LocalSocket", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
164 |
- {"MailFollowURLs", OPT_BOOL, 0, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
165 |
- {"MaxScanSize", OPT_COMPSIZE, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
166 |
- {"MaxFiles", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
167 |
- {"MaxRecursion", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
168 |
- {"PhishingSignatures", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
169 |
- {"ScanArchive", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
170 |
- {"ScanHTML", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
171 |
- {"ScanMail", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
172 |
- {"ScanOLE2", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
173 |
- {"ScanPE", OPT_BOOL, 1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
174 |
- {"StreamMaxLength", OPT_COMPSIZE, 10485760, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
175 |
- {"TCPAddr", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
176 |
- {"TCPSocket", OPT_NUM, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
177 |
- {"TemporaryDirectory", OPT_QUOTESTR, -1, NULL, 0, OPT_MILTER | OPT_DEPRECATED}, |
|
178 |
- {NULL, 0, 0, NULL, 0, 0} |
|
179 |
-}; |
|
180 |
- |
|
181 |
-static int regcfg(struct cfgstruct **copt, const char *optname, char *strarg, int numarg, short multiple); |
|
182 |
- |
|
183 |
-struct cfgstruct *getcfg(const char *cfgfile, int verbose, int toolmask) |
|
184 |
-{ |
|
185 |
- char buff[LINE_LENGTH], *name, *arg, *c; |
|
186 |
- FILE *fs; |
|
187 |
- int line = 0, i, found, ctype, calc, val; |
|
188 |
- struct cfgstruct *copt = NULL; |
|
189 |
- struct cfgoption *pt; |
|
190 |
- |
|
191 |
- |
|
192 |
- for(i = 0; ; i++) { |
|
193 |
- pt = &cfg_options[i]; |
|
194 |
- if(!pt->name) |
|
195 |
- break; |
|
196 |
- |
|
197 |
- if((pt->owner & toolmask) && regcfg(&copt, pt->name, pt->strarg ? strdup(pt->strarg) : NULL, pt->numarg, pt->multiple) < 0) { |
|
198 |
- fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n"); |
|
199 |
- freecfg(copt); |
|
200 |
- return NULL; |
|
201 |
- } |
|
202 |
- } |
|
203 |
- |
|
204 |
- if((fs = fopen(cfgfile, "rb")) == NULL) { |
|
205 |
- /* do not print error message here! */ |
|
206 |
- freecfg(copt); |
|
207 |
- return NULL; |
|
208 |
- } |
|
209 |
- |
|
210 |
- while(fgets(buff, LINE_LENGTH, fs)) { |
|
211 |
- line++; |
|
212 |
- |
|
213 |
- if(buff[0] == '#') |
|
214 |
- continue; |
|
215 |
- |
|
216 |
- if(!strncmp("Example", buff, 7)) { |
|
217 |
- if(verbose) |
|
218 |
- fprintf(stderr, "ERROR: Please edit the example config file %s.\n", cfgfile); |
|
219 |
- fclose(fs); |
|
220 |
- freecfg(copt); |
|
221 |
- return NULL; |
|
222 |
- } |
|
223 |
- |
|
224 |
- if((name = cli_strtok(buff, 0, " \r\n"))) { |
|
225 |
- arg = cli_strtok(buff, 1, " \r\n"); |
|
226 |
- found = 0; |
|
227 |
- for(i = 0; ; i++) { |
|
228 |
- pt = &cfg_options[i]; |
|
229 |
- if(pt->name) { |
|
230 |
- if((pt->owner & toolmask) && !strcmp(name, pt->name)) { |
|
231 |
- found = 1; |
|
232 |
- if(pt->owner & OPT_DEPRECATED) { |
|
233 |
- fprintf(stderr, "WARNING: Ignoring deprecated option %s at line %u\n", pt->name, line); |
|
234 |
- break; |
|
235 |
- } |
|
236 |
- switch(pt->argtype) { |
|
237 |
- case OPT_STR: |
|
238 |
- /* deprecated. Use OPT_QUOTESTR instead since it behaves like this, but supports quotes to allow values to contain whitespace */ |
|
239 |
- if(!arg) { |
|
240 |
- if(verbose) |
|
241 |
- fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string argument.\n", line, name); |
|
242 |
- fclose(fs); |
|
243 |
- free(name); |
|
244 |
- freecfg(copt); |
|
245 |
- return NULL; |
|
246 |
- } |
|
247 |
- if(regcfg(&copt, name, arg, -1, pt->multiple) < 0) { |
|
248 |
- fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n"); |
|
249 |
- fclose(fs); |
|
250 |
- free(name); |
|
251 |
- free(arg); |
|
252 |
- freecfg(copt); |
|
253 |
- return NULL; |
|
254 |
- } |
|
255 |
- break; |
|
256 |
- case OPT_FULLSTR: |
|
257 |
- /* an ugly hack of the above case */ |
|
258 |
- if(!arg) { |
|
259 |
- if(verbose) |
|
260 |
- fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string argument.\n", line, name); |
|
261 |
- fclose(fs); |
|
262 |
- free(name); |
|
263 |
- freecfg(copt); |
|
264 |
- return NULL; |
|
265 |
- } |
|
266 |
- free(arg); |
|
267 |
- arg = strstr(buff, " "); |
|
268 |
- arg = strdup(++arg); |
|
269 |
- if((arg) && (c = strpbrk(arg, "\n\r"))) |
|
270 |
- *c = '\0'; |
|
271 |
- if((!arg) || (regcfg(&copt, name, arg, -1, pt->multiple) < 0)) { |
|
272 |
- fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n"); |
|
273 |
- fclose(fs); |
|
274 |
- free(name); |
|
275 |
- free(arg); |
|
276 |
- freecfg(copt); |
|
277 |
- return NULL; |
|
278 |
- } |
|
279 |
- break; |
|
280 |
- case OPT_QUOTESTR: |
|
281 |
- /* an ugly hack of the above case */ |
|
282 |
- if(!arg) { |
|
283 |
- if(verbose) |
|
284 |
- fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string argument.\n", line, name); |
|
285 |
- fclose(fs); |
|
286 |
- free(name); |
|
287 |
- freecfg(copt); |
|
288 |
- return NULL; |
|
289 |
- } |
|
290 |
- if((*arg == '\'') || (*arg == '"')) { |
|
291 |
- free(arg); |
|
292 |
- c = strstr(buff, " "); |
|
293 |
- arg = strdup(c+2); |
|
294 |
- if(arg) { |
|
295 |
- if((c = strchr(arg, c[1]))) |
|
296 |
- *c = '\0'; |
|
297 |
- else { |
|
298 |
- if(verbose) |
|
299 |
- fprintf(stderr, "ERROR: Parse error at line %d: Option %s missing closing quote.\n", line, name); |
|
300 |
- fclose(fs); |
|
301 |
- free(name); |
|
302 |
- free(arg); |
|
303 |
- freecfg(copt); |
|
304 |
- return NULL; |
|
305 |
- } |
|
306 |
- } |
|
307 |
- } |
|
308 |
- if((!arg) || (regcfg(&copt, name, arg, -1, pt->multiple) < 0)) { |
|
309 |
- fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n"); |
|
310 |
- fclose(fs); |
|
311 |
- free(name); |
|
312 |
- free(arg); |
|
313 |
- freecfg(copt); |
|
314 |
- return NULL; |
|
315 |
- } |
|
316 |
- break; |
|
317 |
- case OPT_NUM: |
|
318 |
- if(!arg || !cli_isnumber(arg)) { |
|
319 |
- if(verbose) |
|
320 |
- fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical argument.\n", line, name); |
|
321 |
- fclose(fs); |
|
322 |
- free(name); |
|
323 |
- free(arg); |
|
324 |
- freecfg(copt); |
|
325 |
- return NULL; |
|
326 |
- } |
|
327 |
- if(regcfg(&copt, name, NULL, atoi(arg), pt->multiple) < 0) { |
|
328 |
- fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n"); |
|
329 |
- fclose(fs); |
|
330 |
- free(name); |
|
331 |
- free(arg); |
|
332 |
- freecfg(copt); |
|
333 |
- return NULL; |
|
334 |
- } |
|
335 |
- free(arg); |
|
336 |
- break; |
|
337 |
- case OPT_COMPSIZE: |
|
338 |
- if(!arg) { |
|
339 |
- if(verbose) |
|
340 |
- fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires argument.\n", line, name); |
|
341 |
- fclose(fs); |
|
342 |
- free(name); |
|
343 |
- freecfg(copt); |
|
344 |
- return NULL; |
|
345 |
- } |
|
346 |
- ctype = tolower(arg[strlen(arg) - 1]); |
|
347 |
- if(ctype == 'm' || ctype == 'k') { |
|
348 |
- char *cpy = strdup(arg); |
|
349 |
- if(!cpy) { |
|
350 |
- fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n"); |
|
351 |
- fclose(fs); |
|
352 |
- free(name); |
|
353 |
- freecfg(copt); |
|
354 |
- return NULL; |
|
355 |
- } |
|
356 |
- cpy[strlen(arg) - 1] = '\0'; |
|
357 |
- if(!cli_isnumber(cpy)) { |
|
358 |
- if(verbose) |
|
359 |
- fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical (raw/K/M) argument.\n", line, name); |
|
360 |
- fclose(fs); |
|
361 |
- free(name); |
|
362 |
- free(arg); |
|
363 |
- freecfg(copt); |
|
364 |
- return NULL; |
|
365 |
- } |
|
366 |
- if(ctype == 'm') |
|
367 |
- calc = atoi(cpy) * 1024 * 1024; |
|
368 |
- else |
|
369 |
- calc = atoi(cpy) * 1024; |
|
370 |
- free(cpy); |
|
371 |
- } else { |
|
372 |
- if(!cli_isnumber(arg)) { |
|
373 |
- if(verbose) |
|
374 |
- fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical (raw/K/M) argument.\n", line, name); |
|
375 |
- fclose(fs); |
|
376 |
- free(name); |
|
377 |
- free(arg); |
|
378 |
- freecfg(copt); |
|
379 |
- return NULL; |
|
380 |
- } |
|
381 |
- calc = atoi(arg); |
|
382 |
- } |
|
383 |
- free(arg); |
|
384 |
- if(regcfg(&copt, name, NULL, calc, pt->multiple) < 0) { |
|
385 |
- fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n"); |
|
386 |
- fclose(fs); |
|
387 |
- free(name); |
|
388 |
- free(arg); |
|
389 |
- freecfg(copt); |
|
390 |
- return NULL; |
|
391 |
- } |
|
392 |
- break; |
|
393 |
- case OPT_BOOL: |
|
394 |
- |
|
395 |
- if(!arg) { |
|
396 |
- if(verbose) |
|
397 |
- fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires boolean argument.\n", line, name); |
|
398 |
- fclose(fs); |
|
399 |
- free(name); |
|
400 |
- freecfg(copt); |
|
401 |
- return NULL; |
|
402 |
- } |
|
403 |
- |
|
404 |
- if(!strcasecmp(arg, "yes") || !strcmp(arg, "1") || !strcasecmp(arg, "true")) { |
|
405 |
- val = 1; |
|
406 |
- } else if(!strcasecmp(arg, "no") || !strcmp(arg, "0") || !strcasecmp(arg, "false")) { |
|
407 |
- val = 0; |
|
408 |
- } else { |
|
409 |
- if(verbose) |
|
410 |
- fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires boolean argument.\n", line, name); |
|
411 |
- fclose(fs); |
|
412 |
- free(name); |
|
413 |
- free(arg); |
|
414 |
- freecfg(copt); |
|
415 |
- return NULL; |
|
416 |
- } |
|
417 |
- free(arg); |
|
418 |
- if(regcfg(&copt, name, NULL, val, pt->multiple) < 0) { |
|
419 |
- fprintf(stderr, "ERROR: Can't register new options (not enough memory)\n"); |
|
420 |
- fclose(fs); |
|
421 |
- free(name); |
|
422 |
- free(arg); |
|
423 |
- freecfg(copt); |
|
424 |
- return NULL; |
|
425 |
- } |
|
426 |
- break; |
|
427 |
- default: |
|
428 |
- if(verbose) |
|
429 |
- fprintf(stderr, "ERROR: Parse error at line %d: Option %s is of unknown type %d\n", line, name, pt->argtype); |
|
430 |
- fclose(fs); |
|
431 |
- free(name); |
|
432 |
- free(arg); |
|
433 |
- freecfg(copt); |
|
434 |
- return NULL; |
|
435 |
- } |
|
436 |
- } |
|
437 |
- } else |
|
438 |
- break; |
|
439 |
- } |
|
440 |
- |
|
441 |
- if(!found) { |
|
442 |
- if(verbose) |
|
443 |
- fprintf(stderr, "ERROR: Parse error at line %d: Unknown option %s.\n", line, name); |
|
444 |
- free(name); |
|
445 |
- fclose(fs); |
|
446 |
- freecfg(copt); |
|
447 |
- return NULL; |
|
448 |
- } |
|
449 |
- free(name); |
|
450 |
- } |
|
451 |
- } |
|
452 |
- |
|
453 |
- fclose(fs); |
|
454 |
- return copt; |
|
455 |
-} |
|
456 |
- |
|
457 |
-void freecfg(struct cfgstruct *copt) |
|
458 |
-{ |
|
459 |
- struct cfgstruct *handler; |
|
460 |
- struct cfgstruct *arg; |
|
461 |
- |
|
462 |
- while(copt) { |
|
463 |
- arg = copt->nextarg; |
|
464 |
- while(arg) { |
|
465 |
- if(arg->strarg) { |
|
466 |
- free(arg->optname); |
|
467 |
- free(arg->strarg); |
|
468 |
- handler = arg; |
|
469 |
- arg = arg->nextarg; |
|
470 |
- free(handler); |
|
471 |
- } else |
|
472 |
- arg = arg->nextarg; |
|
473 |
- } |
|
474 |
- if(copt->optname) |
|
475 |
- free(copt->optname); |
|
476 |
- |
|
477 |
- if(copt->strarg) |
|
478 |
- free(copt->strarg); |
|
479 |
- |
|
480 |
- handler = copt; |
|
481 |
- copt = copt->next; |
|
482 |
- free(handler); |
|
483 |
- } |
|
484 |
- return; |
|
485 |
-} |
|
486 |
- |
|
487 |
-const struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname) |
|
488 |
-{ |
|
489 |
- while(copt) { |
|
490 |
- if(copt->optname && !strcmp(copt->optname, optname)) |
|
491 |
- return copt; |
|
492 |
- |
|
493 |
- copt = copt->next; |
|
494 |
- } |
|
495 |
- |
|
496 |
- return NULL; |
|
497 |
-} |
|
498 |
- |
|
499 |
-static struct cfgstruct *cfgopt_i(struct cfgstruct *copt, const char *optname) |
|
500 |
-{ |
|
501 |
- while(copt) { |
|
502 |
- if(copt->optname && !strcmp(copt->optname, optname)) |
|
503 |
- return copt; |
|
504 |
- |
|
505 |
- copt = copt->next; |
|
506 |
- } |
|
507 |
- |
|
508 |
- return NULL; |
|
509 |
-} |
|
510 |
- |
|
511 |
-static int regcfg(struct cfgstruct **copt, const char *optname, char *strarg, int numarg, short multiple) |
|
512 |
-{ |
|
513 |
- struct cfgstruct *newnode, *pt; |
|
514 |
- |
|
515 |
- |
|
516 |
- newnode = (struct cfgstruct *) malloc(sizeof(struct cfgstruct)); |
|
517 |
- |
|
518 |
- if(!newnode) |
|
519 |
- return -1; |
|
520 |
- |
|
521 |
- newnode->optname = optname ? strdup(optname) : NULL; |
|
522 |
- newnode->nextarg = NULL; |
|
523 |
- newnode->next = NULL; |
|
524 |
- newnode->enabled = 0; |
|
525 |
- newnode->multiple = multiple; |
|
526 |
- |
|
527 |
- if(strarg) { |
|
528 |
- newnode->strarg = strarg; |
|
529 |
- newnode->enabled = 1; |
|
530 |
- } else { |
|
531 |
- newnode->strarg = NULL; |
|
532 |
- } |
|
533 |
- |
|
534 |
- newnode->numarg = numarg; |
|
535 |
- if(numarg != -1 && numarg != 0) |
|
536 |
- newnode->enabled = 1; |
|
537 |
- |
|
538 |
- if((pt = cfgopt_i(*copt, optname))) { |
|
539 |
- if(pt->multiple) { |
|
540 |
- |
|
541 |
- if(pt->enabled) { |
|
542 |
- while(pt->nextarg) |
|
543 |
- pt = pt->nextarg; |
|
544 |
- |
|
545 |
- pt->nextarg = newnode; |
|
546 |
- } else { |
|
547 |
- if(pt->strarg) |
|
548 |
- free(pt->strarg); |
|
549 |
- pt->strarg = newnode->strarg; |
|
550 |
- pt->numarg = newnode->numarg; |
|
551 |
- pt->enabled = newnode->enabled; |
|
552 |
- if(newnode->optname) |
|
553 |
- free(newnode->optname); |
|
554 |
- free(newnode); |
|
555 |
- } |
|
556 |
- return 3; /* registered additional argument */ |
|
557 |
- |
|
558 |
- } else { |
|
559 |
- if(pt->strarg) |
|
560 |
- free(pt->strarg); |
|
561 |
- pt->strarg = newnode->strarg; |
|
562 |
- pt->numarg = newnode->numarg; |
|
563 |
- pt->enabled = newnode->enabled; |
|
564 |
- if(newnode->optname) |
|
565 |
- free(newnode->optname); |
|
566 |
- free(newnode); |
|
567 |
- return 2; |
|
568 |
- } |
|
569 |
- |
|
570 |
- } else { |
|
571 |
- newnode->next = *copt; |
|
572 |
- *copt = newnode; |
|
573 |
- return 1; |
|
574 |
- } |
|
575 |
-} |
|
576 |
- |
577 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,63 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
4 |
- * This program is free software; you can redistribute it and/or modify |
|
5 |
- * it under the terms of the GNU General Public License as published by |
|
6 |
- * the Free Software Foundation; either version 2 of the License, or |
|
7 |
- * (at your option) any later version. |
|
8 |
- * |
|
9 |
- * This program is distributed in the hope that it will be useful, |
|
10 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
- * GNU General Public License for more details. |
|
13 |
- * |
|
14 |
- * You should have received a copy of the GNU General Public License |
|
15 |
- * along with this program; if not, write to the Free Software |
|
16 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
17 |
- * MA 02110-1301, USA. |
|
18 |
- */ |
|
19 |
- |
|
20 |
-#ifndef __CFGPARSER_H |
|
21 |
-#define __CFGPARSER_H |
|
22 |
- |
|
23 |
-#define LINE_LENGTH 1024 |
|
24 |
- |
|
25 |
-#define OPT_STR 1 /* string argument (space delimited) */ |
|
26 |
-#define OPT_NUM 2 /* numerical argument */ |
|
27 |
-#define OPT_COMPSIZE 3 /* convert kilobytes (k) and megabytes (m) to bytes */ |
|
28 |
-#define OPT_BOOL 4 /* boolean value */ |
|
29 |
-#define OPT_FULLSTR 5 /* string argument, but get a full line */ |
|
30 |
-#define OPT_QUOTESTR 6 /* string argument, (space delimited unless the argument starts with ' or ". If the argument starts with a quote character, then the argument data is what appears between the starting quote character and the matching ending quote character.) */ |
|
31 |
- |
|
32 |
-/* don't share bits! */ |
|
33 |
-#define OPT_CLAMD 1 |
|
34 |
-#define OPT_FRESHCLAM 2 |
|
35 |
-#define OPT_MILTER 4 |
|
36 |
-#define OPT_DEPRECATED 16 |
|
37 |
- |
|
38 |
-struct cfgoption { |
|
39 |
- const char *name; |
|
40 |
- unsigned short argtype; |
|
41 |
- int numarg; |
|
42 |
- const char *strarg; |
|
43 |
- short multiple; |
|
44 |
- unsigned short owner; |
|
45 |
-}; |
|
46 |
- |
|
47 |
-struct cfgstruct { |
|
48 |
- char *optname; |
|
49 |
- char *strarg; |
|
50 |
- int numarg; |
|
51 |
- unsigned int enabled; |
|
52 |
- unsigned int multiple; |
|
53 |
- struct cfgstruct *nextarg; |
|
54 |
- struct cfgstruct *next; |
|
55 |
-}; |
|
56 |
- |
|
57 |
-extern struct cfgoption cfg_options[]; |
|
58 |
- |
|
59 |
-struct cfgstruct *getcfg(const char *cfgfile, int verbose, int toolmask); |
|
60 |
-const struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname); |
|
61 |
-void freecfg(struct cfgstruct *copt); |
|
62 |
- |
|
63 |
-#endif |
... | ... |
@@ -1,1022 +1,281 @@ |
1 |
-/* Getopt for GNU. |
|
2 |
- NOTE: getopt is now part of the C library, so if you don't know what |
|
3 |
- "Keep this file name-space clean" means, talk to drepper@gnu.org |
|
4 |
- before changing it! |
|
5 |
- |
|
6 |
- Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000 |
|
7 |
- Free Software Foundation, Inc. |
|
8 |
- |
|
9 |
- The GNU C Library is free software; you can redistribute it and/or |
|
10 |
- modify it under the terms of the GNU Library General Public License as |
|
11 |
- published by the Free Software Foundation; either version 2 of the |
|
12 |
- License, or (at your option) any later version. |
|
13 |
- |
|
14 |
- The GNU C Library is distributed in the hope that it will be useful, |
|
15 |
- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 |
- Library General Public License for more details. |
|
18 |
- |
|
19 |
- You should have received a copy of the GNU Library General Public |
|
20 |
- License along with the GNU C Library; see the file COPYING.LIB. If not, |
|
21 |
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
22 |
- Boston, MA 02111-1307, USA. */ |
|
23 |
- |
|
24 |
-/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. |
|
25 |
- Ditto for AIX 3.2 and <stdlib.h>. */ |
|
26 |
-#ifndef _NO_PROTO |
|
27 |
-# define _NO_PROTO |
|
28 |
-#endif |
|
29 |
- |
|
30 |
-#ifdef HAVE_CONFIG_H |
|
31 |
-# include <clamav-config.h> |
|
32 |
-#endif |
|
33 |
- |
|
34 |
-#if !defined __STDC__ || !__STDC__ |
|
35 |
-/* This is a separate conditional since some stdc systems |
|
36 |
- reject `defined (const)'. */ |
|
37 |
-# ifndef const |
|
38 |
-# define const |
|
39 |
-# endif |
|
40 |
-#endif |
|
41 |
- |
|
1 |
+/* |
|
2 |
+ * getopt.c - my re-implementation of getopt. |
|
3 |
+ * Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler |
|
4 |
+ * |
|
5 |
+ * Permission is hereby granted, free of charge, to any person |
|
6 |
+ * obtaining a copy of this software and associated documentation |
|
7 |
+ * files (the "Software"), to deal in the Software without |
|
8 |
+ * restriction, including without limitation the rights to use, copy, |
|
9 |
+ * modify, merge, publish, distribute, sublicense, and/or sell copies |
|
10 |
+ * of the Software, and to permit persons to whom the Software is |
|
11 |
+ * furnished to do so, subject to the following conditions: |
|
12 |
+ * |
|
13 |
+ * The above copyright notice and this permission notice shall be |
|
14 |
+ * included in all copies or substantial portions of the Software. |
|
15 |
+ * |
|
16 |
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
18 |
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22 |
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
23 |
+ * DEALINGS IN THE SOFTWARE. |
|
24 |
+ */ |
|
25 |
+ |
|
26 |
+#include <sys/types.h> |
|
27 |
+#include <stdlib.h> |
|
42 | 28 |
#include <stdio.h> |
43 |
- |
|
44 |
-#ifndef C_WINDOWS |
|
45 |
-int strncmp(const char *s1, const char *s2, size_t n); |
|
46 |
-#endif |
|
47 |
- |
|
48 |
-/* Comment out all this code if we are using the GNU C Library, and are not |
|
49 |
- actually compiling the library itself. This code is part of the GNU C |
|
50 |
- Library, but also included in many other GNU distributions. Compiling |
|
51 |
- and linking in this code is a waste when using the GNU C library |
|
52 |
- (especially if it is a shared library). Rather than having every GNU |
|
53 |
- program understand `configure --with-gnu-libc' and omit the object files, |
|
54 |
- it is simpler to just do this in the source for each such file. */ |
|
55 |
- |
|
56 |
-#define GETOPT_INTERFACE_VERSION 2 |
|
57 |
-#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 |
|
58 |
-# include <gnu-versions.h> |
|
59 |
-# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION |
|
60 |
-# define ELIDE_CODE |
|
61 |
-# endif |
|
62 |
-#endif |
|
63 |
- |
|
64 |
-#ifndef ELIDE_CODE |
|
65 |
- |
|
66 |
- |
|
67 |
-/* This needs to come after some library #include |
|
68 |
- to get __GNU_LIBRARY__ defined. */ |
|
69 |
-#ifdef __GNU_LIBRARY__ |
|
70 |
-/* Don't include stdlib.h for non-GNU C libraries because some of them |
|
71 |
- contain conflicting prototypes for getopt. */ |
|
72 |
-# include <stdlib.h> |
|
73 |
-# include <unistd.h> |
|
74 |
-#endif /* GNU C library. */ |
|
75 |
- |
|
76 |
-#ifdef VMS |
|
77 |
-# include <unixlib.h> |
|
78 |
-# if HAVE_STRING_H - 0 |
|
79 |
-# include <string.h> |
|
80 |
-# endif |
|
81 |
-#endif |
|
82 |
- |
|
83 |
-#ifndef _ |
|
84 |
-/* This is for other GNU distributions with internationalized messages. */ |
|
85 |
-# if defined HAVE_LIBINTL_H || defined _LIBC |
|
86 |
-# include <libintl.h> |
|
87 |
-# ifndef _ |
|
88 |
-# define _(msgid) gettext (msgid) |
|
89 |
-# endif |
|
90 |
-# else |
|
91 |
-# define _(msgid) (msgid) |
|
92 |
-# endif |
|
93 |
-#endif |
|
94 |
- |
|
95 |
-/* This version of `getopt' appears to the caller like standard Unix `getopt' |
|
96 |
- but it behaves differently for the user, since it allows the user |
|
97 |
- to intersperse the options with the other arguments. |
|
98 |
- |
|
99 |
- As `getopt' works, it permutes the elements of ARGV so that, |
|
100 |
- when it is done, all the options precede everything else. Thus |
|
101 |
- all application programs are extended to handle flexible argument order. |
|
102 |
- |
|
103 |
- Setting the environment variable POSIXLY_CORRECT disables permutation. |
|
104 |
- Then the behavior is completely standard. |
|
105 |
- |
|
106 |
- GNU application programs can use a third alternative mode in which |
|
107 |
- they can distinguish the relative order of options and other arguments. */ |
|
108 |
- |
|
29 |
+#include <string.h> |
|
109 | 30 |
#include "getopt.h" |
110 | 31 |
|
111 |
-/* For communication from `getopt' to the caller. |
|
112 |
- When `getopt' finds an option that takes an argument, |
|
113 |
- the argument value is returned here. |
|
114 |
- Also, when `ordering' is RETURN_IN_ORDER, |
|
115 |
- each non-option ARGV-element is returned here. */ |
|
116 |
- |
|
117 |
-char *optarg; |
|
118 |
- |
|
119 |
-/* Index in ARGV of the next element to be scanned. |
|
120 |
- This is used for communication to and from the caller |
|
121 |
- and for communication between successive calls to `getopt'. |
|
122 |
- |
|
123 |
- On entry to `getopt', zero means this is the first call; initialize. |
|
124 |
- |
|
125 |
- When `getopt' returns -1, this is the index of the first of the |
|
126 |
- non-option elements that the caller should itself scan. |
|
127 |
- |
|
128 |
- Otherwise, `optind' communicates from one call to the next |
|
129 |
- how much of ARGV has been scanned so far. */ |
|
130 |
- |
|
131 |
-/* 1003.2 says this must be 1 before any call. */ |
|
132 |
-int optind = 1; |
|
133 |
- |
|
134 |
-/* Formerly, initialization of getopt depended on optind==0, which |
|
135 |
- causes problems with re-calling getopt as programs generally don't |
|
136 |
- know that. */ |
|
137 |
- |
|
138 |
-int __getopt_initialized; |
|
139 |
- |
|
140 |
-/* The next char to be scanned in the option-element |
|
141 |
- in which the last option character we returned was found. |
|
142 |
- This allows us to pick up the scan where we left off. |
|
143 |
- |
|
144 |
- If this is zero, or a null string, it means resume the scan |
|
145 |
- by advancing to the next ARGV-element. */ |
|
146 |
- |
|
147 |
-static char *nextchar; |
|
148 |
- |
|
149 |
-/* Callers store zero here to inhibit the error message |
|
150 |
- for unrecognized options. */ |
|
151 |
- |
|
152 |
-int opterr = 1; |
|
153 |
- |
|
154 |
-/* Set to an option character which was unrecognized. |
|
155 |
- This must be initialized on some systems to avoid linking in the |
|
156 |
- system's own getopt implementation. */ |
|
157 |
- |
|
158 |
-int optopt = '?'; |
|
159 |
- |
|
160 |
-/* Describe how to deal with options that follow non-option ARGV-elements. |
|
161 |
- |
|
162 |
- If the caller did not specify anything, |
|
163 |
- the default is REQUIRE_ORDER if the environment variable |
|
164 |
- POSIXLY_CORRECT is defined, PERMUTE otherwise. |
|
32 |
+int optind=1, opterr=1, optopt=0; |
|
33 |
+char *optarg=0; |
|
165 | 34 |
|
166 |
- REQUIRE_ORDER means don't recognize them as options; |
|
167 |
- stop option processing when the first non-option is seen. |
|
168 |
- This is what Unix does. |
|
169 |
- This mode of operation is selected by either setting the environment |
|
170 |
- variable POSIXLY_CORRECT, or using `+' as the first character |
|
171 |
- of the list of option characters. |
|
172 |
- |
|
173 |
- PERMUTE is the default. We permute the contents of ARGV as we scan, |
|
174 |
- so that eventually all the non-options are at the end. This allows options |
|
175 |
- to be given in any order, even with programs that were not written to |
|
176 |
- expect this. |
|
177 |
- |
|
178 |
- RETURN_IN_ORDER is an option available to programs that were written |
|
179 |
- to expect options and other ARGV-elements in any order and that care about |
|
180 |
- the ordering of the two. We describe each non-option ARGV-element |
|
181 |
- as if it were the argument of an option with character code 1. |
|
182 |
- Using `-' as the first character of the list of option characters |
|
183 |
- selects this mode of operation. |
|
184 |
- |
|
185 |
- The special argument `--' forces an end of option-scanning regardless |
|
186 |
- of the value of `ordering'. In the case of RETURN_IN_ORDER, only |
|
187 |
- `--' can cause `getopt' to return -1 with `optind' != ARGC. */ |
|
188 |
- |
|
189 |
-static enum |
|
190 |
-{ |
|
191 |
- REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER |
|
192 |
-} ordering; |
|
193 |
- |
|
194 |
-/* Value of POSIXLY_CORRECT environment variable. */ |
|
195 |
-static char *posixly_correct; |
|
196 |
- |
|
197 |
-#ifdef __GNU_LIBRARY__ |
|
198 |
-/* We want to avoid inclusion of string.h with non-GNU libraries |
|
199 |
- because there are many ways it can cause trouble. |
|
200 |
- On some systems, it contains special magic macros that don't work |
|
201 |
- in GCC. */ |
|
202 |
-# include <string.h> |
|
203 |
-# define my_index strchr |
|
204 |
-#else |
|
205 |
- |
|
206 |
-# if HAVE_STRING_H |
|
207 |
-# include <string.h> |
|
208 |
-# else |
|
209 |
-# include <strings.h> |
|
210 |
-# endif |
|
211 |
- |
|
212 |
-/* Avoid depending on library functions or files |
|
213 |
- whose names are inconsistent. */ |
|
214 |
- |
|
215 |
-#ifndef getenv |
|
216 |
-extern char *getenv (); |
|
217 |
-#endif |
|
218 |
- |
|
219 |
-static char * |
|
220 |
-my_index (str, chr) |
|
221 |
- const char *str; |
|
222 |
- int chr; |
|
35 |
+/* reset argument parser to start-up values */ |
|
36 |
+int getopt_reset(void) |
|
223 | 37 |
{ |
224 |
- while (*str) |
|
225 |
- { |
|
226 |
- if (*str == chr) |
|
227 |
- return (char *) str; |
|
228 |
- str++; |
|
229 |
- } |
|
230 |
- return 0; |
|
38 |
+ optind = 1; |
|
39 |
+ opterr = 1; |
|
40 |
+ optopt = 0; |
|
41 |
+ optarg = 0; |
|
42 |
+ return 0; |
|
231 | 43 |
} |
232 | 44 |
|
233 |
-/* If using GCC, we can safely declare strlen this way. |
|
234 |
- If not using GCC, it is ok not to declare it. */ |
|
235 |
-#ifdef __GNUC__ |
|
236 |
-/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. |
|
237 |
- That was relevant to code that was here before. */ |
|
238 |
-# if (!defined __STDC__ || !__STDC__) && !defined strlen |
|
239 |
-/* gcc with -traditional declares the built-in strlen to return int, |
|
240 |
- and has done so at least since version 2.4.5. -- rms. */ |
|
241 |
-extern int strlen (const char *); |
|
242 |
-# endif /* not __STDC__ */ |
|
243 |
-#endif /* __GNUC__ */ |
|
244 |
- |
|
245 |
-#endif /* not __GNU_LIBRARY__ */ |
|
246 |
- |
|
247 |
-/* Handle permutation of arguments. */ |
|
248 |
- |
|
249 |
-/* Describe the part of ARGV that contains non-options that have |
|
250 |
- been skipped. `first_nonopt' is the index in ARGV of the first of them; |
|
251 |
- `last_nonopt' is the index after the last of them. */ |
|
252 |
- |
|
253 |
-static int first_nonopt; |
|
254 |
-static int last_nonopt; |
|
255 |
- |
|
256 |
-#ifdef _LIBC |
|
257 |
-/* Bash 2.0 gives us an environment variable containing flags |
|
258 |
- indicating ARGV elements that should not be considered arguments. */ |
|
45 |
+/* this is the plain old UNIX getopt, with GNU-style extensions. */ |
|
46 |
+/* if you're porting some piece of UNIX software, this is all you need. */ |
|
47 |
+/* this supports GNU-style permution and optional arguments */ |
|
259 | 48 |
|
260 |
-/* Defined in getopt_init.c */ |
|
261 |
-extern char *__getopt_nonoption_flags; |
|
262 |
- |
|
263 |
-static int nonoption_flags_max_len; |
|
264 |
-static int nonoption_flags_len; |
|
265 |
- |
|
266 |
-static int original_argc; |
|
267 |
-static char *const *original_argv; |
|
268 |
- |
|
269 |
-/* Make sure the environment variable bash 2.0 puts in the environment |
|
270 |
- is valid for the getopt call we must make sure that the ARGV passed |
|
271 |
- to getopt is that one passed to the process. */ |
|
272 |
-static void |
|
273 |
-__attribute__ ((unused)) |
|
274 |
-store_args_and_env (int argc, char *const *argv) |
|
49 |
+int getopt(int argc, char * argv[], const char *opts) |
|
275 | 50 |
{ |
276 |
- /* XXX This is no good solution. We should rather copy the args so |
|
277 |
- that we can compare them later. But we must not use malloc(3). */ |
|
278 |
- original_argc = argc; |
|
279 |
- original_argv = argv; |
|
280 |
-} |
|
281 |
-# ifdef text_set_element |
|
282 |
-text_set_element (__libc_subinit, store_args_and_env); |
|
283 |
-# endif /* text_set_element */ |
|
284 |
- |
|
285 |
-# define SWAP_FLAGS(ch1, ch2) \ |
|
286 |
- if (nonoption_flags_len > 0) \ |
|
287 |
- { \ |
|
288 |
- char __tmp = __getopt_nonoption_flags[ch1]; \ |
|
289 |
- __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ |
|
290 |
- __getopt_nonoption_flags[ch2] = __tmp; \ |
|
291 |
- } |
|
292 |
-#else /* !_LIBC */ |
|
293 |
-# define SWAP_FLAGS(ch1, ch2) |
|
294 |
-#endif /* _LIBC */ |
|
295 |
- |
|
296 |
-/* Exchange two adjacent subsequences of ARGV. |
|
297 |
- One subsequence is elements [first_nonopt,last_nonopt) |
|
298 |
- which contains all the non-options that have been skipped so far. |
|
299 |
- The other is elements [last_nonopt,optind), which contains all |
|
300 |
- the options processed since those non-options were skipped. |
|
301 |
- |
|
302 |
- `first_nonopt' and `last_nonopt' are relocated so that they describe |
|
303 |
- the new indices of the non-options in ARGV after they are moved. */ |
|
304 |
- |
|
305 |
-#if defined __STDC__ && __STDC__ |
|
306 |
-static void exchange (char **); |
|
307 |
-#endif |
|
308 |
- |
|
309 |
-static void |
|
310 |
-exchange (argv) |
|
311 |
- char **argv; |
|
312 |
-{ |
|
313 |
- int bottom = first_nonopt; |
|
314 |
- int middle = last_nonopt; |
|
315 |
- int top = optind; |
|
316 |
- char *tem; |
|
317 |
- |
|
318 |
- /* Exchange the shorter segment with the far end of the longer segment. |
|
319 |
- That puts the shorter segment into the right place. |
|
320 |
- It leaves the longer segment in the right place overall, |
|
321 |
- but it consists of two parts that need to be swapped next. */ |
|
322 |
- |
|
323 |
-#ifdef _LIBC |
|
324 |
- /* First make sure the handling of the `__getopt_nonoption_flags' |
|
325 |
- string can work normally. Our top argument must be in the range |
|
326 |
- of the string. */ |
|
327 |
- if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) |
|
328 |
- { |
|
329 |
- /* We must extend the array. The user plays games with us and |
|
330 |
- presents new arguments. */ |
|
331 |
- char *new_str = malloc (top + 1); |
|
332 |
- if (new_str == NULL) |
|
333 |
- nonoption_flags_len = nonoption_flags_max_len = 0; |
|
334 |
- else |
|
335 |
- { |
|
336 |
- memset (__mempcpy (new_str, __getopt_nonoption_flags, |
|
337 |
- nonoption_flags_max_len), |
|
338 |
- '\0', top + 1 - nonoption_flags_max_len); |
|
339 |
- nonoption_flags_max_len = top + 1; |
|
340 |
- __getopt_nonoption_flags = new_str; |
|
341 |
- } |
|
51 |
+ static int charind=0; |
|
52 |
+ const char *s; |
|
53 |
+ char mode, colon_mode; |
|
54 |
+ int off = 0, opt = -1; |
|
55 |
+ |
|
56 |
+ if(getenv("POSIXLY_CORRECT")) colon_mode = mode = '+'; |
|
57 |
+ else { |
|
58 |
+ if((colon_mode = *opts) == ':') off ++; |
|
59 |
+ if(((mode = opts[off]) == '+') || (mode == '-')) { |
|
60 |
+ off++; |
|
61 |
+ if((colon_mode != ':') && ((colon_mode = opts[off]) == ':')) |
|
62 |
+ off ++; |
|
342 | 63 |
} |
343 |
-#endif |
|
344 |
- |
|
345 |
- while (top > middle && middle > bottom) |
|
346 |
- { |
|
347 |
- if (top - middle > middle - bottom) |
|
348 |
- { |
|
349 |
- /* Bottom segment is the short one. */ |
|
350 |
- int len = middle - bottom; |
|
351 |
- register int i; |
|
352 |
- |
|
353 |
- /* Swap it with the top part of the top segment. */ |
|
354 |
- for (i = 0; i < len; i++) |
|
355 |
- { |
|
356 |
- tem = argv[bottom + i]; |
|
357 |
- argv[bottom + i] = argv[top - (middle - bottom) + i]; |
|
358 |
- argv[top - (middle - bottom) + i] = tem; |
|
359 |
- SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); |
|
360 |
- } |
|
361 |
- /* Exclude the moved bottom segment from further swapping. */ |
|
362 |
- top -= len; |
|
363 |
- } |
|
364 |
- else |
|
365 |
- { |
|
366 |
- /* Top segment is the short one. */ |
|
367 |
- int len = top - middle; |
|
368 |
- register int i; |
|
369 |
- |
|
370 |
- /* Swap it with the bottom part of the bottom segment. */ |
|
371 |
- for (i = 0; i < len; i++) |
|
372 |
- { |
|
373 |
- tem = argv[bottom + i]; |
|
374 |
- argv[bottom + i] = argv[middle + i]; |
|
375 |
- argv[middle + i] = tem; |
|
376 |
- SWAP_FLAGS (bottom + i, middle + i); |
|
377 |
- } |
|
378 |
- /* Exclude the moved top segment from further swapping. */ |
|
379 |
- bottom += len; |
|
380 |
- } |
|
64 |
+ } |
|
65 |
+ optarg = 0; |
|
66 |
+ if(charind) { |
|
67 |
+ optopt = argv[optind][charind]; |
|
68 |
+ for(s=opts+off; *s; s++) if(optopt == *s) { |
|
69 |
+ charind++; |
|
70 |
+ if((*(++s) == ':') || ((optopt == 'W') && (*s == ';'))) { |
|
71 |
+ if(argv[optind][charind]) { |
|
72 |
+ optarg = &(argv[optind++][charind]); |
|
73 |
+ charind = 0; |
|
74 |
+ } else if(*(++s) != ':') { |
|
75 |
+ charind = 0; |
|
76 |
+ if(++optind >= argc) { |
|
77 |
+ if(opterr) fprintf(stderr, |
|
78 |
+ "%s: option requires an argument -- %c\n", |
|
79 |
+ argv[0], optopt); |
|
80 |
+ opt = (colon_mode == ':') ? ':' : '?'; |
|
81 |
+ goto getopt_ok; |
|
82 |
+ } |
|
83 |
+ optarg = argv[optind++]; |
|
84 |
+ } |
|
85 |
+ } |
|
86 |
+ opt = optopt; |
|
87 |
+ goto getopt_ok; |
|
381 | 88 |
} |
382 |
- |
|
383 |
- /* Update records for the slots the non-options now occupy. */ |
|
384 |
- |
|
385 |
- first_nonopt += (optind - last_nonopt); |
|
386 |
- last_nonopt = optind; |
|
387 |
-} |
|
388 |
- |
|
389 |
-/* Initialize the internal data when the first call is made. */ |
|
390 |
- |
|
391 |
-#if defined __STDC__ && __STDC__ |
|
392 |
-static const char *_getopt_initialize (int, char *const *, const char *); |
|
393 |
-#endif |
|
394 |
-static const char * |
|
395 |
-_getopt_initialize (argc, argv, optstring) |
|
396 |
- int argc; |
|
397 |
- char *const *argv; |
|
398 |
- const char *optstring; |
|
399 |
-{ |
|
400 |
- /* Start processing options with ARGV-element 1 (since ARGV-element 0 |
|
401 |
- is the program name); the sequence of previously skipped |
|
402 |
- non-option ARGV-elements is empty. */ |
|
403 |
- |
|
404 |
- first_nonopt = last_nonopt = optind; |
|
405 |
- |
|
406 |
- nextchar = NULL; |
|
407 |
- |
|
408 |
- posixly_correct = getenv ("POSIXLY_CORRECT"); |
|
409 |
- |
|
410 |
- /* Determine how to handle the ordering of options and nonoptions. */ |
|
411 |
- |
|
412 |
- if (optstring[0] == '-') |
|
413 |
- { |
|
414 |
- ordering = RETURN_IN_ORDER; |
|
415 |
- ++optstring; |
|
89 |
+ if(opterr) fprintf(stderr, |
|
90 |
+ "%s: illegal option -- %c\n", |
|
91 |
+ argv[0], optopt); |
|
92 |
+ opt = '?'; |
|
93 |
+ if(argv[optind][++charind] == '\0') { |
|
94 |
+ optind++; |
|
95 |
+ charind = 0; |
|
416 | 96 |
} |
417 |
- else if (optstring[0] == '+') |
|
418 |
- { |
|
419 |
- ordering = REQUIRE_ORDER; |
|
420 |
- ++optstring; |
|
97 |
+ getopt_ok: |
|
98 |
+ if(charind && ! argv[optind][charind]) { |
|
99 |
+ optind++; |
|
100 |
+ charind = 0; |
|
421 | 101 |
} |
422 |
- else if (posixly_correct != NULL) |
|
423 |
- ordering = REQUIRE_ORDER; |
|
424 |
- else |
|
425 |
- ordering = PERMUTE; |
|
426 |
- |
|
427 |
-#ifdef _LIBC |
|
428 |
- if (posixly_correct == NULL |
|
429 |
- && argc == original_argc && argv == original_argv) |
|
430 |
- { |
|
431 |
- if (nonoption_flags_max_len == 0) |
|
432 |
- { |
|
433 |
- if (__getopt_nonoption_flags == NULL |
|
434 |
- || __getopt_nonoption_flags[0] == '\0') |
|
435 |
- nonoption_flags_max_len = -1; |
|
436 |
- else |
|
437 |
- { |
|
438 |
- const char *orig_str = __getopt_nonoption_flags; |
|
439 |
- int len = nonoption_flags_max_len = strlen (orig_str); |
|
440 |
- if (nonoption_flags_max_len < argc) |
|
441 |
- nonoption_flags_max_len = argc; |
|
442 |
- __getopt_nonoption_flags = |
|
443 |
- (char *) malloc (nonoption_flags_max_len); |
|
444 |
- if (__getopt_nonoption_flags == NULL) |
|
445 |
- nonoption_flags_max_len = -1; |
|
446 |
- else |
|
447 |
- memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), |
|
448 |
- '\0', nonoption_flags_max_len - len); |
|
449 |
- } |
|
450 |
- } |
|
451 |
- nonoption_flags_len = nonoption_flags_max_len; |
|
102 |
+ } else if((optind >= argc) || |
|
103 |
+ ((argv[optind][0] == '-') && |
|
104 |
+ (argv[optind][1] == '-') && |
|
105 |
+ (argv[optind][2] == '\0'))) { |
|
106 |
+ optind++; |
|
107 |
+ opt = -1; |
|
108 |
+ } else if((argv[optind][0] != '-') || |
|
109 |
+ (argv[optind][1] == '\0')) { |
|
110 |
+ char *tmp; |
|
111 |
+ int i, j, k; |
|
112 |
+ |
|
113 |
+ if(mode == '+') opt = -1; |
|
114 |
+ else if(mode == '-') { |
|
115 |
+ optarg = argv[optind++]; |
|
116 |
+ charind = 0; |
|
117 |
+ opt = 1; |
|
118 |
+ } else { |
|
119 |
+ for(i=j=optind; i<argc; i++) if((argv[i][0] == '-') && |
|
120 |
+ (argv[i][1] != '\0')) { |
|
121 |
+ optind=i; |
|
122 |
+ opt=getopt(argc, argv, opts); |
|
123 |
+ while(i > j) { |
|
124 |
+ tmp=argv[--i]; |
|
125 |
+ for(k=i; k+1<optind; k++) argv[k]=argv[k+1]; |
|
126 |
+ argv[--optind]=tmp; |
|
127 |
+ } |
|
128 |
+ break; |
|
129 |
+ } |
|
130 |
+ if(i == argc) opt = -1; |
|
452 | 131 |
} |
453 |
- else |
|
454 |
- nonoption_flags_len = 0; |
|
455 |
-#endif |
|
456 |
- |
|
457 |
- return optstring; |
|
132 |
+ } else { |
|
133 |
+ charind++; |
|
134 |
+ opt = getopt(argc, argv, opts); |
|
135 |
+ } |
|
136 |
+ if (optind > argc) optind = argc; |
|
137 |
+ return opt; |
|
458 | 138 |
} |
459 |
- |
|
460 |
-/* Scan elements of ARGV (whose length is ARGC) for option characters |
|
461 |
- given in OPTSTRING. |
|
462 |
- |
|
463 |
- If an element of ARGV starts with '-', and is not exactly "-" or "--", |
|
464 |
- then it is an option element. The characters of this element |
|
465 |
- (aside from the initial '-') are option characters. If `getopt' |
|
466 |
- is called repeatedly, it returns successively each of the option characters |
|
467 |
- from each of the option elements. |
|
468 |
- |
|
469 |
- If `getopt' finds another option character, it returns that character, |
|
470 |
- updating `optind' and `nextchar' so that the next call to `getopt' can |
|
471 |
- resume the scan with the following option character or ARGV-element. |
|
472 |
- |
|
473 |
- If there are no more option characters, `getopt' returns -1. |
|
474 |
- Then `optind' is the index in ARGV of the first ARGV-element |
|
475 |
- that is not an option. (The ARGV-elements have been permuted |
|
476 |
- so that those that are not options now come last.) |
|
477 |
- |
|
478 |
- OPTSTRING is a string containing the legitimate option characters. |
|
479 |
- If an option character is seen that is not listed in OPTSTRING, |
|
480 |
- return '?' after printing an error message. If you set `opterr' to |
|
481 |
- zero, the error message is suppressed but we still return '?'. |
|
482 |
- |
|
483 |
- If a char in OPTSTRING is followed by a colon, that means it wants an arg, |
|
484 |
- so the following text in the same ARGV-element, or the text of the following |
|
485 |
- ARGV-element, is returned in `optarg'. Two colons mean an option that |
|
486 |
- wants an optional arg; if there is text in the current ARGV-element, |
|
487 |
- it is returned in `optarg', otherwise `optarg' is set to zero. |
|
488 |
- |
|
489 |
- If OPTSTRING starts with `-' or `+', it requests different methods of |
|
490 |
- handling the non-option ARGV-elements. |
|
491 |
- See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. |
|
492 |
- |
|
493 |
- Long-named options begin with `--' instead of `-'. |
|
494 |
- Their names may be abbreviated as long as the abbreviation is unique |
|
495 |
- or is an exact match for some defined option. If they have an |
|
496 |
- argument, it follows the option name in the same ARGV-element, separated |
|
497 |
- from the option name by a `=', or else the in next ARGV-element. |
|
498 |
- When `getopt' finds a long-named option, it returns 0 if that option's |
|
499 |
- `flag' field is nonzero, the value of the option's `val' field |
|
500 |
- if the `flag' field is zero. |
|
501 |
- |
|
502 |
- The elements of ARGV aren't really const, because we permute them. |
|
503 |
- But we pretend they're const in the prototype to be compatible |
|
504 |
- with other systems. |
|
505 | 139 |
|
506 |
- LONGOPTS is a vector of `struct option' terminated by an |
|
507 |
- element containing a name which is zero. |
|
140 |
+/* this is the extended getopt_long{,_only}, with some GNU-like |
|
141 |
+ * extensions. Implements _getopt_internal in case any programs |
|
142 |
+ * expecting GNU libc getopt call it. |
|
143 |
+ */ |
|
508 | 144 |
|
509 |
- LONGIND returns the index in LONGOPT of the long-named option found. |
|
510 |
- It is only valid when a long-named option has been found by the most |
|
511 |
- recent call. |
|
512 |
- |
|
513 |
- If LONG_ONLY is nonzero, '-' as well as '--' can introduce |
|
514 |
- long-named options. */ |
|
515 |
- |
|
516 |
-int |
|
517 |
-_getopt_internal (argc, argv, optstring, longopts, longind, long_only) |
|
518 |
- int argc; |
|
519 |
- char *const *argv; |
|
520 |
- const char *optstring; |
|
521 |
- const struct option *longopts; |
|
522 |
- int *longind; |
|
523 |
- int long_only; |
|
145 |
+int _getopt_internal(int argc, char * argv[], const char *shortopts, |
|
146 |
+ const struct option *longopts, int *longind, |
|
147 |
+ int long_only) |
|
524 | 148 |
{ |
525 |
- int print_errors = opterr; |
|
526 |
- if (optstring[0] == ':') |
|
527 |
- print_errors = 0; |
|
528 |
- |
|
529 |
- if (argc < 1) |
|
530 |
- return -1; |
|
531 |
- |
|
532 |
- optarg = NULL; |
|
533 |
- |
|
534 |
- if (optind == 0 || !__getopt_initialized) |
|
535 |
- { |
|
536 |
- if (optind == 0) |
|
537 |
- optind = 1; /* Don't scan ARGV[0], the program name. */ |
|
538 |
- optstring = _getopt_initialize (argc, argv, optstring); |
|
539 |
- __getopt_initialized = 1; |
|
149 |
+ char mode, colon_mode = *shortopts; |
|
150 |
+ int shortoff = 0, opt = -1; |
|
151 |
+ |
|
152 |
+ if(getenv("POSIXLY_CORRECT")) colon_mode = mode = '+'; |
|
153 |
+ else { |
|
154 |
+ if((colon_mode = *shortopts) == ':') shortoff ++; |
|
155 |
+ if(((mode = shortopts[shortoff]) == '+') || (mode == '-')) { |
|
156 |
+ shortoff++; |
|
157 |
+ if((colon_mode != ':') && ((colon_mode = shortopts[shortoff]) == ':')) |
|
158 |
+ shortoff ++; |
|
540 | 159 |
} |
541 |
- |
|
542 |
- /* Test whether ARGV[optind] points to a non-option argument. |
|
543 |
- Either it does not have option syntax, or there is an environment flag |
|
544 |
- from the shell indicating it is not an option. The later information |
|
545 |
- is only used when the used in the GNU libc. */ |
|
546 |
-#ifdef _LIBC |
|
547 |
-# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ |
|
548 |
- || (optind < nonoption_flags_len \ |
|
549 |
- && __getopt_nonoption_flags[optind] == '1')) |
|
550 |
-#else |
|
551 |
-# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') |
|
552 |
-#endif |
|
553 |
- |
|
554 |
- if (nextchar == NULL || *nextchar == '\0') |
|
555 |
- { |
|
556 |
- /* Advance to the next ARGV-element. */ |
|
557 |
- |
|
558 |
- /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been |
|
559 |
- moved back by the user (who may also have changed the arguments). */ |
|
560 |
- if (last_nonopt > optind) |
|
561 |
- last_nonopt = optind; |
|
562 |
- if (first_nonopt > optind) |
|
563 |
- first_nonopt = optind; |
|
564 |
- |
|
565 |
- if (ordering == PERMUTE) |
|
566 |
- { |
|
567 |
- /* If we have just processed some options following some non-options, |
|
568 |
- exchange them so that the options come first. */ |
|
569 |
- |
|
570 |
- if (first_nonopt != last_nonopt && last_nonopt != optind) |
|
571 |
- exchange ((char **) argv); |
|
572 |
- else if (last_nonopt != optind) |
|
573 |
- first_nonopt = optind; |
|
574 |
- |
|
575 |
- /* Skip any additional non-options |
|
576 |
- and extend the range of non-options previously skipped. */ |
|
577 |
- |
|
578 |
- while (optind < argc && NONOPTION_P) |
|
579 |
- optind++; |
|
580 |
- last_nonopt = optind; |
|
581 |
- } |
|
582 |
- |
|
583 |
- /* The special ARGV-element `--' means premature end of options. |
|
584 |
- Skip it like a null option, |
|
585 |
- then exchange with previous non-options as if it were an option, |
|
586 |
- then skip everything else like a non-option. */ |
|
587 |
- |
|
588 |
- if (optind != argc && !strcmp (argv[optind], "--")) |
|
589 |
- { |
|
590 |
- optind++; |
|
591 |
- |
|
592 |
- if (first_nonopt != last_nonopt && last_nonopt != optind) |
|
593 |
- exchange ((char **) argv); |
|
594 |
- else if (first_nonopt == last_nonopt) |
|
595 |
- first_nonopt = optind; |
|
596 |
- last_nonopt = argc; |
|
597 |
- |
|
598 |
- optind = argc; |
|
599 |
- } |
|
600 |
- |
|
601 |
- /* If we have done all the ARGV-elements, stop the scan |
|
602 |
- and back over any non-options that we skipped and permuted. */ |
|
603 |
- |
|
604 |
- if (optind == argc) |
|
605 |
- { |
|
606 |
- /* Set the next-arg-index to point at the non-options |
|
607 |
- that we previously skipped, so the caller will digest them. */ |
|
608 |
- if (first_nonopt != last_nonopt) |
|
609 |
- optind = first_nonopt; |
|
610 |
- return -1; |
|
611 |
- } |
|
612 |
- |
|
613 |
- /* If we have come to a non-option and did not permute it, |
|
614 |
- either stop the scan or describe it to the caller and pass it by. */ |
|
615 |
- |
|
616 |
- if (NONOPTION_P) |
|
617 |
- { |
|
618 |
- if (ordering == REQUIRE_ORDER) |
|
619 |
- return -1; |
|
620 |
- optarg = argv[optind++]; |
|
621 |
- return 1; |
|
622 |
- } |
|
623 |
- |
|
624 |
- /* We have found another option-ARGV-element. |
|
625 |
- Skip the initial punctuation. */ |
|
626 |
- |
|
627 |
- nextchar = (argv[optind] + 1 |
|
628 |
- + (longopts != NULL && argv[optind][1] == '-')); |
|
160 |
+ } |
|
161 |
+ optarg = 0; |
|
162 |
+ if((optind >= argc) || |
|
163 |
+ ((argv[optind][0] == '-') && |
|
164 |
+ (argv[optind][1] == '-') && |
|
165 |
+ (argv[optind][2] == '\0'))) { |
|
166 |
+ optind++; |
|
167 |
+ opt = -1; |
|
168 |
+ } else if((argv[optind][0] != '-') || |
|
169 |
+ (argv[optind][1] == '\0')) { |
|
170 |
+ char *tmp; |
|
171 |
+ int i, j, k; |
|
172 |
+ |
|
173 |
+ opt = -1; |
|
174 |
+ if(mode == '+') return -1; |
|
175 |
+ else if(mode == '-') { |
|
176 |
+ optarg = argv[optind++]; |
|
177 |
+ return 1; |
|
629 | 178 |
} |
630 |
- |
|
631 |
- /* Decode the current option-ARGV-element. */ |
|
632 |
- |
|
633 |
- /* Check whether the ARGV-element is a long option. |
|
634 |
- |
|
635 |
- If long_only and the ARGV-element has the form "-f", where f is |
|
636 |
- a valid short option, don't consider it an abbreviated form of |
|
637 |
- a long option that starts with f. Otherwise there would be no |
|
638 |
- way to give the -f short option. |
|
639 |
- |
|
640 |
- On the other hand, if there's a long option "fubar" and |
|
641 |
- the ARGV-element is "-fu", do consider that an abbreviation of |
|
642 |
- the long option, just like "--fu", and not "-f" with arg "u". |
|
643 |
- |
|
644 |
- This distinction seems to be the most useful approach. */ |
|
645 |
- |
|
646 |
- if (longopts != NULL |
|
647 |
- && (argv[optind][1] == '-' |
|
648 |
- || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) |
|
649 |
- { |
|
650 |
- char *nameend; |
|
651 |
- const struct option *p; |
|
652 |
- const struct option *pfound = NULL; |
|
653 |
- int exact = 0; |
|
654 |
- int ambig = 0; |
|
655 |
- int indfound = -1; |
|
656 |
- int option_index; |
|
657 |
- |
|
658 |
- for (nameend = nextchar; *nameend && *nameend != '='; nameend++) |
|
659 |
- /* Do nothing. */ ; |
|
660 |
- |
|
661 |
- /* Test all long options for either exact match |
|
662 |
- or abbreviated matches. */ |
|
663 |
- for (p = longopts, option_index = 0; p->name; p++, option_index++) |
|
664 |
- if (!strncmp (p->name, nextchar, nameend - nextchar)) |
|
665 |
- { |
|
666 |
- if ((unsigned int) (nameend - nextchar) |
|
667 |
- == (unsigned int) strlen (p->name)) |
|
668 |
- { |
|
669 |
- /* Exact match found. */ |
|
670 |
- pfound = p; |
|
671 |
- indfound = option_index; |
|
672 |
- exact = 1; |
|
673 |
- break; |
|
674 |
- } |
|
675 |
- else if (pfound == NULL) |
|
676 |
- { |
|
677 |
- /* First nonexact match found. */ |
|
678 |
- pfound = p; |
|
679 |
- indfound = option_index; |
|
680 |
- } |
|
681 |
- else if (long_only |
|
682 |
- || pfound->has_arg != p->has_arg |
|
683 |
- || pfound->flag != p->flag |
|
684 |
- || pfound->val != p->val) |
|
685 |
- /* Second or later nonexact match found. */ |
|
686 |
- ambig = 1; |
|
687 |
- } |
|
688 |
- |
|
689 |
- if (ambig && !exact) |
|
690 |
- { |
|
691 |
- if (print_errors) |
|
692 |
- fprintf (stderr, _("%s: option `%s' is ambiguous\n"), |
|
693 |
- argv[0], argv[optind]); |
|
694 |
- nextchar += strlen (nextchar); |
|
695 |
- optind++; |
|
696 |
- optopt = 0; |
|
697 |
- return '?'; |
|
698 |
- } |
|
699 |
- |
|
700 |
- if (pfound != NULL) |
|
701 |
- { |
|
702 |
- option_index = indfound; |
|
703 |
- optind++; |
|
704 |
- if (*nameend) |
|
705 |
- { |
|
706 |
- /* Don't test has_arg with >, because some C compilers don't |
|
707 |
- allow it to be used on enums. */ |
|
708 |
- if (pfound->has_arg) |
|
709 |
- optarg = nameend + 1; |
|
710 |
- else |
|
711 |
- { |
|
712 |
- if (print_errors) |
|
713 |
- { |
|
714 |
- if (argv[optind - 1][1] == '-') |
|
715 |
- /* --option */ |
|
716 |
- fprintf (stderr, |
|
717 |
- _("%s: option `--%s' doesn't allow an argument\n"), |
|
718 |
- argv[0], pfound->name); |
|
719 |
- else |
|
720 |
- /* +option or -option */ |
|
721 |
- fprintf (stderr, |
|
722 |
- _("%s: option `%c%s' doesn't allow an argument\n"), |
|
723 |
- argv[0], argv[optind - 1][0], pfound->name); |
|
724 |
- } |
|
725 |
- |
|
726 |
- nextchar += strlen (nextchar); |
|
727 |
- |
|
728 |
- optopt = pfound->val; |
|
729 |
- return '?'; |
|
730 |
- } |
|
731 |
- } |
|
732 |
- else if (pfound->has_arg == 1) |
|
733 |
- { |
|
734 |
- if (optind < argc) |
|
735 |
- optarg = argv[optind++]; |
|
736 |
- else |
|
737 |
- { |
|
738 |
- if (print_errors) |
|
739 |
- fprintf (stderr, |
|
740 |
- _("%s: option `%s' requires an argument\n"), |
|
741 |
- argv[0], argv[optind - 1]); |
|
742 |
- nextchar += strlen (nextchar); |
|
743 |
- optopt = pfound->val; |
|
744 |
- return optstring[0] == ':' ? ':' : '?'; |
|
745 |
- } |
|
746 |
- } |
|
747 |
- nextchar += strlen (nextchar); |
|
748 |
- if (longind != NULL) |
|
749 |
- *longind = option_index; |
|
750 |
- if (pfound->flag) |
|
751 |
- { |
|
752 |
- *(pfound->flag) = pfound->val; |
|
753 |
- return 0; |
|
754 |
- } |
|
755 |
- return pfound->val; |
|
756 |
- } |
|
757 |
- |
|
758 |
- /* Can't find it as a long option. If this is not getopt_long_only, |
|
759 |
- or the option starts with '--' or is not a valid short |
|
760 |
- option, then it's an error. |
|
761 |
- Otherwise interpret it as a short option. */ |
|
762 |
- if (!long_only || argv[optind][1] == '-' |
|
763 |
- || my_index (optstring, *nextchar) == NULL) |
|
764 |
- { |
|
765 |
- if (print_errors) |
|
766 |
- { |
|
767 |
- if (argv[optind][1] == '-') |
|
768 |
- /* --option */ |
|
769 |
- fprintf (stderr, _("%s: unrecognized option `--%s'\n"), |
|
770 |
- argv[0], nextchar); |
|
771 |
- else |
|
772 |
- /* +option or -option */ |
|
773 |
- fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), |
|
774 |
- argv[0], argv[optind][0], nextchar); |
|
775 |
- } |
|
776 |
- nextchar = (char *) ""; |
|
777 |
- optind++; |
|
778 |
- optopt = 0; |
|
779 |
- return '?'; |
|
780 |
- } |
|
179 |
+ for(i=j=optind; i<argc; i++) if((argv[i][0] == '-') && |
|
180 |
+ (argv[i][1] != '\0')) { |
|
181 |
+ optind=i; |
|
182 |
+ opt=_getopt_internal(argc, argv, shortopts, |
|
183 |
+ longopts, longind, |
|
184 |
+ long_only); |
|
185 |
+ while(i > j) { |
|
186 |
+ tmp=argv[--i]; |
|
187 |
+ for(k=i; k+1<optind; k++) |
|
188 |
+ argv[k]=argv[k+1]; |
|
189 |
+ argv[--optind]=tmp; |
|
190 |
+ } |
|
191 |
+ break; |
|
781 | 192 |
} |
782 |
- |
|
783 |
- /* Look at and handle the next short option-character. */ |
|
784 |
- |
|
785 |
- { |
|
786 |
- char c = *nextchar++; |
|
787 |
- char *temp = my_index (optstring, c); |
|
788 |
- |
|
789 |
- /* Increment `optind' when we start to process its last character. */ |
|
790 |
- if (*nextchar == '\0') |
|
791 |
- ++optind; |
|
792 |
- |
|
793 |
- if (temp == NULL || c == ':') |
|
794 |
- { |
|
795 |
- if (print_errors) |
|
796 |
- { |
|
797 |
- if (posixly_correct) |
|
798 |
- /* 1003.2 specifies the format of this message. */ |
|
799 |
- fprintf (stderr, _("%s: illegal option -- %c\n"), |
|
800 |
- argv[0], c); |
|
801 |
- else |
|
802 |
- fprintf (stderr, _("%s: invalid option -- %c\n"), |
|
803 |
- argv[0], c); |
|
804 |
- } |
|
805 |
- optopt = c; |
|
806 |
- return '?'; |
|
193 |
+ } else if((!long_only) && (argv[optind][1] != '-')) |
|
194 |
+ opt = getopt(argc, argv, shortopts); |
|
195 |
+ else { |
|
196 |
+ int charind, offset; |
|
197 |
+ int found = 0, ind, hits = 0; |
|
198 |
+ |
|
199 |
+ if(((optopt = argv[optind][1]) != '-') && ! argv[optind][2]) { |
|
200 |
+ int c; |
|
201 |
+ |
|
202 |
+ ind = shortoff; |
|
203 |
+ while((c = shortopts[ind++])) { |
|
204 |
+ if(((shortopts[ind] == ':') || |
|
205 |
+ ((c == 'W') && (shortopts[ind] == ';'))) && |
|
206 |
+ (shortopts[++ind] == ':')) |
|
207 |
+ ind ++; |
|
208 |
+ if(optopt == c) return getopt(argc, argv, shortopts); |
|
807 | 209 |
} |
808 |
- /* Convenience. Treat POSIX -W foo same as long option --foo */ |
|
809 |
- if (temp[0] == 'W' && temp[1] == ';') |
|
810 |
- { |
|
811 |
- char *nameend; |
|
812 |
- const struct option *p; |
|
813 |
- const struct option *pfound = NULL; |
|
814 |
- int exact = 0; |
|
815 |
- int ambig = 0; |
|
816 |
- int indfound = 0; |
|
817 |
- int option_index; |
|
818 |
- |
|
819 |
- /* This is an option that requires an argument. */ |
|
820 |
- if (*nextchar != '\0') |
|
821 |
- { |
|
822 |
- optarg = nextchar; |
|
823 |
- /* If we end this ARGV-element by taking the rest as an arg, |
|
824 |
- we must advance to the next element now. */ |
|
825 |
- optind++; |
|
826 |
- } |
|
827 |
- else if (optind == argc) |
|
828 |
- { |
|
829 |
- if (print_errors) |
|
830 |
- { |
|
831 |
- /* 1003.2 specifies the format of this message. */ |
|
832 |
- fprintf (stderr, _("%s: option requires an argument -- %c\n"), |
|
833 |
- argv[0], c); |
|
834 |
- } |
|
835 |
- optopt = c; |
|
836 |
- if (optstring[0] == ':') |
|
837 |
- c = ':'; |
|
838 |
- else |
|
839 |
- c = '?'; |
|
840 |
- return c; |
|
841 |
- } |
|
842 |
- else |
|
843 |
- /* We already incremented `optind' once; |
|
844 |
- increment it again when taking next ARGV-elt as argument. */ |
|
845 |
- optarg = argv[optind++]; |
|
846 |
- |
|
847 |
- /* optarg is now the argument, see if it's in the |
|
848 |
- table of longopts. */ |
|
849 |
- |
|
850 |
- for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) |
|
851 |
- /* Do nothing. */ ; |
|
852 |
- |
|
853 |
- /* Test all long options for either exact match |
|
854 |
- or abbreviated matches. */ |
|
855 |
- for (p = longopts, option_index = 0; p->name; p++, option_index++) |
|
856 |
- if (!strncmp (p->name, nextchar, nameend - nextchar)) |
|
857 |
- { |
|
858 |
- if ((unsigned int) (nameend - nextchar) == strlen (p->name)) |
|
859 |
- { |
|
860 |
- /* Exact match found. */ |
|
861 |
- pfound = p; |
|
862 |
- indfound = option_index; |
|
863 |
- exact = 1; |
|
864 |
- break; |
|
865 |
- } |
|
866 |
- else if (pfound == NULL) |
|
867 |
- { |
|
868 |
- /* First nonexact match found. */ |
|
869 |
- pfound = p; |
|
870 |
- indfound = option_index; |
|
871 |
- } |
|
872 |
- else |
|
873 |
- /* Second or later nonexact match found. */ |
|
874 |
- ambig = 1; |
|
875 |
- } |
|
876 |
- if (ambig && !exact) |
|
877 |
- { |
|
878 |
- if (print_errors) |
|
879 |
- fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), |
|
880 |
- argv[0], argv[optind]); |
|
881 |
- nextchar += strlen (nextchar); |
|
882 |
- optind++; |
|
883 |
- return '?'; |
|
884 |
- } |
|
885 |
- if (pfound != NULL) |
|
886 |
- { |
|
887 |
- option_index = indfound; |
|
888 |
- if (*nameend) |
|
889 |
- { |
|
890 |
- /* Don't test has_arg with >, because some C compilers don't |
|
891 |
- allow it to be used on enums. */ |
|
892 |
- if (pfound->has_arg) |
|
893 |
- optarg = nameend + 1; |
|
894 |
- else |
|
895 |
- { |
|
896 |
- if (print_errors) |
|
897 |
- fprintf (stderr, _("\ |
|
898 |
-%s: option `-W %s' doesn't allow an argument\n"), |
|
899 |
- argv[0], pfound->name); |
|
900 |
- |
|
901 |
- nextchar += strlen (nextchar); |
|
902 |
- return '?'; |
|
903 |
- } |
|
904 |
- } |
|
905 |
- else if (pfound->has_arg == 1) |
|
906 |
- { |
|
907 |
- if (optind < argc) |
|
908 |
- optarg = argv[optind++]; |
|
909 |
- else |
|
910 |
- { |
|
911 |
- if (print_errors) |
|
912 |
- fprintf (stderr, |
|
913 |
- _("%s: option `%s' requires an argument\n"), |
|
914 |
- argv[0], argv[optind - 1]); |
|
915 |
- nextchar += strlen (nextchar); |
|
916 |
- return optstring[0] == ':' ? ':' : '?'; |
|
917 |
- } |
|
918 |
- } |
|
919 |
- nextchar += strlen (nextchar); |
|
920 |
- if (longind != NULL) |
|
921 |
- *longind = option_index; |
|
922 |
- if (pfound->flag) |
|
923 |
- { |
|
924 |
- *(pfound->flag) = pfound->val; |
|
925 |
- return 0; |
|
926 |
- } |
|
927 |
- return pfound->val; |
|
928 |
- } |
|
929 |
- nextchar = NULL; |
|
930 |
- return 'W'; /* Let the application handle it. */ |
|
210 |
+ } |
|
211 |
+ offset = 2 - (argv[optind][1] != '-'); |
|
212 |
+ for(charind = offset; |
|
213 |
+ (argv[optind][charind] != '\0') && |
|
214 |
+ (argv[optind][charind] != '='); |
|
215 |
+ charind++); |
|
216 |
+ for(ind = 0; longopts[ind].name && !hits; ind++) |
|
217 |
+ if((strlen(longopts[ind].name) == (size_t) (charind - offset)) && |
|
218 |
+ (strncmp(longopts[ind].name, |
|
219 |
+ argv[optind] + offset, charind - offset) == 0)) |
|
220 |
+ found = ind, hits++; |
|
221 |
+ if(!hits) for(ind = 0; longopts[ind].name; ind++) |
|
222 |
+ if(strncmp(longopts[ind].name, |
|
223 |
+ argv[optind] + offset, charind - offset) == 0) |
|
224 |
+ found = ind, hits++; |
|
225 |
+ if(hits == 1) { |
|
226 |
+ opt = 0; |
|
227 |
+ |
|
228 |
+ if(argv[optind][charind] == '=') { |
|
229 |
+ if(longopts[found].has_arg == 0) { |
|
230 |
+ opt = '?'; |
|
231 |
+ if(opterr) fprintf(stderr, |
|
232 |
+ "%s: option `--%s' doesn't allow an argument\n", |
|
233 |
+ argv[0], longopts[found].name); |
|
234 |
+ } else { |
|
235 |
+ optarg = argv[optind] + ++charind; |
|
236 |
+ charind = 0; |
|
237 |
+ } |
|
238 |
+ } else if(longopts[found].has_arg == 1) { |
|
239 |
+ if(++optind >= argc) { |
|
240 |
+ opt = (colon_mode == ':') ? ':' : '?'; |
|
241 |
+ if(opterr) fprintf(stderr, |
|
242 |
+ "%s: option `--%s' requires an argument\n", |
|
243 |
+ argv[0], longopts[found].name); |
|
244 |
+ } else optarg = argv[optind]; |
|
245 |
+ } |
|
246 |
+ if(!opt) { |
|
247 |
+ if (longind) *longind = found; |
|
248 |
+ if(!longopts[found].flag) opt = longopts[found].val; |
|
249 |
+ else *(longopts[found].flag) = longopts[found].val; |
|
931 | 250 |
} |
932 |
- if (temp[1] == ':') |
|
933 |
- { |
|
934 |
- if (temp[2] == ':') |
|
935 |
- { |
|
936 |
- /* This is an option that accepts an argument optionally. */ |
|
937 |
- if (*nextchar != '\0') |
|
938 |
- { |
|
939 |
- optarg = nextchar; |
|
940 |
- optind++; |
|
941 |
- } |
|
942 |
- else |
|
943 |
- optarg = NULL; |
|
944 |
- nextchar = NULL; |
|
945 |
- } |
|
946 |
- else |
|
947 |
- { |
|
948 |
- /* This is an option that requires an argument. */ |
|
949 |
- if (*nextchar != '\0') |
|
950 |
- { |
|
951 |
- optarg = nextchar; |
|
952 |
- /* If we end this ARGV-element by taking the rest as an arg, |
|
953 |
- we must advance to the next element now. */ |
|
954 |
- optind++; |
|
955 |
- } |
|
956 |
- else if (optind == argc) |
|
957 |
- { |
|
958 |
- if (print_errors) |
|
959 |
- { |
|
960 |
- /* 1003.2 specifies the format of this message. */ |
|
961 |
- fprintf (stderr, |
|
962 |
- _("%s: option requires an argument -- %c\n"), |
|
963 |
- argv[0], c); |
|
964 |
- } |
|
965 |
- optopt = c; |
|
966 |
- if (optstring[0] == ':') |
|
967 |
- c = ':'; |
|
968 |
- else |
|
969 |
- c = '?'; |
|
970 |
- } |
|
971 |
- else |
|
972 |
- /* We already incremented `optind' once; |
|
973 |
- increment it again when taking next ARGV-elt as argument. */ |
|
974 |
- optarg = argv[optind++]; |
|
975 |
- nextchar = NULL; |
|
976 |
- } |
|
251 |
+ optind++; |
|
252 |
+ } else if(!hits) { |
|
253 |
+ if(offset == 1) opt = getopt(argc, argv, shortopts); |
|
254 |
+ else { |
|
255 |
+ opt = '?'; |
|
256 |
+ if(opterr) fprintf(stderr, |
|
257 |
+ "%s: unrecognized option `%s'\n", |
|
258 |
+ argv[0], argv[optind++]); |
|
977 | 259 |
} |
978 |
- return c; |
|
260 |
+ } else { |
|
261 |
+ opt = '?'; |
|
262 |
+ if(opterr) fprintf(stderr, |
|
263 |
+ "%s: option `%s' is ambiguous\n", |
|
264 |
+ argv[0], argv[optind++]); |
|
265 |
+ } |
|
979 | 266 |
} |
267 |
+ if (optind > argc) optind = argc; |
|
268 |
+ return opt; |
|
980 | 269 |
} |
981 | 270 |
|
982 |
-int |
|
983 |
-getopt (argc, argv, optstring) |
|
984 |
- int argc; |
|
985 |
- char *const *argv; |
|
986 |
- const char *optstring; |
|
271 |
+int getopt_long(int argc, char * argv[], const char *shortopts, |
|
272 |
+ const struct option *longopts, int *longind) |
|
987 | 273 |
{ |
988 |
- return _getopt_internal (argc, argv, optstring, |
|
989 |
- (const struct option *) 0, |
|
990 |
- (int *) 0, |
|
991 |
- 0); |
|
274 |
+ return _getopt_internal(argc, argv, shortopts, longopts, longind, 0); |
|
992 | 275 |
} |
993 | 276 |
|
994 |
- |
|
995 |
-int |
|
996 |
-getopt_long (argc, argv, options, long_options, opt_index) |
|
997 |
- int argc; |
|
998 |
- char *const *argv; |
|
999 |
- const char *options; |
|
1000 |
- const struct option *long_options; |
|
1001 |
- int *opt_index; |
|
277 |
+int getopt_long_only(int argc, char * argv[], const char *shortopts, |
|
278 |
+ const struct option *longopts, int *longind) |
|
1002 | 279 |
{ |
1003 |
- return _getopt_internal (argc, argv, options, long_options, opt_index, 0); |
|
280 |
+ return _getopt_internal(argc, argv, shortopts, longopts, longind, 1); |
|
1004 | 281 |
} |
1005 |
- |
|
1006 |
-/* Like getopt_long, but '-' as well as '--' can indicate a long option. |
|
1007 |
- If an option that starts with '-' (not '--') doesn't match a long option, |
|
1008 |
- but does match a short option, it is parsed as a short option |
|
1009 |
- instead. */ |
|
1010 |
- |
|
1011 |
-int |
|
1012 |
-getopt_long_only (argc, argv, options, long_options, opt_index) |
|
1013 |
- int argc; |
|
1014 |
- char *const *argv; |
|
1015 |
- const char *options; |
|
1016 |
- const struct option *long_options; |
|
1017 |
- int *opt_index; |
|
1018 |
-{ |
|
1019 |
- return _getopt_internal (argc, argv, options, long_options, opt_index, 1); |
|
1020 |
-} |
|
1021 |
- |
|
1022 |
-#endif /* Not ELIDE_CODE. */ |
... | ... |
@@ -1,180 +1,72 @@ |
1 |
-/* Declarations for getopt. |
|
2 |
- Copyright (C) 1989,90,91,92,93,94,96,97,98,99 Free Software Foundation, Inc. |
|
3 |
- This file is part of the GNU C Library. |
|
4 |
- |
|
5 |
- The GNU C Library is free software; you can redistribute it and/or |
|
6 |
- modify it under the terms of the GNU Library General Public License as |
|
7 |
- published by the Free Software Foundation; either version 2 of the |
|
8 |
- License, or (at your option) any later version. |
|
9 |
- |
|
10 |
- The GNU C Library is distributed in the hope that it will be useful, |
|
11 |
- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
- Library General Public License for more details. |
|
14 |
- |
|
15 |
- You should have received a copy of the GNU Library General Public |
|
16 |
- License along with the GNU C Library; see the file COPYING.LIB. If not, |
|
17 |
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
18 |
- Boston, MA 02111-1307, USA. */ |
|
19 |
- |
|
20 |
-#ifndef _GETOPT_H |
|
21 |
- |
|
22 |
-#ifndef __need_getopt |
|
23 |
-# define _GETOPT_H 1 |
|
24 |
-#endif |
|
25 |
- |
|
26 |
-/* If __GNU_LIBRARY__ is not already defined, either we are being used |
|
27 |
- standalone, or this is the first header included in the source file. |
|
28 |
- If we are being used with glibc, we need to include <features.h>, but |
|
29 |
- that does not exist if we are standalone. So: if __GNU_LIBRARY__ is |
|
30 |
- not defined, include <ctype.h>, which will pull in <features.h> for us |
|
31 |
- if it's from glibc. (Why ctype.h? It's guaranteed to exist and it |
|
32 |
- doesn't flood the namespace with stuff the way some other headers do.) */ |
|
33 |
-#if !defined __GNU_LIBRARY__ |
|
34 |
-# include <ctype.h> |
|
35 |
-#endif |
|
36 |
- |
|
37 |
-#ifdef __cplusplus |
|
1 |
+/* |
|
2 |
+ * getopt.h - interface to my re-implementation of getopt. |
|
3 |
+ * Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler |
|
4 |
+ * |
|
5 |
+ * Permission is hereby granted, free of charge, to any person |
|
6 |
+ * obtaining a copy of this software and associated documentation |
|
7 |
+ * files (the "Software"), to deal in the Software without |
|
8 |
+ * restriction, including without limitation the rights to use, copy, |
|
9 |
+ * modify, merge, publish, distribute, sublicense, and/or sell copies |
|
10 |
+ * of the Software, and to permit persons to whom the Software is |
|
11 |
+ * furnished to do so, subject to the following conditions: |
|
12 |
+ * |
|
13 |
+ * The above copyright notice and this permission notice shall be |
|
14 |
+ * included in all copies or substantial portions of the Software. |
|
15 |
+ * |
|
16 |
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
18 |
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22 |
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
23 |
+ * DEALINGS IN THE SOFTWARE. |
|
24 |
+ */ |
|
25 |
+ |
|
26 |
+#ifndef _GETOPT_H_INCLUDED |
|
27 |
+#define _GETOPT_H_INCLUDED |
|
28 |
+ |
|
29 |
+#ifdef __cplusplus |
|
38 | 30 |
extern "C" { |
39 | 31 |
#endif |
40 | 32 |
|
41 |
-/* For communication from `getopt' to the caller. |
|
42 |
- When `getopt' finds an option that takes an argument, |
|
43 |
- the argument value is returned here. |
|
44 |
- Also, when `ordering' is RETURN_IN_ORDER, |
|
45 |
- each non-option ARGV-element is returned here. */ |
|
46 |
- |
|
47 |
-extern char *optarg; |
|
48 |
- |
|
49 |
-/* Index in ARGV of the next element to be scanned. |
|
50 |
- This is used for communication to and from the caller |
|
51 |
- and for communication between successive calls to `getopt'. |
|
52 |
- |
|
53 |
- On entry to `getopt', zero means this is the first call; initialize. |
|
54 |
- |
|
55 |
- When `getopt' returns -1, this is the index of the first of the |
|
56 |
- non-option elements that the caller should itself scan. |
|
57 |
- |
|
58 |
- Otherwise, `optind' communicates from one call to the next |
|
59 |
- how much of ARGV has been scanned so far. */ |
|
60 |
- |
|
61 |
-extern int optind; |
|
62 |
- |
|
63 |
-/* Callers store zero here to inhibit the error message `getopt' prints |
|
64 |
- for unrecognized options. */ |
|
33 |
+/* reset argument parser to start-up values */ |
|
34 |
+extern int getopt_reset(void); |
|
65 | 35 |
|
66 |
-extern int opterr; |
|
36 |
+/* UNIX-style short-argument parser */ |
|
37 |
+extern int getopt(int argc, char * argv[], const char *opts); |
|
67 | 38 |
|
68 |
-/* Set to an option character which was unrecognized. */ |
|
69 |
- |
|
70 |
-extern int optopt; |
|
71 |
- |
|
72 |
-#ifndef __need_getopt |
|
73 |
-/* Describe the long-named options requested by the application. |
|
74 |
- The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector |
|
75 |
- of `struct option' terminated by an element containing a name which is |
|
76 |
- zero. |
|
77 |
- |
|
78 |
- The field `has_arg' is: |
|
79 |
- no_argument (or 0) if the option does not take an argument, |
|
80 |
- required_argument (or 1) if the option requires an argument, |
|
81 |
- optional_argument (or 2) if the option takes an optional argument. |
|
82 |
- |
|
83 |
- If the field `flag' is not NULL, it points to a variable that is set |
|
84 |
- to the value given in the field `val' when the option is found, but |
|
85 |
- left unchanged if the option is not found. |
|
86 |
- |
|
87 |
- To have a long-named option do something other than set an `int' to |
|
88 |
- a compiled-in constant, such as set a value from `optarg', set the |
|
89 |
- option's `flag' field to zero and its `val' field to a nonzero |
|
90 |
- value (the equivalent single-letter option character, if there is |
|
91 |
- one). For long options that have a zero `flag' field, `getopt' |
|
92 |
- returns the contents of the `val' field. */ |
|
39 |
+extern int optind, opterr, optopt; |
|
40 |
+extern char *optarg; |
|
93 | 41 |
|
94 |
-struct option |
|
95 |
-{ |
|
96 |
-# if defined __STDC__ && __STDC__ |
|
42 |
+struct option { |
|
97 | 43 |
const char *name; |
98 |
-# else |
|
99 |
- char *name; |
|
100 |
-# endif |
|
101 |
- /* has_arg can't be an enum because some compilers complain about |
|
102 |
- type mismatches in all the code that assumes it is an int. */ |
|
103 | 44 |
int has_arg; |
104 | 45 |
int *flag; |
105 | 46 |
int val; |
106 | 47 |
}; |
107 | 48 |
|
108 |
-/* Names for the values of the `has_arg' field of `struct option'. */ |
|
109 |
- |
|
110 |
-# define no_argument 0 |
|
111 |
-# define required_argument 1 |
|
112 |
-# define optional_argument 2 |
|
113 |
-#endif /* need getopt */ |
|
114 |
- |
|
49 |
+/* human-readable values for has_arg */ |
|
50 |
+#undef no_argument |
|
51 |
+#define no_argument 0 |
|
52 |
+#undef required_argument |
|
53 |
+#define required_argument 1 |
|
54 |
+#undef optional_argument |
|
55 |
+#define optional_argument 2 |
|
115 | 56 |
|
116 |
-/* Get definitions and prototypes for functions to process the |
|
117 |
- arguments in ARGV (ARGC of them, minus the program name) for |
|
118 |
- options given in OPTS. |
|
57 |
+/* GNU-style long-argument parsers */ |
|
58 |
+extern int getopt_long(int argc, char * argv[], const char *shortopts, |
|
59 |
+ const struct option *longopts, int *longind); |
|
119 | 60 |
|
120 |
- Return the option character from OPTS just read. Return -1 when |
|
121 |
- there are no more options. For unrecognized options, or options |
|
122 |
- missing arguments, `optopt' is set to the option letter, and '?' is |
|
123 |
- returned. |
|
61 |
+extern int getopt_long_only(int argc, char * argv[], const char *shortopts, |
|
62 |
+ const struct option *longopts, int *longind); |
|
124 | 63 |
|
125 |
- The OPTS string is a list of characters which are recognized option |
|
126 |
- letters, optionally followed by colons, specifying that that letter |
|
127 |
- takes an argument, to be placed in `optarg'. |
|
64 |
+extern int _getopt_internal(int argc, char * argv[], const char *shortopts, |
|
65 |
+ const struct option *longopts, int *longind, |
|
66 |
+ int long_only); |
|
128 | 67 |
|
129 |
- If a letter in OPTS is followed by two colons, its argument is |
|
130 |
- optional. This behavior is specific to the GNU `getopt'. |
|
131 |
- |
|
132 |
- The argument `--' causes premature termination of argument |
|
133 |
- scanning, explicitly telling `getopt' that there are no more |
|
134 |
- options. |
|
135 |
- |
|
136 |
- If OPTS begins with `--', then non-option arguments are treated as |
|
137 |
- arguments to the option '\0'. This behavior is specific to the GNU |
|
138 |
- `getopt'. */ |
|
139 |
- |
|
140 |
-#if defined __STDC__ && __STDC__ |
|
141 |
-# ifdef __GNU_LIBRARY__ |
|
142 |
-/* Many other libraries have conflicting prototypes for getopt, with |
|
143 |
- differences in the consts, in stdlib.h. To avoid compilation |
|
144 |
- errors, only prototype getopt for the GNU C library. */ |
|
145 |
-extern int getopt (int __argc, char *const *__argv, const char *__shortopts); |
|
146 |
-# else /* not __GNU_LIBRARY__ */ |
|
147 |
-extern int getopt (); |
|
148 |
-# endif /* __GNU_LIBRARY__ */ |
|
149 |
- |
|
150 |
-# ifndef __need_getopt |
|
151 |
-extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, |
|
152 |
- const struct option *__longopts, int *__longind); |
|
153 |
-extern int getopt_long_only (int __argc, char *const *__argv, |
|
154 |
- const char *__shortopts, |
|
155 |
- const struct option *__longopts, int *__longind); |
|
156 |
- |
|
157 |
-/* Internal only. Users should not call this directly. */ |
|
158 |
-extern int _getopt_internal (int __argc, char *const *__argv, |
|
159 |
- const char *__shortopts, |
|
160 |
- const struct option *__longopts, int *__longind, |
|
161 |
- int __long_only); |
|
162 |
-# endif |
|
163 |
-#else /* not __STDC__ */ |
|
164 |
-extern int getopt (); |
|
165 |
-# ifndef __need_getopt |
|
166 |
-extern int getopt_long (); |
|
167 |
-extern int getopt_long_only (); |
|
168 |
- |
|
169 |
-extern int _getopt_internal (); |
|
170 |
-# endif |
|
171 |
-#endif /* __STDC__ */ |
|
172 |
- |
|
173 |
-#ifdef __cplusplus |
|
68 |
+#ifdef __cplusplus |
|
174 | 69 |
} |
175 | 70 |
#endif |
176 | 71 |
|
177 |
-/* Make sure we later can get all the definitions and declarations. */ |
|
178 |
-#undef __need_getopt |
|
179 |
- |
|
180 |
-#endif /* getopt.h */ |
|
72 |
+#endif /* _GETOPT_H_INCLUDED */ |
181 | 73 |
deleted file mode 100644 |
... | ... |
@@ -1,309 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2001 - 2007 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
4 |
- * This program is free software; you can redistribute it and/or modify |
|
5 |
- * it under the terms of the GNU General Public License version 2 as |
|
6 |
- * published by the Free Software Foundation. |
|
7 |
- * |
|
8 |
- * This program is distributed in the hope that it will be useful, |
|
9 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
- * GNU General Public License for more details. |
|
12 |
- * |
|
13 |
- * You should have received a copy of the GNU General Public License |
|
14 |
- * along with this program; if not, write to the Free Software |
|
15 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
16 |
- * MA 02110-1301, USA. |
|
17 |
- * |
|
18 |
- */ |
|
19 |
- |
|
20 |
-#if HAVE_CONFIG_H |
|
21 |
-#include "clamav-config.h" |
|
22 |
-#endif |
|
23 |
- |
|
24 |
-#include <stdio.h> |
|
25 |
-#include <stdlib.h> |
|
26 |
-#include <string.h> |
|
27 |
-#define _GNU_SOURCE |
|
28 |
-#include "getopt.h" |
|
29 |
- |
|
30 |
-#include "options.h" |
|
31 |
-#include "output.h" |
|
32 |
- |
|
33 |
- |
|
34 |
-static int register_option(struct optstruct *opt, const char *optlong, char optshort, const struct option *options_long, const char * const *accepted_long, const char * const *deprecated_long) |
|
35 |
-{ |
|
36 |
- struct optnode *newnode; |
|
37 |
- int i, found; |
|
38 |
- const char *longname = NULL; |
|
39 |
- |
|
40 |
- |
|
41 |
- if(optshort) { |
|
42 |
- for(i = 0; options_long[i].name; i++) { |
|
43 |
- if(options_long[i].val == optshort) { |
|
44 |
- longname = options_long[i].name; |
|
45 |
- break; |
|
46 |
- } |
|
47 |
- } |
|
48 |
- } else |
|
49 |
- longname = optlong; |
|
50 |
- |
|
51 |
- if(!longname) { |
|
52 |
- mprintf("!register_option: No long option for -%c\n", optshort); |
|
53 |
- return -1; |
|
54 |
- } |
|
55 |
- |
|
56 |
- if(accepted_long) { |
|
57 |
- found = 0; |
|
58 |
- for(i = 0; accepted_long[i]; i++) |
|
59 |
- if(!strcmp(accepted_long[i], longname)) { |
|
60 |
- found = 1; |
|
61 |
- break; |
|
62 |
- } |
|
63 |
- |
|
64 |
- if(!found) { |
|
65 |
- if(optshort) |
|
66 |
- mprintf("WARNING: Ignoring option --%s (-%c)\n", longname, optshort); |
|
67 |
- else |
|
68 |
- mprintf("WARNING: Ignoring option --%s\n", longname); |
|
69 |
- |
|
70 |
- return 0; |
|
71 |
- } |
|
72 |
- } |
|
73 |
- |
|
74 |
- if(deprecated_long) { |
|
75 |
- found = 0; |
|
76 |
- for(i = 0; deprecated_long[i]; i++) { |
|
77 |
- if(!strcmp(deprecated_long[i], longname)) { |
|
78 |
- found = 1; |
|
79 |
- break; |
|
80 |
- } |
|
81 |
- } |
|
82 |
- |
|
83 |
- if(found) { |
|
84 |
- if(optshort) |
|
85 |
- mprintf("WARNING: Ignoring deprecated option --%s (-%c)\n", longname, optshort); |
|
86 |
- else |
|
87 |
- mprintf("WARNING: Ignoring deprecated option --%s\n", longname); |
|
88 |
- |
|
89 |
- return 0; |
|
90 |
- } |
|
91 |
- } |
|
92 |
- |
|
93 |
- newnode = (struct optnode *) malloc(sizeof(struct optnode)); |
|
94 |
- if(!newnode) { |
|
95 |
- mprintf("!register_long_option: malloc failed\n"); |
|
96 |
- return -1; |
|
97 |
- } |
|
98 |
- |
|
99 |
- newnode->optshort = optshort; |
|
100 |
- |
|
101 |
- if(optarg) { |
|
102 |
- newnode->optarg = (char *) malloc(strlen(optarg) + 1); |
|
103 |
- if(!newnode->optarg) { |
|
104 |
- mprintf("!register_long_option: malloc failed\n"); |
|
105 |
- free(newnode); |
|
106 |
- return -1; |
|
107 |
- } |
|
108 |
- strcpy(newnode->optarg, optarg); |
|
109 |
- } else |
|
110 |
- newnode->optarg = NULL; |
|
111 |
- |
|
112 |
- newnode->optlong = (char *) malloc(strlen(longname) + 1); |
|
113 |
- if(!newnode->optlong) { |
|
114 |
- mprintf("ERROR: register_long_option: malloc failed\n"); |
|
115 |
- free(newnode->optarg); |
|
116 |
- free(newnode); |
|
117 |
- return -1; |
|
118 |
- } |
|
119 |
- strcpy(newnode->optlong, longname); |
|
120 |
- |
|
121 |
- newnode->next = opt->optlist; |
|
122 |
- opt->optlist = newnode; |
|
123 |
- return 0; |
|
124 |
-} |
|
125 |
- |
|
126 |
-void opt_free(struct optstruct *opt) |
|
127 |
-{ |
|
128 |
- struct optnode *handler, *prev; |
|
129 |
- |
|
130 |
- if(!opt) |
|
131 |
- return; |
|
132 |
- |
|
133 |
- handler = opt->optlist; |
|
134 |
- while(handler) { |
|
135 |
- if(handler->optarg) |
|
136 |
- free(handler->optarg); |
|
137 |
- if(handler->optlong) |
|
138 |
- free(handler->optlong); |
|
139 |
- prev = handler; |
|
140 |
- handler = handler->next; |
|
141 |
- free(prev); |
|
142 |
- } |
|
143 |
- |
|
144 |
- if(opt->filename) |
|
145 |
- free(opt->filename); |
|
146 |
- |
|
147 |
- free(opt); |
|
148 |
-} |
|
149 |
- |
|
150 |
-struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_short, const struct option *options_long, const char * const *accepted_long, const char * const *deprecated_long) |
|
151 |
-{ |
|
152 |
- int ret, opt_index, i, len; |
|
153 |
- struct optstruct *opt; |
|
154 |
- const char *longname; |
|
155 |
- |
|
156 |
- |
|
157 |
- opt = (struct optstruct *) calloc(1, sizeof(struct optstruct)); |
|
158 |
- if(!opt) { |
|
159 |
- mprintf("!opt_parse: calloc failed\n"); |
|
160 |
- return NULL; |
|
161 |
- } |
|
162 |
- |
|
163 |
- while(1) { |
|
164 |
- opt_index = 0; |
|
165 |
- ret = getopt_long(argc, argv, getopt_short, options_long, &opt_index); |
|
166 |
- |
|
167 |
- if(ret == -1) |
|
168 |
- break; |
|
169 |
- |
|
170 |
- switch(ret) { |
|
171 |
- case 0: |
|
172 |
- if(register_option(opt, options_long[opt_index].name, 0, options_long, accepted_long, deprecated_long) == -1) { |
|
173 |
- opt_free(opt); |
|
174 |
- return NULL; |
|
175 |
- } |
|
176 |
- break; |
|
177 |
- |
|
178 |
- default: |
|
179 |
- if(strchr(getopt_short, ret)) { |
|
180 |
- if(opt_index) |
|
181 |
- longname = options_long[opt_index].name; |
|
182 |
- else |
|
183 |
- longname = NULL; |
|
184 |
- |
|
185 |
- if(register_option(opt, longname, ret, options_long, accepted_long, deprecated_long) == -1) { |
|
186 |
- opt_free(opt); |
|
187 |
- return NULL; |
|
188 |
- } |
|
189 |
- |
|
190 |
- } else { |
|
191 |
- mprintf("!Unknown option passed.\n"); |
|
192 |
- opt_free(opt); |
|
193 |
- return NULL; |
|
194 |
- } |
|
195 |
- } |
|
196 |
- } |
|
197 |
- |
|
198 |
- if(optind < argc) { |
|
199 |
- len = 0; |
|
200 |
- |
|
201 |
- /* count length of non-option arguments */ |
|
202 |
- for(i = optind; i < argc; i++) |
|
203 |
- len += strlen(argv[i]); |
|
204 |
- |
|
205 |
- len += argc - optind - 1; |
|
206 |
- opt->filename = (char *) calloc(len + 64, sizeof(char)); |
|
207 |
- if(!opt->filename) { |
|
208 |
- mprintf("!opt_parse: calloc failed\n"); |
|
209 |
- opt_free(opt); |
|
210 |
- return NULL; |
|
211 |
- } |
|
212 |
- |
|
213 |
- for(i = optind; i < argc; i++) { |
|
214 |
- strncat(opt->filename, argv[i], strlen(argv[i])); |
|
215 |
- if(i != argc - 1) |
|
216 |
- strncat(opt->filename, "\t", 1); |
|
217 |
- } |
|
218 |
- } |
|
219 |
- |
|
220 |
- return opt; |
|
221 |
-} |
|
222 |
- |
|
223 |
-int opt_check(const struct optstruct *opt, const char *optlong) |
|
224 |
-{ |
|
225 |
- struct optnode *handler; |
|
226 |
- |
|
227 |
- if(!opt) { |
|
228 |
- mprintf("!opt_check: opt == NULL\n"); |
|
229 |
- return 0; |
|
230 |
- } |
|
231 |
- |
|
232 |
- handler = opt->optlist; |
|
233 |
- |
|
234 |
- while(handler) { |
|
235 |
- if(handler->optlong && !strcmp(handler->optlong, optlong)) |
|
236 |
- return 1; |
|
237 |
- |
|
238 |
- handler = handler->next; |
|
239 |
- } |
|
240 |
- |
|
241 |
- return 0; |
|
242 |
-} |
|
243 |
- |
|
244 |
-char *opt_arg(const struct optstruct *opt, const char *optlong) |
|
245 |
-{ |
|
246 |
- struct optnode *handler; |
|
247 |
- |
|
248 |
- if(!opt) { |
|
249 |
- mprintf("!opt_arg: opt == NULL\n"); |
|
250 |
- return 0; |
|
251 |
- } |
|
252 |
- |
|
253 |
- handler = opt->optlist; |
|
254 |
- |
|
255 |
- while(handler) { |
|
256 |
- if(handler->optlong && !strcmp(handler->optlong, optlong)) |
|
257 |
- return handler->optarg; |
|
258 |
- |
|
259 |
- handler = handler->next; |
|
260 |
- } |
|
261 |
- |
|
262 |
- return NULL; |
|
263 |
-} |
|
264 |
- |
|
265 |
-char *opt_firstarg(const struct optstruct *opt, const char *optlong, const struct optnode **optnode) |
|
266 |
-{ |
|
267 |
- const struct optnode *handler; |
|
268 |
- |
|
269 |
- if(!opt) { |
|
270 |
- mprintf("!opt_firstarg: opt == NULL\n"); |
|
271 |
- return 0; |
|
272 |
- } |
|
273 |
- |
|
274 |
- handler = opt->optlist; |
|
275 |
- |
|
276 |
- while(handler) { |
|
277 |
- if(handler->optlong && !strcmp(handler->optlong, optlong)) { |
|
278 |
- *optnode = handler; |
|
279 |
- return handler->optarg; |
|
280 |
- } |
|
281 |
- handler = handler->next; |
|
282 |
- } |
|
283 |
- |
|
284 |
- *optnode = NULL; |
|
285 |
- return NULL; |
|
286 |
-} |
|
287 |
- |
|
288 |
-char *opt_nextarg(const struct optnode **optnode, const char *optlong) |
|
289 |
-{ |
|
290 |
- struct optnode *handler; |
|
291 |
- |
|
292 |
- if(!optnode || !*optnode) { |
|
293 |
- mprintf("!opt_nextarg: *optnode == NULL\n"); |
|
294 |
- return 0; |
|
295 |
- } |
|
296 |
- |
|
297 |
- handler = (*optnode)->next; |
|
298 |
- |
|
299 |
- while(handler) { |
|
300 |
- if(handler->optlong && !strcmp(handler->optlong, optlong)) { |
|
301 |
- *optnode = handler; |
|
302 |
- return handler->optarg; |
|
303 |
- } |
|
304 |
- handler = handler->next; |
|
305 |
- } |
|
306 |
- |
|
307 |
- *optnode = NULL; |
|
308 |
- return NULL; |
|
309 |
-} |
310 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,49 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net> |
|
3 |
- * |
|
4 |
- * This program is free software; you can redistribute it and/or modify |
|
5 |
- * it under the terms of the GNU General Public License version 2 as |
|
6 |
- * published by the Free Software Foundation. |
|
7 |
- * |
|
8 |
- * This program is distributed in the hope that it will be useful, |
|
9 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
- * GNU General Public License for more details. |
|
12 |
- * |
|
13 |
- * You should have received a copy of the GNU General Public License |
|
14 |
- * along with this program; if not, write to the Free Software |
|
15 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
16 |
- * MA 02110-1301, USA. |
|
17 |
- */ |
|
18 |
- |
|
19 |
-#ifndef __OPTIONS_H |
|
20 |
-#define __OPTIONS_H |
|
21 |
- |
|
22 |
-#define _GNU_SOURCE |
|
23 |
-#include "getopt.h" |
|
24 |
- |
|
25 |
-struct optnode { |
|
26 |
- char optshort; |
|
27 |
- char *optlong; |
|
28 |
- char *optarg; |
|
29 |
- struct optnode *next; |
|
30 |
-}; |
|
31 |
- |
|
32 |
-struct optstruct { |
|
33 |
- struct optnode *optlist; |
|
34 |
- char *filename; |
|
35 |
-}; |
|
36 |
- |
|
37 |
-void opt_free(struct optstruct *opt); |
|
38 |
- |
|
39 |
-struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_short, const struct option *options_long, const char * const *accepted_long, const char * const *deprecated_long); |
|
40 |
- |
|
41 |
-int opt_check(const struct optstruct *opt, const char *optlong); |
|
42 |
- |
|
43 |
-char *opt_arg(const struct optstruct *opt, const char *optlong); |
|
44 |
- |
|
45 |
-char *opt_firstarg(const struct optstruct *opt, const char *optlong, const struct optnode **optnode); |
|
46 |
- |
|
47 |
-char *opt_nextarg(const struct optnode **optnode, const char *optlong); |
|
48 |
- |
|
49 |
-#endif |
... | ... |
@@ -606,7 +606,7 @@ void optfree(struct optstruct *opts) |
606 | 606 |
return; |
607 | 607 |
} |
608 | 608 |
|
609 |
-struct optstruct *optparse(const char *cfgfile, int argc, char * const *argv, int verbose, int toolmask, int ignore, struct optstruct *oldopts) |
|
609 |
+struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbose, int toolmask, int ignore, struct optstruct *oldopts) |
|
610 | 610 |
{ |
611 | 611 |
FILE *fs = NULL; |
612 | 612 |
const struct clam_option *optentry; |
... | ... |
@@ -49,6 +49,6 @@ const struct optstruct *optget(const struct optstruct *opts, const char *name); |
49 | 49 |
|
50 | 50 |
void optfree(struct optstruct *opts); |
51 | 51 |
|
52 |
-struct optstruct *optparse(const char *cfgfile, int argc, char * const *argv, int verbose, int toolmask, int ignore, struct optstruct *oldopts); |
|
52 |
+struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbose, int toolmask, int ignore, struct optstruct *oldopts); |
|
53 | 53 |
|
54 | 54 |
#endif |