Browse code

Big cleanup

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@448 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2004/03/29 09:00:58
Showing 70 changed files
... ...
@@ -1,3 +1,14 @@
1
+Mon Mar 29 02:05:39 CEST 2004 (tk)
2
+----------------------------------
3
+  * big cleanup: remove duplicated code and move it to /shared (fixes
4
+		 a dependency problem when compiling with --disable-pthreads
5
+		 and LogSyslog support in freshclam); eliminate warnings
6
+  * libclamav: include backup snprintf implementation (patch by Phil Oleson
7
+	       <oz*nixil.net>, snprintf by Patrick Powell)
8
+  * clamd: fix clamd hangup when log size is exceeded (bug reported by
9
+	   Ryan Thompson <clamav*sasknow.com>)
10
+  * examples/ex1.c: update
11
+
1 12
 Sat Mar 27 21:55:33 GMT 2004 (njh)
2 13
 ----------------------------------
3 14
   * clamav-milter:	Delay connection to clamd to handle clamd's timeout
... ...
@@ -1,5 +1,5 @@
1 1
 #
2
-#  Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
2
+#  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
3 3
 #
4 4
 #  This program is free software; you can redistribute it and/or modify
5 5
 #  it under the terms of the GNU General Public License as published by
... ...
@@ -16,4 +16,4 @@
16 16
 #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
 
18 18
 SUBDIRS = libclamav clamscan clamd clamdscan freshclam sigtool database docs etc clamav-milter
19
-EXTRA_DIST = FAQ contrib test examples BUGS
19
+EXTRA_DIST = FAQ contrib test examples BUGS shared
... ...
@@ -15,7 +15,7 @@
15 15
 @SET_MAKE@
16 16
 
17 17
 #
18
-#  Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
18
+#  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
19 19
 #
20 20
 #  This program is free software; you can redistribute it and/or modify
21 21
 #  it under the terms of the GNU General Public License as published by
... ...
@@ -117,7 +117,7 @@ am__quote = @am__quote@
117 117
 install_sh = @install_sh@
118 118
 
119 119
 SUBDIRS = libclamav clamscan clamd clamdscan freshclam sigtool database docs etc clamav-milter
120
-EXTRA_DIST = FAQ contrib test examples BUGS
120
+EXTRA_DIST = FAQ contrib test examples BUGS shared
121 121
 subdir = .
122 122
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
123 123
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
... ...
@@ -1,4 +1,4 @@
1
-# aclocal.m4 generated automatically by aclocal 1.6.1 -*- Autoconf -*-
1
+# aclocal.m4t generated automatically by aclocal 1.6.1 -*- Autoconf -*-
2 2
 
3 3
 # Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 4
 # Free Software Foundation, Inc.
... ...
@@ -81,7 +81,7 @@ dnl there is now a CREATE_PREFIX_TARGET_H in this file as a shorthand for
81 81
 dnl PREFIX_CONFIG_H from a target.h file, however w/o the target.h ever created
82 82
 dnl (the prefix is a bit different, since we add an extra -target- and -host-)
83 83
 dnl 
84
-dnl @version: $Id: aclocal.m4,v 1.29 2004/03/19 23:12:33 kojm Exp $
84
+dnl @version: $Id: aclocal.m4,v 1.30 2004/03/29 00:00:57 kojm Exp $
85 85
 dnl @author Guido Draheim <guidod@gmx.de>                 STATUS: used often
86 86
 
87 87
 AC_DEFUN([AC_CREATE_TARGET_H],
... ...
@@ -4041,7 +4041,7 @@ dnl      AC_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers)
4041 4041
 dnl      AC_COMPILE_CHECK_SIZEOF(off_t, $headers)
4042 4042
 dnl
4043 4043
 dnl @author Kaveh Ghazi <ghazi@caip.rutgers.edu>
4044
-dnl @version $Id: aclocal.m4,v 1.29 2004/03/19 23:12:33 kojm Exp $
4044
+dnl @version $Id: aclocal.m4,v 1.30 2004/03/29 00:00:57 kojm Exp $
4045 4045
 dnl
4046 4046
 AC_DEFUN([AC_COMPILE_CHECK_SIZEOF],
4047 4047
 [changequote(<<, >>)dnl
... ...
@@ -1,5 +1,8 @@
1 1
 /* clamav-config.h.in.  Generated from configure.in by autoheader.  */
2 2
 
3
+/* Define if your snprintf is busted */
4
+#undef BROKEN_SNPRINTF
5
+
3 6
 /* "build clamd" */
4 7
 #undef BUILD_CLAMD
5 8
 
... ...
@@ -9,9 +12,6 @@
9 9
 /* name of the clamav user */
10 10
 #undef CLAMAVUSER
11 11
 
12
-/* use syslog */
13
-#undef CLAMD_USE_SYSLOG
14
-
15 12
 /* enable clamuko */
16 13
 #undef CLAMUKO
17 14
 
... ...
@@ -150,9 +150,15 @@
150 150
 /* Define to 1 if you have the <sys/types.h> header file. */
151 151
 #undef HAVE_SYS_TYPES_H
152 152
 
153
+/* Define to 1 if you have the <tcpd.h> header file. */
154
+#undef HAVE_TCPD_H
155
+
153 156
 /* Define to 1 if you have the <unistd.h> header file. */
154 157
 #undef HAVE_UNISTD_H
155 158
 
159
+/* Define to 1 if you have the `vsnprintf' function. */
160
+#undef HAVE_VSNPRINTF
161
+
156 162
 /* zlib installed */
157 163
 #undef HAVE_ZLIB_H
158 164
 
... ...
@@ -198,6 +204,9 @@
198 198
 /* Define to 1 if you have the ANSI C header files. */
199 199
 #undef STDC_HEADERS
200 200
 
201
+/* use syslog */
202
+#undef USE_SYSLOG
203
+
201 204
 /* Version number of package */
202 205
 #undef VERSION
203 206
 
... ...
@@ -20,10 +20,16 @@ if BUILD_CLAMD
20 20
 sbin_PROGRAMS = clamd
21 21
 
22 22
 clamd_SOURCES = \
23
+    $(top_srcdir)/shared/output.c \
24
+    $(top_srcdir)/shared/output.h \
25
+    $(top_srcdir)/shared/cfgparser.c \
26
+    $(top_srcdir)/shared/cfgparser.h \
27
+    $(top_srcdir)/shared/getopt.c \
28
+    $(top_srcdir)/shared/getopt.h \
29
+    $(top_srcdir)/shared/memory.c \
30
+    $(top_srcdir)/shared/memory.h \
23 31
     options.c \
24 32
     options.h \
25
-    cfgfile.c \
26
-    cfgfile.h \
27 33
     clamd.c \
28 34
     defaults.h \
29 35
     tcpserver.c \
... ...
@@ -49,12 +55,11 @@ clamd_SOURCES = \
49 49
     dazuko_xp.h \
50 50
     dazukoio_xp.h \
51 51
     tests.c \
52
-    tests.h
53
-
54
-clamd_LDADD = $(top_builddir)/clamscan/getopt.o
52
+    tests.h \
53
+    shared.h
55 54
 
56 55
 endif
57 56
 
58 57
 DEFS = @DEFS@
59 58
 LIBS = -L$(top_builddir)/libclamav -lclamav @CLAMD_LIBS@
60
-INCLUDES = -I$(top_srcdir)/clamscan -I$(top_srcdir)/libclamav
59
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
... ...
@@ -119,10 +119,16 @@ install_sh = @install_sh@
119 119
 @BUILD_CLAMD_TRUE@sbin_PROGRAMS = clamd
120 120
 
121 121
 @BUILD_CLAMD_TRUE@clamd_SOURCES = \
122
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/output.c \
123
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/output.h \
124
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/cfgparser.c \
125
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/cfgparser.h \
126
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/getopt.c \
127
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/getopt.h \
128
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/memory.c \
129
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/memory.h \
122 130
 @BUILD_CLAMD_TRUE@    options.c \
123 131
 @BUILD_CLAMD_TRUE@    options.h \
124
-@BUILD_CLAMD_TRUE@    cfgfile.c \
125
-@BUILD_CLAMD_TRUE@    cfgfile.h \
126 132
 @BUILD_CLAMD_TRUE@    clamd.c \
127 133
 @BUILD_CLAMD_TRUE@    defaults.h \
128 134
 @BUILD_CLAMD_TRUE@    tcpserver.c \
... ...
@@ -148,14 +154,13 @@ install_sh = @install_sh@
148 148
 @BUILD_CLAMD_TRUE@    dazuko_xp.h \
149 149
 @BUILD_CLAMD_TRUE@    dazukoio_xp.h \
150 150
 @BUILD_CLAMD_TRUE@    tests.c \
151
-@BUILD_CLAMD_TRUE@    tests.h
151
+@BUILD_CLAMD_TRUE@    tests.h \
152
+@BUILD_CLAMD_TRUE@    shared.h
152 153
 
153 154
 
154
-@BUILD_CLAMD_TRUE@clamd_LDADD = $(top_builddir)/clamscan/getopt.o
155
-
156 155
 DEFS = @DEFS@
157 156
 LIBS = -L$(top_builddir)/libclamav -lclamav @CLAMD_LIBS@
158
-INCLUDES = -I$(top_srcdir)/clamscan -I$(top_srcdir)/libclamav
157
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
159 158
 subdir = clamd
160 159
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
161 160
 CONFIG_HEADER = $(top_builddir)/clamav-config.h
... ...
@@ -164,7 +169,9 @@ CONFIG_CLEAN_FILES =
164 164
 @BUILD_CLAMD_FALSE@sbin_PROGRAMS =
165 165
 PROGRAMS = $(sbin_PROGRAMS)
166 166
 
167
-@BUILD_CLAMD_TRUE@am_clamd_OBJECTS = options.$(OBJEXT) cfgfile.$(OBJEXT) \
167
+@BUILD_CLAMD_TRUE@am_clamd_OBJECTS = output.$(OBJEXT) \
168
+@BUILD_CLAMD_TRUE@	cfgparser.$(OBJEXT) getopt.$(OBJEXT) \
169
+@BUILD_CLAMD_TRUE@	memory.$(OBJEXT) options.$(OBJEXT) \
168 170
 @BUILD_CLAMD_TRUE@	clamd.$(OBJEXT) tcpserver.$(OBJEXT) \
169 171
 @BUILD_CLAMD_TRUE@	localserver.$(OBJEXT) session.$(OBJEXT) \
170 172
 @BUILD_CLAMD_TRUE@	thrmgr.$(OBJEXT) server-th.$(OBJEXT) \
... ...
@@ -172,22 +179,23 @@ PROGRAMS = $(sbin_PROGRAMS)
172 172
 @BUILD_CLAMD_TRUE@	clamuko.$(OBJEXT) dazukoio_compat12.$(OBJEXT) \
173 173
 @BUILD_CLAMD_TRUE@	dazukoio.$(OBJEXT) tests.$(OBJEXT)
174 174
 clamd_OBJECTS = $(am_clamd_OBJECTS)
175
-@BUILD_CLAMD_TRUE@clamd_DEPENDENCIES = $(top_builddir)/clamscan/getopt.o
176
-@BUILD_CLAMD_FALSE@clamd_DEPENDENCIES =
175
+clamd_LDADD = $(LDADD)
176
+clamd_DEPENDENCIES =
177 177
 clamd_LDFLAGS =
178 178
 DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)
179 179
 CPPFLAGS = @CPPFLAGS@
180 180
 LDFLAGS = @LDFLAGS@
181 181
 depcomp = $(SHELL) $(top_srcdir)/depcomp
182 182
 am__depfiles_maybe = depfiles
183
-@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/cfgfile.Po ./$(DEPDIR)/clamd.Po \
183
+@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/cfgparser.Po ./$(DEPDIR)/clamd.Po \
184 184
 @AMDEP_TRUE@	./$(DEPDIR)/clamuko.Po ./$(DEPDIR)/dazukoio.Po \
185 185
 @AMDEP_TRUE@	./$(DEPDIR)/dazukoio_compat12.Po \
186
-@AMDEP_TRUE@	./$(DEPDIR)/localserver.Po ./$(DEPDIR)/options.Po \
187
-@AMDEP_TRUE@	./$(DEPDIR)/others.Po ./$(DEPDIR)/scanner.Po \
188
-@AMDEP_TRUE@	./$(DEPDIR)/server-th.Po ./$(DEPDIR)/session.Po \
189
-@AMDEP_TRUE@	./$(DEPDIR)/tcpserver.Po ./$(DEPDIR)/tests.Po \
190
-@AMDEP_TRUE@	./$(DEPDIR)/thrmgr.Po
186
+@AMDEP_TRUE@	./$(DEPDIR)/getopt.Po ./$(DEPDIR)/localserver.Po \
187
+@AMDEP_TRUE@	./$(DEPDIR)/memory.Po ./$(DEPDIR)/options.Po \
188
+@AMDEP_TRUE@	./$(DEPDIR)/others.Po ./$(DEPDIR)/output.Po \
189
+@AMDEP_TRUE@	./$(DEPDIR)/scanner.Po ./$(DEPDIR)/server-th.Po \
190
+@AMDEP_TRUE@	./$(DEPDIR)/session.Po ./$(DEPDIR)/tcpserver.Po \
191
+@AMDEP_TRUE@	./$(DEPDIR)/tests.Po ./$(DEPDIR)/thrmgr.Po
191 192
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
192 193
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
193 194
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
... ...
@@ -236,6 +244,10 @@ uninstall-sbinPROGRAMS:
236 236
 
237 237
 clean-sbinPROGRAMS:
238 238
 	-test -z "$(sbin_PROGRAMS)" || rm -f $(sbin_PROGRAMS)
239
+output.$(OBJEXT): $(top_srcdir)/shared/output.c
240
+cfgparser.$(OBJEXT): $(top_srcdir)/shared/cfgparser.c
241
+getopt.$(OBJEXT): $(top_srcdir)/shared/getopt.c
242
+memory.$(OBJEXT): $(top_srcdir)/shared/memory.c
239 243
 clamd$(EXEEXT): $(clamd_OBJECTS) $(clamd_DEPENDENCIES) 
240 244
 	@rm -f clamd$(EXEEXT)
241 245
 	$(LINK) $(clamd_LDFLAGS) $(clamd_OBJECTS) $(clamd_LDADD) $(LIBS)
... ...
@@ -246,14 +258,17 @@ mostlyclean-compile:
246 246
 distclean-compile:
247 247
 	-rm -f *.tab.c
248 248
 
249
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgfile.Po@am__quote@
249
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgparser.Po@am__quote@
250 250
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clamd.Po@am__quote@
251 251
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clamuko.Po@am__quote@
252 252
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dazukoio.Po@am__quote@
253 253
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dazukoio_compat12.Po@am__quote@
254
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
254 255
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/localserver.Po@am__quote@
256
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Po@am__quote@
255 257
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@
256 258
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/others.Po@am__quote@
259
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/output.Po@am__quote@
257 260
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scanner.Po@am__quote@
258 261
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/server-th.Po@am__quote@
259 262
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/session.Po@am__quote@
... ...
@@ -281,6 +296,78 @@ distclean-depend:
281 281
 @AMDEP_TRUE@	depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@
282 282
 @AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
283 283
 	$(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<
284
+
285
+output.o: $(top_srcdir)/shared/output.c
286
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.o' libtool=no @AMDEPBACKSLASH@
287
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Po' tmpdepfile='$(DEPDIR)/output.TPo' @AMDEPBACKSLASH@
288
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
289
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.o `test -f '$(top_srcdir)/shared/output.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/output.c
290
+
291
+output.obj: $(top_srcdir)/shared/output.c
292
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.obj' libtool=no @AMDEPBACKSLASH@
293
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Po' tmpdepfile='$(DEPDIR)/output.TPo' @AMDEPBACKSLASH@
294
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
295
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.obj `cygpath -w $(top_srcdir)/shared/output.c`
296
+
297
+output.lo: $(top_srcdir)/shared/output.c
298
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.lo' libtool=yes @AMDEPBACKSLASH@
299
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Plo' tmpdepfile='$(DEPDIR)/output.TPlo' @AMDEPBACKSLASH@
300
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
301
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.lo `test -f '$(top_srcdir)/shared/output.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/output.c
302
+
303
+cfgparser.o: $(top_srcdir)/shared/cfgparser.c
304
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.o' libtool=no @AMDEPBACKSLASH@
305
+@AMDEP_TRUE@	depfile='$(DEPDIR)/cfgparser.Po' tmpdepfile='$(DEPDIR)/cfgparser.TPo' @AMDEPBACKSLASH@
306
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
307
+	$(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
308
+
309
+cfgparser.obj: $(top_srcdir)/shared/cfgparser.c
310
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.obj' libtool=no @AMDEPBACKSLASH@
311
+@AMDEP_TRUE@	depfile='$(DEPDIR)/cfgparser.Po' tmpdepfile='$(DEPDIR)/cfgparser.TPo' @AMDEPBACKSLASH@
312
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
313
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.obj `cygpath -w $(top_srcdir)/shared/cfgparser.c`
314
+
315
+cfgparser.lo: $(top_srcdir)/shared/cfgparser.c
316
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.lo' libtool=yes @AMDEPBACKSLASH@
317
+@AMDEP_TRUE@	depfile='$(DEPDIR)/cfgparser.Plo' tmpdepfile='$(DEPDIR)/cfgparser.TPlo' @AMDEPBACKSLASH@
318
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
319
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.lo `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c
320
+
321
+getopt.o: $(top_srcdir)/shared/getopt.c
322
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.o' libtool=no @AMDEPBACKSLASH@
323
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Po' tmpdepfile='$(DEPDIR)/getopt.TPo' @AMDEPBACKSLASH@
324
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
325
+	$(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
326
+
327
+getopt.obj: $(top_srcdir)/shared/getopt.c
328
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.obj' libtool=no @AMDEPBACKSLASH@
329
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Po' tmpdepfile='$(DEPDIR)/getopt.TPo' @AMDEPBACKSLASH@
330
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
331
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.obj `cygpath -w $(top_srcdir)/shared/getopt.c`
332
+
333
+getopt.lo: $(top_srcdir)/shared/getopt.c
334
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.lo' libtool=yes @AMDEPBACKSLASH@
335
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Plo' tmpdepfile='$(DEPDIR)/getopt.TPlo' @AMDEPBACKSLASH@
336
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
337
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.lo `test -f '$(top_srcdir)/shared/getopt.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/getopt.c
338
+
339
+memory.o: $(top_srcdir)/shared/memory.c
340
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.o' libtool=no @AMDEPBACKSLASH@
341
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Po' tmpdepfile='$(DEPDIR)/memory.TPo' @AMDEPBACKSLASH@
342
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
343
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.o `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c
344
+
345
+memory.obj: $(top_srcdir)/shared/memory.c
346
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.obj' libtool=no @AMDEPBACKSLASH@
347
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Po' tmpdepfile='$(DEPDIR)/memory.TPo' @AMDEPBACKSLASH@
348
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
349
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.obj `cygpath -w $(top_srcdir)/shared/memory.c`
350
+
351
+memory.lo: $(top_srcdir)/shared/memory.c
352
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.lo' libtool=yes @AMDEPBACKSLASH@
353
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Plo' tmpdepfile='$(DEPDIR)/memory.TPlo' @AMDEPBACKSLASH@
354
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
355
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.lo `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c
284 356
 CCDEPMODE = @CCDEPMODE@
285 357
 
286 358
 mostlyclean-libtool:
287 359
deleted file mode 100644
... ...
@@ -1,294 +0,0 @@
1
-/*
2
- *  Copyright (C) 2002 - 2004 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., 675 Mass Ave, Cambridge, MA 02139, USA.
17
- */
18
-
19
-#if HAVE_CONFIG_H
20
-#include "clamav-config.h"
21
-#endif
22
-
23
-#include <stdio.h>
24
-#include <stdlib.h>
25
-#include <string.h>
26
-#include <ctype.h>
27
-
28
-#include "options.h"
29
-#include "cfgfile.h"
30
-#include "others.h"
31
-#include "defaults.h"
32
-#include "str.h"
33
-
34
-struct cfgstruct *parsecfg(const char *cfgfile)
35
-{
36
-	char buff[LINE_LENGTH], *name, *arg;
37
-	FILE *fs;
38
-	int line = 0, i, found, ctype, calc;
39
-	struct cfgstruct *copt = NULL;
40
-	struct cfgoption *pt;
41
-
42
-	struct cfgoption cfg_options[] = {
43
-	    {"LogFile", OPT_STR},
44
-	    {"LogFileUnlock", OPT_NOARG},
45
-	    {"LogFileMaxSize", OPT_COMPSIZE},
46
-	    {"LogTime", OPT_NOARG},
47
-	    {"LogClean", OPT_NOARG},
48
-	    {"LogVerbose", OPT_NOARG}, /* clamd + freshclam */
49
-	    {"LogSyslog", OPT_NOARG},
50
-	    {"PidFile", OPT_STR},
51
-	    {"TemporaryDirectory", OPT_STR},
52
-	    {"MaxFileSize", OPT_COMPSIZE},
53
-	    {"ScanMail", OPT_NOARG},
54
-	    {"ScanOLE2", OPT_NOARG},
55
-	    {"ScanArchive", OPT_NOARG},
56
-	    {"ScanRAR", OPT_NOARG},
57
-	    {"ArchiveMaxFileSize", OPT_COMPSIZE},
58
-	    {"ArchiveMaxRecursion", OPT_NUM},
59
-	    {"ArchiveMaxFiles", OPT_NUM},
60
-	    {"ArchiveMaxCompressionRatio", OPT_NUM},
61
-	    {"ArchiveLimitMemoryUsage", OPT_NOARG},
62
-	    {"ArchiveDetectEncrypted", OPT_NOARG},
63
-	    {"DataDirectory", OPT_STR}, /* obsolete */
64
-	    {"DatabaseDirectory", OPT_STR}, /* clamd + freshclam */
65
-	    {"TCPAddr", OPT_STR},
66
-	    {"TCPSocket", OPT_NUM},
67
-	    {"LocalSocket", OPT_STR},
68
-	    {"MaxConnectionQueueLength", OPT_NUM},
69
-	    {"StreamSaveToDisk", OPT_NOARG},
70
-	    {"StreamMaxLength", OPT_COMPSIZE},
71
-	    {"MaxThreads", OPT_NUM},
72
-	    {"ThreadTimeout", OPT_NUM},
73
-	    {"MaxDirectoryRecursion", OPT_NUM},
74
-	    {"FollowDirectorySymlinks", OPT_NOARG},
75
-	    {"FollowFileSymlinks", OPT_NOARG},
76
-	    {"Foreground", OPT_NOARG},
77
-	    {"Debug", OPT_NOARG},
78
-	    {"FixStaleSocket", OPT_NOARG},
79
-	    {"User", OPT_STR},
80
-	    {"AllowSupplementaryGroups", OPT_NOARG},
81
-	    {"SelfCheck", OPT_NUM},
82
-	    {"VirusEvent", OPT_FULLSTR},
83
-	    {"ClamukoScanOnLine", OPT_NOARG},
84
-	    {"ClamukoScanOnOpen", OPT_NOARG},
85
-	    {"ClamukoScanOnClose", OPT_NOARG},
86
-	    {"ClamukoScanOnExec", OPT_NOARG},
87
-	    {"ClamukoIncludePath", OPT_STR},
88
-	    {"ClamukoExcludePath", OPT_STR},
89
-	    {"ClamukoMaxFileSize", OPT_COMPSIZE},
90
-	    {"ClamukoScanArchive", OPT_NOARG},
91
-	    {"DatabaseOwner", OPT_STR}, /* freshclam */
92
-	    {"Checks", OPT_NUM}, /* freshclam */
93
-	    {"UpdateLogFile", OPT_STR}, /* freshclam */
94
-	    {"DatabaseMirror", OPT_STR}, /* freshclam */
95
-	    {"MaxAttempts", OPT_NUM}, /* freshclam */
96
-	    {"HTTPProxyServer", OPT_STR}, /* freshclam */
97
-	    {"HTTPProxyPort", OPT_NUM}, /* freshclam */
98
-	    {"HTTPProxyUsername", OPT_STR}, /* freshclam */
99
-	    {"HTTPProxyPassword", OPT_STR}, /* freshclam */
100
-	    {"NotifyClamd", OPT_OPTARG}, /* freshclam */
101
-	    {"OnUpdateExecute", OPT_FULLSTR}, /* freshclam */
102
-	    {"OnErrorExecute", OPT_FULLSTR}, /* freshclam */
103
-	    {0, 0}
104
-	};
105
-
106
-
107
-    if((fs = fopen(cfgfile, "r")) == NULL) {
108
-	return NULL;
109
-    }
110
-
111
-
112
-    while(fgets(buff, LINE_LENGTH, fs)) {
113
-
114
-	line++;
115
-
116
-	if(buff[0] == '#')
117
-	    continue;
118
-
119
-	if(!strncmp("Example", buff, 7)) {
120
-	    fprintf(stderr, "ERROR: Please edit the example config file %s.\n", cfgfile);
121
-	    return NULL;
122
-	}
123
-
124
-
125
-	if((name = cli_strtok(buff, 0, " \r\n"))) {
126
-	    arg = cli_strtok(buff, 1, " \r\n");
127
-	    found = 0;
128
-	    for(i = 0; ; i++) {
129
-		pt = &cfg_options[i];
130
-		if(pt->name) {
131
-		    if(!strcmp(name, pt->name)) {
132
-			found = 1;
133
-			switch(pt->argtype) {
134
-			    case OPT_STR:
135
-				if(!arg) {
136
-				    fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string as argument.\n", line, name);
137
-				    return NULL;
138
-				}
139
-				copt = regcfg(copt, name, arg, 0);
140
-				break;
141
-			    case OPT_FULLSTR:
142
-				if(!arg) {
143
-				    fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string as argument.\n", line, name);
144
-				    return NULL;
145
-				}
146
-				/* FIXME: this one is an ugly hack of the above case */
147
-				free(arg);
148
-				arg = strstr(buff, " ");
149
-				arg = strdup(++arg);
150
-				copt = regcfg(copt, name, arg, 0);
151
-				break;
152
-			    case OPT_NUM:
153
-				if(!arg || !isnumb(arg)) {
154
-				    fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical argument.\n", line, name);
155
-				    return NULL;
156
-				}
157
-				copt = regcfg(copt, name, NULL, atoi(arg));
158
-				free(arg);
159
-				break;
160
-			    case OPT_COMPSIZE:
161
-				if(!arg) {
162
-				    fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires argument.\n", line, name);
163
-				    return NULL;
164
-				}
165
-				ctype = tolower(arg[strlen(arg) - 1]);
166
-				if(ctype == 'm' || ctype == 'k') {
167
-				    char *cpy = mcalloc(strlen(arg), sizeof(char));
168
-				    strncpy(cpy, arg, strlen(arg) - 1);
169
-				    if(!isnumb(cpy)) {
170
-					fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical (raw/K/M) argument.\n", line, name);
171
-					return NULL;
172
-				    }
173
-				    if(ctype == 'm')
174
-					calc = atoi(cpy) * 1024 * 1024;
175
-				    else
176
-					calc = atoi(cpy) * 1024;
177
-				    free(cpy);
178
-				} else {
179
-				    if(!isnumb(arg)) {
180
-					fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical (raw/K/M) argument.\n", line, name);
181
-					return NULL;
182
-				    }
183
-				    calc = atoi(arg);
184
-				}
185
-				copt = regcfg(copt, name, NULL, calc);
186
-				free(arg);
187
-				break;
188
-			    case OPT_NOARG:
189
-				if(arg) {
190
-				    fprintf(stderr, "ERROR: Parse error at line %d: Option %s doesn't support arguments (got '%s').\n", line, name, arg);
191
-				    return NULL;
192
-				}
193
-				copt = regcfg(copt, name, NULL, 0);
194
-				break;
195
-			    case OPT_OPTARG:
196
-				copt = regcfg(copt, name, arg, 0);
197
-				break;
198
-			    default:
199
-				fprintf(stderr, "ERROR: Parse error at line %d: Option %s is of unknown type %d\n", line, name, pt->argtype);
200
-				free(name);
201
-				free(arg);
202
-				break;
203
-			}
204
-		    }
205
-		} else
206
-		    break;
207
-	    } 
208
-
209
-	    if(!found) {
210
-		fprintf(stderr, "ERROR: Parse error at line %d: Unknown option %s.\n", line, name);
211
-		return NULL;
212
-	    }
213
-	}
214
-    }
215
-
216
-    fclose(fs);
217
-    return copt;
218
-}
219
-
220
-void freecfg(struct cfgstruct *copt)
221
-{
222
-    	struct cfgstruct *handler;
223
-    	struct cfgstruct *arg;
224
-
225
-    while (copt) {
226
-	arg = copt->nextarg;
227
-	while (arg) {
228
-	    if(arg->strarg) {
229
-		free(arg->optname);
230
-		free(arg->strarg);
231
-		handler = arg;
232
-		arg=arg->nextarg;
233
-		free(handler);
234
-	    }
235
-	}
236
-	if(copt->optname) {
237
-	    free(copt->optname);
238
-	}
239
-	if(copt->strarg) {
240
-	    free(copt->strarg);
241
-	}
242
-	handler = copt;
243
-	copt = copt->next;
244
-	free(handler);
245
-    }
246
-    return;
247
-}
248
-
249
-struct cfgstruct *regcfg(struct cfgstruct *copt, char *optname, char *strarg, int numarg)
250
-{
251
-	struct cfgstruct *newnode, *pt;
252
-
253
-    newnode = (struct cfgstruct *) mmalloc(sizeof(struct cfgstruct));
254
-    newnode->optname = optname;
255
-    newnode->nextarg = NULL;
256
-    newnode->next = NULL;
257
-
258
-    if(strarg)
259
-	newnode->strarg = strarg;
260
-    else {
261
-	newnode->strarg = NULL;
262
-	newnode->numarg = numarg;
263
-    }
264
-
265
-    if((pt = cfgopt(copt, optname))) {
266
-	while(pt->nextarg)
267
-	    pt = pt->nextarg;
268
-
269
-	pt->nextarg = newnode;
270
-	return copt;
271
-    } else {
272
-	newnode->next = copt;
273
-	return newnode;
274
-    }
275
-}
276
-
277
-struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname)
278
-{
279
-	struct cfgstruct *handler;
280
-
281
-    handler = (struct cfgstruct *) copt;
282
-
283
-    while(1) {
284
-	if(handler) {
285
-	    if(handler->optname)
286
-		if(!strcmp(handler->optname, optname))
287
-		    return handler;
288
-	} else break;
289
-	handler = handler->next;
290
-    }
291
-
292
-    return NULL;
293
-}
294
-
295 1
deleted file mode 100644
... ...
@@ -1,54 +0,0 @@
1
-/*
2
- *  Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
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., 675 Mass Ave, Cambridge, MA 02139, USA.
17
- */
18
-
19
-#ifndef __CFGFILE_H
20
-#define __CFGFILE_H
21
-
22
-#define LINE_LENGTH 1024
23
-
24
-
25
-#define OPT_STR 1 /* string argument */
26
-#define OPT_NUM 2 /* numerical argument */
27
-#define OPT_COMPSIZE 3 /* convert kilobytes (k) and megabytes (m) to bytes */
28
-#define OPT_NOARG 4 /* no argument */
29
-#define OPT_OPTARG 5 /* argument is optional, it's registered as string */
30
-#define OPT_FULLSTR 6 /* string argument, but get a full line */
31
-
32
-struct cfgoption {
33
-    const char *name;
34
-    int argtype;
35
-};
36
-
37
-struct cfgstruct {
38
-    char *optname;
39
-    char *strarg;
40
-    int numarg;
41
-    struct cfgstruct *nextarg;
42
-    struct cfgstruct *next;
43
-};
44
-
45
-
46
-struct cfgstruct *parsecfg(const char *cfgfile);
47
-
48
-struct cfgstruct *regcfg(struct cfgstruct *copt, char *optname, char *strarg, int numarg);
49
-
50
-struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname);
51
-
52
-void freecfg(struct cfgstruct *copt);
53
-
54
-#endif
... ...
@@ -33,7 +33,7 @@
33 33
 #include <grp.h>
34 34
 #include <clamav.h>
35 35
 
36
-#if defined(CLAMD_USE_SYSLOG) && !defined(C_AIX)
36
+#if defined(USE_SYSLOG) && !defined(C_AIX)
37 37
 #include <syslog.h>
38 38
 #endif
39 39
 
... ...
@@ -42,7 +42,7 @@
42 42
 #endif
43 43
 
44 44
 #include "options.h"
45
-#include "cfgfile.h"
45
+#include "cfgparser.h"
46 46
 #include "others.h"
47 47
 /* Fixes gcc warning */
48 48
 #include "../libclamav/others.h"
... ...
@@ -50,7 +50,9 @@
50 50
 #include "localserver.h"
51 51
 #include "others.h"
52 52
 #include "defaults.h"
53
-
53
+#include "memory.h"
54
+#include "output.h"
55
+#include "shared.h"
54 56
 
55 57
 void help(void);
56 58
 void daemonize(void);
... ...
@@ -107,14 +109,14 @@ void clamd(struct optstruct *opt)
107 107
     /* initialize logger */
108 108
 
109 109
     if(cfgopt(copt, "LogFileUnlock"))
110
-	loglock = 0;
110
+	logg_lock = 0;
111 111
     else
112
-	loglock = 1;
112
+	logg_lock = 1;
113 113
 
114 114
     if(cfgopt(copt, "LogTime"))
115
-	logtime = 1;
115
+	logg_time = 1;
116 116
     else
117
-	logtime = 0;
117
+	logg_time = 0;
118 118
 
119 119
     if(cfgopt(copt, "LogClean"))
120 120
 	logok = 1;
... ...
@@ -122,45 +124,44 @@ void clamd(struct optstruct *opt)
122 122
 	logok = 0;
123 123
 
124 124
     if((cpt = cfgopt(copt, "LogFileMaxSize")))
125
-	logsize = cpt->numarg;
125
+	logg_size = cpt->numarg;
126 126
     else
127
-	logsize = CL_DEFAULT_LOGSIZE;
127
+	logg_size = CL_DEFAULT_LOGSIZE;
128 128
 
129 129
     if(cfgopt(copt, "Debug")) /* enable debug messages in libclamav */
130 130
 	cl_debug();
131 131
 
132 132
     if(cfgopt(copt, "LogVerbose"))
133
-	logverbose = 1;
133
+	logg_verbose = 1;
134 134
     else
135
-	logverbose = 0;
135
+	logg_verbose = 0;
136 136
 
137 137
     if((cpt = cfgopt(copt, "LogFile"))) {
138
-	logfile = cpt->strarg;
139
-	if(logfile[0] != '/') {
138
+	logg_file = cpt->strarg;
139
+	if(logg_file[0] != '/') {
140 140
 	    fprintf(stderr, "ERROR: LogFile requires full path.\n");
141 141
 	    exit(1);
142 142
 	}
143 143
 	time(&currtime);
144 144
 	if(logg("+++ Started at %s", ctime(&currtime))) {
145
-	    fprintf(stderr, "ERROR: Problem with internal logger. Please check the permissions on the %s file.\n", logfile);
145
+	    fprintf(stderr, "ERROR: Problem with internal logger. Please check the permissions on the %s file.\n", logg_file);
146 146
 	    exit(1);
147 147
 	}
148 148
     } else
149
-	logfile = NULL;
149
+	logg_file = NULL;
150 150
 
151 151
 
152
-#if defined(CLAMD_USE_SYSLOG) && !defined(C_AIX)
152
+#if defined(USE_SYSLOG) && !defined(C_AIX)
153 153
     if((cpt = cfgopt(copt, "LogSyslog"))) {
154 154
 	openlog("clamd", LOG_PID, LOG_LOCAL6);
155
-	use_syslog = 1;
155
+	logg_syslog = 1;
156 156
 	syslog(LOG_INFO, "Daemon started.\n");
157 157
     } else
158
-	use_syslog = 0;
158
+	logg_syslog = 0;
159 159
 #endif
160 160
 
161
-
162
-    if(logsize)
163
-	logg("Log file size limited to %d bytes.\n", logsize);
161
+    if(logg_size)
162
+	logg("Log file size limited to %d bytes.\n", logg_size);
164 163
     else
165 164
 	logg("Log file size limit disabled.\n");
166 165
 
... ...
@@ -32,10 +32,11 @@
32 32
 
33 33
 #include "server.h"
34 34
 #include "others.h"
35
-#include "cfgfile.h"
35
+#include "cfgparser.h"
36 36
 #include "dazukoio.h"
37 37
 #include "clamuko.h"
38 38
 #include "defaults.h"
39
+#include "output.h"
39 40
 
40 41
 struct dazuko_access *acc;
41 42
 
... ...
@@ -30,10 +30,11 @@
30 30
 #include <errno.h>
31 31
 
32 32
 #include "options.h"
33
-#include "cfgfile.h"
33
+#include "cfgparser.h"
34 34
 #include "defaults.h"
35 35
 #include "others.h"
36 36
 #include "server.h"
37
+#include "output.h"
37 38
 
38 39
 int localserver(const struct optstruct *opt, const struct cfgstruct *copt, struct cl_node *root)
39 40
 {
... ...
@@ -36,6 +36,7 @@
36 36
 #include "options.h"
37 37
 #include "others.h"
38 38
 #include "../libclamav/others.h"
39
+#include "memory.h"
39 40
 
40 41
 void clamd(struct optstruct *opt);
41 42
 
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2002, 2003 Tomasz Kojm <zolw@konarski.edu.pl>
2
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -24,9 +24,7 @@
24 24
 #include <stdarg.h>
25 25
 #include <stdlib.h>
26 26
 #include <string.h>
27
-#include <ctype.h>
28 27
 #include <unistd.h>
29
-#include <pthread.h>
30 28
 #include <fcntl.h>
31 29
 #include <time.h>
32 30
 #include <sys/stat.h>
... ...
@@ -48,203 +46,8 @@
48 48
 #endif /* HAVE_POLL_H */
49 49
 #endif /* HAVE_POLL */
50 50
 
51
-#if defined(CLAMD_USE_SYSLOG) && !defined(C_AIX)
52
-#include <syslog.h>
53
-#endif
54
-
55
-#include "others.h"
56
-
57
-pthread_mutex_t logg_mutex = PTHREAD_MUTEX_INITIALIZER;
58
-pthread_mutex_t rand_mutex = PTHREAD_MUTEX_INITIALIZER;
59
-
60
-FILE *log_fd = NULL;
61
-
62
-int mdprintf(int desc, const char *str, ...)
63
-{
64
-	va_list args;
65
-	char buff[512];
66
-	int bytes;
67
-
68
-    va_start(args, str);
69
-    bytes = vsnprintf(buff, 512, str, args);
70
-    va_end(args);
71
-    write(desc, buff, bytes);
72
-    return bytes;
73
-}
74
-
75
-
76
-void logg_close(void) {
77
-    pthread_mutex_lock(&logg_mutex);
78
-    if (log_fd) {
79
-	fclose(log_fd);
80
-	log_fd = NULL;
81
-    }
82
-    pthread_mutex_unlock(&logg_mutex);
83
-#if defined(CLAMD_USE_SYSLOG) && !defined(C_AIX)
84
-    if(use_syslog) {
85
-    	closelog();
86
-    }
87
-#endif
88
-}
89
-
90
-
91
-int logg(const char *str, ...)
92
-{
93
-	va_list args;
94
-	struct flock fl;
95
-	char *pt, *timestr;
96
-	time_t currtime;
97
-	struct stat sb;
98
-	mode_t old_umask;
99
-
100
-
101
-    if(logfile) {
102
-
103
-	pthread_mutex_lock(&logg_mutex);
104
-
105
-	if(!log_fd) {
106
-	    old_umask = umask(0037);
107
-	    if((log_fd = fopen(logfile, "a")) == NULL) {
108
-		umask(old_umask);
109
-		pthread_mutex_unlock(&logg_mutex);
110
-		return -1;
111
-	    } else umask(old_umask);
112
-
113
-	    if(loglock) {
114
-		memset(&fl, 0, sizeof(fl));
115
-		fl.l_type = F_WRLCK;
116
-		if(fcntl(fileno(log_fd), F_SETLK, &fl) == -1) {
117
-		    pthread_mutex_unlock(&logg_mutex);
118
-		    return -1;
119
-		}
120
-	    }
121
-	}
122
-
123
-        /* Need to avoid logging time for verbose messages when logverbose
124
-           is not set or we get a bunch of timestamps in the log without
125
-           newlines... */
126
-	if(logtime && ((*str != '*') || logverbose)) {
127
-	    time(&currtime);
128
-	    pt = ctime(&currtime);
129
-	    timestr = mcalloc(strlen(pt), sizeof(char));
130
-	    strncpy(timestr, pt, strlen(pt) - 1);
131
-	    fprintf(log_fd, "%s -> ", timestr);
132
-	    free(timestr);
133
-	}
134
-
135
-
136
-	if(logsize) {
137
-	    if(stat(logfile, &sb) != -1) {
138
-		if(sb.st_size > logsize) {
139
-		    logfile = NULL;
140
-		    fprintf(log_fd, "Log size = %d, maximal = %d\n", (int) sb.st_size, logsize);
141
-		    fprintf(log_fd, "LOGGING DISABLED (Maximal log file size exceeded).\n");
142
-		    fclose(log_fd);
143
-		    log_fd = NULL;
144
-		    pthread_mutex_unlock(&logg_mutex);
145
-		    return 0;
146
-		}
147
-	    }
148
-	}
149
-
150
-	va_start(args, str);
151
-
152
-	if(*str == '!') {
153
-	    fprintf(log_fd, "ERROR: ");
154
-	    vfprintf(log_fd, str+1, args);
155
-	} else if(*str == '^') {
156
-	    fprintf(log_fd, "WARNING: ");
157
-	    vfprintf(log_fd, str+1, args);
158
-	} else if(*str == '*') {
159
-	    if(logverbose)
160
-		vfprintf(log_fd, str+1, args);
161
-	} else vfprintf(log_fd, str, args);
162
-
163
-	va_end(args);
164
-
165
-	fflush(log_fd);
166
-	pthread_mutex_unlock(&logg_mutex);
167
-    }
168
-
169
-#if defined(CLAMD_USE_SYSLOG) && !defined(C_AIX)
170
-    if(use_syslog) {
171
-
172
-      /* SYSLOG logging - no need for locking, mutexes, times & stuff ... :-) */
173
-
174
-#ifndef vsyslog
175
-#define vsyslog(a,b,c)	{ \
176
-	char my_tmp[4096]; \
177
-	vsnprintf(my_tmp,4095,b,c); \
178
-	my_tmp[4095]=0; \
179
-	syslog(a,my_tmp); }
180
-#endif
181
-
182
-	va_start(args, str);
183
-
184
-	if(*str == '!') {
185
-	    vsyslog(LOG_ERR, str+1, args);
186
-	} else if(*str == '^') {
187
-	    vsyslog(LOG_WARNING, str+1, args);
188
-	} else if(*str == '*') {
189
-	    if(logverbose) {
190
-		vsyslog(LOG_DEBUG, str+1, args);
191
-	    }
192
-	} else vsyslog(LOG_INFO, str, args);
193
-
194
-	va_end(args);
195
-    }
196
-#endif
197
-
198
-    return 0;
199
-}
200
-
201
-int isnumb(const char *str)
202
-{
203
-	int i;
204
-
205
-    for(i = 0; i < strlen(str); i++)
206
-	if(!isdigit(str[i]))
207
-	    return 0;
208
-
209
-    return 1;
210
-}
211
-
212
-void *mmalloc(size_t size)
213
-{
214
-	void *alloc;
215
-
216
-    alloc = malloc(size);
217
-
218
-    if(!alloc) {
219
-	printf("CRITICAL: Can't allocate memory (%d bytes).\n", size);
220
-	exit(71);
221
-	return NULL;
222
-    } else return alloc;
223
-}
224
-
225
-void *mcalloc(size_t nmemb, size_t size)
226
-{
227
-	void *alloc;
228
-
229
-    alloc = calloc(nmemb, size);
230
-
231
-    if(!alloc) {
232
-	printf("CRITICAL: Can't allocate memory (%d bytes).\n", nmemb * size);
233
-	exit(70);
234
-	return NULL;
235
-    } else return alloc;
236
-}
237
-
238
-void chomp(char *string)
239
-{
240
-	char *pt;
241
-
242
-    if((pt = strchr(string, 13)))
243
-	*pt = 0;
244
-
245
-    if((pt = strchr(string, 10)))
246
-	*pt = 0;
247
-}
51
+#include "memory.h"
52
+#include "cfgparser.h"
248 53
 
249 54
 void virusaction(const char *filename, const char *virname, const struct cfgstruct *copt)
250 55
 {
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
2
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -24,26 +24,11 @@
24 24
 #endif
25 25
 
26 26
 #include <stdlib.h>
27
-#include "cfgfile.h"
27
+#include "cfgparser.h"
28 28
 
29
-int mdprintf(int desc, const char *str, ...);
30
-int isnumb(const char *str);
31
-void *mmalloc(size_t size);
32
-void *mcalloc(size_t nmemb, size_t size);
33
-void chomp(char *string);
34 29
 
35
-short int logverbose, logcompressed, loglock, logtime, logok, debug_mode;
36
-int logsize;
37
-const char *logfile;
38
-int logg(const char *str, ...);
39
-void logg_close(void);
40 30
 int poll_fd(int fd, int timeout_sec);
41 31
 int is_fd_connected(int fd);
42
-
43
-#if defined(CLAMD_USE_SYSLOG) && !defined(C_AIX)
44
-short use_syslog;
45
-#endif
46
-
47 32
 void virusaction(const char *filename, const char *virname, const struct cfgstruct *copt);
48 33
 
49 34
 #endif
... ...
@@ -35,10 +35,13 @@
35 35
 #include <errno.h>
36 36
 #include <clamav.h>
37 37
 
38
-#include "cfgfile.h"
38
+#include "cfgparser.h"
39 39
 #include "others.h"
40 40
 #include "scanner.h"
41 41
 #include "defaults.h"
42
+#include "memory.h"
43
+#include "shared.h"
44
+#include "output.h"
42 45
 
43 46
 int checksymlink(const char *path)
44 47
 {
... ...
@@ -86,7 +89,7 @@ int dirscan(const char *dirname, const char **virname, unsigned long int *scanne
86 86
 	    if(dent->d_ino) {
87 87
 		if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
88 88
 		    /* build the full name */
89
-		    fname = mcalloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
89
+		    fname = (char *) mcalloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
90 90
 		    sprintf(fname, "%s/%s", dirname, dent->d_name);
91 91
 
92 92
 		    /* stat the file */
... ...
@@ -20,7 +20,8 @@
20 20
 #define __SCANNER_H
21 21
 
22 22
 #include <clamav.h>
23
-#include "cfgfile.h"
23
+#include "cfgparser.h"
24
+
24 25
 
25 26
 int dirscan(const char *dirname, const char **virname, unsigned long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt, int odesc, unsigned int *reclev, short contscan);
26 27
 
... ...
@@ -37,6 +37,9 @@
37 37
 #include "defaults.h"
38 38
 #include "clamuko.h"
39 39
 #include "others.h"
40
+#include "memory.h"
41
+#include "shared.h"
42
+#include "output.h"
40 43
 
41 44
 #define BUFFSIZE 1024
42 45
 #define FALSE (0)
... ...
@@ -205,7 +208,7 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop
205 205
 #ifdef CLAMUKO
206 206
 	pthread_t clamuko_pid;
207 207
 	pthread_attr_t clamuko_attr;
208
-	struct thrarg *tharg;
208
+	struct thrarg *tharg = NULL; /* shut up gcc */
209 209
 #endif
210 210
 	memset(&sigact, 0, sizeof(struct sigaction));
211 211
 
... ...
@@ -32,7 +32,7 @@
32 32
 #include <signal.h>
33 33
 #include <errno.h>
34 34
 
35
-#include "cfgfile.h"
35
+#include "cfgparser.h"
36 36
 #include "others.h"
37 37
 #include "defaults.h"
38 38
 #include "scanner.h"
... ...
@@ -40,6 +40,8 @@
40 40
 #include "clamuko.h"
41 41
 #include "tests.h"
42 42
 #include "session.h"
43
+#include "str.h" /* libclamav */
44
+#include "output.h"
43 45
 
44 46
 #define CMD1 "SCAN"
45 47
 #define CMD2 "RAWSCAN"
... ...
@@ -79,7 +81,7 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits
79 79
     }
80 80
 
81 81
     buff[bread] = 0;
82
-    chomp(buff);
82
+    cli_chomp(buff);
83 83
 
84 84
     if(!strncmp(buff, CMD1, strlen(CMD1))) { /* SCAN */
85 85
 	scan(buff + strlen(CMD1) + 1, NULL, root, limits, options, copt, desc, 0);
... ...
@@ -24,7 +24,7 @@
24 24
 #define COMMAND_END 3
25 25
 
26 26
 #include <clamav.h>
27
-#include "cfgfile.h"
27
+#include "cfgparser.h"
28 28
 
29 29
 int command(int desc, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt);
30 30
 
31 31
new file mode 100644
... ...
@@ -0,0 +1,24 @@
0
+/*
1
+ *  Copyright (C) 2004 Tomasz Kojm <tkojm@clamav.net>
2
+ *
3
+ *  This program is free software; you can redistribute it and/or modify
4
+ *  it under the terms of the GNU General Public License as published by
5
+ *  the Free Software Foundation; either version 2 of the License, or
6
+ *  (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ */
17
+
18
+#ifndef __SHARED_H
19
+#define __SHARED_H
20
+
21
+short debug_mode, logok;
22
+
23
+#endif
... ...
@@ -32,10 +32,11 @@
32 32
 
33 33
 
34 34
 #include "options.h"
35
-#include "cfgfile.h"
35
+#include "cfgparser.h"
36 36
 #include "defaults.h"
37 37
 #include "others.h"
38 38
 #include "server.h"
39
+#include "output.h"
39 40
 
40 41
 int tcpserver(const struct optstruct *opt, const struct cfgstruct *copt, struct cl_node *root)
41 42
 {
... ...
@@ -20,7 +20,7 @@
20 20
 #define __TCPSERVER_H
21 21
 
22 22
 #include "options.h"
23
-#include "cfgfile.h"
23
+#include "cfgparser.h"
24 24
 
25 25
 int tcpserver(const struct optstruct *opt, const struct cfgstruct *copt, struct cl_node *root);
26 26
 
... ...
@@ -23,6 +23,8 @@
23 23
 #include "thrmgr.h"
24 24
 
25 25
 #include "others.h"
26
+#include "memory.h"
27
+#include "output.h"
26 28
 
27 29
 #define FALSE (0)
28 30
 #define TRUE (1)
... ...
@@ -20,14 +20,20 @@ if BUILD_CLAMD
20 20
 bin_PROGRAMS = clamdscan
21 21
 
22 22
 clamdscan_SOURCES = \
23
+    $(top_srcdir)/shared/output.c \
24
+    $(top_srcdir)/shared/output.h \
25
+    $(top_srcdir)/shared/cfgparser.c \
26
+    $(top_srcdir)/shared/cfgparser.h \
27
+    $(top_srcdir)/shared/memory.c \
28
+    $(top_srcdir)/shared/memory.h \
23 29
     clamdscan.c \
24 30
     client.c \
25 31
     client.h \
26 32
     defaults.h
27 33
 
28
-clamdscan_LDADD = $(top_builddir)/clamscan/getopt.o $(top_builddir)/clamscan/options.o $(top_builddir)/clamscan/others.o $(top_builddir)/clamd/cfgfile.o
34
+clamdscan_LDADD = $(top_builddir)/clamscan/options.o $(top_builddir)/clamscan/getopt.o
29 35
 
30 36
 endif
31 37
 
32
-INCLUDES = -I$(top_srcdir)/clamscan -I$(top_srcdir)/clamd -I$(top_srcdir)/libclamav
38
+INCLUDES = -I$(top_srcdir)/clamscan -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
33 39
 LIBS = -L$(top_builddir)/libclamav -lclamav @FRESHCLAM_LIBS@
... ...
@@ -119,15 +119,21 @@ install_sh = @install_sh@
119 119
 @BUILD_CLAMD_TRUE@bin_PROGRAMS = clamdscan
120 120
 
121 121
 @BUILD_CLAMD_TRUE@clamdscan_SOURCES = \
122
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/output.c \
123
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/output.h \
124
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/cfgparser.c \
125
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/cfgparser.h \
126
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/memory.c \
127
+@BUILD_CLAMD_TRUE@    $(top_srcdir)/shared/memory.h \
122 128
 @BUILD_CLAMD_TRUE@    clamdscan.c \
123 129
 @BUILD_CLAMD_TRUE@    client.c \
124 130
 @BUILD_CLAMD_TRUE@    client.h \
125 131
 @BUILD_CLAMD_TRUE@    defaults.h
126 132
 
127 133
 
128
-@BUILD_CLAMD_TRUE@clamdscan_LDADD = $(top_builddir)/clamscan/getopt.o $(top_builddir)/clamscan/options.o $(top_builddir)/clamscan/others.o $(top_builddir)/clamd/cfgfile.o
134
+@BUILD_CLAMD_TRUE@clamdscan_LDADD = $(top_builddir)/clamscan/options.o $(top_builddir)/clamscan/getopt.o
129 135
 
130
-INCLUDES = -I$(top_srcdir)/clamscan -I$(top_srcdir)/clamd -I$(top_srcdir)/libclamav
136
+INCLUDES = -I$(top_srcdir)/clamscan -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
131 137
 LIBS = -L$(top_builddir)/libclamav -lclamav @FRESHCLAM_LIBS@
132 138
 subdir = clamdscan
133 139
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
... ...
@@ -137,14 +143,13 @@ CONFIG_CLEAN_FILES =
137 137
 @BUILD_CLAMD_FALSE@bin_PROGRAMS =
138 138
 PROGRAMS = $(bin_PROGRAMS)
139 139
 
140
-@BUILD_CLAMD_TRUE@am_clamdscan_OBJECTS = clamdscan.$(OBJEXT) \
141
-@BUILD_CLAMD_TRUE@	client.$(OBJEXT)
140
+@BUILD_CLAMD_TRUE@am_clamdscan_OBJECTS = output.$(OBJEXT) \
141
+@BUILD_CLAMD_TRUE@	cfgparser.$(OBJEXT) memory.$(OBJEXT) \
142
+@BUILD_CLAMD_TRUE@	clamdscan.$(OBJEXT) client.$(OBJEXT)
142 143
 clamdscan_OBJECTS = $(am_clamdscan_OBJECTS)
143 144
 @BUILD_CLAMD_TRUE@clamdscan_DEPENDENCIES = \
144
-@BUILD_CLAMD_TRUE@	$(top_builddir)/clamscan/getopt.o \
145 145
 @BUILD_CLAMD_TRUE@	$(top_builddir)/clamscan/options.o \
146
-@BUILD_CLAMD_TRUE@	$(top_builddir)/clamscan/others.o \
147
-@BUILD_CLAMD_TRUE@	$(top_builddir)/clamd/cfgfile.o
146
+@BUILD_CLAMD_TRUE@	$(top_builddir)/clamscan/getopt.o
148 147
 @BUILD_CLAMD_FALSE@clamdscan_DEPENDENCIES =
149 148
 clamdscan_LDFLAGS =
150 149
 
... ...
@@ -154,7 +159,9 @@ CPPFLAGS = @CPPFLAGS@
154 154
 LDFLAGS = @LDFLAGS@
155 155
 depcomp = $(SHELL) $(top_srcdir)/depcomp
156 156
 am__depfiles_maybe = depfiles
157
-@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/clamdscan.Po ./$(DEPDIR)/client.Po
157
+@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/cfgparser.Po \
158
+@AMDEP_TRUE@	./$(DEPDIR)/clamdscan.Po ./$(DEPDIR)/client.Po \
159
+@AMDEP_TRUE@	./$(DEPDIR)/memory.Po ./$(DEPDIR)/output.Po
158 160
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
159 161
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
160 162
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
... ...
@@ -203,6 +210,9 @@ uninstall-binPROGRAMS:
203 203
 
204 204
 clean-binPROGRAMS:
205 205
 	-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
206
+output.$(OBJEXT): $(top_srcdir)/shared/output.c
207
+cfgparser.$(OBJEXT): $(top_srcdir)/shared/cfgparser.c
208
+memory.$(OBJEXT): $(top_srcdir)/shared/memory.c
206 209
 clamdscan$(EXEEXT): $(clamdscan_OBJECTS) $(clamdscan_DEPENDENCIES) 
207 210
 	@rm -f clamdscan$(EXEEXT)
208 211
 	$(LINK) $(clamdscan_LDFLAGS) $(clamdscan_OBJECTS) $(clamdscan_LDADD) $(LIBS)
... ...
@@ -213,8 +223,11 @@ mostlyclean-compile:
213 213
 distclean-compile:
214 214
 	-rm -f *.tab.c
215 215
 
216
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgparser.Po@am__quote@
216 217
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clamdscan.Po@am__quote@
217 218
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/client.Po@am__quote@
219
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Po@am__quote@
220
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/output.Po@am__quote@
218 221
 
219 222
 distclean-depend:
220 223
 	-rm -rf ./$(DEPDIR)
... ...
@@ -236,6 +249,60 @@ distclean-depend:
236 236
 @AMDEP_TRUE@	depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@
237 237
 @AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
238 238
 	$(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<
239
+
240
+output.o: $(top_srcdir)/shared/output.c
241
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.o' libtool=no @AMDEPBACKSLASH@
242
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Po' tmpdepfile='$(DEPDIR)/output.TPo' @AMDEPBACKSLASH@
243
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
244
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.o `test -f '$(top_srcdir)/shared/output.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/output.c
245
+
246
+output.obj: $(top_srcdir)/shared/output.c
247
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.obj' libtool=no @AMDEPBACKSLASH@
248
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Po' tmpdepfile='$(DEPDIR)/output.TPo' @AMDEPBACKSLASH@
249
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
250
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.obj `cygpath -w $(top_srcdir)/shared/output.c`
251
+
252
+output.lo: $(top_srcdir)/shared/output.c
253
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.lo' libtool=yes @AMDEPBACKSLASH@
254
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Plo' tmpdepfile='$(DEPDIR)/output.TPlo' @AMDEPBACKSLASH@
255
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
256
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.lo `test -f '$(top_srcdir)/shared/output.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/output.c
257
+
258
+cfgparser.o: $(top_srcdir)/shared/cfgparser.c
259
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.o' libtool=no @AMDEPBACKSLASH@
260
+@AMDEP_TRUE@	depfile='$(DEPDIR)/cfgparser.Po' tmpdepfile='$(DEPDIR)/cfgparser.TPo' @AMDEPBACKSLASH@
261
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
262
+	$(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
263
+
264
+cfgparser.obj: $(top_srcdir)/shared/cfgparser.c
265
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.obj' libtool=no @AMDEPBACKSLASH@
266
+@AMDEP_TRUE@	depfile='$(DEPDIR)/cfgparser.Po' tmpdepfile='$(DEPDIR)/cfgparser.TPo' @AMDEPBACKSLASH@
267
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
268
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.obj `cygpath -w $(top_srcdir)/shared/cfgparser.c`
269
+
270
+cfgparser.lo: $(top_srcdir)/shared/cfgparser.c
271
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.lo' libtool=yes @AMDEPBACKSLASH@
272
+@AMDEP_TRUE@	depfile='$(DEPDIR)/cfgparser.Plo' tmpdepfile='$(DEPDIR)/cfgparser.TPlo' @AMDEPBACKSLASH@
273
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
274
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.lo `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c
275
+
276
+memory.o: $(top_srcdir)/shared/memory.c
277
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.o' libtool=no @AMDEPBACKSLASH@
278
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Po' tmpdepfile='$(DEPDIR)/memory.TPo' @AMDEPBACKSLASH@
279
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
280
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.o `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c
281
+
282
+memory.obj: $(top_srcdir)/shared/memory.c
283
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.obj' libtool=no @AMDEPBACKSLASH@
284
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Po' tmpdepfile='$(DEPDIR)/memory.TPo' @AMDEPBACKSLASH@
285
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
286
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.obj `cygpath -w $(top_srcdir)/shared/memory.c`
287
+
288
+memory.lo: $(top_srcdir)/shared/memory.c
289
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.lo' libtool=yes @AMDEPBACKSLASH@
290
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Plo' tmpdepfile='$(DEPDIR)/memory.TPlo' @AMDEPBACKSLASH@
291
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
292
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.lo `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c
239 293
 CCDEPMODE = @CCDEPMODE@
240 294
 
241 295
 mostlyclean-libtool:
... ...
@@ -32,6 +32,7 @@
32 32
 #include "shared.h"
33 33
 #include "defaults.h"
34 34
 #include "client.h"
35
+#include "output.h"
35 36
 
36 37
 
37 38
 void help(void);
... ...
@@ -56,8 +57,13 @@ void clamscan(struct optstruct *opt)
56 56
 
57 57
     mprintf_disabled = 0;
58 58
 
59
-    if(optc(opt, 'v')) mprintf_verbose = 1;
60
-    else mprintf_verbose = 0;
59
+    if(optc(opt, 'v')) {
60
+	mprintf_verbose = 1;
61
+	logg_verbose = 1;
62
+    } else {
63
+	mprintf_verbose = 0;
64
+	logg_verbose = 0;
65
+    }
61 66
 
62 67
     if(optl(opt, "quiet")) mprintf_quiet = 1;
63 68
     else mprintf_quiet = 0;
... ...
@@ -80,14 +86,19 @@ void clamscan(struct optstruct *opt)
80 80
 
81 81
     /* initialize logger */
82 82
 
83
+    /* FIXME: enable in the future */
84
+    logg_size = 0;
85
+    logg_lock = 0;
86
+    logg_time = 0;
87
+
83 88
     if(optc(opt, 'l')) {
84
-	logfile = getargc(opt, 'l');
89
+	logg_file = getargc(opt, 'l');
85 90
 	if(logg("--------------------------------------\n")) {
86 91
 	    mprintf("!Problem with internal logger.\n");
87 92
 	    mexit(2);
88 93
 	}
89 94
     } else 
90
-	logfile = NULL;
95
+	logg_file = NULL;
91 96
 
92 97
 
93 98
     time(&starttime);
... ...
@@ -21,8 +21,9 @@
21 21
 #endif
22 22
 
23 23
 #include <stdio.h>
24
-#include <unistd.h>
25 24
 #include <sys/types.h>
25
+#include <sys/stat.h>
26
+#include <unistd.h>
26 27
 #include <sys/socket.h>
27 28
 #include <sys/un.h>
28 29
 #include <netinet/in.h>
... ...
@@ -31,9 +32,12 @@
31 31
 #include <string.h>
32 32
 
33 33
 #include "others.h"
34
-#include "cfgfile.h"
35 34
 #include "defaults.h"
36 35
 #include "shared.h"
36
+#include "options.h"
37
+#include "cfgparser.h"
38
+#include "memory.h"
39
+#include "output.h"
37 40
 
38 41
 #ifdef PF_INET
39 42
 # define SOCKET_INET	PF_INET
... ...
@@ -202,7 +206,9 @@ int client(const struct optstruct *opt)
202 202
     } else if(opt->filename[0] == '/') {
203 203
 	file = (char *) strdup(opt->filename);
204 204
     } else {
205
-	if(fileinfo(opt->filename, 2) == -1) {
205
+	    struct stat foo;
206
+
207
+	if(stat(opt->filename, &foo) == -1) {
206 208
 	    mprintf("@Can't access file %s\n", opt->filename);
207 209
 	    perror(opt->filename);
208 210
 	    return 2;
... ...
@@ -19,6 +19,8 @@
19 19
 #ifndef __CLIENT_H
20 20
 #define __CLIENT_H
21 21
 
22
+#include "options.h"
23
+
22 24
 int client(const struct optstruct *opt);
23 25
 
24 26
 #endif
... ...
@@ -1,6 +1,6 @@
1 1
 #
2
-#  Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
3
-#  Fixes - Arkadiusz Miskiewicz <misiek@pld.org.pl>
2
+#  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
3
+#  Fixes by Arkadiusz Miskiewicz <misiek@pld.org.pl>
4 4
 #
5 5
 #  This program is free software; you can redistribute it and/or modify
6 6
 #  it under the terms of the GNU General Public License as published by
... ...
@@ -19,11 +19,15 @@
19 19
 bin_PROGRAMS = clamscan
20 20
 
21 21
 clamscan_SOURCES = \
22
+    $(top_srcdir)/shared/output.c \
23
+    $(top_srcdir)/shared/output.h \
24
+    $(top_srcdir)/shared/getopt.c \
25
+    $(top_srcdir)/shared/getopt.h \
26
+    $(top_srcdir)/shared/memory.c \
27
+    $(top_srcdir)/shared/memory.h \
22 28
     clamscan.c \
23 29
     options.c \
24 30
     options.h \
25
-    getopt.c \
26
-    getopt.h \
27 31
     others.c \
28 32
     others.h \
29 33
     shared.h \
... ...
@@ -35,4 +39,4 @@ clamscan_SOURCES = \
35 35
 
36 36
 DEFS = @DEFS@
37 37
 LIBS = -L$(top_builddir)/libclamav -lclamav
38
-INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/libclamav
38
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
... ...
@@ -15,8 +15,8 @@
15 15
 @SET_MAKE@
16 16
 
17 17
 #
18
-#  Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
19
-#  Fixes - Arkadiusz Miskiewicz <misiek@pld.org.pl>
18
+#  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
19
+#  Fixes by Arkadiusz Miskiewicz <misiek@pld.org.pl>
20 20
 #
21 21
 #  This program is free software; you can redistribute it and/or modify
22 22
 #  it under the terms of the GNU General Public License as published by
... ...
@@ -120,11 +120,15 @@ install_sh = @install_sh@
120 120
 bin_PROGRAMS = clamscan
121 121
 
122 122
 clamscan_SOURCES = \
123
+    $(top_srcdir)/shared/output.c \
124
+    $(top_srcdir)/shared/output.h \
125
+    $(top_srcdir)/shared/getopt.c \
126
+    $(top_srcdir)/shared/getopt.h \
127
+    $(top_srcdir)/shared/memory.c \
128
+    $(top_srcdir)/shared/memory.h \
123 129
     clamscan.c \
124 130
     options.c \
125 131
     options.h \
126
-    getopt.c \
127
-    getopt.h \
128 132
     others.c \
129 133
     others.h \
130 134
     shared.h \
... ...
@@ -137,7 +141,7 @@ clamscan_SOURCES = \
137 137
 
138 138
 DEFS = @DEFS@
139 139
 LIBS = -L$(top_builddir)/libclamav -lclamav
140
-INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/libclamav
140
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
141 141
 subdir = clamscan
142 142
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
143 143
 CONFIG_HEADER = $(top_builddir)/clamav-config.h
... ...
@@ -145,9 +149,9 @@ CONFIG_CLEAN_FILES =
145 145
 bin_PROGRAMS = clamscan$(EXEEXT)
146 146
 PROGRAMS = $(bin_PROGRAMS)
147 147
 
148
-am_clamscan_OBJECTS = clamscan.$(OBJEXT) options.$(OBJEXT) \
149
-	getopt.$(OBJEXT) others.$(OBJEXT) manager.$(OBJEXT) \
150
-	treewalk.$(OBJEXT)
148
+am_clamscan_OBJECTS = output.$(OBJEXT) getopt.$(OBJEXT) memory.$(OBJEXT) \
149
+	clamscan.$(OBJEXT) options.$(OBJEXT) others.$(OBJEXT) \
150
+	manager.$(OBJEXT) treewalk.$(OBJEXT)
151 151
 clamscan_OBJECTS = $(am_clamscan_OBJECTS)
152 152
 clamscan_LDADD = $(LDADD)
153 153
 clamscan_DEPENDENCIES =
... ...
@@ -158,8 +162,9 @@ LDFLAGS = @LDFLAGS@
158 158
 depcomp = $(SHELL) $(top_srcdir)/depcomp
159 159
 am__depfiles_maybe = depfiles
160 160
 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/clamscan.Po ./$(DEPDIR)/getopt.Po \
161
-@AMDEP_TRUE@	./$(DEPDIR)/manager.Po ./$(DEPDIR)/options.Po \
162
-@AMDEP_TRUE@	./$(DEPDIR)/others.Po ./$(DEPDIR)/treewalk.Po
161
+@AMDEP_TRUE@	./$(DEPDIR)/manager.Po ./$(DEPDIR)/memory.Po \
162
+@AMDEP_TRUE@	./$(DEPDIR)/options.Po ./$(DEPDIR)/others.Po \
163
+@AMDEP_TRUE@	./$(DEPDIR)/output.Po ./$(DEPDIR)/treewalk.Po
163 164
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
164 165
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
165 166
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
... ...
@@ -208,6 +213,9 @@ uninstall-binPROGRAMS:
208 208
 
209 209
 clean-binPROGRAMS:
210 210
 	-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
211
+output.$(OBJEXT): $(top_srcdir)/shared/output.c
212
+getopt.$(OBJEXT): $(top_srcdir)/shared/getopt.c
213
+memory.$(OBJEXT): $(top_srcdir)/shared/memory.c
211 214
 clamscan$(EXEEXT): $(clamscan_OBJECTS) $(clamscan_DEPENDENCIES) 
212 215
 	@rm -f clamscan$(EXEEXT)
213 216
 	$(LINK) $(clamscan_LDFLAGS) $(clamscan_OBJECTS) $(clamscan_LDADD) $(LIBS)
... ...
@@ -221,8 +229,10 @@ distclean-compile:
221 221
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clamscan.Po@am__quote@
222 222
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
223 223
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/manager.Po@am__quote@
224
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Po@am__quote@
224 225
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@
225 226
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/others.Po@am__quote@
227
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/output.Po@am__quote@
226 228
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/treewalk.Po@am__quote@
227 229
 
228 230
 distclean-depend:
... ...
@@ -245,6 +255,60 @@ distclean-depend:
245 245
 @AMDEP_TRUE@	depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@
246 246
 @AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
247 247
 	$(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<
248
+
249
+output.o: $(top_srcdir)/shared/output.c
250
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.o' libtool=no @AMDEPBACKSLASH@
251
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Po' tmpdepfile='$(DEPDIR)/output.TPo' @AMDEPBACKSLASH@
252
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
253
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.o `test -f '$(top_srcdir)/shared/output.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/output.c
254
+
255
+output.obj: $(top_srcdir)/shared/output.c
256
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.obj' libtool=no @AMDEPBACKSLASH@
257
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Po' tmpdepfile='$(DEPDIR)/output.TPo' @AMDEPBACKSLASH@
258
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
259
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.obj `cygpath -w $(top_srcdir)/shared/output.c`
260
+
261
+output.lo: $(top_srcdir)/shared/output.c
262
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.lo' libtool=yes @AMDEPBACKSLASH@
263
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Plo' tmpdepfile='$(DEPDIR)/output.TPlo' @AMDEPBACKSLASH@
264
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
265
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.lo `test -f '$(top_srcdir)/shared/output.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/output.c
266
+
267
+getopt.o: $(top_srcdir)/shared/getopt.c
268
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.o' libtool=no @AMDEPBACKSLASH@
269
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Po' tmpdepfile='$(DEPDIR)/getopt.TPo' @AMDEPBACKSLASH@
270
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
271
+	$(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
272
+
273
+getopt.obj: $(top_srcdir)/shared/getopt.c
274
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.obj' libtool=no @AMDEPBACKSLASH@
275
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Po' tmpdepfile='$(DEPDIR)/getopt.TPo' @AMDEPBACKSLASH@
276
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
277
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.obj `cygpath -w $(top_srcdir)/shared/getopt.c`
278
+
279
+getopt.lo: $(top_srcdir)/shared/getopt.c
280
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.lo' libtool=yes @AMDEPBACKSLASH@
281
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Plo' tmpdepfile='$(DEPDIR)/getopt.TPlo' @AMDEPBACKSLASH@
282
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
283
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.lo `test -f '$(top_srcdir)/shared/getopt.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/getopt.c
284
+
285
+memory.o: $(top_srcdir)/shared/memory.c
286
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.o' libtool=no @AMDEPBACKSLASH@
287
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Po' tmpdepfile='$(DEPDIR)/memory.TPo' @AMDEPBACKSLASH@
288
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
289
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.o `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c
290
+
291
+memory.obj: $(top_srcdir)/shared/memory.c
292
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.obj' libtool=no @AMDEPBACKSLASH@
293
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Po' tmpdepfile='$(DEPDIR)/memory.TPo' @AMDEPBACKSLASH@
294
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
295
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.obj `cygpath -w $(top_srcdir)/shared/memory.c`
296
+
297
+memory.lo: $(top_srcdir)/shared/memory.c
298
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.lo' libtool=yes @AMDEPBACKSLASH@
299
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Plo' tmpdepfile='$(DEPDIR)/memory.TPlo' @AMDEPBACKSLASH@
300
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
301
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.lo `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c
248 302
 CCDEPMODE = @CCDEPMODE@
249 303
 
250 304
 mostlyclean-libtool:
... ...
@@ -34,6 +34,8 @@
34 34
 #include "defaults.h"
35 35
 #include "treewalk.h"
36 36
 
37
+#include "output.h"
38
+
37 39
 #ifdef C_LINUX
38 40
 #include <sys/resource.h>
39 41
 #endif
... ...
@@ -53,8 +55,13 @@ int clamscan(struct optstruct *opt)
53 53
 
54 54
     mprintf_disabled = 0;
55 55
 
56
-    if(optc(opt, 'v')) mprintf_verbose = 1;
57
-    else mprintf_verbose = 0;
56
+    if(optc(opt, 'v')) {
57
+	mprintf_verbose = 1;
58
+	logg_verbose = 1;
59
+    } else {
60
+	mprintf_verbose = 0;
61
+	logg_verbose = 0;
62
+    }
58 63
 
59 64
     if(optl(opt, "quiet")) mprintf_quiet = 1;
60 65
     else mprintf_quiet = 0;
... ...
@@ -96,14 +103,19 @@ int clamscan(struct optstruct *opt)
96 96
 
97 97
     /* initialize logger */
98 98
 
99
+    /* FIXME: enable in the future */
100
+    logg_size = 0;
101
+    logg_lock = 0;
102
+    logg_time = 0;
103
+
99 104
     if(optc(opt, 'l')) {
100
-	logfile = getargc(opt, 'l');
105
+	logg_file = getargc(opt, 'l');
101 106
 	if(logg("--------------------------------------\n")) {
102 107
 	    mprintf("!Problem with internal logger.\n");
103 108
 	    return 1;
104 109
 	}
105 110
     } else 
106
-	logfile = NULL;
111
+	logg_file = NULL;
107 112
 
108 113
     /* we need some pre-checks */
109 114
     if(optl(opt, "max-space"))
110 115
deleted file mode 100644
... ...
@@ -1,1020 +0,0 @@
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
-
42
-#include <stdio.h>
43
-
44
-int strncmp(const char *s1, const char *s2, size_t n);
45
-
46
-/* Comment out all this code if we are using the GNU C Library, and are not
47
-   actually compiling the library itself.  This code is part of the GNU C
48
-   Library, but also included in many other GNU distributions.  Compiling
49
-   and linking in this code is a waste when using the GNU C library
50
-   (especially if it is a shared library).  Rather than having every GNU
51
-   program understand `configure --with-gnu-libc' and omit the object files,
52
-   it is simpler to just do this in the source for each such file.  */
53
-
54
-#define GETOPT_INTERFACE_VERSION 2
55
-#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
56
-# include <gnu-versions.h>
57
-# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
58
-#  define ELIDE_CODE
59
-# endif
60
-#endif
61
-
62
-#ifndef ELIDE_CODE
63
-
64
-
65
-/* This needs to come after some library #include
66
-   to get __GNU_LIBRARY__ defined.  */
67
-#ifdef	__GNU_LIBRARY__
68
-/* Don't include stdlib.h for non-GNU C libraries because some of them
69
-   contain conflicting prototypes for getopt.  */
70
-# include <stdlib.h>
71
-# include <unistd.h>
72
-#endif	/* GNU C library.  */
73
-
74
-#ifdef VMS
75
-# include <unixlib.h>
76
-# if HAVE_STRING_H - 0
77
-#  include <string.h>
78
-# endif
79
-#endif
80
-
81
-#ifndef _
82
-/* This is for other GNU distributions with internationalized messages.  */
83
-# if defined HAVE_LIBINTL_H || defined _LIBC
84
-#  include <libintl.h>
85
-#  ifndef _
86
-#   define _(msgid)	gettext (msgid)
87
-#  endif
88
-# else
89
-#  define _(msgid)	(msgid)
90
-# endif
91
-#endif
92
-
93
-/* This version of `getopt' appears to the caller like standard Unix `getopt'
94
-   but it behaves differently for the user, since it allows the user
95
-   to intersperse the options with the other arguments.
96
-
97
-   As `getopt' works, it permutes the elements of ARGV so that,
98
-   when it is done, all the options precede everything else.  Thus
99
-   all application programs are extended to handle flexible argument order.
100
-
101
-   Setting the environment variable POSIXLY_CORRECT disables permutation.
102
-   Then the behavior is completely standard.
103
-
104
-   GNU application programs can use a third alternative mode in which
105
-   they can distinguish the relative order of options and other arguments.  */
106
-
107
-#include "getopt.h"
108
-
109
-/* For communication from `getopt' to the caller.
110
-   When `getopt' finds an option that takes an argument,
111
-   the argument value is returned here.
112
-   Also, when `ordering' is RETURN_IN_ORDER,
113
-   each non-option ARGV-element is returned here.  */
114
-
115
-char *optarg;
116
-
117
-/* Index in ARGV of the next element to be scanned.
118
-   This is used for communication to and from the caller
119
-   and for communication between successive calls to `getopt'.
120
-
121
-   On entry to `getopt', zero means this is the first call; initialize.
122
-
123
-   When `getopt' returns -1, this is the index of the first of the
124
-   non-option elements that the caller should itself scan.
125
-
126
-   Otherwise, `optind' communicates from one call to the next
127
-   how much of ARGV has been scanned so far.  */
128
-
129
-/* 1003.2 says this must be 1 before any call.  */
130
-int optind = 1;
131
-
132
-/* Formerly, initialization of getopt depended on optind==0, which
133
-   causes problems with re-calling getopt as programs generally don't
134
-   know that. */
135
-
136
-int __getopt_initialized;
137
-
138
-/* The next char to be scanned in the option-element
139
-   in which the last option character we returned was found.
140
-   This allows us to pick up the scan where we left off.
141
-
142
-   If this is zero, or a null string, it means resume the scan
143
-   by advancing to the next ARGV-element.  */
144
-
145
-static char *nextchar;
146
-
147
-/* Callers store zero here to inhibit the error message
148
-   for unrecognized options.  */
149
-
150
-int opterr = 1;
151
-
152
-/* Set to an option character which was unrecognized.
153
-   This must be initialized on some systems to avoid linking in the
154
-   system's own getopt implementation.  */
155
-
156
-int optopt = '?';
157
-
158
-/* Describe how to deal with options that follow non-option ARGV-elements.
159
-
160
-   If the caller did not specify anything,
161
-   the default is REQUIRE_ORDER if the environment variable
162
-   POSIXLY_CORRECT is defined, PERMUTE otherwise.
163
-
164
-   REQUIRE_ORDER means don't recognize them as options;
165
-   stop option processing when the first non-option is seen.
166
-   This is what Unix does.
167
-   This mode of operation is selected by either setting the environment
168
-   variable POSIXLY_CORRECT, or using `+' as the first character
169
-   of the list of option characters.
170
-
171
-   PERMUTE is the default.  We permute the contents of ARGV as we scan,
172
-   so that eventually all the non-options are at the end.  This allows options
173
-   to be given in any order, even with programs that were not written to
174
-   expect this.
175
-
176
-   RETURN_IN_ORDER is an option available to programs that were written
177
-   to expect options and other ARGV-elements in any order and that care about
178
-   the ordering of the two.  We describe each non-option ARGV-element
179
-   as if it were the argument of an option with character code 1.
180
-   Using `-' as the first character of the list of option characters
181
-   selects this mode of operation.
182
-
183
-   The special argument `--' forces an end of option-scanning regardless
184
-   of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
185
-   `--' can cause `getopt' to return -1 with `optind' != ARGC.  */
186
-
187
-static enum
188
-{
189
-  REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
190
-} ordering;
191
-
192
-/* Value of POSIXLY_CORRECT environment variable.  */
193
-static char *posixly_correct;
194
-
195
-#ifdef	__GNU_LIBRARY__
196
-/* We want to avoid inclusion of string.h with non-GNU libraries
197
-   because there are many ways it can cause trouble.
198
-   On some systems, it contains special magic macros that don't work
199
-   in GCC.  */
200
-# include <string.h>
201
-# define my_index	strchr
202
-#else
203
-
204
-# if HAVE_STRING_H
205
-#  include <string.h>
206
-# else
207
-#  include <strings.h>
208
-# endif
209
-
210
-/* Avoid depending on library functions or files
211
-   whose names are inconsistent.  */
212
-
213
-#ifndef getenv
214
-extern char *getenv ();
215
-#endif
216
-
217
-static char *
218
-my_index (str, chr)
219
-     const char *str;
220
-     int chr;
221
-{
222
-  while (*str)
223
-    {
224
-      if (*str == chr)
225
-	return (char *) str;
226
-      str++;
227
-    }
228
-  return 0;
229
-}
230
-
231
-/* If using GCC, we can safely declare strlen this way.
232
-   If not using GCC, it is ok not to declare it.  */
233
-#ifdef __GNUC__
234
-/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
235
-   That was relevant to code that was here before.  */
236
-# if (!defined __STDC__ || !__STDC__) && !defined strlen
237
-/* gcc with -traditional declares the built-in strlen to return int,
238
-   and has done so at least since version 2.4.5. -- rms.  */
239
-extern int strlen (const char *);
240
-# endif /* not __STDC__ */
241
-#endif /* __GNUC__ */
242
-
243
-#endif /* not __GNU_LIBRARY__ */
244
-
245
-/* Handle permutation of arguments.  */
246
-
247
-/* Describe the part of ARGV that contains non-options that have
248
-   been skipped.  `first_nonopt' is the index in ARGV of the first of them;
249
-   `last_nonopt' is the index after the last of them.  */
250
-
251
-static int first_nonopt;
252
-static int last_nonopt;
253
-
254
-#ifdef _LIBC
255
-/* Bash 2.0 gives us an environment variable containing flags
256
-   indicating ARGV elements that should not be considered arguments.  */
257
-
258
-/* Defined in getopt_init.c  */
259
-extern char *__getopt_nonoption_flags;
260
-
261
-static int nonoption_flags_max_len;
262
-static int nonoption_flags_len;
263
-
264
-static int original_argc;
265
-static char *const *original_argv;
266
-
267
-/* Make sure the environment variable bash 2.0 puts in the environment
268
-   is valid for the getopt call we must make sure that the ARGV passed
269
-   to getopt is that one passed to the process.  */
270
-static void
271
-__attribute__ ((unused))
272
-store_args_and_env (int argc, char *const *argv)
273
-{
274
-  /* XXX This is no good solution.  We should rather copy the args so
275
-     that we can compare them later.  But we must not use malloc(3).  */
276
-  original_argc = argc;
277
-  original_argv = argv;
278
-}
279
-# ifdef text_set_element
280
-text_set_element (__libc_subinit, store_args_and_env);
281
-# endif /* text_set_element */
282
-
283
-# define SWAP_FLAGS(ch1, ch2) \
284
-  if (nonoption_flags_len > 0)						      \
285
-    {									      \
286
-      char __tmp = __getopt_nonoption_flags[ch1];			      \
287
-      __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2];	      \
288
-      __getopt_nonoption_flags[ch2] = __tmp;				      \
289
-    }
290
-#else	/* !_LIBC */
291
-# define SWAP_FLAGS(ch1, ch2)
292
-#endif	/* _LIBC */
293
-
294
-/* Exchange two adjacent subsequences of ARGV.
295
-   One subsequence is elements [first_nonopt,last_nonopt)
296
-   which contains all the non-options that have been skipped so far.
297
-   The other is elements [last_nonopt,optind), which contains all
298
-   the options processed since those non-options were skipped.
299
-
300
-   `first_nonopt' and `last_nonopt' are relocated so that they describe
301
-   the new indices of the non-options in ARGV after they are moved.  */
302
-
303
-#if defined __STDC__ && __STDC__
304
-static void exchange (char **);
305
-#endif
306
-
307
-static void
308
-exchange (argv)
309
-     char **argv;
310
-{
311
-  int bottom = first_nonopt;
312
-  int middle = last_nonopt;
313
-  int top = optind;
314
-  char *tem;
315
-
316
-  /* Exchange the shorter segment with the far end of the longer segment.
317
-     That puts the shorter segment into the right place.
318
-     It leaves the longer segment in the right place overall,
319
-     but it consists of two parts that need to be swapped next.  */
320
-
321
-#ifdef _LIBC
322
-  /* First make sure the handling of the `__getopt_nonoption_flags'
323
-     string can work normally.  Our top argument must be in the range
324
-     of the string.  */
325
-  if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
326
-    {
327
-      /* We must extend the array.  The user plays games with us and
328
-	 presents new arguments.  */
329
-      char *new_str = malloc (top + 1);
330
-      if (new_str == NULL)
331
-	nonoption_flags_len = nonoption_flags_max_len = 0;
332
-      else
333
-	{
334
-	  memset (__mempcpy (new_str, __getopt_nonoption_flags,
335
-			     nonoption_flags_max_len),
336
-		  '\0', top + 1 - nonoption_flags_max_len);
337
-	  nonoption_flags_max_len = top + 1;
338
-	  __getopt_nonoption_flags = new_str;
339
-	}
340
-    }
341
-#endif
342
-
343
-  while (top > middle && middle > bottom)
344
-    {
345
-      if (top - middle > middle - bottom)
346
-	{
347
-	  /* Bottom segment is the short one.  */
348
-	  int len = middle - bottom;
349
-	  register int i;
350
-
351
-	  /* Swap it with the top part of the top segment.  */
352
-	  for (i = 0; i < len; i++)
353
-	    {
354
-	      tem = argv[bottom + i];
355
-	      argv[bottom + i] = argv[top - (middle - bottom) + i];
356
-	      argv[top - (middle - bottom) + i] = tem;
357
-	      SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
358
-	    }
359
-	  /* Exclude the moved bottom segment from further swapping.  */
360
-	  top -= len;
361
-	}
362
-      else
363
-	{
364
-	  /* Top segment is the short one.  */
365
-	  int len = top - middle;
366
-	  register int i;
367
-
368
-	  /* Swap it with the bottom part of the bottom segment.  */
369
-	  for (i = 0; i < len; i++)
370
-	    {
371
-	      tem = argv[bottom + i];
372
-	      argv[bottom + i] = argv[middle + i];
373
-	      argv[middle + i] = tem;
374
-	      SWAP_FLAGS (bottom + i, middle + i);
375
-	    }
376
-	  /* Exclude the moved top segment from further swapping.  */
377
-	  bottom += len;
378
-	}
379
-    }
380
-
381
-  /* Update records for the slots the non-options now occupy.  */
382
-
383
-  first_nonopt += (optind - last_nonopt);
384
-  last_nonopt = optind;
385
-}
386
-
387
-/* Initialize the internal data when the first call is made.  */
388
-
389
-#if defined __STDC__ && __STDC__
390
-static const char *_getopt_initialize (int, char *const *, const char *);
391
-#endif
392
-static const char *
393
-_getopt_initialize (argc, argv, optstring)
394
-     int argc;
395
-     char *const *argv;
396
-     const char *optstring;
397
-{
398
-  /* Start processing options with ARGV-element 1 (since ARGV-element 0
399
-     is the program name); the sequence of previously skipped
400
-     non-option ARGV-elements is empty.  */
401
-
402
-  first_nonopt = last_nonopt = optind;
403
-
404
-  nextchar = NULL;
405
-
406
-  posixly_correct = getenv ("POSIXLY_CORRECT");
407
-
408
-  /* Determine how to handle the ordering of options and nonoptions.  */
409
-
410
-  if (optstring[0] == '-')
411
-    {
412
-      ordering = RETURN_IN_ORDER;
413
-      ++optstring;
414
-    }
415
-  else if (optstring[0] == '+')
416
-    {
417
-      ordering = REQUIRE_ORDER;
418
-      ++optstring;
419
-    }
420
-  else if (posixly_correct != NULL)
421
-    ordering = REQUIRE_ORDER;
422
-  else
423
-    ordering = PERMUTE;
424
-
425
-#ifdef _LIBC
426
-  if (posixly_correct == NULL
427
-      && argc == original_argc && argv == original_argv)
428
-    {
429
-      if (nonoption_flags_max_len == 0)
430
-	{
431
-	  if (__getopt_nonoption_flags == NULL
432
-	      || __getopt_nonoption_flags[0] == '\0')
433
-	    nonoption_flags_max_len = -1;
434
-	  else
435
-	    {
436
-	      const char *orig_str = __getopt_nonoption_flags;
437
-	      int len = nonoption_flags_max_len = strlen (orig_str);
438
-	      if (nonoption_flags_max_len < argc)
439
-		nonoption_flags_max_len = argc;
440
-	      __getopt_nonoption_flags =
441
-		(char *) malloc (nonoption_flags_max_len);
442
-	      if (__getopt_nonoption_flags == NULL)
443
-		nonoption_flags_max_len = -1;
444
-	      else
445
-		memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
446
-			'\0', nonoption_flags_max_len - len);
447
-	    }
448
-	}
449
-      nonoption_flags_len = nonoption_flags_max_len;
450
-    }
451
-  else
452
-    nonoption_flags_len = 0;
453
-#endif
454
-
455
-  return optstring;
456
-}
457
-
458
-/* Scan elements of ARGV (whose length is ARGC) for option characters
459
-   given in OPTSTRING.
460
-
461
-   If an element of ARGV starts with '-', and is not exactly "-" or "--",
462
-   then it is an option element.  The characters of this element
463
-   (aside from the initial '-') are option characters.  If `getopt'
464
-   is called repeatedly, it returns successively each of the option characters
465
-   from each of the option elements.
466
-
467
-   If `getopt' finds another option character, it returns that character,
468
-   updating `optind' and `nextchar' so that the next call to `getopt' can
469
-   resume the scan with the following option character or ARGV-element.
470
-
471
-   If there are no more option characters, `getopt' returns -1.
472
-   Then `optind' is the index in ARGV of the first ARGV-element
473
-   that is not an option.  (The ARGV-elements have been permuted
474
-   so that those that are not options now come last.)
475
-
476
-   OPTSTRING is a string containing the legitimate option characters.
477
-   If an option character is seen that is not listed in OPTSTRING,
478
-   return '?' after printing an error message.  If you set `opterr' to
479
-   zero, the error message is suppressed but we still return '?'.
480
-
481
-   If a char in OPTSTRING is followed by a colon, that means it wants an arg,
482
-   so the following text in the same ARGV-element, or the text of the following
483
-   ARGV-element, is returned in `optarg'.  Two colons mean an option that
484
-   wants an optional arg; if there is text in the current ARGV-element,
485
-   it is returned in `optarg', otherwise `optarg' is set to zero.
486
-
487
-   If OPTSTRING starts with `-' or `+', it requests different methods of
488
-   handling the non-option ARGV-elements.
489
-   See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
490
-
491
-   Long-named options begin with `--' instead of `-'.
492
-   Their names may be abbreviated as long as the abbreviation is unique
493
-   or is an exact match for some defined option.  If they have an
494
-   argument, it follows the option name in the same ARGV-element, separated
495
-   from the option name by a `=', or else the in next ARGV-element.
496
-   When `getopt' finds a long-named option, it returns 0 if that option's
497
-   `flag' field is nonzero, the value of the option's `val' field
498
-   if the `flag' field is zero.
499
-
500
-   The elements of ARGV aren't really const, because we permute them.
501
-   But we pretend they're const in the prototype to be compatible
502
-   with other systems.
503
-
504
-   LONGOPTS is a vector of `struct option' terminated by an
505
-   element containing a name which is zero.
506
-
507
-   LONGIND returns the index in LONGOPT of the long-named option found.
508
-   It is only valid when a long-named option has been found by the most
509
-   recent call.
510
-
511
-   If LONG_ONLY is nonzero, '-' as well as '--' can introduce
512
-   long-named options.  */
513
-
514
-int
515
-_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
516
-     int argc;
517
-     char *const *argv;
518
-     const char *optstring;
519
-     const struct option *longopts;
520
-     int *longind;
521
-     int long_only;
522
-{
523
-  int print_errors = opterr;
524
-  if (optstring[0] == ':')
525
-    print_errors = 0;
526
-
527
-  if (argc < 1)
528
-    return -1;
529
-
530
-  optarg = NULL;
531
-
532
-  if (optind == 0 || !__getopt_initialized)
533
-    {
534
-      if (optind == 0)
535
-	optind = 1;	/* Don't scan ARGV[0], the program name.  */
536
-      optstring = _getopt_initialize (argc, argv, optstring);
537
-      __getopt_initialized = 1;
538
-    }
539
-
540
-  /* Test whether ARGV[optind] points to a non-option argument.
541
-     Either it does not have option syntax, or there is an environment flag
542
-     from the shell indicating it is not an option.  The later information
543
-     is only used when the used in the GNU libc.  */
544
-#ifdef _LIBC
545
-# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0'	      \
546
-		      || (optind < nonoption_flags_len			      \
547
-			  && __getopt_nonoption_flags[optind] == '1'))
548
-#else
549
-# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
550
-#endif
551
-
552
-  if (nextchar == NULL || *nextchar == '\0')
553
-    {
554
-      /* Advance to the next ARGV-element.  */
555
-
556
-      /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
557
-	 moved back by the user (who may also have changed the arguments).  */
558
-      if (last_nonopt > optind)
559
-	last_nonopt = optind;
560
-      if (first_nonopt > optind)
561
-	first_nonopt = optind;
562
-
563
-      if (ordering == PERMUTE)
564
-	{
565
-	  /* If we have just processed some options following some non-options,
566
-	     exchange them so that the options come first.  */
567
-
568
-	  if (first_nonopt != last_nonopt && last_nonopt != optind)
569
-	    exchange ((char **) argv);
570
-	  else if (last_nonopt != optind)
571
-	    first_nonopt = optind;
572
-
573
-	  /* Skip any additional non-options
574
-	     and extend the range of non-options previously skipped.  */
575
-
576
-	  while (optind < argc && NONOPTION_P)
577
-	    optind++;
578
-	  last_nonopt = optind;
579
-	}
580
-
581
-      /* The special ARGV-element `--' means premature end of options.
582
-	 Skip it like a null option,
583
-	 then exchange with previous non-options as if it were an option,
584
-	 then skip everything else like a non-option.  */
585
-
586
-      if (optind != argc && !strcmp (argv[optind], "--"))
587
-	{
588
-	  optind++;
589
-
590
-	  if (first_nonopt != last_nonopt && last_nonopt != optind)
591
-	    exchange ((char **) argv);
592
-	  else if (first_nonopt == last_nonopt)
593
-	    first_nonopt = optind;
594
-	  last_nonopt = argc;
595
-
596
-	  optind = argc;
597
-	}
598
-
599
-      /* If we have done all the ARGV-elements, stop the scan
600
-	 and back over any non-options that we skipped and permuted.  */
601
-
602
-      if (optind == argc)
603
-	{
604
-	  /* Set the next-arg-index to point at the non-options
605
-	     that we previously skipped, so the caller will digest them.  */
606
-	  if (first_nonopt != last_nonopt)
607
-	    optind = first_nonopt;
608
-	  return -1;
609
-	}
610
-
611
-      /* If we have come to a non-option and did not permute it,
612
-	 either stop the scan or describe it to the caller and pass it by.  */
613
-
614
-      if (NONOPTION_P)
615
-	{
616
-	  if (ordering == REQUIRE_ORDER)
617
-	    return -1;
618
-	  optarg = argv[optind++];
619
-	  return 1;
620
-	}
621
-
622
-      /* We have found another option-ARGV-element.
623
-	 Skip the initial punctuation.  */
624
-
625
-      nextchar = (argv[optind] + 1
626
-		  + (longopts != NULL && argv[optind][1] == '-'));
627
-    }
628
-
629
-  /* Decode the current option-ARGV-element.  */
630
-
631
-  /* Check whether the ARGV-element is a long option.
632
-
633
-     If long_only and the ARGV-element has the form "-f", where f is
634
-     a valid short option, don't consider it an abbreviated form of
635
-     a long option that starts with f.  Otherwise there would be no
636
-     way to give the -f short option.
637
-
638
-     On the other hand, if there's a long option "fubar" and
639
-     the ARGV-element is "-fu", do consider that an abbreviation of
640
-     the long option, just like "--fu", and not "-f" with arg "u".
641
-
642
-     This distinction seems to be the most useful approach.  */
643
-
644
-  if (longopts != NULL
645
-      && (argv[optind][1] == '-'
646
-	  || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
647
-    {
648
-      char *nameend;
649
-      const struct option *p;
650
-      const struct option *pfound = NULL;
651
-      int exact = 0;
652
-      int ambig = 0;
653
-      int indfound = -1;
654
-      int option_index;
655
-
656
-      for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
657
-	/* Do nothing.  */ ;
658
-
659
-      /* Test all long options for either exact match
660
-	 or abbreviated matches.  */
661
-      for (p = longopts, option_index = 0; p->name; p++, option_index++)
662
-	if (!strncmp (p->name, nextchar, nameend - nextchar))
663
-	  {
664
-	    if ((unsigned int) (nameend - nextchar)
665
-		== (unsigned int) strlen (p->name))
666
-	      {
667
-		/* Exact match found.  */
668
-		pfound = p;
669
-		indfound = option_index;
670
-		exact = 1;
671
-		break;
672
-	      }
673
-	    else if (pfound == NULL)
674
-	      {
675
-		/* First nonexact match found.  */
676
-		pfound = p;
677
-		indfound = option_index;
678
-	      }
679
-	    else if (long_only
680
-		     || pfound->has_arg != p->has_arg
681
-		     || pfound->flag != p->flag
682
-		     || pfound->val != p->val)
683
-	      /* Second or later nonexact match found.  */
684
-	      ambig = 1;
685
-	  }
686
-
687
-      if (ambig && !exact)
688
-	{
689
-	  if (print_errors)
690
-	    fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
691
-		     argv[0], argv[optind]);
692
-	  nextchar += strlen (nextchar);
693
-	  optind++;
694
-	  optopt = 0;
695
-	  return '?';
696
-	}
697
-
698
-      if (pfound != NULL)
699
-	{
700
-	  option_index = indfound;
701
-	  optind++;
702
-	  if (*nameend)
703
-	    {
704
-	      /* Don't test has_arg with >, because some C compilers don't
705
-		 allow it to be used on enums.  */
706
-	      if (pfound->has_arg)
707
-		optarg = nameend + 1;
708
-	      else
709
-		{
710
-		  if (print_errors)
711
-		    {
712
-		      if (argv[optind - 1][1] == '-')
713
-			/* --option */
714
-			fprintf (stderr,
715
-				 _("%s: option `--%s' doesn't allow an argument\n"),
716
-				 argv[0], pfound->name);
717
-		      else
718
-			/* +option or -option */
719
-			fprintf (stderr,
720
-				 _("%s: option `%c%s' doesn't allow an argument\n"),
721
-				 argv[0], argv[optind - 1][0], pfound->name);
722
-		    }
723
-
724
-		  nextchar += strlen (nextchar);
725
-
726
-		  optopt = pfound->val;
727
-		  return '?';
728
-		}
729
-	    }
730
-	  else if (pfound->has_arg == 1)
731
-	    {
732
-	      if (optind < argc)
733
-		optarg = argv[optind++];
734
-	      else
735
-		{
736
-		  if (print_errors)
737
-		    fprintf (stderr,
738
-			   _("%s: option `%s' requires an argument\n"),
739
-			   argv[0], argv[optind - 1]);
740
-		  nextchar += strlen (nextchar);
741
-		  optopt = pfound->val;
742
-		  return optstring[0] == ':' ? ':' : '?';
743
-		}
744
-	    }
745
-	  nextchar += strlen (nextchar);
746
-	  if (longind != NULL)
747
-	    *longind = option_index;
748
-	  if (pfound->flag)
749
-	    {
750
-	      *(pfound->flag) = pfound->val;
751
-	      return 0;
752
-	    }
753
-	  return pfound->val;
754
-	}
755
-
756
-      /* Can't find it as a long option.  If this is not getopt_long_only,
757
-	 or the option starts with '--' or is not a valid short
758
-	 option, then it's an error.
759
-	 Otherwise interpret it as a short option.  */
760
-      if (!long_only || argv[optind][1] == '-'
761
-	  || my_index (optstring, *nextchar) == NULL)
762
-	{
763
-	  if (print_errors)
764
-	    {
765
-	      if (argv[optind][1] == '-')
766
-		/* --option */
767
-		fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
768
-			 argv[0], nextchar);
769
-	      else
770
-		/* +option or -option */
771
-		fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
772
-			 argv[0], argv[optind][0], nextchar);
773
-	    }
774
-	  nextchar = (char *) "";
775
-	  optind++;
776
-	  optopt = 0;
777
-	  return '?';
778
-	}
779
-    }
780
-
781
-  /* Look at and handle the next short option-character.  */
782
-
783
-  {
784
-    char c = *nextchar++;
785
-    char *temp = my_index (optstring, c);
786
-
787
-    /* Increment `optind' when we start to process its last character.  */
788
-    if (*nextchar == '\0')
789
-      ++optind;
790
-
791
-    if (temp == NULL || c == ':')
792
-      {
793
-	if (print_errors)
794
-	  {
795
-	    if (posixly_correct)
796
-	      /* 1003.2 specifies the format of this message.  */
797
-	      fprintf (stderr, _("%s: illegal option -- %c\n"),
798
-		       argv[0], c);
799
-	    else
800
-	      fprintf (stderr, _("%s: invalid option -- %c\n"),
801
-		       argv[0], c);
802
-	  }
803
-	optopt = c;
804
-	return '?';
805
-      }
806
-    /* Convenience. Treat POSIX -W foo same as long option --foo */
807
-    if (temp[0] == 'W' && temp[1] == ';')
808
-      {
809
-	char *nameend;
810
-	const struct option *p;
811
-	const struct option *pfound = NULL;
812
-	int exact = 0;
813
-	int ambig = 0;
814
-	int indfound = 0;
815
-	int option_index;
816
-
817
-	/* This is an option that requires an argument.  */
818
-	if (*nextchar != '\0')
819
-	  {
820
-	    optarg = nextchar;
821
-	    /* If we end this ARGV-element by taking the rest as an arg,
822
-	       we must advance to the next element now.  */
823
-	    optind++;
824
-	  }
825
-	else if (optind == argc)
826
-	  {
827
-	    if (print_errors)
828
-	      {
829
-		/* 1003.2 specifies the format of this message.  */
830
-		fprintf (stderr, _("%s: option requires an argument -- %c\n"),
831
-			 argv[0], c);
832
-	      }
833
-	    optopt = c;
834
-	    if (optstring[0] == ':')
835
-	      c = ':';
836
-	    else
837
-	      c = '?';
838
-	    return c;
839
-	  }
840
-	else
841
-	  /* We already incremented `optind' once;
842
-	     increment it again when taking next ARGV-elt as argument.  */
843
-	  optarg = argv[optind++];
844
-
845
-	/* optarg is now the argument, see if it's in the
846
-	   table of longopts.  */
847
-
848
-	for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
849
-	  /* Do nothing.  */ ;
850
-
851
-	/* Test all long options for either exact match
852
-	   or abbreviated matches.  */
853
-	for (p = longopts, option_index = 0; p->name; p++, option_index++)
854
-	  if (!strncmp (p->name, nextchar, nameend - nextchar))
855
-	    {
856
-	      if ((unsigned int) (nameend - nextchar) == strlen (p->name))
857
-		{
858
-		  /* Exact match found.  */
859
-		  pfound = p;
860
-		  indfound = option_index;
861
-		  exact = 1;
862
-		  break;
863
-		}
864
-	      else if (pfound == NULL)
865
-		{
866
-		  /* First nonexact match found.  */
867
-		  pfound = p;
868
-		  indfound = option_index;
869
-		}
870
-	      else
871
-		/* Second or later nonexact match found.  */
872
-		ambig = 1;
873
-	    }
874
-	if (ambig && !exact)
875
-	  {
876
-	    if (print_errors)
877
-	      fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
878
-		       argv[0], argv[optind]);
879
-	    nextchar += strlen (nextchar);
880
-	    optind++;
881
-	    return '?';
882
-	  }
883
-	if (pfound != NULL)
884
-	  {
885
-	    option_index = indfound;
886
-	    if (*nameend)
887
-	      {
888
-		/* Don't test has_arg with >, because some C compilers don't
889
-		   allow it to be used on enums.  */
890
-		if (pfound->has_arg)
891
-		  optarg = nameend + 1;
892
-		else
893
-		  {
894
-		    if (print_errors)
895
-		      fprintf (stderr, _("\
896
-%s: option `-W %s' doesn't allow an argument\n"),
897
-			       argv[0], pfound->name);
898
-
899
-		    nextchar += strlen (nextchar);
900
-		    return '?';
901
-		  }
902
-	      }
903
-	    else if (pfound->has_arg == 1)
904
-	      {
905
-		if (optind < argc)
906
-		  optarg = argv[optind++];
907
-		else
908
-		  {
909
-		    if (print_errors)
910
-		      fprintf (stderr,
911
-			       _("%s: option `%s' requires an argument\n"),
912
-			       argv[0], argv[optind - 1]);
913
-		    nextchar += strlen (nextchar);
914
-		    return optstring[0] == ':' ? ':' : '?';
915
-		  }
916
-	      }
917
-	    nextchar += strlen (nextchar);
918
-	    if (longind != NULL)
919
-	      *longind = option_index;
920
-	    if (pfound->flag)
921
-	      {
922
-		*(pfound->flag) = pfound->val;
923
-		return 0;
924
-	      }
925
-	    return pfound->val;
926
-	  }
927
-	  nextchar = NULL;
928
-	  return 'W';	/* Let the application handle it.   */
929
-      }
930
-    if (temp[1] == ':')
931
-      {
932
-	if (temp[2] == ':')
933
-	  {
934
-	    /* This is an option that accepts an argument optionally.  */
935
-	    if (*nextchar != '\0')
936
-	      {
937
-		optarg = nextchar;
938
-		optind++;
939
-	      }
940
-	    else
941
-	      optarg = NULL;
942
-	    nextchar = NULL;
943
-	  }
944
-	else
945
-	  {
946
-	    /* This is an option that requires an argument.  */
947
-	    if (*nextchar != '\0')
948
-	      {
949
-		optarg = nextchar;
950
-		/* If we end this ARGV-element by taking the rest as an arg,
951
-		   we must advance to the next element now.  */
952
-		optind++;
953
-	      }
954
-	    else if (optind == argc)
955
-	      {
956
-		if (print_errors)
957
-		  {
958
-		    /* 1003.2 specifies the format of this message.  */
959
-		    fprintf (stderr,
960
-			     _("%s: option requires an argument -- %c\n"),
961
-			     argv[0], c);
962
-		  }
963
-		optopt = c;
964
-		if (optstring[0] == ':')
965
-		  c = ':';
966
-		else
967
-		  c = '?';
968
-	      }
969
-	    else
970
-	      /* We already incremented `optind' once;
971
-		 increment it again when taking next ARGV-elt as argument.  */
972
-	      optarg = argv[optind++];
973
-	    nextchar = NULL;
974
-	  }
975
-      }
976
-    return c;
977
-  }
978
-}
979
-
980
-int
981
-getopt (argc, argv, optstring)
982
-     int argc;
983
-     char *const *argv;
984
-     const char *optstring;
985
-{
986
-  return _getopt_internal (argc, argv, optstring,
987
-			   (const struct option *) 0,
988
-			   (int *) 0,
989
-			   0);
990
-}
991
-
992
-
993
-int
994
-getopt_long (argc, argv, options, long_options, opt_index)
995
-     int argc;
996
-     char *const *argv;
997
-     const char *options;
998
-     const struct option *long_options;
999
-     int *opt_index;
1000
-{
1001
-  return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
1002
-}
1003
-
1004
-/* Like getopt_long, but '-' as well as '--' can indicate a long option.
1005
-   If an option that starts with '-' (not '--') doesn't match a long option,
1006
-   but does match a short option, it is parsed as a short option
1007
-   instead.  */
1008
-
1009
-int
1010
-getopt_long_only (argc, argv, options, long_options, opt_index)
1011
-     int argc;
1012
-     char *const *argv;
1013
-     const char *options;
1014
-     const struct option *long_options;
1015
-     int *opt_index;
1016
-{
1017
-  return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
1018
-}
1019
-
1020
-#endif	/* Not ELIDE_CODE.  */
1021 1
deleted file mode 100644
... ...
@@ -1,180 +0,0 @@
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
38
-extern "C" {
39
-#endif
40
-
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.  */
65
-
66
-extern int opterr;
67
-
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.  */
93
-
94
-struct option
95
-{
96
-# if defined __STDC__ && __STDC__
97
-  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
-  int has_arg;
104
-  int *flag;
105
-  int val;
106
-};
107
-
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
-
115
-
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.
119
-
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.
124
-
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'.
128
-
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
174
-}
175
-#endif
176
-
177
-/* Make sure we later can get all the definitions and declarations.  */
178
-#undef __need_getopt
179
-
180
-#endif /* getopt.h */
... ...
@@ -47,6 +47,8 @@
47 47
 #include "mbox.h"
48 48
 #include "str.h"
49 49
 #include "strrcpy.h"
50
+#include "memory.h"
51
+#include "output.h"
50 52
 
51 53
 #ifdef C_LINUX
52 54
 dev_t procdev;
... ...
@@ -374,7 +376,7 @@ int scanfile(const char *filename, struct cl_node *root, const struct passwd *us
374 374
      * external (if provided) when internal cannot extract data.
375 375
      */
376 376
 
377
-    if((strbcasestr(filename, ".zip") || strbcasestr(filename, ".rar")) && (options & CL_ARCHIVE)) {
377
+    if((cli_strbcasestr(filename, ".zip") || cli_strbcasestr(filename, ".rar")) && (options & CL_ARCHIVE)) {
378 378
 	/* try to use internal archivers */
379 379
 	if((ret = checkfile(filename, root, limits, options)) == CL_VIRUS) {
380 380
 	    if(optl(opt, "remove")) {
... ...
@@ -398,16 +400,16 @@ int scanfile(const char *filename, struct cl_node *root, const struct passwd *us
398 398
 	claminfo.files--; /* don't count it */
399 399
     }
400 400
 
401
-    if((strbcasestr(filename, ".zip") && optl(opt, "unzip"))
402
-    || (strbcasestr(filename, ".rar") && optl(opt, "unrar"))
403
-    || (strbcasestr(filename, ".ace") && optl(opt, "unace"))
404
-    || (strbcasestr(filename, ".arj") && optl(opt, "arj"))
405
-    || (strbcasestr(filename, ".zoo") && optl(opt, "unzoo"))
406
-    || (strbcasestr(filename, ".jar") && optl(opt, "jar"))
407
-    || (strbcasestr(filename, ".lzh") && optl(opt, "lha"))
408
-    || (strbcasestr(filename, ".tar") && optl(opt, "tar"))
409
-    || (strbcasestr(filename, ".deb") && optl(opt, "deb"))
410
-    || ((strbcasestr(filename, ".tar.gz") || strbcasestr(filename, ".tgz")) 
401
+    if((cli_strbcasestr(filename, ".zip") && optl(opt, "unzip"))
402
+    || (cli_strbcasestr(filename, ".rar") && optl(opt, "unrar"))
403
+    || (cli_strbcasestr(filename, ".ace") && optl(opt, "unace"))
404
+    || (cli_strbcasestr(filename, ".arj") && optl(opt, "arj"))
405
+    || (cli_strbcasestr(filename, ".zoo") && optl(opt, "unzoo"))
406
+    || (cli_strbcasestr(filename, ".jar") && optl(opt, "jar"))
407
+    || (cli_strbcasestr(filename, ".lzh") && optl(opt, "lha"))
408
+    || (cli_strbcasestr(filename, ".tar") && optl(opt, "tar"))
409
+    || (cli_strbcasestr(filename, ".deb") && optl(opt, "deb"))
410
+    || ((cli_strbcasestr(filename, ".tar.gz") || cli_strbcasestr(filename, ".tgz")) 
411 411
 	 && (optl(opt, "tgz") || optl(opt, "deb"))) ) {
412 412
 
413 413
 	/* check permissions */
... ...
@@ -511,7 +513,7 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass
511 511
 
512 512
 
513 513
     /* unpack file  - as unprivileged user */
514
-    if(strbcasestr(filename, ".zip")) {
514
+    if(cli_strbcasestr(filename, ".zip")) {
515 515
 	char *args[] = { "unzip", "-P", "clam", "-o", (char *) filename, NULL };
516 516
 
517 517
 	if((userprg = getargl(opt, "unzip")))
... ...
@@ -519,63 +521,63 @@ int scancompressed(const char *filename, struct cl_node *root, const struct pass
519 519
 	else
520 520
 	    ret = clamav_unpack("unzip", args, gendir, user, opt);
521 521
 
522
-    } else if(strbcasestr(filename, ".rar")) { 
522
+    } else if(cli_strbcasestr(filename, ".rar")) { 
523 523
 	char *args[] = { "unrar", "x", "-p-", "-y", (char *) filename, NULL };
524 524
 	if((userprg = getargl(opt, "unrar")))
525 525
 	    ret = clamav_unpack(userprg, args, gendir, user, opt);
526 526
 	else
527 527
 	    ret = clamav_unpack("unrar", args, gendir, user, opt);
528 528
 
529
-    } else if(strbcasestr(filename, ".ace")) { 
529
+    } else if(cli_strbcasestr(filename, ".ace")) { 
530 530
 	char *args[] = { "unace", "x", "-y", (char *) filename, NULL };
531 531
 	if((userprg = getargl(opt, "unace")))
532 532
 	    ret = clamav_unpack(userprg, args, gendir, user, opt);
533 533
 	else
534 534
 	    ret = clamav_unpack("unace", args, gendir, user, opt);
535 535
 
536
-    } else if(strbcasestr(filename, ".arj")) { 
536
+    } else if(cli_strbcasestr(filename, ".arj")) { 
537 537
         char *args[] = { "arj", "x","-y", (char *) filename, NULL };
538 538
         if((userprg = getargl(opt, "arj")))
539 539
 	    ret = clamav_unpack(userprg, args, gendir, user, opt);
540 540
 	else
541 541
 	    ret = clamav_unpack("arj", args, gendir, user, opt);
542 542
 
543
-    } else if(strbcasestr(filename, ".zoo")) { 
543
+    } else if(cli_strbcasestr(filename, ".zoo")) { 
544 544
 	char *args[] = { "unzoo", "-x","-j","./", (char *) filename, NULL };
545 545
 	if((userprg = getargl(opt, "unzoo")))
546 546
 	    ret = clamav_unpack(userprg, args, gendir, user, opt);
547 547
 	else
548 548
 	    ret = clamav_unpack("unzoo", args, gendir, user, opt);
549 549
 
550
-    } else if(strbcasestr(filename, ".jar")) { 
550
+    } else if(cli_strbcasestr(filename, ".jar")) { 
551 551
 	char *args[] = { "unzip", "-P", "clam", "-o", (char *) filename, NULL };
552 552
 	if((userprg = getargl(opt, "jar")))
553 553
 	    ret = clamav_unpack(userprg, args, gendir, user, opt);
554 554
 	else
555 555
 	    ret = clamav_unpack("unzip", args, gendir, user, opt);
556 556
 
557
-    } else if(strbcasestr(filename, ".lzh")) { 
557
+    } else if(cli_strbcasestr(filename, ".lzh")) { 
558 558
 	char *args[] = { "lha", "xf", (char *) filename, NULL };
559 559
 	if((userprg = getargl(opt, "lha")))
560 560
 	    ret = clamav_unpack(userprg, args, gendir, user, opt);
561 561
 	else
562 562
 	    ret = clamav_unpack("lha", args, gendir, user, opt);
563 563
 
564
-    } else if(strbcasestr(filename, ".tar")) { 
564
+    } else if(cli_strbcasestr(filename, ".tar")) { 
565 565
 	char *args[] = { "tar", "-xpvf", (char *) filename, NULL };
566 566
 	if((userprg = getargl(opt, "tar")))
567 567
 	    ret = clamav_unpack(userprg, args, gendir, user, opt);
568 568
 	else
569 569
 	    ret = clamav_unpack("tar", args, gendir, user, opt);
570 570
 
571
-    } else if(strbcasestr(filename, ".deb")) { 
571
+    } else if(cli_strbcasestr(filename, ".deb")) { 
572 572
 	char *args[] = { "ar", "x", (char *) filename, NULL };
573 573
 	if((userprg = getargl(opt, "deb")))
574 574
 	    ret = clamav_unpack(userprg, args, gendir, user, opt);
575 575
 	else
576 576
 	    ret = clamav_unpack("ar", args, gendir, user, opt);
577 577
 
578
-    } else if((strbcasestr(filename, ".tar.gz") || strbcasestr(filename, ".tgz"))) {
578
+    } else if((cli_strbcasestr(filename, ".tar.gz") || cli_strbcasestr(filename, ".tgz"))) {
579 579
 	char *args[] = { "tar", "-zxpvf", (char *) filename, NULL };
580 580
 	if((userprg = getargl(opt, "tgz")))
581 581
 	    ret = clamav_unpack(userprg, args, gendir, user, opt);
... ...
@@ -32,8 +32,9 @@
32 32
 
33 33
 
34 34
 #include "options.h"
35
-#include "others.h"
36 35
 #include "shared.h"
36
+#include "memory.h"
37
+#include "output.h"
37 38
 
38 39
 extern int clamscan(struct optstruct *opt);
39 40
 
... ...
@@ -25,12 +25,12 @@
25 25
 #endif
26 26
 
27 27
 #include <stdio.h>
28
-#include <stdarg.h>
29
-#include <string.h>
30 28
 #include <stdlib.h>
29
+#include <string.h>
31 30
 #include <ctype.h>
32 31
 #include <unistd.h>
33 32
 #include <errno.h>
33
+#include <pwd.h>
34 34
 #include <sys/types.h>
35 35
 #include <sys/stat.h>
36 36
 #include <sys/wait.h>
... ...
@@ -38,184 +38,9 @@
38 38
 #include <time.h>
39 39
 #include <fcntl.h>
40 40
 #include <signal.h>
41
-#include <pwd.h>
42
-#include <errno.h>
43 41
 #include <target.h>
44
-#include <clamav.h>
45
-
46
-#include "shared.h"
47
-#include "others.h"
48
-#include "defaults.h"
49
-#include "treewalk.h"
50
-
51
-
52
-void mprintf(const char *str, ...)
53
-{
54
-	va_list args;
55
-	FILE *fd;
56
-	char logbuf[512];
57
-
58
-
59
-    if(mprintf_disabled) {
60
-	if(*str == '@') {
61
-	    va_start(args, str);
62
-#ifdef NO_SNPRINTF
63
-	    vsprintf(logbuf, ++str, args);
64
-#else
65
-	    vsnprintf(logbuf, sizeof(logbuf), ++str, args);
66
-#endif
67
-	    va_end(args);
68
-	    logg("ERROR: %s", logbuf);
69
-	}
70
-	return;
71
-    }
72
-
73
-    if(mprintf_stdout)
74
-	fd = stdout;
75
-    else
76
-	fd = stderr;
77
-
78
-/* legend:
79
- * ! - error
80
- * @ - error with logging
81
- * ...
82
- */
83
-
84
-/*
85
- *             ERROR    WARNING    STANDARD
86
- * normal       yes       yes        yes
87
- * 
88
- * verbose      yes       yes        yes
89
- * 
90
- * quiet        yes       no         no
91
- */
92
-
93
-
94
-    va_start(args, str);
95
-
96
-    if(*str == '!') {
97
-	fprintf(fd, "ERROR: ");
98
-	vfprintf(fd, ++str, args);
99
-    } else if(*str == '@') {
100
-	fprintf(fd, "ERROR: ");
101
-	vfprintf(fd, ++str, args);
102
-#ifdef NO_SNPRINTF
103
-	vsprintf(logbuf, str, args);
104
-#else
105
-	vsnprintf(logbuf, sizeof(logbuf), str, args);
106
-#endif
107
-	logg("ERROR: %s", logbuf);
108
-    } else if(!mprintf_quiet) {
109
-	if(*str == '^') {
110
-	    fprintf(fd, "WARNING: ");
111
-	    vfprintf(fd, ++str, args);
112
-	} else if(*str == '*') {
113
-	    if(mprintf_verbose)
114
-		vfprintf(fd, ++str, args);
115
-	} else vfprintf(fd, str, args);
116
-    }
117
-
118
-    va_end(args);
119
-
120
-    if(fd == stdout)
121
-	fflush(stdout);
122
-
123
-}
124
-
125
-int logg(const char *str, ...)
126
-{
127
-	va_list args;
128
-	static FILE *fd = NULL;
129
-	mode_t old_umask;
130
-
131
-
132
-    if(logfile) {
133
-
134
-	if (str == NULL && fd != NULL) {
135
-	    /* re-open logfile */
136
-	    fclose(fd);
137
-	    fd = NULL;
138
-	}
139
-	if(!fd) {
140
-            old_umask = umask(0037);
141
-	    if((fd = fopen(logfile, "a")) == NULL) {
142
-                umask(old_umask);
143
-		mprintf("!LOGGER: Can't open %s for writing: %s.\n", logfile, strerror(errno));
144
-		return 1;
145
-	    }
146
-	    umask(old_umask);
147
-	}
148
-	if (str == NULL) {
149
-	    return 0;
150
-	}
151
-
152
-	va_start(args, str);
153
-
154
-	if(*str == '!') {
155
-	    fprintf(fd, "ERROR: ");
156
-	    vfprintf(fd, ++str, args);
157
-	} else if(*str == '^') {
158
-	    fprintf(fd, "WARNING: ");
159
-	    vfprintf(fd, ++str, args);
160
-	} else if(*str == '*') {
161
-	    vfprintf(fd, ++str, args);
162
-	} else vfprintf(fd, str, args);
163
-
164
-	va_end(args);
165
-
166
-	fflush(fd);
167
-    }
168
-
169
-    return 0;
170
-}
171
-
172
-void *mmalloc(size_t size)
173
-{
174
-	void *alloc;
175
-
176
-    alloc = malloc(size);
177
-
178
-    if(!alloc) {
179
-	printf("CRITICAL: Can't allocate memory (%ld bytes).\n", (long int) size);
180
-	exit(71);
181
-	return NULL;
182
-    } else return alloc;
183
-}
184
-
185
-void *mcalloc(size_t nmemb, size_t size)
186
-{
187
-	void *alloc;
188 42
 
189
-    alloc = calloc(nmemb, size);
190
-
191
-    if(!alloc) {
192
-	printf("CRITICAL: Can't allocate memory (%ld bytes).\n", (long int) nmemb * size);
193
-	exit(70);
194
-	return NULL;
195
-    } else return alloc;
196
-}
197
-
198
-int isnumb(const char *str)
199
-{
200
-	int i;
201
-
202
-    for(i = 0; i < strlen(str); i++)
203
-	if(!isdigit(str[i]))
204
-	    return 0;
205
-
206
-    return 1;
207
-}
208
-
209
-void chomp(char *string)
210
-{
211
-	char *pt;
212
-
213
-    if((pt = strchr(string, 13)))
214
-	*pt = 0;
215
-
216
-    if((pt = strchr(string, 10)))
217
-	*pt = 0;
218
-}
43
+#include "output.h"
219 44
 
220 45
 int fileinfo(const char *filename, short i)
221 46
 {
... ...
@@ -242,87 +67,6 @@ int fileinfo(const char *filename, short i)
242 242
     }
243 243
 }
244 244
 
245
-/* these functions return pseudo random number from [0, max) */
246
-
247
-/*
248
-#ifdef C_LINUX
249
-int detectcpu(void)
250
-{
251
-  unsigned int i=0,nrThreads=1;
252
-  int retScan;
253
-  char line[1000];
254
-  char* ret;
255
-  FILE* fs;
256
-
257
-  if(strcmp(TARGET_OS_TYPE,"linux-gnu") != 0)
258
-    return 1;
259
-  if((fs = fopen("/proc/cpuinfo","r")) == NULL)
260
-    return 1;
261
-  do
262
-    {
263
-      ret = fgets(line,1000,fs);
264
-      if(strcmp(TARGET_ARCH_TYPE,"i386") == 0 || 
265
-	 strcmp(TARGET_ARCH_TYPE,"parisc") == 0)
266
-	{
267
-	  retScan = sscanf(line,"processor\t: %d",&i);
268
-	  if(retScan != EOF && retScan != 0 && i>=nrThreads )
269
-	    nrThreads=i+1;
270
-	}
271
-      else if (strcmp(TARGET_ARCH_TYPE,"ppc") == 0 || 
272
-	       strcmp(TARGET_ARCH_TYPE,"ppc64") == 0)
273
-	{
274
-	  retScan = sscanf(line,"processor\t: %d",&i);
275
-	  if(retScan != EOF && retScan != 0 && i>=nrThreads )
276
-	    nrThreads=i+1;	  
277
-	}
278
-      else if (strcmp(TARGET_ARCH_TYPE,"ia64") == 0)
279
-	{
280
-	  retScan = sscanf(line,"processor  : %d",&i);
281
-	  if(retScan != EOF && retScan != 0 && i>=nrThreads )
282
-	    nrThreads=i+1;	  
283
-	}
284
-      else if (strcmp(TARGET_ARCH_TYPE,"alpha") == 0)
285
-	{
286
-	  retScan = sscanf(line,"cpus detected\t: %d",&i);
287
-	  if (retScan != 0 && retScan != EOF)
288
-	    return i;
289
-	}
290
-      else if (strcmp(TARGET_ARCH_TYPE,"s390") == 0)
291
-	{
292
-	  retScan = sscanf(line,"# processors    : %d",&i);
293
-	  if (retScan != 0 && retScan != EOF)
294
-	    return i;
295
-	}
296
-      else if (strcmp(TARGET_ARCH_TYPE,"sparc") == 0 || 
297
-	       strcmp(TARGET_ARCH_TYPE,"sparc64") == 0)
298
-	{
299
-	  retScan = sscanf(line,"ncpus active\t: %d",&i);
300
-	  if (retScan != 0 && retScan != EOF)
301
-	    return i;
302
-	}
303
-      else if (strcmp(TARGET_ARCH_TYPE,"arm") == 0 || 
304
-	       strcmp(TARGET_ARCH_TYPE,"m68k") == 0 || 
305
-	       strcmp(TARGET_ARCH_TYPE,"mips") == 0 ||
306
-	       strcmp(TARGET_ARCH_TYPE,"mips64") == 0 )
307
-	{
308
-	  return 1; 
309
-
310
-	}
311
-    }
312
-  while(ret != NULL);
313
-
314
-  fclose(fs);
315
-  return nrThreads;
316
-
317
-}
318
-#else
319
-int detectcpu(void)
320
-{
321
-    return 1;
322
-}
323
-#endif
324
-*/
325
-
326 245
 int readaccess(const char *path, const char *username)
327 246
 {
328 247
 	struct passwd *user;
... ...
@@ -407,18 +151,13 @@ int filecopy(const char *src, const char *dest)
407 407
     return close(d);
408 408
 }
409 409
 
410
-int strbcasestr(const char *haystack, const char *needle)
410
+int isnumb(const char *str)
411 411
 {
412
-	char *pt = (char *) haystack;
413
-	int i, j;
414
-
415
-    i = strlen(haystack);
416
-    j = strlen(needle);
417
-
418
-    if(i < j)
419
-	return 0;
412
+	int i;
420 413
 
421
-    pt += i - j;
414
+    for(i = 0; i < strlen(str); i++)
415
+	if(!isdigit(str[i]))
416
+	    return 0;
422 417
 
423
-    return !strcasecmp(pt, needle);
418
+    return 1;
424 419
 }
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 1999-2003 Tomasz Kojm <zolw@konarski.edu.pl>
2
+ *  Copyright (C) 1999 - 2004 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -19,22 +19,12 @@
19 19
 #ifndef __OTHERS_H
20 20
 #define __OTHERS_H
21 21
 
22
-#include "pwd.h"
23
-#include "options.h"
24
-
25
-void mprintf(const char *str, ...);
26
-int logg(const char *str, ...);
27
-void texit(int no);
28
-int isnumb(const char *str);
29
-void *mmalloc(size_t nmemb);
30
-void *mcalloc(size_t nmemb, size_t size);
31
-void chomp(char *string);
32
-int detectcpu(void);
33 22
 int fileinfo(const char *filename, short i);
34
-int strbcasestr(const char *haystack, const char *needle);
35 23
 int readaccess(const char *path, const char *username);
36 24
 int writeaccess(const char *path, const char *username);
37 25
 int filecopy(const char *src, const char *dest);
26
+int isnumb(const char *str);
27
+
38 28
 
39 29
 /* njh@bandsman.co.uk: for BeOS */
40 30
 /* TODO: configure should see if sete[ug]id is set on the target */
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2002, 2003 Tomasz Kojm <zolw@konarski.edu.pl>
2
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -32,7 +32,6 @@ struct s_info {
32 32
     long int blocks; /* number of read 16kb blocks */
33 33
 } claminfo;
34 34
 
35
-short int mprintf_disabled, mprintf_verbose, mprintf_quiet, mprintf_stdout, recursion, printinfected, bell;
36
-const char *logfile;
35
+short recursion, printinfected, bell;
37 36
 
38 37
 #endif
... ...
@@ -37,6 +37,8 @@
37 37
 #include "options.h"
38 38
 #include "treewalk.h"
39 39
 #include "defaults.h"
40
+#include "memory.h"
41
+#include "output.h"
40 42
 
41 43
 /*
42 44
  * recursive functions, similar to ftw(), these functions are duplicated below
... ...
@@ -8230,7 +8230,8 @@ _ACEOF
8230 8230
 
8231 8231
 
8232 8232
 
8233
-for ac_func in poll setsid memcpy snprintf strerror_r
8233
+
8234
+for ac_func in poll setsid memcpy snprintf vsnprintf strerror_r
8234 8235
 do
8235 8236
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
8236 8237
 echo "$as_me:$LINENO: checking for $ac_func" >&5
... ...
@@ -8306,6 +8307,58 @@ fi
8306 8306
 done
8307 8307
 
8308 8308
 
8309
+# Check for broken snprintf
8310
+if test "x$ac_cv_func_snprintf" = "xyes" ; then
8311
+        echo "$as_me:$LINENO: checking whether snprintf correctly terminates long strings" >&5
8312
+echo $ECHO_N "checking whether snprintf correctly terminates long strings... $ECHO_C" >&6
8313
+        if test "$cross_compiling" = yes; then
8314
+  { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling" >&5
8315
+echo "$as_me: error: cannot run test program while cross compiling" >&2;}
8316
+   { (exit 1); exit 1; }; }
8317
+else
8318
+  cat >conftest.$ac_ext <<_ACEOF
8319
+#line $LINENO "configure"
8320
+#include "confdefs.h"
8321
+
8322
+#include <stdio.h>
8323
+int main(void){char b[5];snprintf(b,5,"123456789");return(b[4]!='\0');}
8324
+
8325
+_ACEOF
8326
+rm -f conftest$ac_exeext
8327
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
8328
+  (eval $ac_link) 2>&5
8329
+  ac_status=$?
8330
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
8331
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
8332
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
8333
+  (eval $ac_try) 2>&5
8334
+  ac_status=$?
8335
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
8336
+  (exit $ac_status); }; }; then
8337
+  echo "$as_me:$LINENO: result: yes" >&5
8338
+echo "${ECHO_T}yes" >&6
8339
+else
8340
+  echo "$as_me: program exited with status $ac_status" >&5
8341
+echo "$as_me: failed program was:" >&5
8342
+cat conftest.$ac_ext >&5
8343
+( exit $ac_status )
8344
+
8345
+                        echo "$as_me:$LINENO: result: no" >&5
8346
+echo "${ECHO_T}no" >&6
8347
+
8348
+cat >>confdefs.h <<\_ACEOF
8349
+#define BROKEN_SNPRINTF 1
8350
+_ACEOF
8351
+
8352
+                        { echo "$as_me:$LINENO: WARNING: ****** Your snprintf() function is broken, complain to your vendor" >&5
8353
+echo "$as_me: WARNING: ****** Your snprintf() function is broken, complain to your vendor" >&2;}
8354
+
8355
+
8356
+fi
8357
+rm -f core core.* *.core conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
8358
+fi
8359
+fi
8360
+
8309 8361
 have_pthreads=no
8310 8362
 if test "${ac_cv_header_pthread_h+set}" = set; then
8311 8363
   echo "$as_me:$LINENO: checking for pthread.h" >&5
... ...
@@ -9145,7 +9198,7 @@ fi
9145 9145
 if test $ac_cv_header_syslog_h = yes; then
9146 9146
 
9147 9147
 cat >>confdefs.h <<\_ACEOF
9148
-#define CLAMD_USE_SYSLOG 1
9148
+#define USE_SYSLOG 1
9149 9149
 _ACEOF
9150 9150
 
9151 9151
 fi
... ...
@@ -9775,7 +9828,8 @@ _ACEOF
9775 9775
 _ACEOF
9776 9776
 
9777 9777
     fi
9778
-    cat >>confdefs.h <<\_ACEOF
9778
+
9779
+cat >>confdefs.h <<\_ACEOF
9779 9780
 #define C_BSD 1
9780 9781
 _ACEOF
9781 9782
 
... ...
@@ -57,7 +57,24 @@ AC_TYPE_OFF_T
57 57
 AC_COMPILE_CHECK_SIZEOF(short)
58 58
 AC_COMPILE_CHECK_SIZEOF(int)
59 59
 AC_COMPILE_CHECK_SIZEOF(long)
60
-AC_CHECK_FUNCS(poll setsid memcpy snprintf strerror_r)
60
+AC_CHECK_FUNCS(poll setsid memcpy snprintf vsnprintf strerror_r)
61
+
62
+# Check for broken snprintf
63
+if test "x$ac_cv_func_snprintf" = "xyes" ; then
64
+        AC_MSG_CHECKING([whether snprintf correctly terminates long strings])
65
+        AC_TRY_RUN(
66
+                [
67
+#include <stdio.h>
68
+int main(void){char b[5];snprintf(b,5,"123456789");return(b[4]!='\0');}
69
+                ],
70
+                [AC_MSG_RESULT(yes)],
71
+                [
72
+                        AC_MSG_RESULT(no)
73
+                        AC_DEFINE(BROKEN_SNPRINTF,1,[Define if your snprintf is busted])
74
+                        AC_MSG_WARN([****** Your snprintf() function is broken, complain to your vendor])
75
+                ]
76
+        )
77
+fi
61 78
 
62 79
 have_pthreads=no
63 80
 AC_CHECK_HEADER(pthread.h,[have_pthreads=yes],)
... ...
@@ -99,7 +116,7 @@ then
99 99
     AC_CHECK_LIB(gmp, __gmpz_init, [LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -lgmp"; AC_DEFINE(HAVE_GMP,1,have gmp installed)], [AC_CHECK_LIB(gmp, mpz_init, [LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -lgmp"; AC_DEFINE(HAVE_GMP,1,have gmp installed)], [echo "WARNING: GNU MP 2 or newer NOT FOUND - digital signature support will be disabled !"; want_dsig="no"])])
100 100
 fi
101 101
 
102
-AC_CHECK_HEADER(syslog.h,AC_DEFINE(CLAMD_USE_SYSLOG,1,[use syslog]),)
102
+AC_CHECK_HEADER(syslog.h,AC_DEFINE(USE_SYSLOG,1,[use syslog]),)
103 103
 
104 104
 dnl AC_CHECK_LIB(c, strtok_r,, AC_DEFINE(NO_STRTOK_R))
105 105
 dnl AC_CHECK_LIB(c, mkstemp, AC_DEFINE(HAVE_MKSTEMP),)
... ...
@@ -336,7 +353,7 @@ openbsd3.3*)
336 336
 	AC_DEFINE(CL_THREAD_SAFE)
337 337
 	AC_DEFINE(_REENTRANT)
338 338
     fi
339
-    AC_DEFINE(C_BSD)
339
+    AC_DEFINE(C_BSD,1,[os is bsd flavor])
340 340
     ;;
341 341
 openbsd*)
342 342
     if test "$have_pthreads" = "yes"; then
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  *  Compilation: gcc -Wall ex1.c -o ex1 -lclamav
3 3
  *
4
- *  Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
4
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
5 5
  *
6 6
  *  This program is free software; you can redistribute it and/or modify
7 7
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -20,6 +20,7 @@
20 20
 
21 21
 #include <stdio.h>
22 22
 #include <stdlib.h>
23
+#include <string.h>
23 24
 #include <unistd.h>
24 25
 #include <sys/types.h>
25 26
 #include <sys/stat.h>
... ...
@@ -31,34 +32,36 @@ int main(int argc, char **argv)
31 31
 	int fd, ret, no = 0;
32 32
 	unsigned long int size = 0;
33 33
 	long double mb;
34
-	char *virname;
34
+	const char *virname;
35 35
 	struct cl_node *root = NULL;
36 36
 	struct cl_limits limits;
37 37
 
38
+
38 39
     if(argc != 2) {
39 40
 	printf("Usage: %s file\n", argv[0]);
40 41
 	exit(2);
41 42
     }
42 43
 
43
-    /* load all available databases from the default (hardcoded) data
44
-     * directory
45
-     */
44
+    if((fd = open(argv[1], O_RDONLY)) == -1) {
45
+	printf("Can't open file %s\n", argv[1]);
46
+	exit(2);
47
+    }
48
+
49
+    /* load all available databases from default directory */
46 50
 
47 51
     if((ret = cl_loaddbdir(cl_retdbdir(), &root, &no))) {
48 52
 	printf("cl_loaddbdir: %s\n", cl_perror(ret));
53
+	close(fd);
49 54
 	exit(2);
50 55
     }
51 56
 
52 57
     printf("Loaded %d signatures.\n", no);
53 58
 
54
-    /* build the trie */
55
-    if((ret = cl_buildtrie(root)) != 0) {
59
+    /* build the final trie */
60
+    if((ret = cl_buildtrie(root))) {
56 61
 	printf("Database initialization error: %s\n", cl_strerror(ret));;
57
-	exit(2);
58
-    }
59
-
60
-    if((fd = open(argv[1], O_RDONLY)) == -1) {
61
-	printf("Can't open file %s\n", argv[1]);
62
+	cl_freetrie(root); /* free the partial trie */
63
+	close(fd);
62 64
 	exit(2);
63 65
     }
64 66
 
... ...
@@ -66,11 +69,13 @@ int main(int argc, char **argv)
66 66
     memset(&limits, 0, sizeof(struct cl_limits));
67 67
     limits.maxfiles = 1000; /* max files */
68 68
     limits.maxfilesize = 10 * 1048576; /* maximal archived file size == 10 Mb */
69
-    limits.maxreclevel = 8; /* maximal recursion level */
69
+    limits.maxreclevel = 5; /* maximal recursion level */
70
+    limits.maxratio = 200; /* maximal compression ratio */
71
+    limits.archivememlim = 0; /* disable memory limit for bzip2 scanner */
70 72
 
71 73
     /* scan descriptor (with archive and mail scanning enabled) */
72
-    if((ret = cl_scandesc(fd, &virname, &size, root, &limits, CL_ARCHIVE | CL_MAIL)) == CL_VIRUS)
73
-	printf("Detected %s virus.\n", virname);
74
+    if((ret = cl_scandesc(fd, &virname, &size, root, &limits, CL_ARCHIVE | CL_MAIL | CL_OLE2)) == CL_VIRUS)
75
+	printf("Virus detected: %s\n", virname);
74 76
     else {
75 77
 	printf("No virus detected.\n");
76 78
 	if(ret != CL_CLEAN)
... ...
@@ -19,22 +19,25 @@
19 19
 bin_PROGRAMS = freshclam
20 20
 
21 21
 freshclam_SOURCES = \
22
+    $(top_srcdir)/shared/output.c \
23
+    $(top_srcdir)/shared/output.h \
24
+    $(top_srcdir)/shared/cfgparser.c \
25
+    $(top_srcdir)/shared/cfgparser.h \
26
+    $(top_srcdir)/shared/getopt.c \
27
+    $(top_srcdir)/shared/getopt.h \
28
+    $(top_srcdir)/shared/memory.c \
29
+    $(top_srcdir)/shared/memory.h \
22 30
     freshclam.c \
23 31
     freshclam.h \
24 32
     options.c \
33
+    options.h \
25 34
     manager.c \
26 35
     manager.h \
27 36
     defaults.h \
28 37
     notify.c \
29 38
     notify.h
30 39
 
31
-if BUILD_CLAMD
32
-freshclam_LDADD = $(top_builddir)/clamscan/getopt.o $(top_builddir)/clamscan/others.o $(top_builddir)/clamd/cfgfile.o
33
-else
34
-freshclam_LDADD = $(top_builddir)/clamscan/getopt.o $(top_builddir)/clamscan/others.o
35
-endif
36
-
37 40
 
38 41
 DEFS = @DEFS@
39
-INCLUDES = -I$(top_srcdir)/clamscan -I$(top_srcdir)/clamd -I$(top_srcdir)/libclamav
42
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
40 43
 LIBS = -L$(top_builddir)/libclamav -lclamav @FRESHCLAM_LIBS@
... ...
@@ -120,9 +120,18 @@ install_sh = @install_sh@
120 120
 bin_PROGRAMS = freshclam
121 121
 
122 122
 freshclam_SOURCES = \
123
+    $(top_srcdir)/shared/output.c \
124
+    $(top_srcdir)/shared/output.h \
125
+    $(top_srcdir)/shared/cfgparser.c \
126
+    $(top_srcdir)/shared/cfgparser.h \
127
+    $(top_srcdir)/shared/getopt.c \
128
+    $(top_srcdir)/shared/getopt.h \
129
+    $(top_srcdir)/shared/memory.c \
130
+    $(top_srcdir)/shared/memory.h \
123 131
     freshclam.c \
124 132
     freshclam.h \
125 133
     options.c \
134
+    options.h \
126 135
     manager.c \
127 136
     manager.h \
128 137
     defaults.h \
... ...
@@ -130,11 +139,8 @@ freshclam_SOURCES = \
130 130
     notify.h
131 131
 
132 132
 
133
-@BUILD_CLAMD_TRUE@freshclam_LDADD = $(top_builddir)/clamscan/getopt.o $(top_builddir)/clamscan/others.o $(top_builddir)/clamd/cfgfile.o
134
-@BUILD_CLAMD_FALSE@freshclam_LDADD = $(top_builddir)/clamscan/getopt.o $(top_builddir)/clamscan/others.o
135
-
136 133
 DEFS = @DEFS@
137
-INCLUDES = -I$(top_srcdir)/clamscan -I$(top_srcdir)/clamd -I$(top_srcdir)/libclamav
134
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
138 135
 LIBS = -L$(top_builddir)/libclamav -lclamav @FRESHCLAM_LIBS@
139 136
 subdir = freshclam
140 137
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
... ...
@@ -143,24 +149,23 @@ CONFIG_CLEAN_FILES =
143 143
 bin_PROGRAMS = freshclam$(EXEEXT)
144 144
 PROGRAMS = $(bin_PROGRAMS)
145 145
 
146
-am_freshclam_OBJECTS = freshclam.$(OBJEXT) options.$(OBJEXT) \
147
-	manager.$(OBJEXT) notify.$(OBJEXT)
146
+am_freshclam_OBJECTS = output.$(OBJEXT) cfgparser.$(OBJEXT) \
147
+	getopt.$(OBJEXT) memory.$(OBJEXT) freshclam.$(OBJEXT) \
148
+	options.$(OBJEXT) manager.$(OBJEXT) notify.$(OBJEXT)
148 149
 freshclam_OBJECTS = $(am_freshclam_OBJECTS)
149
-@BUILD_CLAMD_TRUE@freshclam_DEPENDENCIES = \
150
-@BUILD_CLAMD_TRUE@	$(top_builddir)/clamscan/getopt.o \
151
-@BUILD_CLAMD_TRUE@	$(top_builddir)/clamscan/others.o \
152
-@BUILD_CLAMD_TRUE@	$(top_builddir)/clamd/cfgfile.o
153
-@BUILD_CLAMD_FALSE@freshclam_DEPENDENCIES = \
154
-@BUILD_CLAMD_FALSE@	$(top_builddir)/clamscan/getopt.o \
155
-@BUILD_CLAMD_FALSE@	$(top_builddir)/clamscan/others.o
150
+freshclam_LDADD = $(LDADD)
151
+freshclam_DEPENDENCIES =
156 152
 freshclam_LDFLAGS =
157 153
 DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)
158 154
 CPPFLAGS = @CPPFLAGS@
159 155
 LDFLAGS = @LDFLAGS@
160 156
 depcomp = $(SHELL) $(top_srcdir)/depcomp
161 157
 am__depfiles_maybe = depfiles
162
-@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/freshclam.Po ./$(DEPDIR)/manager.Po \
163
-@AMDEP_TRUE@	./$(DEPDIR)/notify.Po ./$(DEPDIR)/options.Po
158
+@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/cfgparser.Po \
159
+@AMDEP_TRUE@	./$(DEPDIR)/freshclam.Po ./$(DEPDIR)/getopt.Po \
160
+@AMDEP_TRUE@	./$(DEPDIR)/manager.Po ./$(DEPDIR)/memory.Po \
161
+@AMDEP_TRUE@	./$(DEPDIR)/notify.Po ./$(DEPDIR)/options.Po \
162
+@AMDEP_TRUE@	./$(DEPDIR)/output.Po
164 163
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
165 164
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
166 165
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
... ...
@@ -209,6 +214,10 @@ uninstall-binPROGRAMS:
209 209
 
210 210
 clean-binPROGRAMS:
211 211
 	-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
212
+output.$(OBJEXT): $(top_srcdir)/shared/output.c
213
+cfgparser.$(OBJEXT): $(top_srcdir)/shared/cfgparser.c
214
+getopt.$(OBJEXT): $(top_srcdir)/shared/getopt.c
215
+memory.$(OBJEXT): $(top_srcdir)/shared/memory.c
212 216
 freshclam$(EXEEXT): $(freshclam_OBJECTS) $(freshclam_DEPENDENCIES) 
213 217
 	@rm -f freshclam$(EXEEXT)
214 218
 	$(LINK) $(freshclam_LDFLAGS) $(freshclam_OBJECTS) $(freshclam_LDADD) $(LIBS)
... ...
@@ -219,10 +228,14 @@ mostlyclean-compile:
219 219
 distclean-compile:
220 220
 	-rm -f *.tab.c
221 221
 
222
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgparser.Po@am__quote@
222 223
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/freshclam.Po@am__quote@
224
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
223 225
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/manager.Po@am__quote@
226
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Po@am__quote@
224 227
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/notify.Po@am__quote@
225 228
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@
229
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/output.Po@am__quote@
226 230
 
227 231
 distclean-depend:
228 232
 	-rm -rf ./$(DEPDIR)
... ...
@@ -244,6 +257,78 @@ distclean-depend:
244 244
 @AMDEP_TRUE@	depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@
245 245
 @AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
246 246
 	$(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<
247
+
248
+output.o: $(top_srcdir)/shared/output.c
249
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.o' libtool=no @AMDEPBACKSLASH@
250
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Po' tmpdepfile='$(DEPDIR)/output.TPo' @AMDEPBACKSLASH@
251
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
252
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.o `test -f '$(top_srcdir)/shared/output.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/output.c
253
+
254
+output.obj: $(top_srcdir)/shared/output.c
255
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.obj' libtool=no @AMDEPBACKSLASH@
256
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Po' tmpdepfile='$(DEPDIR)/output.TPo' @AMDEPBACKSLASH@
257
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
258
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.obj `cygpath -w $(top_srcdir)/shared/output.c`
259
+
260
+output.lo: $(top_srcdir)/shared/output.c
261
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.lo' libtool=yes @AMDEPBACKSLASH@
262
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Plo' tmpdepfile='$(DEPDIR)/output.TPlo' @AMDEPBACKSLASH@
263
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
264
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.lo `test -f '$(top_srcdir)/shared/output.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/output.c
265
+
266
+cfgparser.o: $(top_srcdir)/shared/cfgparser.c
267
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.o' libtool=no @AMDEPBACKSLASH@
268
+@AMDEP_TRUE@	depfile='$(DEPDIR)/cfgparser.Po' tmpdepfile='$(DEPDIR)/cfgparser.TPo' @AMDEPBACKSLASH@
269
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
270
+	$(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
271
+
272
+cfgparser.obj: $(top_srcdir)/shared/cfgparser.c
273
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.obj' libtool=no @AMDEPBACKSLASH@
274
+@AMDEP_TRUE@	depfile='$(DEPDIR)/cfgparser.Po' tmpdepfile='$(DEPDIR)/cfgparser.TPo' @AMDEPBACKSLASH@
275
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
276
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.obj `cygpath -w $(top_srcdir)/shared/cfgparser.c`
277
+
278
+cfgparser.lo: $(top_srcdir)/shared/cfgparser.c
279
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.lo' libtool=yes @AMDEPBACKSLASH@
280
+@AMDEP_TRUE@	depfile='$(DEPDIR)/cfgparser.Plo' tmpdepfile='$(DEPDIR)/cfgparser.TPlo' @AMDEPBACKSLASH@
281
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
282
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.lo `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c
283
+
284
+getopt.o: $(top_srcdir)/shared/getopt.c
285
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.o' libtool=no @AMDEPBACKSLASH@
286
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Po' tmpdepfile='$(DEPDIR)/getopt.TPo' @AMDEPBACKSLASH@
287
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
288
+	$(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
289
+
290
+getopt.obj: $(top_srcdir)/shared/getopt.c
291
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.obj' libtool=no @AMDEPBACKSLASH@
292
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Po' tmpdepfile='$(DEPDIR)/getopt.TPo' @AMDEPBACKSLASH@
293
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
294
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.obj `cygpath -w $(top_srcdir)/shared/getopt.c`
295
+
296
+getopt.lo: $(top_srcdir)/shared/getopt.c
297
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.lo' libtool=yes @AMDEPBACKSLASH@
298
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Plo' tmpdepfile='$(DEPDIR)/getopt.TPlo' @AMDEPBACKSLASH@
299
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
300
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.lo `test -f '$(top_srcdir)/shared/getopt.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/getopt.c
301
+
302
+memory.o: $(top_srcdir)/shared/memory.c
303
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.o' libtool=no @AMDEPBACKSLASH@
304
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Po' tmpdepfile='$(DEPDIR)/memory.TPo' @AMDEPBACKSLASH@
305
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
306
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.o `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c
307
+
308
+memory.obj: $(top_srcdir)/shared/memory.c
309
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.obj' libtool=no @AMDEPBACKSLASH@
310
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Po' tmpdepfile='$(DEPDIR)/memory.TPo' @AMDEPBACKSLASH@
311
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
312
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.obj `cygpath -w $(top_srcdir)/shared/memory.c`
313
+
314
+memory.lo: $(top_srcdir)/shared/memory.c
315
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.lo' libtool=yes @AMDEPBACKSLASH@
316
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Plo' tmpdepfile='$(DEPDIR)/memory.TPlo' @AMDEPBACKSLASH@
317
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
318
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.lo `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c
247 319
 CCDEPMODE = @CCDEPMODE@
248 320
 
249 321
 mostlyclean-libtool:
... ...
@@ -34,18 +34,15 @@
34 34
 #include <pwd.h>
35 35
 #include <grp.h>
36 36
 
37
-#if defined(CLAMD_USE_SYSLOG) && !defined(C_AIX)
37
+#if defined(USE_SYSLOG) && !defined(C_AIX)
38 38
 #include <syslog.h>
39 39
 #endif
40 40
 
41 41
 #include "options.h"
42
-#include "shared.h"
43
-#include "others.h"
44
-#include "clamd/others.h"
45 42
 #include "manager.h"
46 43
 #include "defaults.h"
47 44
 #include "freshclam.h"
48
-
45
+#include "output.h"
49 46
 
50 47
 static short terminate = 0;
51 48
 
... ...
@@ -183,33 +180,38 @@ int freshclam(struct optstruct *opt)
183 183
 
184 184
     /* initialize logger */
185 185
 
186
+    /* FIXME: enable in config file */
187
+    logg_size = 0;
188
+    logg_lock = 0;
189
+    logg_time = 0;
190
+
186 191
     if(cfgopt(copt, "LogVerbose"))
187
-	logverbose = 1;
192
+	logg_verbose = 1;
188 193
     else
189
-	logverbose = 0;
194
+	logg_verbose = 0;
190 195
 
191 196
     if(optc(opt, 'l')) {
192
-	logfile = getargc(opt, 'l');
197
+	logg_file = getargc(opt, 'l');
193 198
 	if(logg("--------------------------------------\n")) {
194 199
 	    mprintf("!Problem with internal logger.\n");
195 200
 	    mexit(1);
196 201
 	}
197 202
     } else if((cpt = cfgopt(copt, "UpdateLogFile"))) {
198
-	logfile = cpt->strarg; 
203
+	logg_file = cpt->strarg; 
199 204
 	if(logg("--------------------------------------\n")) {
200 205
 	    mprintf("!Problem with internal logger.\n");
201 206
 	    mexit(1);
202 207
 	}
203 208
     } else
204
-	logfile = NULL;
209
+	logg_file = NULL;
205 210
 
206
-#if defined(CLAMD_USE_SYSLOG) && !defined(C_AIX)
211
+#if defined(USE_SYSLOG) && !defined(C_AIX)
207 212
     if((cpt = cfgopt(copt, "LogSyslog"))) {
208 213
 	openlog("freshclam", LOG_PID, LOG_LOCAL6);
209
-	use_syslog = 1;
214
+	logg_syslog = 1;
210 215
 	syslog(LOG_INFO, "Freshclam started.\n");
211 216
     } else
212
-	use_syslog = 0;
217
+	logg_syslog = 0;
213 218
 #endif
214 219
 
215 220
     /* change the current working directory */
... ...
@@ -19,7 +19,7 @@
19 19
 #ifndef __FRESHCLAM_H
20 20
 #define __FRESHCLAM_H
21 21
 
22
-#include "cfgfile.h"
22
+#include "cfgparser.h"
23 23
 
24 24
 void help(void);
25 25
 void daemonize(void);
... ...
@@ -39,12 +39,11 @@
39 39
 #include <sys/stat.h>
40 40
 #include <clamav.h>
41 41
 
42
-#include "others.h"
43 42
 #include "options.h"
44 43
 #include "defaults.h"
45 44
 #include "manager.h"
46
-#include "shared.h"
47 45
 #include "notify.h"
46
+#include "memory.h"
48 47
 
49 48
 int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, const char *hostname)
50 49
 {
... ...
@@ -19,7 +19,7 @@
19 19
 #ifndef __MANAGER_H
20 20
 #define __MANAGER_H
21 21
 
22
-#include "cfgfile.h"
22
+#include "cfgparser.h"
23 23
 #include "clamav.h"
24 24
 
25 25
 int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, const char *hostname);
... ...
@@ -33,7 +33,7 @@
33 33
 #include <string.h>
34 34
 
35 35
 #include "others.h"
36
-#include "cfgfile.h"
36
+#include "cfgparser.h"
37 37
 
38 38
 int notify(const char *cfgfile)
39 39
 {
... ...
@@ -19,7 +19,7 @@
19 19
 #ifndef __NOTIFY_H
20 20
 #define __NOTIFY_H
21 21
 
22
-#include "cfgfile.h"
22
+#include "cfgparser.h"
23 23
 
24 24
 int notify(const char *cfgfile);
25 25
 
... ...
@@ -24,8 +24,7 @@
24 24
 #include "getopt.h"
25 25
 
26 26
 #include "options.h"
27
-#include "others.h"
28
-#include "shared.h"
27
+#include "output.h"
29 28
 
30 29
 int freshclam(struct optstruct *opt);
31 30
 
32 31
new file mode 100644
... ...
@@ -0,0 +1,46 @@
0
+/*
1
+ *  Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
2
+ *
3
+ *  This program is free software; you can redistribute it and/or modify
4
+ *  it under the terms of the GNU General Public License as published by
5
+ *  the Free Software Foundation; either version 2 of the License, or
6
+ *  (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ */
17
+
18
+#ifndef __OPTIONS_H
19
+#define __OPTIONS_H
20
+
21
+struct optnode {
22
+    char optchar;
23
+    char *optarg;
24
+    char *optname;
25
+    struct optnode *next;
26
+};
27
+
28
+struct optstruct {
29
+    struct optnode *optlist;
30
+    char *filename;
31
+};
32
+
33
+int optc(const struct optstruct *opt, char ch);
34
+int optl(const struct optstruct *opt, const char *optname);
35
+void register_char_option(struct optstruct *opt, char ch);
36
+void register_long_option(struct optstruct *opt, const char *optname);
37
+char *getargc(const struct optstruct *opt, char ch);
38
+char *getfirstargc(const struct optstruct *opt, char ch, struct optnode **optnode);
39
+char *getnextargc(struct optnode **optnode, char ch);
40
+char *getargl(const struct optstruct *opt, const char *optname);
41
+char *getfirstargl(const struct optstruct *opt, const char *optname, struct optnode **optnode);
42
+char *getnextargl(struct optnode **optnode, const char *optname);
43
+void free_opt(struct optstruct *opt);
44
+
45
+#endif
... ...
@@ -67,6 +67,8 @@ libclamav_la_SOURCES = \
67 67
 	mbox.h \
68 68
 	message.c \
69 69
 	message.h \
70
+	snprintf.c \
71
+	snprintf.h \
70 72
 	strrcpy.c \
71 73
 	strrcpy.h \
72 74
 	table.c \
... ...
@@ -167,6 +167,8 @@ libclamav_la_SOURCES = \
167 167
 	mbox.h \
168 168
 	message.c \
169 169
 	message.h \
170
+	snprintf.c \
171
+	snprintf.h \
170 172
 	strrcpy.c \
171 173
 	strrcpy.h \
172 174
 	table.c \
... ...
@@ -191,8 +193,8 @@ libclamav_la_DEPENDENCIES =
191 191
 am_libclamav_la_OBJECTS = matcher.lo md5.lo others.lo readdb.lo cvd.lo \
192 192
 	dsig.lo str.lo scanners.lo unrarlib.lo zzip-dir.lo zzip-err.lo \
193 193
 	zzip-file.lo zzip-info.lo zzip-io.lo zzip-stat.lo zzip-zip.lo \
194
-	strc.lo blob.lo mbox.lo message.lo strrcpy.lo table.lo text.lo \
195
-	ole2_extract.lo vba_extract.lo
194
+	strc.lo blob.lo mbox.lo message.lo snprintf.lo strrcpy.lo \
195
+	table.lo text.lo ole2_extract.lo vba_extract.lo
196 196
 libclamav_la_OBJECTS = $(am_libclamav_la_OBJECTS)
197 197
 
198 198
 DEFS = @DEFS@
... ...
@@ -208,9 +210,10 @@ am__depfiles_maybe = depfiles
208 208
 @AMDEP_TRUE@	./$(DEPDIR)/message.Plo \
209 209
 @AMDEP_TRUE@	./$(DEPDIR)/ole2_extract.Plo ./$(DEPDIR)/others.Plo \
210 210
 @AMDEP_TRUE@	./$(DEPDIR)/readdb.Plo ./$(DEPDIR)/scanners.Plo \
211
-@AMDEP_TRUE@	./$(DEPDIR)/str.Plo ./$(DEPDIR)/strc.Plo \
212
-@AMDEP_TRUE@	./$(DEPDIR)/strrcpy.Plo ./$(DEPDIR)/table.Plo \
213
-@AMDEP_TRUE@	./$(DEPDIR)/text.Plo ./$(DEPDIR)/unrarlib.Plo \
211
+@AMDEP_TRUE@	./$(DEPDIR)/snprintf.Plo ./$(DEPDIR)/str.Plo \
212
+@AMDEP_TRUE@	./$(DEPDIR)/strc.Plo ./$(DEPDIR)/strrcpy.Plo \
213
+@AMDEP_TRUE@	./$(DEPDIR)/table.Plo ./$(DEPDIR)/text.Plo \
214
+@AMDEP_TRUE@	./$(DEPDIR)/unrarlib.Plo \
214 215
 @AMDEP_TRUE@	./$(DEPDIR)/vba_extract.Plo \
215 216
 @AMDEP_TRUE@	./$(DEPDIR)/zzip-dir.Plo ./$(DEPDIR)/zzip-err.Plo \
216 217
 @AMDEP_TRUE@	./$(DEPDIR)/zzip-file.Plo ./$(DEPDIR)/zzip-info.Plo \
... ...
@@ -289,6 +292,7 @@ distclean-compile:
289 289
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/others.Plo@am__quote@
290 290
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readdb.Plo@am__quote@
291 291
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scanners.Plo@am__quote@
292
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snprintf.Plo@am__quote@
292 293
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str.Plo@am__quote@
293 294
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strc.Plo@am__quote@
294 295
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strrcpy.Plo@am__quote@
295 296
new file mode 100644
... ...
@@ -0,0 +1,652 @@
0
+/*
1
+ * Copyright Patrick Powell 1995
2
+ * This code is based on code written by Patrick Powell (papowell@astart.com)
3
+ * It may be used for any purpose as long as this notice remains intact
4
+ * on all source code distributions
5
+ */
6
+
7
+/**************************************************************
8
+ * Original:
9
+ * Patrick Powell Tue Apr 11 09:48:21 PDT 1995
10
+ * A bombproof version of doprnt (dopr) included.
11
+ * Sigh.  This sort of thing is always nasty do deal with.  Note that
12
+ * the version here does not include floating point...
13
+ *
14
+ * snprintf() is used instead of sprintf() as it does limit checks
15
+ * for string length.  This covers a nasty loophole.
16
+ *
17
+ * The other functions are there to prevent NULL pointers from
18
+ * causing nast effects.
19
+ *
20
+ * More Recently:
21
+ *  Brandon Long <blong@fiction.net> 9/15/96 for mutt 0.43
22
+ *  This was ugly.  It is still ugly.  I opted out of floating point
23
+ *  numbers, but the formatter understands just about everything
24
+ *  from the normal C string format, at least as far as I can tell from
25
+ *  the Solaris 2.5 printf(3S) man page.
26
+ *
27
+ *  Brandon Long <blong@fiction.net> 10/22/97 for mutt 0.87.1
28
+ *    Ok, added some minimal floating point support, which means this
29
+ *    probably requires libm on most operating systems.  Don't yet
30
+ *    support the exponent (e,E) and sigfig (g,G).  Also, fmtint()
31
+ *    was pretty badly broken, it just wasn't being exercised in ways
32
+ *    which showed it, so that's been fixed.  Also, formated the code
33
+ *    to mutt conventions, and removed dead code left over from the
34
+ *    original.  Also, there is now a builtin-test, just compile with:
35
+ *           gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
36
+ *    and run snprintf for results.
37
+ * 
38
+ *  Thomas Roessler <roessler@guug.de> 01/27/98 for mutt 0.89i
39
+ *    The PGP code was using unsigned hexadecimal formats. 
40
+ *    Unfortunately, unsigned formats simply didn't work.
41
+ *
42
+ *  Michael Elkins <me@cs.hmc.edu> 03/05/98 for mutt 0.90.8
43
+ *    The original code assumed that both snprintf() and vsnprintf() were
44
+ *    missing.  Some systems only have snprintf() but not vsnprintf(), so
45
+ *    the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
46
+ *
47
+ *  Ben Lindstrom <mouring@eviladmin.org> 09/27/00 for OpenSSH
48
+ *    Welcome to the world of %lld and %qd support.  With other
49
+ *    long long support.  This is needed for sftp-server to work
50
+ *    right.
51
+ *
52
+ *  Ben Lindstrom <mouring@eviladmin.org> 02/12/01 for OpenSSH
53
+ *    Removed all hint of VARARGS stuff and banished it to the void,
54
+ *    and did a bit of KNF style work to make things a bit more
55
+ *    acceptable.  Consider stealing from mutt or enlightenment.
56
+ **************************************************************/
57
+
58
+#if HAVE_CONFIG_H
59
+#include "clamav-config.h"
60
+#endif
61
+
62
+#if defined(BROKEN_SNPRINTF)		/* For those with broken snprintf() */
63
+# undef HAVE_SNPRINTF
64
+# undef HAVE_VSNPRINTF
65
+#endif
66
+
67
+#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
68
+
69
+static void 
70
+dopr(char *buffer, size_t maxlen, const char *format, va_list args);
71
+
72
+static void 
73
+fmtstr(char *buffer, size_t *currlen, size_t maxlen, char *value, int flags, 
74
+    int min, int max);
75
+
76
+static void 
77
+fmtint(char *buffer, size_t *currlen, size_t maxlen, long value, int base, 
78
+    int min, int max, int flags);
79
+
80
+static void 
81
+fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue, 
82
+    int min, int max, int flags);
83
+
84
+static void
85
+dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
86
+
87
+/*
88
+ * dopr(): poor man's version of doprintf
89
+ */
90
+
91
+/* format read states */
92
+#define DP_S_DEFAULT 0
93
+#define DP_S_FLAGS   1
94
+#define DP_S_MIN     2
95
+#define DP_S_DOT     3
96
+#define DP_S_MAX     4
97
+#define DP_S_MOD     5
98
+#define DP_S_CONV    6
99
+#define DP_S_DONE    7
100
+
101
+/* format flags - Bits */
102
+#define DP_F_MINUS 	(1 << 0)
103
+#define DP_F_PLUS  	(1 << 1)
104
+#define DP_F_SPACE 	(1 << 2)
105
+#define DP_F_NUM   	(1 << 3)
106
+#define DP_F_ZERO  	(1 << 4)
107
+#define DP_F_UP    	(1 << 5)
108
+#define DP_F_UNSIGNED 	(1 << 6)
109
+
110
+/* Conversion Flags */
111
+#define DP_C_SHORT     1
112
+#define DP_C_LONG      2
113
+#define DP_C_LDOUBLE   3
114
+#define DP_C_LONG_LONG 4
115
+
116
+#define char_to_int(p) (p - '0')
117
+#define abs_val(p) (p < 0 ? -p : p)
118
+
119
+
120
+static void 
121
+dopr(char *buffer, size_t maxlen, const char *format, va_list args)
122
+{
123
+	char *strvalue, ch;
124
+	long value;
125
+	long double fvalue;
126
+	int min = 0, max = -1, state = DP_S_DEFAULT, flags = 0, cflags = 0;
127
+	size_t currlen = 0;
128
+  
129
+	ch = *format++;
130
+
131
+	while (state != DP_S_DONE) {
132
+		if ((ch == '\0') || (currlen >= maxlen)) 
133
+			state = DP_S_DONE;
134
+
135
+		switch(state) {
136
+		case DP_S_DEFAULT:
137
+			if (ch == '%') 
138
+				state = DP_S_FLAGS;
139
+			else 
140
+				dopr_outch(buffer, &currlen, maxlen, ch);
141
+			ch = *format++;
142
+			break;
143
+		case DP_S_FLAGS:
144
+			switch (ch) {
145
+			case '-':
146
+				flags |= DP_F_MINUS;
147
+				ch = *format++;
148
+				break;
149
+			case '+':
150
+				flags |= DP_F_PLUS;
151
+				ch = *format++;
152
+				break;
153
+			case ' ':
154
+				flags |= DP_F_SPACE;
155
+				ch = *format++;
156
+				break;
157
+			case '#':
158
+				flags |= DP_F_NUM;
159
+				ch = *format++;
160
+				break;
161
+			case '0':
162
+				flags |= DP_F_ZERO;
163
+				ch = *format++;
164
+				break;
165
+			default:
166
+				state = DP_S_MIN;
167
+				break;
168
+			}
169
+			break;
170
+		case DP_S_MIN:
171
+			if (isdigit((unsigned char)ch)) {
172
+				min = 10 * min + char_to_int (ch);
173
+				ch = *format++;
174
+			} else if (ch == '*') {
175
+				min = va_arg (args, int);
176
+				ch = *format++;
177
+				state = DP_S_DOT;
178
+			} else 
179
+				state = DP_S_DOT;
180
+			break;
181
+		case DP_S_DOT:
182
+			if (ch == '.') {
183
+				state = DP_S_MAX;
184
+				ch = *format++;
185
+			} else 
186
+				state = DP_S_MOD;
187
+			break;
188
+		case DP_S_MAX:
189
+			if (isdigit((unsigned char)ch)) {
190
+				if (max < 0)
191
+					max = 0;
192
+				max = 10 * max + char_to_int(ch);
193
+				ch = *format++;
194
+			} else if (ch == '*') {
195
+				max = va_arg (args, int);
196
+				ch = *format++;
197
+				state = DP_S_MOD;
198
+			} else 
199
+				state = DP_S_MOD;
200
+			break;
201
+		case DP_S_MOD:
202
+			switch (ch) {
203
+			case 'h':
204
+				cflags = DP_C_SHORT;
205
+				ch = *format++;
206
+				break;
207
+			case 'l':
208
+				cflags = DP_C_LONG;
209
+				ch = *format++;
210
+				if (ch == 'l') {
211
+					cflags = DP_C_LONG_LONG;
212
+					ch = *format++;
213
+				}
214
+				break;
215
+			case 'q':
216
+				cflags = DP_C_LONG_LONG;
217
+				ch = *format++;
218
+				break;
219
+			case 'L':
220
+				cflags = DP_C_LDOUBLE;
221
+				ch = *format++;
222
+				break;
223
+			default:
224
+				break;
225
+			}
226
+			state = DP_S_CONV;
227
+			break;
228
+		case DP_S_CONV:
229
+			switch (ch) {
230
+			case 'd':
231
+			case 'i':
232
+				if (cflags == DP_C_SHORT) 
233
+					value = va_arg(args, int);
234
+				else if (cflags == DP_C_LONG)
235
+					value = va_arg(args, long int);
236
+				else if (cflags == DP_C_LONG_LONG)
237
+					value = va_arg (args, long long);
238
+				else
239
+					value = va_arg (args, int);
240
+				fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
241
+				break;
242
+			case 'o':
243
+				flags |= DP_F_UNSIGNED;
244
+				if (cflags == DP_C_SHORT)
245
+					value = va_arg(args, unsigned int);
246
+				else if (cflags == DP_C_LONG)
247
+					value = va_arg(args, unsigned long int);
248
+				else if (cflags == DP_C_LONG_LONG)
249
+					value = va_arg(args, unsigned long long);
250
+				else
251
+					value = va_arg(args, unsigned int);
252
+				fmtint(buffer, &currlen, maxlen, value, 8, min, max, flags);
253
+				break;
254
+			case 'u':
255
+				flags |= DP_F_UNSIGNED;
256
+				if (cflags == DP_C_SHORT)
257
+					value = va_arg(args, unsigned int);
258
+				else if (cflags == DP_C_LONG)
259
+					value = va_arg(args, unsigned long int);
260
+				else if (cflags == DP_C_LONG_LONG)
261
+					value = va_arg(args, unsigned long long);
262
+				else
263
+					value = va_arg(args, unsigned int);
264
+				fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
265
+				break;
266
+			case 'X':
267
+				flags |= DP_F_UP;
268
+			case 'x':
269
+				flags |= DP_F_UNSIGNED;
270
+				if (cflags == DP_C_SHORT)
271
+					value = va_arg(args, unsigned int);
272
+				else if (cflags == DP_C_LONG)
273
+					value = va_arg(args, unsigned long int);
274
+				else if (cflags == DP_C_LONG_LONG)
275
+					value = va_arg(args, unsigned long long);
276
+				else
277
+					value = va_arg(args, unsigned int);
278
+				fmtint(buffer, &currlen, maxlen, value, 16, min, max, flags);
279
+				break;
280
+			case 'f':
281
+				if (cflags == DP_C_LDOUBLE)
282
+					fvalue = va_arg(args, long double);
283
+				else
284
+					fvalue = va_arg(args, double);
285
+				/* um, floating point? */
286
+				fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags);
287
+				break;
288
+			case 'E':
289
+				flags |= DP_F_UP;
290
+			case 'e':
291
+				if (cflags == DP_C_LDOUBLE)
292
+					fvalue = va_arg(args, long double);
293
+				else
294
+					fvalue = va_arg(args, double);
295
+				break;
296
+			case 'G':
297
+				flags |= DP_F_UP;
298
+			case 'g':
299
+				if (cflags == DP_C_LDOUBLE)
300
+					fvalue = va_arg(args, long double);
301
+				else
302
+					fvalue = va_arg(args, double);
303
+				break;
304
+			case 'c':
305
+				dopr_outch(buffer, &currlen, maxlen, va_arg(args, int));
306
+				break;
307
+			case 's':
308
+				strvalue = va_arg(args, char *);
309
+				if (max < 0) 
310
+					max = maxlen; /* ie, no max */
311
+				fmtstr(buffer, &currlen, maxlen, strvalue, flags, min, max);
312
+				break;
313
+			case 'p':
314
+				strvalue = va_arg(args, void *);
315
+				fmtint(buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
316
+				break;
317
+			case 'n':
318
+				if (cflags == DP_C_SHORT) {
319
+					short int *num;
320
+					num = va_arg(args, short int *);
321
+					*num = currlen;
322
+				} else if (cflags == DP_C_LONG) {
323
+					long int *num;
324
+					num = va_arg(args, long int *);
325
+					*num = currlen;
326
+				} else if (cflags == DP_C_LONG_LONG) {
327
+					long long *num;
328
+					num = va_arg(args, long long *);
329
+					*num = currlen;
330
+				} else {
331
+					int *num;
332
+					num = va_arg(args, int *);
333
+					*num = currlen;
334
+				}
335
+				break;
336
+			case '%':
337
+				dopr_outch(buffer, &currlen, maxlen, ch);
338
+				break;
339
+			case 'w': /* not supported yet, treat as next char */
340
+				ch = *format++;
341
+				break;
342
+			default: /* Unknown, skip */
343
+			break;
344
+			}
345
+			ch = *format++;
346
+			state = DP_S_DEFAULT;
347
+			flags = cflags = min = 0;
348
+			max = -1;
349
+			break;
350
+		case DP_S_DONE:
351
+			break;
352
+		default: /* hmm? */
353
+			break; /* some picky compilers need this */
354
+		}
355
+	}
356
+	if (currlen < maxlen - 1) 
357
+		buffer[currlen] = '\0';
358
+	else 
359
+		buffer[maxlen - 1] = '\0';
360
+}
361
+
362
+static void
363
+fmtstr(char *buffer, size_t *currlen, size_t maxlen,
364
+    char *value, int flags, int min, int max)
365
+{
366
+	int cnt = 0, padlen, strln;     /* amount to pad */
367
+  
368
+	if (value == 0) 
369
+		value = "<NULL>";
370
+
371
+	for (strln = 0; value[strln]; ++strln); /* strlen */
372
+	padlen = min - strln;
373
+	if (padlen < 0) 
374
+		padlen = 0;
375
+	if (flags & DP_F_MINUS) 
376
+		padlen = -padlen; /* Left Justify */
377
+
378
+	while ((padlen > 0) && (cnt < max)) {
379
+		dopr_outch(buffer, currlen, maxlen, ' ');
380
+		--padlen;
381
+		++cnt;
382
+	}
383
+	while (*value && (cnt < max)) {
384
+		dopr_outch(buffer, currlen, maxlen, *value++);
385
+		++cnt;
386
+	}
387
+	while ((padlen < 0) && (cnt < max)) {
388
+		dopr_outch(buffer, currlen, maxlen, ' ');
389
+		++padlen;
390
+		++cnt;
391
+	}
392
+}
393
+
394
+/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
395
+
396
+static void 
397
+fmtint(char *buffer, size_t *currlen, size_t maxlen,
398
+    long value, int base, int min, int max, int flags)
399
+{
400
+	unsigned long uvalue;
401
+	char convert[20];
402
+	int signvalue = 0, place = 0, caps = 0;
403
+	int spadlen = 0; /* amount to space pad */
404
+	int zpadlen = 0; /* amount to zero pad */
405
+  
406
+	if (max < 0)
407
+		max = 0;
408
+
409
+	uvalue = value;
410
+
411
+	if (!(flags & DP_F_UNSIGNED)) {
412
+		if (value < 0) {
413
+			signvalue = '-';
414
+			uvalue = -value;
415
+		} else if (flags & DP_F_PLUS)  /* Do a sign (+/i) */
416
+			signvalue = '+';
417
+		else if (flags & DP_F_SPACE)
418
+			signvalue = ' ';
419
+	}
420
+  
421
+	if (flags & DP_F_UP) 
422
+		caps = 1; /* Should characters be upper case? */
423
+	do {
424
+		convert[place++] =
425
+		    (caps ? "0123456789ABCDEF" : "0123456789abcdef")
426
+		    [uvalue % (unsigned)base];
427
+		uvalue = (uvalue / (unsigned)base );
428
+	} while (uvalue && (place < 20));
429
+	if (place == 20) 
430
+		place--;
431
+	convert[place] = 0;
432
+
433
+	zpadlen = max - place;
434
+	spadlen = min - MAX (max, place) - (signvalue ? 1 : 0);
435
+	if (zpadlen < 0)
436
+		zpadlen = 0;
437
+	if (spadlen < 0)
438
+		spadlen = 0;
439
+	if (flags & DP_F_ZERO) {
440
+		zpadlen = MAX(zpadlen, spadlen);
441
+		spadlen = 0;
442
+	}
443
+	if (flags & DP_F_MINUS) 
444
+		spadlen = -spadlen; /* Left Justifty */
445
+
446
+	/* Spaces */
447
+	while (spadlen > 0) {
448
+		dopr_outch(buffer, currlen, maxlen, ' ');
449
+		--spadlen;
450
+	}
451
+
452
+	/* Sign */
453
+	if (signvalue) 
454
+		dopr_outch(buffer, currlen, maxlen, signvalue);
455
+
456
+	/* Zeros */
457
+	if (zpadlen > 0) {
458
+		while (zpadlen > 0) {
459
+			dopr_outch(buffer, currlen, maxlen, '0');
460
+			--zpadlen;
461
+		}
462
+	}
463
+
464
+	/* Digits */
465
+	while (place > 0) 
466
+		dopr_outch(buffer, currlen, maxlen, convert[--place]);
467
+  
468
+	/* Left Justified spaces */
469
+	while (spadlen < 0) {
470
+		dopr_outch (buffer, currlen, maxlen, ' ');
471
+		++spadlen;
472
+	}
473
+}
474
+
475
+static long double 
476
+pow10(int exp)
477
+{
478
+	long double result = 1;
479
+
480
+	while (exp) {
481
+		result *= 10;
482
+		exp--;
483
+	}
484
+  
485
+	return result;
486
+}
487
+
488
+static long 
489
+round(long double value)
490
+{
491
+	long intpart = value;
492
+
493
+	value -= intpart;
494
+	if (value >= 0.5)
495
+		intpart++;
496
+
497
+	return intpart;
498
+}
499
+
500
+static void 
501
+fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue, 
502
+      int min, int max, int flags)
503
+{
504
+	char iconvert[20], fconvert[20];
505
+	int signvalue = 0, iplace = 0, fplace = 0;
506
+	int padlen = 0; /* amount to pad */
507
+	int zpadlen = 0, caps = 0;
508
+	long intpart, fracpart;
509
+	long double ufvalue;
510
+  
511
+	/* 
512
+	 * AIX manpage says the default is 0, but Solaris says the default
513
+	 * is 6, and sprintf on AIX defaults to 6
514
+	 */
515
+	if (max < 0)
516
+		max = 6;
517
+
518
+	ufvalue = abs_val(fvalue);
519
+
520
+	if (fvalue < 0)
521
+		signvalue = '-';
522
+	else if (flags & DP_F_PLUS)  /* Do a sign (+/i) */
523
+		signvalue = '+';
524
+	else if (flags & DP_F_SPACE)
525
+		signvalue = ' ';
526
+
527
+	intpart = ufvalue;
528
+
529
+	/* 
530
+	 * Sorry, we only support 9 digits past the decimal because of our 
531
+	 * conversion method
532
+	 */
533
+	if (max > 9)
534
+		max = 9;
535
+
536
+	/* We "cheat" by converting the fractional part to integer by
537
+	 * multiplying by a factor of 10
538
+	 */
539
+	fracpart = round((pow10 (max)) * (ufvalue - intpart));
540
+
541
+	if (fracpart >= pow10 (max)) {
542
+		intpart++;
543
+		fracpart -= pow10 (max);
544
+	}
545
+
546
+	/* Convert integer part */
547
+	do {
548
+		iconvert[iplace++] =
549
+		    (caps ? "0123456789ABCDEF" : "0123456789abcdef")
550
+		    [intpart % 10];
551
+		intpart = (intpart / 10);
552
+	} while(intpart && (iplace < 20));
553
+	if (iplace == 20) 
554
+		iplace--;
555
+	iconvert[iplace] = 0;
556
+
557
+	/* Convert fractional part */
558
+	do {
559
+		fconvert[fplace++] =
560
+		    (caps ? "0123456789ABCDEF" : "0123456789abcdef")
561
+		    [fracpart % 10];
562
+		fracpart = (fracpart / 10);
563
+	} while(fracpart && (fplace < 20));
564
+	if (fplace == 20) 
565
+		fplace--;
566
+	fconvert[fplace] = 0;
567
+
568
+	/* -1 for decimal point, another -1 if we are printing a sign */
569
+	padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); 
570
+	zpadlen = max - fplace;
571
+	if (zpadlen < 0)
572
+		zpadlen = 0;
573
+	if (padlen < 0) 
574
+		padlen = 0;
575
+	if (flags & DP_F_MINUS) 
576
+		padlen = -padlen; /* Left Justifty */
577
+
578
+	if ((flags & DP_F_ZERO) && (padlen > 0)) {
579
+		if (signvalue) {
580
+			dopr_outch(buffer, currlen, maxlen, signvalue);
581
+			--padlen;
582
+			signvalue = 0;
583
+		}
584
+		while (padlen > 0) {
585
+			dopr_outch(buffer, currlen, maxlen, '0');
586
+			--padlen;
587
+		}
588
+	}
589
+	while (padlen > 0) {
590
+		dopr_outch(buffer, currlen, maxlen, ' ');
591
+		--padlen;
592
+	}
593
+	if (signvalue) 
594
+		dopr_outch(buffer, currlen, maxlen, signvalue);
595
+
596
+	while (iplace > 0) 
597
+		dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]);
598
+
599
+	/*
600
+	 * Decimal point.  This should probably use locale to find the 
601
+	 * correct char to print out.
602
+	 */
603
+	dopr_outch(buffer, currlen, maxlen, '.');
604
+
605
+	while (fplace > 0) 
606
+		dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]);
607
+
608
+	while (zpadlen > 0) {
609
+		dopr_outch(buffer, currlen, maxlen, '0');
610
+		--zpadlen;
611
+	}
612
+
613
+	while (padlen < 0) {
614
+		dopr_outch(buffer, currlen, maxlen, ' ');
615
+		++padlen;
616
+	}
617
+}
618
+
619
+static void 
620
+dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
621
+{
622
+	if (*currlen < maxlen)
623
+		buffer[(*currlen)++] = c;
624
+}
625
+#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */
626
+
627
+#ifndef HAVE_VSNPRINTF
628
+int 
629
+vsnprintf(char *str, size_t count, const char *fmt, va_list args)
630
+{
631
+	str[0] = 0;
632
+	dopr(str, count, fmt, args);
633
+
634
+	return(strlen(str));
635
+}
636
+#endif /* !HAVE_VSNPRINTF */
637
+
638
+#ifndef HAVE_SNPRINTF
639
+int 
640
+snprintf(char *str,size_t count,const char *fmt,...)
641
+{
642
+	va_list ap;
643
+
644
+	va_start(ap, fmt);
645
+	(void) vsnprintf(str, count, fmt, ap);
646
+	va_end(ap);
647
+
648
+	return(strlen(str));
649
+}
650
+
651
+#endif /* !HAVE_SNPRINTF */
0 652
new file mode 100644
... ...
@@ -0,0 +1,16 @@
0
+#ifndef _SNPRINTF_H
1
+#define _SNPRINTF_H
2
+
3
+#include "clamav-config.h"
4
+
5
+#include <sys/types.h> /* For size_t */
6
+
7
+#ifndef HAVE_SNPRINTF
8
+int snprintf(char *str, size_t count, const char *fmt, ...);
9
+#endif /* !HAVE_SNPRINTF */
10
+
11
+#ifndef HAVE_VSNPRINTF
12
+int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
13
+#endif /* !HAVE_SNPRINTF */
14
+
15
+#endif /* _SNPRINTF_H */
0 16
new file mode 100644
... ...
@@ -0,0 +1,304 @@
0
+/*
1
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
2
+ *
3
+ *  This program is free software; you can redistribute it and/or modify
4
+ *  it under the terms of the GNU General Public License as published by
5
+ *  the Free Software Foundation; either version 2 of the License, or
6
+ *  (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ */
17
+
18
+#if HAVE_CONFIG_H
19
+#include "clamav-config.h"
20
+#endif
21
+
22
+#include <stdio.h>
23
+#include <stdlib.h>
24
+#include <string.h>
25
+#include <ctype.h>
26
+
27
+#include "options.h"
28
+#include "cfgparser.h"
29
+#include "defaults.h"
30
+#include "str.h"
31
+#include "memory.h"
32
+
33
+static int isnumb(const char *str)
34
+{
35
+	int i;
36
+
37
+    for(i = 0; i < strlen(str); i++)
38
+	if(!isdigit(str[i]))
39
+	    return 0;
40
+
41
+    return 1;
42
+}
43
+
44
+struct cfgstruct *parsecfg(const char *cfgfile)
45
+{
46
+	char buff[LINE_LENGTH], *name, *arg;
47
+	FILE *fs;
48
+	int line = 0, i, found, ctype, calc;
49
+	struct cfgstruct *copt = NULL;
50
+	struct cfgoption *pt;
51
+
52
+	struct cfgoption cfg_options[] = {
53
+	    {"LogFile", OPT_STR},
54
+	    {"LogFileUnlock", OPT_NOARG},
55
+	    {"LogFileMaxSize", OPT_COMPSIZE},
56
+	    {"LogTime", OPT_NOARG},
57
+	    {"LogClean", OPT_NOARG},
58
+	    {"LogVerbose", OPT_NOARG}, /* clamd + freshclam */
59
+	    {"LogSyslog", OPT_NOARG},
60
+	    {"PidFile", OPT_STR},
61
+	    {"TemporaryDirectory", OPT_STR},
62
+	    {"MaxFileSize", OPT_COMPSIZE},
63
+	    {"ScanMail", OPT_NOARG},
64
+	    {"ScanOLE2", OPT_NOARG},
65
+	    {"ScanArchive", OPT_NOARG},
66
+	    {"ScanRAR", OPT_NOARG},
67
+	    {"ArchiveMaxFileSize", OPT_COMPSIZE},
68
+	    {"ArchiveMaxRecursion", OPT_NUM},
69
+	    {"ArchiveMaxFiles", OPT_NUM},
70
+	    {"ArchiveMaxCompressionRatio", OPT_NUM},
71
+	    {"ArchiveLimitMemoryUsage", OPT_NOARG},
72
+	    {"ArchiveDetectEncrypted", OPT_NOARG},
73
+	    {"DataDirectory", OPT_STR}, /* obsolete */
74
+	    {"DatabaseDirectory", OPT_STR}, /* clamd + freshclam */
75
+	    {"TCPAddr", OPT_STR},
76
+	    {"TCPSocket", OPT_NUM},
77
+	    {"LocalSocket", OPT_STR},
78
+	    {"MaxConnectionQueueLength", OPT_NUM},
79
+	    {"StreamSaveToDisk", OPT_NOARG},
80
+	    {"StreamMaxLength", OPT_COMPSIZE},
81
+	    {"MaxThreads", OPT_NUM},
82
+	    {"ThreadTimeout", OPT_NUM},
83
+	    {"MaxDirectoryRecursion", OPT_NUM},
84
+	    {"FollowDirectorySymlinks", OPT_NOARG},
85
+	    {"FollowFileSymlinks", OPT_NOARG},
86
+	    {"Foreground", OPT_NOARG},
87
+	    {"Debug", OPT_NOARG},
88
+	    {"FixStaleSocket", OPT_NOARG},
89
+	    {"User", OPT_STR},
90
+	    {"AllowSupplementaryGroups", OPT_NOARG},
91
+	    {"SelfCheck", OPT_NUM},
92
+	    {"VirusEvent", OPT_FULLSTR},
93
+	    {"ClamukoScanOnLine", OPT_NOARG},
94
+	    {"ClamukoScanOnOpen", OPT_NOARG},
95
+	    {"ClamukoScanOnClose", OPT_NOARG},
96
+	    {"ClamukoScanOnExec", OPT_NOARG},
97
+	    {"ClamukoIncludePath", OPT_STR},
98
+	    {"ClamukoExcludePath", OPT_STR},
99
+	    {"ClamukoMaxFileSize", OPT_COMPSIZE},
100
+	    {"ClamukoScanArchive", OPT_NOARG},
101
+	    {"DatabaseOwner", OPT_STR}, /* freshclam */
102
+	    {"Checks", OPT_NUM}, /* freshclam */
103
+	    {"UpdateLogFile", OPT_STR}, /* freshclam */
104
+	    {"DatabaseMirror", OPT_STR}, /* freshclam */
105
+	    {"MaxAttempts", OPT_NUM}, /* freshclam */
106
+	    {"HTTPProxyServer", OPT_STR}, /* freshclam */
107
+	    {"HTTPProxyPort", OPT_NUM}, /* freshclam */
108
+	    {"HTTPProxyUsername", OPT_STR}, /* freshclam */
109
+	    {"HTTPProxyPassword", OPT_STR}, /* freshclam */
110
+	    {"NotifyClamd", OPT_OPTARG}, /* freshclam */
111
+	    {"OnUpdateExecute", OPT_FULLSTR}, /* freshclam */
112
+	    {"OnErrorExecute", OPT_FULLSTR}, /* freshclam */
113
+	    {0, 0}
114
+	};
115
+
116
+
117
+    if((fs = fopen(cfgfile, "r")) == NULL) {
118
+	return NULL;
119
+    }
120
+
121
+
122
+    while(fgets(buff, LINE_LENGTH, fs)) {
123
+
124
+	line++;
125
+
126
+	if(buff[0] == '#')
127
+	    continue;
128
+
129
+	if(!strncmp("Example", buff, 7)) {
130
+	    fprintf(stderr, "ERROR: Please edit the example config file %s.\n", cfgfile);
131
+	    return NULL;
132
+	}
133
+
134
+
135
+	if((name = cli_strtok(buff, 0, " \r\n"))) {
136
+	    arg = cli_strtok(buff, 1, " \r\n");
137
+	    found = 0;
138
+	    for(i = 0; ; i++) {
139
+		pt = &cfg_options[i];
140
+		if(pt->name) {
141
+		    if(!strcmp(name, pt->name)) {
142
+			found = 1;
143
+			switch(pt->argtype) {
144
+			    case OPT_STR:
145
+				if(!arg) {
146
+				    fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string as argument.\n", line, name);
147
+				    return NULL;
148
+				}
149
+				copt = regcfg(copt, name, arg, 0);
150
+				break;
151
+			    case OPT_FULLSTR:
152
+				if(!arg) {
153
+				    fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string as argument.\n", line, name);
154
+				    return NULL;
155
+				}
156
+				/* FIXME: this one is an ugly hack of the above case */
157
+				free(arg);
158
+				arg = strstr(buff, " ");
159
+				arg = strdup(++arg);
160
+				copt = regcfg(copt, name, arg, 0);
161
+				break;
162
+			    case OPT_NUM:
163
+				if(!arg || !isnumb(arg)) {
164
+				    fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical argument.\n", line, name);
165
+				    return NULL;
166
+				}
167
+				copt = regcfg(copt, name, NULL, atoi(arg));
168
+				free(arg);
169
+				break;
170
+			    case OPT_COMPSIZE:
171
+				if(!arg) {
172
+				    fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires argument.\n", line, name);
173
+				    return NULL;
174
+				}
175
+				ctype = tolower(arg[strlen(arg) - 1]);
176
+				if(ctype == 'm' || ctype == 'k') {
177
+				    char *cpy = (char *) mcalloc(strlen(arg), sizeof(char));
178
+				    strncpy(cpy, arg, strlen(arg) - 1);
179
+				    if(!isnumb(cpy)) {
180
+					fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical (raw/K/M) argument.\n", line, name);
181
+					return NULL;
182
+				    }
183
+				    if(ctype == 'm')
184
+					calc = atoi(cpy) * 1024 * 1024;
185
+				    else
186
+					calc = atoi(cpy) * 1024;
187
+				    free(cpy);
188
+				} else {
189
+				    if(!isnumb(arg)) {
190
+					fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical (raw/K/M) argument.\n", line, name);
191
+					return NULL;
192
+				    }
193
+				    calc = atoi(arg);
194
+				}
195
+				copt = regcfg(copt, name, NULL, calc);
196
+				free(arg);
197
+				break;
198
+			    case OPT_NOARG:
199
+				if(arg) {
200
+				    fprintf(stderr, "ERROR: Parse error at line %d: Option %s doesn't support arguments (got '%s').\n", line, name, arg);
201
+				    return NULL;
202
+				}
203
+				copt = regcfg(copt, name, NULL, 0);
204
+				break;
205
+			    case OPT_OPTARG:
206
+				copt = regcfg(copt, name, arg, 0);
207
+				break;
208
+			    default:
209
+				fprintf(stderr, "ERROR: Parse error at line %d: Option %s is of unknown type %d\n", line, name, pt->argtype);
210
+				free(name);
211
+				free(arg);
212
+				break;
213
+			}
214
+		    }
215
+		} else
216
+		    break;
217
+	    } 
218
+
219
+	    if(!found) {
220
+		fprintf(stderr, "ERROR: Parse error at line %d: Unknown option %s.\n", line, name);
221
+		return NULL;
222
+	    }
223
+	}
224
+    }
225
+
226
+    fclose(fs);
227
+    return copt;
228
+}
229
+
230
+void freecfg(struct cfgstruct *copt)
231
+{
232
+    	struct cfgstruct *handler;
233
+    	struct cfgstruct *arg;
234
+
235
+    while (copt) {
236
+	arg = copt->nextarg;
237
+	while (arg) {
238
+	    if(arg->strarg) {
239
+		free(arg->optname);
240
+		free(arg->strarg);
241
+		handler = arg;
242
+		arg=arg->nextarg;
243
+		free(handler);
244
+	    }
245
+	}
246
+	if(copt->optname) {
247
+	    free(copt->optname);
248
+	}
249
+	if(copt->strarg) {
250
+	    free(copt->strarg);
251
+	}
252
+	handler = copt;
253
+	copt = copt->next;
254
+	free(handler);
255
+    }
256
+    return;
257
+}
258
+
259
+struct cfgstruct *regcfg(struct cfgstruct *copt, char *optname, char *strarg, int numarg)
260
+{
261
+	struct cfgstruct *newnode, *pt;
262
+
263
+    newnode = (struct cfgstruct *) mmalloc(sizeof(struct cfgstruct));
264
+    newnode->optname = optname;
265
+    newnode->nextarg = NULL;
266
+    newnode->next = NULL;
267
+
268
+    if(strarg)
269
+	newnode->strarg = strarg;
270
+    else {
271
+	newnode->strarg = NULL;
272
+	newnode->numarg = numarg;
273
+    }
274
+
275
+    if((pt = cfgopt(copt, optname))) {
276
+	while(pt->nextarg)
277
+	    pt = pt->nextarg;
278
+
279
+	pt->nextarg = newnode;
280
+	return copt;
281
+    } else {
282
+	newnode->next = copt;
283
+	return newnode;
284
+    }
285
+}
286
+
287
+struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname)
288
+{
289
+	struct cfgstruct *handler;
290
+
291
+    handler = (struct cfgstruct *) copt;
292
+
293
+    while(1) {
294
+	if(handler) {
295
+	    if(handler->optname)
296
+		if(!strcmp(handler->optname, optname))
297
+		    return handler;
298
+	} else break;
299
+	handler = handler->next;
300
+    }
301
+
302
+    return NULL;
303
+}
0 304
new file mode 100644
... ...
@@ -0,0 +1,54 @@
0
+/*
1
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
2
+ *
3
+ *  This program is free software; you can redistribute it and/or modify
4
+ *  it under the terms of the GNU General Public License as published by
5
+ *  the Free Software Foundation; either version 2 of the License, or
6
+ *  (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ */
17
+
18
+#ifndef __CFGPARSER_H
19
+#define __CFGPARSER_H
20
+
21
+#define LINE_LENGTH 1024
22
+
23
+
24
+#define OPT_STR 1 /* string argument */
25
+#define OPT_NUM 2 /* numerical argument */
26
+#define OPT_COMPSIZE 3 /* convert kilobytes (k) and megabytes (m) to bytes */
27
+#define OPT_NOARG 4 /* no argument */
28
+#define OPT_OPTARG 5 /* argument is optional, it's registered as string */
29
+#define OPT_FULLSTR 6 /* string argument, but get a full line */
30
+
31
+struct cfgoption {
32
+    const char *name;
33
+    int argtype;
34
+};
35
+
36
+struct cfgstruct {
37
+    char *optname;
38
+    char *strarg;
39
+    int numarg;
40
+    struct cfgstruct *nextarg;
41
+    struct cfgstruct *next;
42
+};
43
+
44
+
45
+struct cfgstruct *parsecfg(const char *cfgfile);
46
+
47
+struct cfgstruct *regcfg(struct cfgstruct *copt, char *optname, char *strarg, int numarg);
48
+
49
+struct cfgstruct *cfgopt(const struct cfgstruct *copt, const char *optname);
50
+
51
+void freecfg(struct cfgstruct *copt);
52
+
53
+#endif
0 54
new file mode 100644
... ...
@@ -0,0 +1,1020 @@
0
+/* Getopt for GNU.
1
+   NOTE: getopt is now part of the C library, so if you don't know what
2
+   "Keep this file name-space clean" means, talk to drepper@gnu.org
3
+   before changing it!
4
+
5
+   Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
6
+   	Free Software Foundation, Inc.
7
+
8
+   The GNU C Library is free software; you can redistribute it and/or
9
+   modify it under the terms of the GNU Library General Public License as
10
+   published by the Free Software Foundation; either version 2 of the
11
+   License, or (at your option) any later version.
12
+
13
+   The GNU C Library is distributed in the hope that it will be useful,
14
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+   Library General Public License for more details.
17
+
18
+   You should have received a copy of the GNU Library General Public
19
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
20
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
+   Boston, MA 02111-1307, USA.  */
22
+
23
+/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
24
+   Ditto for AIX 3.2 and <stdlib.h>.  */
25
+#ifndef _NO_PROTO
26
+# define _NO_PROTO
27
+#endif
28
+
29
+#ifdef HAVE_CONFIG_H
30
+# include <clamav-config.h>
31
+#endif
32
+
33
+#if !defined __STDC__ || !__STDC__
34
+/* This is a separate conditional since some stdc systems
35
+   reject `defined (const)'.  */
36
+# ifndef const
37
+#  define const
38
+# endif
39
+#endif
40
+
41
+#include <stdio.h>
42
+
43
+int strncmp(const char *s1, const char *s2, size_t n);
44
+
45
+/* Comment out all this code if we are using the GNU C Library, and are not
46
+   actually compiling the library itself.  This code is part of the GNU C
47
+   Library, but also included in many other GNU distributions.  Compiling
48
+   and linking in this code is a waste when using the GNU C library
49
+   (especially if it is a shared library).  Rather than having every GNU
50
+   program understand `configure --with-gnu-libc' and omit the object files,
51
+   it is simpler to just do this in the source for each such file.  */
52
+
53
+#define GETOPT_INTERFACE_VERSION 2
54
+#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
55
+# include <gnu-versions.h>
56
+# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
57
+#  define ELIDE_CODE
58
+# endif
59
+#endif
60
+
61
+#ifndef ELIDE_CODE
62
+
63
+
64
+/* This needs to come after some library #include
65
+   to get __GNU_LIBRARY__ defined.  */
66
+#ifdef	__GNU_LIBRARY__
67
+/* Don't include stdlib.h for non-GNU C libraries because some of them
68
+   contain conflicting prototypes for getopt.  */
69
+# include <stdlib.h>
70
+# include <unistd.h>
71
+#endif	/* GNU C library.  */
72
+
73
+#ifdef VMS
74
+# include <unixlib.h>
75
+# if HAVE_STRING_H - 0
76
+#  include <string.h>
77
+# endif
78
+#endif
79
+
80
+#ifndef _
81
+/* This is for other GNU distributions with internationalized messages.  */
82
+# if defined HAVE_LIBINTL_H || defined _LIBC
83
+#  include <libintl.h>
84
+#  ifndef _
85
+#   define _(msgid)	gettext (msgid)
86
+#  endif
87
+# else
88
+#  define _(msgid)	(msgid)
89
+# endif
90
+#endif
91
+
92
+/* This version of `getopt' appears to the caller like standard Unix `getopt'
93
+   but it behaves differently for the user, since it allows the user
94
+   to intersperse the options with the other arguments.
95
+
96
+   As `getopt' works, it permutes the elements of ARGV so that,
97
+   when it is done, all the options precede everything else.  Thus
98
+   all application programs are extended to handle flexible argument order.
99
+
100
+   Setting the environment variable POSIXLY_CORRECT disables permutation.
101
+   Then the behavior is completely standard.
102
+
103
+   GNU application programs can use a third alternative mode in which
104
+   they can distinguish the relative order of options and other arguments.  */
105
+
106
+#include "getopt.h"
107
+
108
+/* For communication from `getopt' to the caller.
109
+   When `getopt' finds an option that takes an argument,
110
+   the argument value is returned here.
111
+   Also, when `ordering' is RETURN_IN_ORDER,
112
+   each non-option ARGV-element is returned here.  */
113
+
114
+char *optarg;
115
+
116
+/* Index in ARGV of the next element to be scanned.
117
+   This is used for communication to and from the caller
118
+   and for communication between successive calls to `getopt'.
119
+
120
+   On entry to `getopt', zero means this is the first call; initialize.
121
+
122
+   When `getopt' returns -1, this is the index of the first of the
123
+   non-option elements that the caller should itself scan.
124
+
125
+   Otherwise, `optind' communicates from one call to the next
126
+   how much of ARGV has been scanned so far.  */
127
+
128
+/* 1003.2 says this must be 1 before any call.  */
129
+int optind = 1;
130
+
131
+/* Formerly, initialization of getopt depended on optind==0, which
132
+   causes problems with re-calling getopt as programs generally don't
133
+   know that. */
134
+
135
+int __getopt_initialized;
136
+
137
+/* The next char to be scanned in the option-element
138
+   in which the last option character we returned was found.
139
+   This allows us to pick up the scan where we left off.
140
+
141
+   If this is zero, or a null string, it means resume the scan
142
+   by advancing to the next ARGV-element.  */
143
+
144
+static char *nextchar;
145
+
146
+/* Callers store zero here to inhibit the error message
147
+   for unrecognized options.  */
148
+
149
+int opterr = 1;
150
+
151
+/* Set to an option character which was unrecognized.
152
+   This must be initialized on some systems to avoid linking in the
153
+   system's own getopt implementation.  */
154
+
155
+int optopt = '?';
156
+
157
+/* Describe how to deal with options that follow non-option ARGV-elements.
158
+
159
+   If the caller did not specify anything,
160
+   the default is REQUIRE_ORDER if the environment variable
161
+   POSIXLY_CORRECT is defined, PERMUTE otherwise.
162
+
163
+   REQUIRE_ORDER means don't recognize them as options;
164
+   stop option processing when the first non-option is seen.
165
+   This is what Unix does.
166
+   This mode of operation is selected by either setting the environment
167
+   variable POSIXLY_CORRECT, or using `+' as the first character
168
+   of the list of option characters.
169
+
170
+   PERMUTE is the default.  We permute the contents of ARGV as we scan,
171
+   so that eventually all the non-options are at the end.  This allows options
172
+   to be given in any order, even with programs that were not written to
173
+   expect this.
174
+
175
+   RETURN_IN_ORDER is an option available to programs that were written
176
+   to expect options and other ARGV-elements in any order and that care about
177
+   the ordering of the two.  We describe each non-option ARGV-element
178
+   as if it were the argument of an option with character code 1.
179
+   Using `-' as the first character of the list of option characters
180
+   selects this mode of operation.
181
+
182
+   The special argument `--' forces an end of option-scanning regardless
183
+   of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
184
+   `--' can cause `getopt' to return -1 with `optind' != ARGC.  */
185
+
186
+static enum
187
+{
188
+  REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
189
+} ordering;
190
+
191
+/* Value of POSIXLY_CORRECT environment variable.  */
192
+static char *posixly_correct;
193
+
194
+#ifdef	__GNU_LIBRARY__
195
+/* We want to avoid inclusion of string.h with non-GNU libraries
196
+   because there are many ways it can cause trouble.
197
+   On some systems, it contains special magic macros that don't work
198
+   in GCC.  */
199
+# include <string.h>
200
+# define my_index	strchr
201
+#else
202
+
203
+# if HAVE_STRING_H
204
+#  include <string.h>
205
+# else
206
+#  include <strings.h>
207
+# endif
208
+
209
+/* Avoid depending on library functions or files
210
+   whose names are inconsistent.  */
211
+
212
+#ifndef getenv
213
+extern char *getenv ();
214
+#endif
215
+
216
+static char *
217
+my_index (str, chr)
218
+     const char *str;
219
+     int chr;
220
+{
221
+  while (*str)
222
+    {
223
+      if (*str == chr)
224
+	return (char *) str;
225
+      str++;
226
+    }
227
+  return 0;
228
+}
229
+
230
+/* If using GCC, we can safely declare strlen this way.
231
+   If not using GCC, it is ok not to declare it.  */
232
+#ifdef __GNUC__
233
+/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
234
+   That was relevant to code that was here before.  */
235
+# if (!defined __STDC__ || !__STDC__) && !defined strlen
236
+/* gcc with -traditional declares the built-in strlen to return int,
237
+   and has done so at least since version 2.4.5. -- rms.  */
238
+extern int strlen (const char *);
239
+# endif /* not __STDC__ */
240
+#endif /* __GNUC__ */
241
+
242
+#endif /* not __GNU_LIBRARY__ */
243
+
244
+/* Handle permutation of arguments.  */
245
+
246
+/* Describe the part of ARGV that contains non-options that have
247
+   been skipped.  `first_nonopt' is the index in ARGV of the first of them;
248
+   `last_nonopt' is the index after the last of them.  */
249
+
250
+static int first_nonopt;
251
+static int last_nonopt;
252
+
253
+#ifdef _LIBC
254
+/* Bash 2.0 gives us an environment variable containing flags
255
+   indicating ARGV elements that should not be considered arguments.  */
256
+
257
+/* Defined in getopt_init.c  */
258
+extern char *__getopt_nonoption_flags;
259
+
260
+static int nonoption_flags_max_len;
261
+static int nonoption_flags_len;
262
+
263
+static int original_argc;
264
+static char *const *original_argv;
265
+
266
+/* Make sure the environment variable bash 2.0 puts in the environment
267
+   is valid for the getopt call we must make sure that the ARGV passed
268
+   to getopt is that one passed to the process.  */
269
+static void
270
+__attribute__ ((unused))
271
+store_args_and_env (int argc, char *const *argv)
272
+{
273
+  /* XXX This is no good solution.  We should rather copy the args so
274
+     that we can compare them later.  But we must not use malloc(3).  */
275
+  original_argc = argc;
276
+  original_argv = argv;
277
+}
278
+# ifdef text_set_element
279
+text_set_element (__libc_subinit, store_args_and_env);
280
+# endif /* text_set_element */
281
+
282
+# define SWAP_FLAGS(ch1, ch2) \
283
+  if (nonoption_flags_len > 0)						      \
284
+    {									      \
285
+      char __tmp = __getopt_nonoption_flags[ch1];			      \
286
+      __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2];	      \
287
+      __getopt_nonoption_flags[ch2] = __tmp;				      \
288
+    }
289
+#else	/* !_LIBC */
290
+# define SWAP_FLAGS(ch1, ch2)
291
+#endif	/* _LIBC */
292
+
293
+/* Exchange two adjacent subsequences of ARGV.
294
+   One subsequence is elements [first_nonopt,last_nonopt)
295
+   which contains all the non-options that have been skipped so far.
296
+   The other is elements [last_nonopt,optind), which contains all
297
+   the options processed since those non-options were skipped.
298
+
299
+   `first_nonopt' and `last_nonopt' are relocated so that they describe
300
+   the new indices of the non-options in ARGV after they are moved.  */
301
+
302
+#if defined __STDC__ && __STDC__
303
+static void exchange (char **);
304
+#endif
305
+
306
+static void
307
+exchange (argv)
308
+     char **argv;
309
+{
310
+  int bottom = first_nonopt;
311
+  int middle = last_nonopt;
312
+  int top = optind;
313
+  char *tem;
314
+
315
+  /* Exchange the shorter segment with the far end of the longer segment.
316
+     That puts the shorter segment into the right place.
317
+     It leaves the longer segment in the right place overall,
318
+     but it consists of two parts that need to be swapped next.  */
319
+
320
+#ifdef _LIBC
321
+  /* First make sure the handling of the `__getopt_nonoption_flags'
322
+     string can work normally.  Our top argument must be in the range
323
+     of the string.  */
324
+  if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
325
+    {
326
+      /* We must extend the array.  The user plays games with us and
327
+	 presents new arguments.  */
328
+      char *new_str = malloc (top + 1);
329
+      if (new_str == NULL)
330
+	nonoption_flags_len = nonoption_flags_max_len = 0;
331
+      else
332
+	{
333
+	  memset (__mempcpy (new_str, __getopt_nonoption_flags,
334
+			     nonoption_flags_max_len),
335
+		  '\0', top + 1 - nonoption_flags_max_len);
336
+	  nonoption_flags_max_len = top + 1;
337
+	  __getopt_nonoption_flags = new_str;
338
+	}
339
+    }
340
+#endif
341
+
342
+  while (top > middle && middle > bottom)
343
+    {
344
+      if (top - middle > middle - bottom)
345
+	{
346
+	  /* Bottom segment is the short one.  */
347
+	  int len = middle - bottom;
348
+	  register int i;
349
+
350
+	  /* Swap it with the top part of the top segment.  */
351
+	  for (i = 0; i < len; i++)
352
+	    {
353
+	      tem = argv[bottom + i];
354
+	      argv[bottom + i] = argv[top - (middle - bottom) + i];
355
+	      argv[top - (middle - bottom) + i] = tem;
356
+	      SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
357
+	    }
358
+	  /* Exclude the moved bottom segment from further swapping.  */
359
+	  top -= len;
360
+	}
361
+      else
362
+	{
363
+	  /* Top segment is the short one.  */
364
+	  int len = top - middle;
365
+	  register int i;
366
+
367
+	  /* Swap it with the bottom part of the bottom segment.  */
368
+	  for (i = 0; i < len; i++)
369
+	    {
370
+	      tem = argv[bottom + i];
371
+	      argv[bottom + i] = argv[middle + i];
372
+	      argv[middle + i] = tem;
373
+	      SWAP_FLAGS (bottom + i, middle + i);
374
+	    }
375
+	  /* Exclude the moved top segment from further swapping.  */
376
+	  bottom += len;
377
+	}
378
+    }
379
+
380
+  /* Update records for the slots the non-options now occupy.  */
381
+
382
+  first_nonopt += (optind - last_nonopt);
383
+  last_nonopt = optind;
384
+}
385
+
386
+/* Initialize the internal data when the first call is made.  */
387
+
388
+#if defined __STDC__ && __STDC__
389
+static const char *_getopt_initialize (int, char *const *, const char *);
390
+#endif
391
+static const char *
392
+_getopt_initialize (argc, argv, optstring)
393
+     int argc;
394
+     char *const *argv;
395
+     const char *optstring;
396
+{
397
+  /* Start processing options with ARGV-element 1 (since ARGV-element 0
398
+     is the program name); the sequence of previously skipped
399
+     non-option ARGV-elements is empty.  */
400
+
401
+  first_nonopt = last_nonopt = optind;
402
+
403
+  nextchar = NULL;
404
+
405
+  posixly_correct = getenv ("POSIXLY_CORRECT");
406
+
407
+  /* Determine how to handle the ordering of options and nonoptions.  */
408
+
409
+  if (optstring[0] == '-')
410
+    {
411
+      ordering = RETURN_IN_ORDER;
412
+      ++optstring;
413
+    }
414
+  else if (optstring[0] == '+')
415
+    {
416
+      ordering = REQUIRE_ORDER;
417
+      ++optstring;
418
+    }
419
+  else if (posixly_correct != NULL)
420
+    ordering = REQUIRE_ORDER;
421
+  else
422
+    ordering = PERMUTE;
423
+
424
+#ifdef _LIBC
425
+  if (posixly_correct == NULL
426
+      && argc == original_argc && argv == original_argv)
427
+    {
428
+      if (nonoption_flags_max_len == 0)
429
+	{
430
+	  if (__getopt_nonoption_flags == NULL
431
+	      || __getopt_nonoption_flags[0] == '\0')
432
+	    nonoption_flags_max_len = -1;
433
+	  else
434
+	    {
435
+	      const char *orig_str = __getopt_nonoption_flags;
436
+	      int len = nonoption_flags_max_len = strlen (orig_str);
437
+	      if (nonoption_flags_max_len < argc)
438
+		nonoption_flags_max_len = argc;
439
+	      __getopt_nonoption_flags =
440
+		(char *) malloc (nonoption_flags_max_len);
441
+	      if (__getopt_nonoption_flags == NULL)
442
+		nonoption_flags_max_len = -1;
443
+	      else
444
+		memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
445
+			'\0', nonoption_flags_max_len - len);
446
+	    }
447
+	}
448
+      nonoption_flags_len = nonoption_flags_max_len;
449
+    }
450
+  else
451
+    nonoption_flags_len = 0;
452
+#endif
453
+
454
+  return optstring;
455
+}
456
+
457
+/* Scan elements of ARGV (whose length is ARGC) for option characters
458
+   given in OPTSTRING.
459
+
460
+   If an element of ARGV starts with '-', and is not exactly "-" or "--",
461
+   then it is an option element.  The characters of this element
462
+   (aside from the initial '-') are option characters.  If `getopt'
463
+   is called repeatedly, it returns successively each of the option characters
464
+   from each of the option elements.
465
+
466
+   If `getopt' finds another option character, it returns that character,
467
+   updating `optind' and `nextchar' so that the next call to `getopt' can
468
+   resume the scan with the following option character or ARGV-element.
469
+
470
+   If there are no more option characters, `getopt' returns -1.
471
+   Then `optind' is the index in ARGV of the first ARGV-element
472
+   that is not an option.  (The ARGV-elements have been permuted
473
+   so that those that are not options now come last.)
474
+
475
+   OPTSTRING is a string containing the legitimate option characters.
476
+   If an option character is seen that is not listed in OPTSTRING,
477
+   return '?' after printing an error message.  If you set `opterr' to
478
+   zero, the error message is suppressed but we still return '?'.
479
+
480
+   If a char in OPTSTRING is followed by a colon, that means it wants an arg,
481
+   so the following text in the same ARGV-element, or the text of the following
482
+   ARGV-element, is returned in `optarg'.  Two colons mean an option that
483
+   wants an optional arg; if there is text in the current ARGV-element,
484
+   it is returned in `optarg', otherwise `optarg' is set to zero.
485
+
486
+   If OPTSTRING starts with `-' or `+', it requests different methods of
487
+   handling the non-option ARGV-elements.
488
+   See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
489
+
490
+   Long-named options begin with `--' instead of `-'.
491
+   Their names may be abbreviated as long as the abbreviation is unique
492
+   or is an exact match for some defined option.  If they have an
493
+   argument, it follows the option name in the same ARGV-element, separated
494
+   from the option name by a `=', or else the in next ARGV-element.
495
+   When `getopt' finds a long-named option, it returns 0 if that option's
496
+   `flag' field is nonzero, the value of the option's `val' field
497
+   if the `flag' field is zero.
498
+
499
+   The elements of ARGV aren't really const, because we permute them.
500
+   But we pretend they're const in the prototype to be compatible
501
+   with other systems.
502
+
503
+   LONGOPTS is a vector of `struct option' terminated by an
504
+   element containing a name which is zero.
505
+
506
+   LONGIND returns the index in LONGOPT of the long-named option found.
507
+   It is only valid when a long-named option has been found by the most
508
+   recent call.
509
+
510
+   If LONG_ONLY is nonzero, '-' as well as '--' can introduce
511
+   long-named options.  */
512
+
513
+int
514
+_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
515
+     int argc;
516
+     char *const *argv;
517
+     const char *optstring;
518
+     const struct option *longopts;
519
+     int *longind;
520
+     int long_only;
521
+{
522
+  int print_errors = opterr;
523
+  if (optstring[0] == ':')
524
+    print_errors = 0;
525
+
526
+  if (argc < 1)
527
+    return -1;
528
+
529
+  optarg = NULL;
530
+
531
+  if (optind == 0 || !__getopt_initialized)
532
+    {
533
+      if (optind == 0)
534
+	optind = 1;	/* Don't scan ARGV[0], the program name.  */
535
+      optstring = _getopt_initialize (argc, argv, optstring);
536
+      __getopt_initialized = 1;
537
+    }
538
+
539
+  /* Test whether ARGV[optind] points to a non-option argument.
540
+     Either it does not have option syntax, or there is an environment flag
541
+     from the shell indicating it is not an option.  The later information
542
+     is only used when the used in the GNU libc.  */
543
+#ifdef _LIBC
544
+# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0'	      \
545
+		      || (optind < nonoption_flags_len			      \
546
+			  && __getopt_nonoption_flags[optind] == '1'))
547
+#else
548
+# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
549
+#endif
550
+
551
+  if (nextchar == NULL || *nextchar == '\0')
552
+    {
553
+      /* Advance to the next ARGV-element.  */
554
+
555
+      /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
556
+	 moved back by the user (who may also have changed the arguments).  */
557
+      if (last_nonopt > optind)
558
+	last_nonopt = optind;
559
+      if (first_nonopt > optind)
560
+	first_nonopt = optind;
561
+
562
+      if (ordering == PERMUTE)
563
+	{
564
+	  /* If we have just processed some options following some non-options,
565
+	     exchange them so that the options come first.  */
566
+
567
+	  if (first_nonopt != last_nonopt && last_nonopt != optind)
568
+	    exchange ((char **) argv);
569
+	  else if (last_nonopt != optind)
570
+	    first_nonopt = optind;
571
+
572
+	  /* Skip any additional non-options
573
+	     and extend the range of non-options previously skipped.  */
574
+
575
+	  while (optind < argc && NONOPTION_P)
576
+	    optind++;
577
+	  last_nonopt = optind;
578
+	}
579
+
580
+      /* The special ARGV-element `--' means premature end of options.
581
+	 Skip it like a null option,
582
+	 then exchange with previous non-options as if it were an option,
583
+	 then skip everything else like a non-option.  */
584
+
585
+      if (optind != argc && !strcmp (argv[optind], "--"))
586
+	{
587
+	  optind++;
588
+
589
+	  if (first_nonopt != last_nonopt && last_nonopt != optind)
590
+	    exchange ((char **) argv);
591
+	  else if (first_nonopt == last_nonopt)
592
+	    first_nonopt = optind;
593
+	  last_nonopt = argc;
594
+
595
+	  optind = argc;
596
+	}
597
+
598
+      /* If we have done all the ARGV-elements, stop the scan
599
+	 and back over any non-options that we skipped and permuted.  */
600
+
601
+      if (optind == argc)
602
+	{
603
+	  /* Set the next-arg-index to point at the non-options
604
+	     that we previously skipped, so the caller will digest them.  */
605
+	  if (first_nonopt != last_nonopt)
606
+	    optind = first_nonopt;
607
+	  return -1;
608
+	}
609
+
610
+      /* If we have come to a non-option and did not permute it,
611
+	 either stop the scan or describe it to the caller and pass it by.  */
612
+
613
+      if (NONOPTION_P)
614
+	{
615
+	  if (ordering == REQUIRE_ORDER)
616
+	    return -1;
617
+	  optarg = argv[optind++];
618
+	  return 1;
619
+	}
620
+
621
+      /* We have found another option-ARGV-element.
622
+	 Skip the initial punctuation.  */
623
+
624
+      nextchar = (argv[optind] + 1
625
+		  + (longopts != NULL && argv[optind][1] == '-'));
626
+    }
627
+
628
+  /* Decode the current option-ARGV-element.  */
629
+
630
+  /* Check whether the ARGV-element is a long option.
631
+
632
+     If long_only and the ARGV-element has the form "-f", where f is
633
+     a valid short option, don't consider it an abbreviated form of
634
+     a long option that starts with f.  Otherwise there would be no
635
+     way to give the -f short option.
636
+
637
+     On the other hand, if there's a long option "fubar" and
638
+     the ARGV-element is "-fu", do consider that an abbreviation of
639
+     the long option, just like "--fu", and not "-f" with arg "u".
640
+
641
+     This distinction seems to be the most useful approach.  */
642
+
643
+  if (longopts != NULL
644
+      && (argv[optind][1] == '-'
645
+	  || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
646
+    {
647
+      char *nameend;
648
+      const struct option *p;
649
+      const struct option *pfound = NULL;
650
+      int exact = 0;
651
+      int ambig = 0;
652
+      int indfound = -1;
653
+      int option_index;
654
+
655
+      for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
656
+	/* Do nothing.  */ ;
657
+
658
+      /* Test all long options for either exact match
659
+	 or abbreviated matches.  */
660
+      for (p = longopts, option_index = 0; p->name; p++, option_index++)
661
+	if (!strncmp (p->name, nextchar, nameend - nextchar))
662
+	  {
663
+	    if ((unsigned int) (nameend - nextchar)
664
+		== (unsigned int) strlen (p->name))
665
+	      {
666
+		/* Exact match found.  */
667
+		pfound = p;
668
+		indfound = option_index;
669
+		exact = 1;
670
+		break;
671
+	      }
672
+	    else if (pfound == NULL)
673
+	      {
674
+		/* First nonexact match found.  */
675
+		pfound = p;
676
+		indfound = option_index;
677
+	      }
678
+	    else if (long_only
679
+		     || pfound->has_arg != p->has_arg
680
+		     || pfound->flag != p->flag
681
+		     || pfound->val != p->val)
682
+	      /* Second or later nonexact match found.  */
683
+	      ambig = 1;
684
+	  }
685
+
686
+      if (ambig && !exact)
687
+	{
688
+	  if (print_errors)
689
+	    fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
690
+		     argv[0], argv[optind]);
691
+	  nextchar += strlen (nextchar);
692
+	  optind++;
693
+	  optopt = 0;
694
+	  return '?';
695
+	}
696
+
697
+      if (pfound != NULL)
698
+	{
699
+	  option_index = indfound;
700
+	  optind++;
701
+	  if (*nameend)
702
+	    {
703
+	      /* Don't test has_arg with >, because some C compilers don't
704
+		 allow it to be used on enums.  */
705
+	      if (pfound->has_arg)
706
+		optarg = nameend + 1;
707
+	      else
708
+		{
709
+		  if (print_errors)
710
+		    {
711
+		      if (argv[optind - 1][1] == '-')
712
+			/* --option */
713
+			fprintf (stderr,
714
+				 _("%s: option `--%s' doesn't allow an argument\n"),
715
+				 argv[0], pfound->name);
716
+		      else
717
+			/* +option or -option */
718
+			fprintf (stderr,
719
+				 _("%s: option `%c%s' doesn't allow an argument\n"),
720
+				 argv[0], argv[optind - 1][0], pfound->name);
721
+		    }
722
+
723
+		  nextchar += strlen (nextchar);
724
+
725
+		  optopt = pfound->val;
726
+		  return '?';
727
+		}
728
+	    }
729
+	  else if (pfound->has_arg == 1)
730
+	    {
731
+	      if (optind < argc)
732
+		optarg = argv[optind++];
733
+	      else
734
+		{
735
+		  if (print_errors)
736
+		    fprintf (stderr,
737
+			   _("%s: option `%s' requires an argument\n"),
738
+			   argv[0], argv[optind - 1]);
739
+		  nextchar += strlen (nextchar);
740
+		  optopt = pfound->val;
741
+		  return optstring[0] == ':' ? ':' : '?';
742
+		}
743
+	    }
744
+	  nextchar += strlen (nextchar);
745
+	  if (longind != NULL)
746
+	    *longind = option_index;
747
+	  if (pfound->flag)
748
+	    {
749
+	      *(pfound->flag) = pfound->val;
750
+	      return 0;
751
+	    }
752
+	  return pfound->val;
753
+	}
754
+
755
+      /* Can't find it as a long option.  If this is not getopt_long_only,
756
+	 or the option starts with '--' or is not a valid short
757
+	 option, then it's an error.
758
+	 Otherwise interpret it as a short option.  */
759
+      if (!long_only || argv[optind][1] == '-'
760
+	  || my_index (optstring, *nextchar) == NULL)
761
+	{
762
+	  if (print_errors)
763
+	    {
764
+	      if (argv[optind][1] == '-')
765
+		/* --option */
766
+		fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
767
+			 argv[0], nextchar);
768
+	      else
769
+		/* +option or -option */
770
+		fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
771
+			 argv[0], argv[optind][0], nextchar);
772
+	    }
773
+	  nextchar = (char *) "";
774
+	  optind++;
775
+	  optopt = 0;
776
+	  return '?';
777
+	}
778
+    }
779
+
780
+  /* Look at and handle the next short option-character.  */
781
+
782
+  {
783
+    char c = *nextchar++;
784
+    char *temp = my_index (optstring, c);
785
+
786
+    /* Increment `optind' when we start to process its last character.  */
787
+    if (*nextchar == '\0')
788
+      ++optind;
789
+
790
+    if (temp == NULL || c == ':')
791
+      {
792
+	if (print_errors)
793
+	  {
794
+	    if (posixly_correct)
795
+	      /* 1003.2 specifies the format of this message.  */
796
+	      fprintf (stderr, _("%s: illegal option -- %c\n"),
797
+		       argv[0], c);
798
+	    else
799
+	      fprintf (stderr, _("%s: invalid option -- %c\n"),
800
+		       argv[0], c);
801
+	  }
802
+	optopt = c;
803
+	return '?';
804
+      }
805
+    /* Convenience. Treat POSIX -W foo same as long option --foo */
806
+    if (temp[0] == 'W' && temp[1] == ';')
807
+      {
808
+	char *nameend;
809
+	const struct option *p;
810
+	const struct option *pfound = NULL;
811
+	int exact = 0;
812
+	int ambig = 0;
813
+	int indfound = 0;
814
+	int option_index;
815
+
816
+	/* This is an option that requires an argument.  */
817
+	if (*nextchar != '\0')
818
+	  {
819
+	    optarg = nextchar;
820
+	    /* If we end this ARGV-element by taking the rest as an arg,
821
+	       we must advance to the next element now.  */
822
+	    optind++;
823
+	  }
824
+	else if (optind == argc)
825
+	  {
826
+	    if (print_errors)
827
+	      {
828
+		/* 1003.2 specifies the format of this message.  */
829
+		fprintf (stderr, _("%s: option requires an argument -- %c\n"),
830
+			 argv[0], c);
831
+	      }
832
+	    optopt = c;
833
+	    if (optstring[0] == ':')
834
+	      c = ':';
835
+	    else
836
+	      c = '?';
837
+	    return c;
838
+	  }
839
+	else
840
+	  /* We already incremented `optind' once;
841
+	     increment it again when taking next ARGV-elt as argument.  */
842
+	  optarg = argv[optind++];
843
+
844
+	/* optarg is now the argument, see if it's in the
845
+	   table of longopts.  */
846
+
847
+	for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
848
+	  /* Do nothing.  */ ;
849
+
850
+	/* Test all long options for either exact match
851
+	   or abbreviated matches.  */
852
+	for (p = longopts, option_index = 0; p->name; p++, option_index++)
853
+	  if (!strncmp (p->name, nextchar, nameend - nextchar))
854
+	    {
855
+	      if ((unsigned int) (nameend - nextchar) == strlen (p->name))
856
+		{
857
+		  /* Exact match found.  */
858
+		  pfound = p;
859
+		  indfound = option_index;
860
+		  exact = 1;
861
+		  break;
862
+		}
863
+	      else if (pfound == NULL)
864
+		{
865
+		  /* First nonexact match found.  */
866
+		  pfound = p;
867
+		  indfound = option_index;
868
+		}
869
+	      else
870
+		/* Second or later nonexact match found.  */
871
+		ambig = 1;
872
+	    }
873
+	if (ambig && !exact)
874
+	  {
875
+	    if (print_errors)
876
+	      fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
877
+		       argv[0], argv[optind]);
878
+	    nextchar += strlen (nextchar);
879
+	    optind++;
880
+	    return '?';
881
+	  }
882
+	if (pfound != NULL)
883
+	  {
884
+	    option_index = indfound;
885
+	    if (*nameend)
886
+	      {
887
+		/* Don't test has_arg with >, because some C compilers don't
888
+		   allow it to be used on enums.  */
889
+		if (pfound->has_arg)
890
+		  optarg = nameend + 1;
891
+		else
892
+		  {
893
+		    if (print_errors)
894
+		      fprintf (stderr, _("\
895
+%s: option `-W %s' doesn't allow an argument\n"),
896
+			       argv[0], pfound->name);
897
+
898
+		    nextchar += strlen (nextchar);
899
+		    return '?';
900
+		  }
901
+	      }
902
+	    else if (pfound->has_arg == 1)
903
+	      {
904
+		if (optind < argc)
905
+		  optarg = argv[optind++];
906
+		else
907
+		  {
908
+		    if (print_errors)
909
+		      fprintf (stderr,
910
+			       _("%s: option `%s' requires an argument\n"),
911
+			       argv[0], argv[optind - 1]);
912
+		    nextchar += strlen (nextchar);
913
+		    return optstring[0] == ':' ? ':' : '?';
914
+		  }
915
+	      }
916
+	    nextchar += strlen (nextchar);
917
+	    if (longind != NULL)
918
+	      *longind = option_index;
919
+	    if (pfound->flag)
920
+	      {
921
+		*(pfound->flag) = pfound->val;
922
+		return 0;
923
+	      }
924
+	    return pfound->val;
925
+	  }
926
+	  nextchar = NULL;
927
+	  return 'W';	/* Let the application handle it.   */
928
+      }
929
+    if (temp[1] == ':')
930
+      {
931
+	if (temp[2] == ':')
932
+	  {
933
+	    /* This is an option that accepts an argument optionally.  */
934
+	    if (*nextchar != '\0')
935
+	      {
936
+		optarg = nextchar;
937
+		optind++;
938
+	      }
939
+	    else
940
+	      optarg = NULL;
941
+	    nextchar = NULL;
942
+	  }
943
+	else
944
+	  {
945
+	    /* This is an option that requires an argument.  */
946
+	    if (*nextchar != '\0')
947
+	      {
948
+		optarg = nextchar;
949
+		/* If we end this ARGV-element by taking the rest as an arg,
950
+		   we must advance to the next element now.  */
951
+		optind++;
952
+	      }
953
+	    else if (optind == argc)
954
+	      {
955
+		if (print_errors)
956
+		  {
957
+		    /* 1003.2 specifies the format of this message.  */
958
+		    fprintf (stderr,
959
+			     _("%s: option requires an argument -- %c\n"),
960
+			     argv[0], c);
961
+		  }
962
+		optopt = c;
963
+		if (optstring[0] == ':')
964
+		  c = ':';
965
+		else
966
+		  c = '?';
967
+	      }
968
+	    else
969
+	      /* We already incremented `optind' once;
970
+		 increment it again when taking next ARGV-elt as argument.  */
971
+	      optarg = argv[optind++];
972
+	    nextchar = NULL;
973
+	  }
974
+      }
975
+    return c;
976
+  }
977
+}
978
+
979
+int
980
+getopt (argc, argv, optstring)
981
+     int argc;
982
+     char *const *argv;
983
+     const char *optstring;
984
+{
985
+  return _getopt_internal (argc, argv, optstring,
986
+			   (const struct option *) 0,
987
+			   (int *) 0,
988
+			   0);
989
+}
990
+
991
+
992
+int
993
+getopt_long (argc, argv, options, long_options, opt_index)
994
+     int argc;
995
+     char *const *argv;
996
+     const char *options;
997
+     const struct option *long_options;
998
+     int *opt_index;
999
+{
1000
+  return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
1001
+}
1002
+
1003
+/* Like getopt_long, but '-' as well as '--' can indicate a long option.
1004
+   If an option that starts with '-' (not '--') doesn't match a long option,
1005
+   but does match a short option, it is parsed as a short option
1006
+   instead.  */
1007
+
1008
+int
1009
+getopt_long_only (argc, argv, options, long_options, opt_index)
1010
+     int argc;
1011
+     char *const *argv;
1012
+     const char *options;
1013
+     const struct option *long_options;
1014
+     int *opt_index;
1015
+{
1016
+  return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
1017
+}
1018
+
1019
+#endif	/* Not ELIDE_CODE.  */
0 1020
new file mode 100644
... ...
@@ -0,0 +1,180 @@
0
+/* Declarations for getopt.
1
+   Copyright (C) 1989,90,91,92,93,94,96,97,98,99 Free Software Foundation, Inc.
2
+   This file is part of the GNU C Library.
3
+
4
+   The GNU C Library is free software; you can redistribute it and/or
5
+   modify it under the terms of the GNU Library General Public License as
6
+   published by the Free Software Foundation; either version 2 of the
7
+   License, or (at your option) any later version.
8
+
9
+   The GNU C Library 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 GNU
12
+   Library General Public License for more details.
13
+
14
+   You should have received a copy of the GNU Library General Public
15
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
16
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
+   Boston, MA 02111-1307, USA.  */
18
+
19
+#ifndef _GETOPT_H
20
+
21
+#ifndef __need_getopt
22
+# define _GETOPT_H 1
23
+#endif
24
+
25
+/* If __GNU_LIBRARY__ is not already defined, either we are being used
26
+   standalone, or this is the first header included in the source file.
27
+   If we are being used with glibc, we need to include <features.h>, but
28
+   that does not exist if we are standalone.  So: if __GNU_LIBRARY__ is
29
+   not defined, include <ctype.h>, which will pull in <features.h> for us
30
+   if it's from glibc.  (Why ctype.h?  It's guaranteed to exist and it
31
+   doesn't flood the namespace with stuff the way some other headers do.)  */
32
+#if !defined __GNU_LIBRARY__
33
+# include <ctype.h>
34
+#endif
35
+
36
+#ifdef	__cplusplus
37
+extern "C" {
38
+#endif
39
+
40
+/* For communication from `getopt' to the caller.
41
+   When `getopt' finds an option that takes an argument,
42
+   the argument value is returned here.
43
+   Also, when `ordering' is RETURN_IN_ORDER,
44
+   each non-option ARGV-element is returned here.  */
45
+
46
+extern char *optarg;
47
+
48
+/* Index in ARGV of the next element to be scanned.
49
+   This is used for communication to and from the caller
50
+   and for communication between successive calls to `getopt'.
51
+
52
+   On entry to `getopt', zero means this is the first call; initialize.
53
+
54
+   When `getopt' returns -1, this is the index of the first of the
55
+   non-option elements that the caller should itself scan.
56
+
57
+   Otherwise, `optind' communicates from one call to the next
58
+   how much of ARGV has been scanned so far.  */
59
+
60
+extern int optind;
61
+
62
+/* Callers store zero here to inhibit the error message `getopt' prints
63
+   for unrecognized options.  */
64
+
65
+extern int opterr;
66
+
67
+/* Set to an option character which was unrecognized.  */
68
+
69
+extern int optopt;
70
+
71
+#ifndef __need_getopt
72
+/* Describe the long-named options requested by the application.
73
+   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
74
+   of `struct option' terminated by an element containing a name which is
75
+   zero.
76
+
77
+   The field `has_arg' is:
78
+   no_argument		(or 0) if the option does not take an argument,
79
+   required_argument	(or 1) if the option requires an argument,
80
+   optional_argument 	(or 2) if the option takes an optional argument.
81
+
82
+   If the field `flag' is not NULL, it points to a variable that is set
83
+   to the value given in the field `val' when the option is found, but
84
+   left unchanged if the option is not found.
85
+
86
+   To have a long-named option do something other than set an `int' to
87
+   a compiled-in constant, such as set a value from `optarg', set the
88
+   option's `flag' field to zero and its `val' field to a nonzero
89
+   value (the equivalent single-letter option character, if there is
90
+   one).  For long options that have a zero `flag' field, `getopt'
91
+   returns the contents of the `val' field.  */
92
+
93
+struct option
94
+{
95
+# if defined __STDC__ && __STDC__
96
+  const char *name;
97
+# else
98
+  char *name;
99
+# endif
100
+  /* has_arg can't be an enum because some compilers complain about
101
+     type mismatches in all the code that assumes it is an int.  */
102
+  int has_arg;
103
+  int *flag;
104
+  int val;
105
+};
106
+
107
+/* Names for the values of the `has_arg' field of `struct option'.  */
108
+
109
+# define no_argument		0
110
+# define required_argument	1
111
+# define optional_argument	2
112
+#endif	/* need getopt */
113
+
114
+
115
+/* Get definitions and prototypes for functions to process the
116
+   arguments in ARGV (ARGC of them, minus the program name) for
117
+   options given in OPTS.
118
+
119
+   Return the option character from OPTS just read.  Return -1 when
120
+   there are no more options.  For unrecognized options, or options
121
+   missing arguments, `optopt' is set to the option letter, and '?' is
122
+   returned.
123
+
124
+   The OPTS string is a list of characters which are recognized option
125
+   letters, optionally followed by colons, specifying that that letter
126
+   takes an argument, to be placed in `optarg'.
127
+
128
+   If a letter in OPTS is followed by two colons, its argument is
129
+   optional.  This behavior is specific to the GNU `getopt'.
130
+
131
+   The argument `--' causes premature termination of argument
132
+   scanning, explicitly telling `getopt' that there are no more
133
+   options.
134
+
135
+   If OPTS begins with `--', then non-option arguments are treated as
136
+   arguments to the option '\0'.  This behavior is specific to the GNU
137
+   `getopt'.  */
138
+
139
+#if defined __STDC__ && __STDC__
140
+# ifdef __GNU_LIBRARY__
141
+/* Many other libraries have conflicting prototypes for getopt, with
142
+   differences in the consts, in stdlib.h.  To avoid compilation
143
+   errors, only prototype getopt for the GNU C library.  */
144
+extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
145
+# else /* not __GNU_LIBRARY__ */
146
+extern int getopt ();
147
+# endif /* __GNU_LIBRARY__ */
148
+
149
+# ifndef __need_getopt
150
+extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
151
+		        const struct option *__longopts, int *__longind);
152
+extern int getopt_long_only (int __argc, char *const *__argv,
153
+			     const char *__shortopts,
154
+		             const struct option *__longopts, int *__longind);
155
+
156
+/* Internal only.  Users should not call this directly.  */
157
+extern int _getopt_internal (int __argc, char *const *__argv,
158
+			     const char *__shortopts,
159
+		             const struct option *__longopts, int *__longind,
160
+			     int __long_only);
161
+# endif
162
+#else /* not __STDC__ */
163
+extern int getopt ();
164
+# ifndef __need_getopt
165
+extern int getopt_long ();
166
+extern int getopt_long_only ();
167
+
168
+extern int _getopt_internal ();
169
+# endif
170
+#endif /* __STDC__ */
171
+
172
+#ifdef	__cplusplus
173
+}
174
+#endif
175
+
176
+/* Make sure we later can get all the definitions and declarations.  */
177
+#undef __need_getopt
178
+
179
+#endif /* getopt.h */
0 180
new file mode 100644
... ...
@@ -0,0 +1,47 @@
0
+/*
1
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
2
+ *
3
+ *  This program is free software; you can redistribute it and/or modify
4
+ *  it under the terms of the GNU General Public License as published by
5
+ *  the Free Software Foundation; either version 2 of the License, or
6
+ *  (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ */
17
+
18
+#include <stdio.h>
19
+#include <stdlib.h>
20
+#include <unistd.h>
21
+
22
+void *mmalloc(size_t size)
23
+{
24
+	void *alloc;
25
+
26
+    alloc = malloc(size);
27
+
28
+    if(!alloc) {
29
+	fprintf(stderr, "CRITICAL: Can't allocate memory (%ld bytes).\n", (long int) size);
30
+	_exit(71);
31
+	return NULL; /* shut up gcc */
32
+    } else return alloc;
33
+}
34
+
35
+void *mcalloc(size_t nmemb, size_t size)
36
+{
37
+	void *alloc;
38
+
39
+    alloc = calloc(nmemb, size);
40
+
41
+    if(!alloc) {
42
+	fprintf(stderr, "CRITICAL: Can't allocate memory (%ld bytes).\n", (long int) nmemb * size);
43
+	_exit(70);
44
+	return NULL;
45
+    } else return alloc;
46
+}
0 47
new file mode 100644
... ...
@@ -0,0 +1,27 @@
0
+/*
1
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
2
+ *
3
+ *  This program is free software; you can redistribute it and/or modify
4
+ *  it under the terms of the GNU General Public License as published by
5
+ *  the Free Software Foundation; either version 2 of the License, or
6
+ *  (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ */
17
+
18
+#ifndef __MEMORY_H
19
+#define __MEMORY_H
20
+
21
+#include <stdlib.h>
22
+
23
+void *mmalloc(size_t size);
24
+void *mcalloc(size_t nmemb, size_t size);
25
+
26
+#endif
0 27
new file mode 100644
... ...
@@ -0,0 +1,275 @@
0
+/*
1
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
2
+ *
3
+ *  This program is free software; you can redistribute it and/or modify
4
+ *  it under the terms of the GNU General Public License as published by
5
+ *  the Free Software Foundation; either version 2 of the License, or
6
+ *  (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ */
17
+
18
+#if HAVE_CONFIG_H
19
+#include "clamav-config.h"
20
+#endif
21
+
22
+#include <stdio.h>
23
+#include <stdarg.h>
24
+#include <stdlib.h>
25
+#include <string.h>
26
+#include <ctype.h>
27
+#include <unistd.h>
28
+#include <fcntl.h>
29
+#include <time.h>
30
+#include <sys/stat.h>
31
+#include <errno.h>
32
+#include <sys/time.h>
33
+#include <sys/socket.h>
34
+#if HAVE_SYS_TYPES_H
35
+#include <sys/types.h>
36
+#endif
37
+
38
+#if defined(USE_SYSLOG) && !defined(C_AIX)
39
+#include <syslog.h>
40
+#endif
41
+
42
+#include "output.h"
43
+#include "memory.h"
44
+
45
+#ifdef CL_THREAD_SAFE
46
+#include <pthread.h>
47
+pthread_mutex_t logg_mutex = PTHREAD_MUTEX_INITIALIZER;
48
+#endif
49
+
50
+FILE *logg_fd = NULL;
51
+
52
+int mdprintf(int desc, const char *str, ...)
53
+{
54
+	va_list args;
55
+	char buff[512];
56
+	int bytes;
57
+
58
+    va_start(args, str);
59
+    bytes = vsnprintf(buff, 512, str, args);
60
+    va_end(args);
61
+    write(desc, buff, bytes);
62
+    return bytes;
63
+}
64
+
65
+void logg_close(void) {
66
+
67
+#ifdef CL_THREAD_SAFE
68
+    pthread_mutex_lock(&logg_mutex);
69
+#endif
70
+    if (logg_fd) {
71
+	fclose(logg_fd);
72
+	logg_fd = NULL;
73
+    }
74
+#ifdef CL_THREAD_SAFE
75
+    pthread_mutex_unlock(&logg_mutex);
76
+#endif
77
+
78
+#if defined(USE_SYSLOG) && !defined(C_AIX)
79
+    if(logg_syslog) {
80
+    	closelog();
81
+    }
82
+#endif
83
+}
84
+
85
+int logg(const char *str, ...)
86
+{
87
+	va_list args;
88
+	struct flock fl;
89
+	char *pt, *timestr;
90
+	time_t currtime;
91
+	struct stat sb;
92
+	mode_t old_umask;
93
+
94
+
95
+    if(logg_file) {
96
+#ifdef CL_THREAD_SAFE
97
+	pthread_mutex_lock(&logg_mutex);
98
+#endif
99
+	if(!logg_fd) {
100
+	    old_umask = umask(0037);
101
+	    if((logg_fd = fopen(logg_file, "a")) == NULL) {
102
+		umask(old_umask);
103
+#ifdef CL_THREAD_SAFE
104
+		pthread_mutex_unlock(&logg_mutex);
105
+#endif
106
+		return -1;
107
+	    } else umask(old_umask);
108
+
109
+	    if(logg_lock) {
110
+		memset(&fl, 0, sizeof(fl));
111
+		fl.l_type = F_WRLCK;
112
+		if(fcntl(fileno(logg_fd), F_SETLK, &fl) == -1) {
113
+#ifdef CL_THREAD_SAFE
114
+		    pthread_mutex_unlock(&logg_mutex);
115
+#endif
116
+		    return -1;
117
+		}
118
+	    }
119
+	}
120
+
121
+        /* Need to avoid logging time for verbose messages when logverbose
122
+           is not set or we get a bunch of timestamps in the log without
123
+           newlines... */
124
+	if(logg_time && ((*str != '*') || logg_verbose)) {
125
+	    time(&currtime);
126
+	    pt = ctime(&currtime);
127
+	    timestr = mcalloc(strlen(pt), sizeof(char));
128
+	    strncpy(timestr, pt, strlen(pt) - 1);
129
+	    fprintf(logg_fd, "%s -> ", timestr);
130
+	    free(timestr);
131
+	}
132
+
133
+	if(logg_size) {
134
+	    if(stat(logg_file, &sb) != -1) {
135
+		if(sb.st_size > logg_size) {
136
+		    logg_file = NULL;
137
+		    fprintf(logg_fd, "Log size = %d, maximal = %d\n", (int) sb.st_size, logg_size);
138
+		    fprintf(logg_fd, "LOGGING DISABLED (Maximal log file size exceeded).\n");
139
+		    fclose(logg_fd);
140
+		    logg_fd = NULL;
141
+#ifdef CL_THREAD_SAFE
142
+		    pthread_mutex_unlock(&logg_mutex);
143
+#endif
144
+		    return 0;
145
+		}
146
+	    }
147
+	}
148
+
149
+	va_start(args, str);
150
+
151
+	if(*str == '!') {
152
+	    fprintf(logg_fd, "ERROR: ");
153
+	    vfprintf(logg_fd, str+1, args);
154
+	} else if(*str == '^') {
155
+	    fprintf(logg_fd, "WARNING: ");
156
+	    vfprintf(logg_fd, str+1, args);
157
+	} else if(*str == '*') {
158
+	    if(logg_verbose)
159
+		vfprintf(logg_fd, str+1, args);
160
+	} else vfprintf(logg_fd, str, args);
161
+
162
+	va_end(args);
163
+
164
+	fflush(logg_fd);
165
+    }
166
+
167
+#ifdef CL_THREAD_SAFE
168
+    pthread_mutex_unlock(&logg_mutex);
169
+#endif
170
+
171
+#if defined(USE_SYSLOG) && !defined(C_AIX)
172
+    if(logg_syslog) {
173
+
174
+      /* SYSLOG logging - no need for locking, mutexes, times & stuff ... :-) */
175
+
176
+#ifndef vsyslog
177
+#define vsyslog(a,b,c)	{ \
178
+	char my_tmp[4096]; \
179
+	vsnprintf(my_tmp,4095,b,c); \
180
+	my_tmp[4095]=0; \
181
+	syslog(a,my_tmp); }
182
+#endif
183
+
184
+	va_start(args, str);
185
+
186
+	if(*str == '!') {
187
+	    vsyslog(LOG_ERR, str+1, args);
188
+	} else if(*str == '^') {
189
+	    vsyslog(LOG_WARNING, str+1, args);
190
+	} else if(*str == '*') {
191
+	    if(logg_verbose) {
192
+		vsyslog(LOG_DEBUG, str+1, args);
193
+	    }
194
+	} else vsyslog(LOG_INFO, str, args);
195
+
196
+	va_end(args);
197
+    }
198
+#endif
199
+
200
+    return 0;
201
+}
202
+
203
+void mprintf(const char *str, ...)
204
+{
205
+	va_list args;
206
+	FILE *fd;
207
+	char logbuf[512];
208
+
209
+
210
+    if(mprintf_disabled) {
211
+	if(*str == '@') {
212
+	    va_start(args, str);
213
+#ifdef NO_SNPRINTF
214
+	    vsprintf(logbuf, ++str, args);
215
+#else
216
+	    vsnprintf(logbuf, sizeof(logbuf), ++str, args);
217
+#endif
218
+	    va_end(args);
219
+	    logg("ERROR: %s", logbuf);
220
+	}
221
+	return;
222
+    }
223
+
224
+    if(mprintf_stdout)
225
+	fd = stdout;
226
+    else
227
+	fd = stderr;
228
+
229
+/* legend:
230
+ * ! - error
231
+ * @ - error with logging
232
+ * ...
233
+ */
234
+
235
+/*
236
+ *             ERROR    WARNING    STANDARD
237
+ * normal       yes       yes        yes
238
+ * 
239
+ * verbose      yes       yes        yes
240
+ * 
241
+ * quiet        yes       no         no
242
+ */
243
+
244
+
245
+    va_start(args, str);
246
+
247
+    if(*str == '!') {
248
+	fprintf(fd, "ERROR: ");
249
+	vfprintf(fd, ++str, args);
250
+    } else if(*str == '@') {
251
+	fprintf(fd, "ERROR: ");
252
+	vfprintf(fd, ++str, args);
253
+#ifdef NO_SNPRINTF
254
+	vsprintf(logbuf, str, args);
255
+#else
256
+	vsnprintf(logbuf, sizeof(logbuf), str, args);
257
+#endif
258
+	logg("ERROR: %s", logbuf);
259
+    } else if(!mprintf_quiet) {
260
+	if(*str == '^') {
261
+	    fprintf(fd, "WARNING: ");
262
+	    vfprintf(fd, ++str, args);
263
+	} else if(*str == '*') {
264
+	    if(mprintf_verbose)
265
+		vfprintf(fd, ++str, args);
266
+	} else vfprintf(fd, str, args);
267
+    }
268
+
269
+    va_end(args);
270
+
271
+    if(fd == stdout)
272
+	fflush(stdout);
273
+
274
+}
0 275
new file mode 100644
... ...
@@ -0,0 +1,44 @@
0
+/*
1
+ *  Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
2
+ *
3
+ *  This program is free software; you can redistribute it and/or modify
4
+ *  it under the terms of the GNU General Public License as published by
5
+ *  the Free Software Foundation; either version 2 of the License, or
6
+ *  (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ */
17
+
18
+#ifndef __OUTPUT_H
19
+#define __OUTPUT_H
20
+
21
+#if HAVE_CONFIG_H
22
+#include "clamav-config.h"
23
+#endif
24
+
25
+#include <stdlib.h>
26
+#include "cfgparser.h"
27
+
28
+int mdprintf(int desc, const char *str, ...);
29
+
30
+int logg(const char *str, ...);
31
+void logg_close(void);
32
+short int logg_verbose, logg_lock, logg_time;
33
+int logg_size;
34
+const char *logg_file;
35
+
36
+#if defined(USE_SYSLOG) && !defined(C_AIX)
37
+short logg_syslog;
38
+#endif
39
+
40
+void mprintf(const char *str, ...);
41
+short int mprintf_disabled, mprintf_verbose, mprintf_quiet, mprintf_stdout;
42
+
43
+#endif
... ...
@@ -15,15 +15,21 @@
15 15
 #  along with this program; if not, write to the Free Software
16 16
 #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
 
18
-INCLUDES = -I$(top_srcdir)/clamscan -I$(top_srcdir)/libclamav
19
-
20 18
 bin_PROGRAMS = sigtool
21 19
 
22 20
 sigtool_SOURCES = \
21
+    $(top_srcdir)/shared/output.c \
22
+    $(top_srcdir)/shared/output.h \
23
+    $(top_srcdir)/shared/getopt.c \
24
+    $(top_srcdir)/shared/getopt.h \
25
+    $(top_srcdir)/shared/memory.c \
26
+    $(top_srcdir)/shared/memory.h \
23 27
     options.c \
28
+    options.h \
24 29
     sigtool.c
25 30
 
26
-sigtool_LDADD = $(top_builddir)/clamscan/getopt.o $(top_builddir)/clamscan/others.o
31
+sigtool_LDADD = $(top_builddir)/clamscan/others.o 
27 32
 
28 33
 DEFS = @DEFS@
34
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
29 35
 LIBS = -L$(top_builddir)/libclamav -lclamav @FRESHCLAM_LIBS@
... ...
@@ -116,18 +116,24 @@ am__include = @am__include@
116 116
 am__quote = @am__quote@
117 117
 install_sh = @install_sh@
118 118
 
119
-INCLUDES = -I$(top_srcdir)/clamscan -I$(top_srcdir)/libclamav
120
-
121 119
 bin_PROGRAMS = sigtool
122 120
 
123 121
 sigtool_SOURCES = \
122
+    $(top_srcdir)/shared/output.c \
123
+    $(top_srcdir)/shared/output.h \
124
+    $(top_srcdir)/shared/getopt.c \
125
+    $(top_srcdir)/shared/getopt.h \
126
+    $(top_srcdir)/shared/memory.c \
127
+    $(top_srcdir)/shared/memory.h \
124 128
     options.c \
129
+    options.h \
125 130
     sigtool.c
126 131
 
127 132
 
128
-sigtool_LDADD = $(top_builddir)/clamscan/getopt.o $(top_builddir)/clamscan/others.o
133
+sigtool_LDADD = $(top_builddir)/clamscan/others.o 
129 134
 
130 135
 DEFS = @DEFS@
136
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav
131 137
 LIBS = -L$(top_builddir)/libclamav -lclamav @FRESHCLAM_LIBS@
132 138
 subdir = sigtool
133 139
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
... ...
@@ -136,17 +142,19 @@ CONFIG_CLEAN_FILES =
136 136
 bin_PROGRAMS = sigtool$(EXEEXT)
137 137
 PROGRAMS = $(bin_PROGRAMS)
138 138
 
139
-am_sigtool_OBJECTS = options.$(OBJEXT) sigtool.$(OBJEXT)
139
+am_sigtool_OBJECTS = output.$(OBJEXT) getopt.$(OBJEXT) memory.$(OBJEXT) \
140
+	options.$(OBJEXT) sigtool.$(OBJEXT)
140 141
 sigtool_OBJECTS = $(am_sigtool_OBJECTS)
141
-sigtool_DEPENDENCIES = $(top_builddir)/clamscan/getopt.o \
142
-	$(top_builddir)/clamscan/others.o
142
+sigtool_DEPENDENCIES = $(top_builddir)/clamscan/others.o
143 143
 sigtool_LDFLAGS =
144 144
 DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)
145 145
 CPPFLAGS = @CPPFLAGS@
146 146
 LDFLAGS = @LDFLAGS@
147 147
 depcomp = $(SHELL) $(top_srcdir)/depcomp
148 148
 am__depfiles_maybe = depfiles
149
-@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/options.Po ./$(DEPDIR)/sigtool.Po
149
+@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/getopt.Po ./$(DEPDIR)/memory.Po \
150
+@AMDEP_TRUE@	./$(DEPDIR)/options.Po ./$(DEPDIR)/output.Po \
151
+@AMDEP_TRUE@	./$(DEPDIR)/sigtool.Po
150 152
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
151 153
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
152 154
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
... ...
@@ -195,6 +203,9 @@ uninstall-binPROGRAMS:
195 195
 
196 196
 clean-binPROGRAMS:
197 197
 	-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
198
+output.$(OBJEXT): $(top_srcdir)/shared/output.c
199
+getopt.$(OBJEXT): $(top_srcdir)/shared/getopt.c
200
+memory.$(OBJEXT): $(top_srcdir)/shared/memory.c
198 201
 sigtool$(EXEEXT): $(sigtool_OBJECTS) $(sigtool_DEPENDENCIES) 
199 202
 	@rm -f sigtool$(EXEEXT)
200 203
 	$(LINK) $(sigtool_LDFLAGS) $(sigtool_OBJECTS) $(sigtool_LDADD) $(LIBS)
... ...
@@ -205,7 +216,10 @@ mostlyclean-compile:
205 205
 distclean-compile:
206 206
 	-rm -f *.tab.c
207 207
 
208
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
209
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Po@am__quote@
208 210
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@
211
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/output.Po@am__quote@
209 212
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sigtool.Po@am__quote@
210 213
 
211 214
 distclean-depend:
... ...
@@ -228,6 +242,60 @@ distclean-depend:
228 228
 @AMDEP_TRUE@	depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@
229 229
 @AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
230 230
 	$(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<
231
+
232
+output.o: $(top_srcdir)/shared/output.c
233
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.o' libtool=no @AMDEPBACKSLASH@
234
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Po' tmpdepfile='$(DEPDIR)/output.TPo' @AMDEPBACKSLASH@
235
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
236
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.o `test -f '$(top_srcdir)/shared/output.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/output.c
237
+
238
+output.obj: $(top_srcdir)/shared/output.c
239
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.obj' libtool=no @AMDEPBACKSLASH@
240
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Po' tmpdepfile='$(DEPDIR)/output.TPo' @AMDEPBACKSLASH@
241
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
242
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.obj `cygpath -w $(top_srcdir)/shared/output.c`
243
+
244
+output.lo: $(top_srcdir)/shared/output.c
245
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/output.c' object='output.lo' libtool=yes @AMDEPBACKSLASH@
246
+@AMDEP_TRUE@	depfile='$(DEPDIR)/output.Plo' tmpdepfile='$(DEPDIR)/output.TPlo' @AMDEPBACKSLASH@
247
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
248
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.lo `test -f '$(top_srcdir)/shared/output.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/output.c
249
+
250
+getopt.o: $(top_srcdir)/shared/getopt.c
251
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.o' libtool=no @AMDEPBACKSLASH@
252
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Po' tmpdepfile='$(DEPDIR)/getopt.TPo' @AMDEPBACKSLASH@
253
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
254
+	$(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
255
+
256
+getopt.obj: $(top_srcdir)/shared/getopt.c
257
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.obj' libtool=no @AMDEPBACKSLASH@
258
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Po' tmpdepfile='$(DEPDIR)/getopt.TPo' @AMDEPBACKSLASH@
259
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
260
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.obj `cygpath -w $(top_srcdir)/shared/getopt.c`
261
+
262
+getopt.lo: $(top_srcdir)/shared/getopt.c
263
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/getopt.c' object='getopt.lo' libtool=yes @AMDEPBACKSLASH@
264
+@AMDEP_TRUE@	depfile='$(DEPDIR)/getopt.Plo' tmpdepfile='$(DEPDIR)/getopt.TPlo' @AMDEPBACKSLASH@
265
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
266
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o getopt.lo `test -f '$(top_srcdir)/shared/getopt.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/getopt.c
267
+
268
+memory.o: $(top_srcdir)/shared/memory.c
269
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.o' libtool=no @AMDEPBACKSLASH@
270
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Po' tmpdepfile='$(DEPDIR)/memory.TPo' @AMDEPBACKSLASH@
271
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
272
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.o `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c
273
+
274
+memory.obj: $(top_srcdir)/shared/memory.c
275
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.obj' libtool=no @AMDEPBACKSLASH@
276
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Po' tmpdepfile='$(DEPDIR)/memory.TPo' @AMDEPBACKSLASH@
277
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
278
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.obj `cygpath -w $(top_srcdir)/shared/memory.c`
279
+
280
+memory.lo: $(top_srcdir)/shared/memory.c
281
+@AMDEP_TRUE@	source='$(top_srcdir)/shared/memory.c' object='memory.lo' libtool=yes @AMDEPBACKSLASH@
282
+@AMDEP_TRUE@	depfile='$(DEPDIR)/memory.Plo' tmpdepfile='$(DEPDIR)/memory.TPlo' @AMDEPBACKSLASH@
283
+@AMDEP_TRUE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
284
+	$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o memory.lo `test -f '$(top_srcdir)/shared/memory.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/memory.c
231 285
 CCDEPMODE = @CCDEPMODE@
232 286
 
233 287
 mostlyclean-libtool:
... ...
@@ -33,7 +33,6 @@
33 33
 
34 34
 #include "options.h"
35 35
 #include "others.h"
36
-#include "shared.h"
37 36
 
38 37
 void sigtool(struct optstruct *opt);
39 38
 
40 39
new file mode 100644
... ...
@@ -0,0 +1,46 @@
0
+/*
1
+ *  Copyright (C) 2002, 2003 Tomasz Kojm <zolw@konarski.edu.pl>
2
+ *
3
+ *  This program is free software; you can redistribute it and/or modify
4
+ *  it under the terms of the GNU General Public License as published by
5
+ *  the Free Software Foundation; either version 2 of the License, or
6
+ *  (at your option) any later version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ */
17
+
18
+#ifndef __OPTIONS_H
19
+#define __OPTIONS_H
20
+
21
+struct optnode {
22
+    char optchar;
23
+    char *optarg;
24
+    char *optname;
25
+    struct optnode *next;
26
+};
27
+
28
+struct optstruct {
29
+    struct optnode *optlist;
30
+    char *filename;
31
+};
32
+
33
+int optc(const struct optstruct *opt, char ch);
34
+int optl(const struct optstruct *opt, const char *optname);
35
+void register_char_option(struct optstruct *opt, char ch);
36
+void register_long_option(struct optstruct *opt, const char *optname);
37
+char *getargc(const struct optstruct *opt, char ch);
38
+char *getfirstargc(const struct optstruct *opt, char ch, struct optnode **optnode);
39
+char *getnextargc(struct optnode **optnode, char ch);
40
+char *getargl(const struct optstruct *opt, const char *optname);
41
+char *getfirstargl(const struct optstruct *opt, const char *optname, struct optnode **optnode);
42
+char *getnextargl(struct optnode **optnode, const char *optname);
43
+void free_opt(struct optstruct *opt);
44
+
45
+#endif
... ...
@@ -41,11 +41,12 @@
41 41
 
42 42
 #include "options.h"
43 43
 #include "others.h"
44
-#include "shared.h"
45 44
 #include "strings.h"
46 45
 #include "md5.h"
47 46
 #include "cvd.h"
48 47
 #include "str.h"
48
+#include "memory.h"
49
+#include "output.h"
49 50
 
50 51
 #define LINE 1024
51 52