Check-in [6a0a10a0ab]
Overview
Comment:Lots of improvements to libconfig: We now process the command line arguments ourselves rather than using getopt(). We now process Apache-style config files. Began work on documentation. Many more bug fixes
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6a0a10a0ab2d45340c26e9cd18af78267c8df633
User & Date: rkeene on 2004-10-24 14:26:31.000
Other Links: manifest | tags
Context
2004-10-26
13:19
Updated man pages. Updated lc_process_files() to work. check-in: 92a0e45fc6 user: rkeene tags: trunk
2004-10-24
14:26
Lots of improvements to libconfig: We now process the command line arguments ourselves rather than using getopt(). We now process Apache-style config files. Began work on documentation. Many more bug fixes check-in: 6a0a10a0ab user: rkeene tags: trunk
2004-10-22
23:59
Made dysfunctional configuration elements return -1. Made conf_section work correctly. check-in: 53df9990ae user: rkeene tags: trunk
Changes
1
2
3
4
5
6
7
8
9
10





libconfig.h
config.log
config.status
config.h
libconfig.a
libconfig.so
Makefile
test-lc
test.cfg
.*.swp















>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
libconfig.h
config.log
config.status
config.h
libconfig.a
libconfig.so
Makefile
test-lc
test.cfg
.*.swp
lc_geterrstr.3
lc_register_var.3
lc_register_callback.3
lc_process.3
lc_geterrno.3
1
2
3
4
5
6
7
8
9
10










11
12
13
14
15
16
17
.*.swp
.*.swp/*
Makefile
Makefile/*
config.h
config.h/*
config.log
config.log/*
config.status
config.status/*










libconfig.a
libconfig.a/*
libconfig.h
libconfig.h/*
libconfig.so
libconfig.so/*
test-lc










>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
.*.swp
.*.swp/*
Makefile
Makefile/*
config.h
config.h/*
config.log
config.log/*
config.status
config.status/*
lc_geterrno.3
lc_geterrno.3/*
lc_geterrstr.3
lc_geterrstr.3/*
lc_process.3
lc_process.3/*
lc_register_callback.3
lc_register_callback.3/*
lc_register_var.3
lc_register_var.3/*
libconfig.a
libconfig.a/*
libconfig.h
libconfig.h/*
libconfig.so
libconfig.so/*
test-lc
Added Docs/USAGE version [1da5b3b06f].
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16


17
18
19
20
21
22
23
CC = @CC@

AR = @AR@
RANLIB = @RANLIB@
CPP = @CPP@
CFLAGS = -Wall @CFLAGS@ @DEFS@
CPPFLAGS = @CPPFLAGS@ @DEFS@
LDFLAGS = @LDFLAGS@ @LIBS@
INSTALL = @INSTALL@
EXEEXT = @EXEEXT@
OBJEXT = @OBJEXT@
PATH_SEPARATOR = @PATH_SEPARATOR@
SHOBJFLAGS = @SHOBJFLAGS@
SHOBJLDFLAGS = @SHOBJLDFLAGS@
SHOBJEXT = so
ARFLAGS = # @ARFLAGS@
AREXT = a



prefix = @prefix@
mandir = @mandir@
sysconfdir = @sysconfdir@
datadir = @datadir@
exec_prefix = @exec_prefix@
bindir = @bindir@

>















>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
CC = @CC@
LN_S = @LN_S@
AR = @AR@
RANLIB = @RANLIB@
CPP = @CPP@
CFLAGS = -Wall @CFLAGS@ @DEFS@
CPPFLAGS = @CPPFLAGS@ @DEFS@
LDFLAGS = @LDFLAGS@ @LIBS@
INSTALL = @INSTALL@
EXEEXT = @EXEEXT@
OBJEXT = @OBJEXT@
PATH_SEPARATOR = @PATH_SEPARATOR@
SHOBJFLAGS = @SHOBJFLAGS@
SHOBJLDFLAGS = @SHOBJLDFLAGS@
SHOBJEXT = so
ARFLAGS = # @ARFLAGS@
AREXT = a
PKGVERS = @PACKAGE_VERSION@
PKGVERSMAJOR = `echo $(PKGVERS) | cut -f 1 -d .`

prefix = @prefix@
mandir = @mandir@
sysconfdir = @sysconfdir@
datadir = @datadir@
exec_prefix = @exec_prefix@
bindir = @bindir@
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54


55
56
57
58





59



libconfig.o: libconfig.c compat.h win32.h config.h libconfig.h

libconfig.h: libconfig.h.in
	cat $^ | $(CPP) $(CPPFLAGS) - | grep -v '^#' | grep -v '^ *$$' | sed 's/^!/#  /g;s/__BLANK_LINE__//' > $@

test-lc: $(LIBS) test-lc.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Wl,-R -Wl,. -L. -lconfig -o $@ $(filter %.c, $^)

.PHONY: clean distclean install
clean:
	rm -f *.o $(BINS) $(LIBS) libconfig.h *~ test-lc
distclean: clean
	rm -f Makefile config.h config.status config.log


install: all libconfig.h


	-$(INSTALL) -d $(libdir)
	-$(INSTALL) -d $(includedir)
	$(INSTALL) -m 755 libconfig.$(SHOBJEXT) $(libdir)/libconfig.$(SHOBJEXT)
	$(INSTALL) -m 644 libconfig.$(AREXT) $(libdir)/libconfig.$(AREXT)





	$(INSTALL) -m 644 libconfig.h $(includedir)/libconfig.h









|





|

>

>
>


|

>
>
>
>
>

>
>
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

libconfig.o: libconfig.c compat.h win32.h config.h libconfig.h

libconfig.h: libconfig.h.in
	cat $^ | $(CPP) $(CPPFLAGS) - | grep -v '^#' | grep -v '^ *$$' | sed 's/^!/#  /g;s/__BLANK_LINE__//' > $@

test-lc: $(LIBS) test-lc.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $(filter %.c, $^) $(LDFLAGS) -Wl,-R -Wl,. -L. -lconfig

.PHONY: clean distclean install
clean:
	rm -f *.o $(BINS) $(LIBS) libconfig.h *~ test-lc
distclean: clean
	rm -f Makefile config.h config.status config.log lc_geterrno.3 lc_process.3 lc_register_var.3 lc_geterrstr.3 lc_register_callback.3


install: all libconfig.h
	-$(INSTALL) -d $(mandir)
	-$(INSTALL) -d $(mandir)/man3
	-$(INSTALL) -d $(libdir)
	-$(INSTALL) -d $(includedir)
	$(INSTALL) -m 755 libconfig.$(SHOBJEXT) $(libdir)/libconfig.$(SHOBJEXT).$(PKGVERS)
	$(INSTALL) -m 644 libconfig.$(AREXT) $(libdir)/libconfig.$(AREXT)
	$(INSTALL) -m 644 lc_register_callback.3 $(mandir)/man3/lc_register_callback.3
	$(INSTALL) -m 644 lc_register_var.3 $(mandir)/man3/lc_register_var.3
	$(INSTALL) -m 644 lc_geterrstr.3 $(mandir)/man3/lc_geterrstr.3
	$(INSTALL) -m 644 lc_geterrno.3 $(mandir)/man3/lc_geterrno.3
	$(INSTALL) -m 644 lc_process.3 $(mandir)/man3/lc_process.3
	$(INSTALL) -m 644 libconfig.h $(includedir)/libconfig.h
	-( cd $(libdir) && rm -f libconfig.$(SHOBJEXT).$(PKGVERSMAJOR) && $(LN_S) libconfig.$(SHOBJEXT).$(PKGVERS) libconfig.$(SHOBJEXT).$(PKGVERSMAJOR) )
	-( cd $(libdir) && rm -f libconfig.$(SHOBJEXT) && $(LN_S) libconfig.$(SHOBJEXT).$(PKGVERS) libconfig.$(SHOBJEXT) )
1
2


#! /bin/sh





>
>
1
2
3
4
#! /bin/sh

autoconf; autoheader
rm -rf autom4te.cache *~
Modified compat.h from [8797b049e9] to [893879d77c].
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "win32.h"
#endif

#ifndef LC_LINEBUF_LEN
#define LC_LINEBUF_LEN 1024
#endif

#ifndef HAVE_GETOPT
#include "getopt.h"
#else
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#endif
#ifndef HAVE_STRSEP
#include "strsep.h"
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_MEMORY_H







<
<
<
<
<
<
<







8
9
10
11
12
13
14







15
16
17
18
19
20
21
#include "win32.h"
#endif

#ifndef LC_LINEBUF_LEN
#define LC_LINEBUF_LEN 1024
#endif








#ifndef HAVE_STRSEP
#include "strsep.h"
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_MEMORY_H
94
95
96
97
98
99
100

101
102
103
104
105
106

107
108
109
110
#define PRINTERR_D(x...) /**/
#define PERROR(x) perror(x);
#define DPERROR(x) /**/
#endif
#define CHECKPOINT PRINTERR_D("*** CHECKPOINT REACHED ***")
#define SPOTVAR_LLX(x) PRINTERR_D(#x " = %llx", x)
#define SPOTVAR_LLU(x) PRINTERR_D(#x " = %llu", x)

#define SPOTVAR_LU(x) PRINTERR_D(#x " = %lu", x)
#define SPOTVAR_D(x) PRINTERR_D(#x " = %lf", x)
#define SPOTVAR_X(x) PRINTERR_D(#x " = 0x%x", x)
#define SPOTVAR_I(x) PRINTERR_D(#x " = %i", x)
#define SPOTVAR_P(x) PRINTERR_D(#x " = %p", x)
#define SPOTVAR_S(x) PRINTERR_D(#x " = \"%s\"", x)

#define PRINTERR(x...) { PRINT_LINE; fprintf(stderr, x); fprintf(stderr, "\n"); fflush(stderr); }
#define LOG(x...) { PRINT_LINE; fprintf(stderr, "LOG: " x); fprintf(stderr, "\n"); }

#endif







>






>




87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#define PRINTERR_D(x...) /**/
#define PERROR(x) perror(x);
#define DPERROR(x) /**/
#endif
#define CHECKPOINT PRINTERR_D("*** CHECKPOINT REACHED ***")
#define SPOTVAR_LLX(x) PRINTERR_D(#x " = %llx", x)
#define SPOTVAR_LLU(x) PRINTERR_D(#x " = %llu", x)
#define SPOTVAR_LL(x) PRINTERR_D(#x " = %lli", x)
#define SPOTVAR_LU(x) PRINTERR_D(#x " = %lu", x)
#define SPOTVAR_D(x) PRINTERR_D(#x " = %lf", x)
#define SPOTVAR_X(x) PRINTERR_D(#x " = 0x%x", x)
#define SPOTVAR_I(x) PRINTERR_D(#x " = %i", x)
#define SPOTVAR_P(x) PRINTERR_D(#x " = %p", x)
#define SPOTVAR_S(x) PRINTERR_D(#x " = \"%s\"", x)
#define SPOTVAR_C(x) PRINTERR_D(#x " = \'%c\'", x)
#define PRINTERR(x...) { PRINT_LINE; fprintf(stderr, x); fprintf(stderr, "\n"); fflush(stderr); }
#define LOG(x...) { PRINT_LINE; fprintf(stderr, "LOG: " x); fprintf(stderr, "\n"); }

#endif

1
2
3




































































































































































































































































































































4
5
6
7

#include "libconfig.h"
#include "libconfig_private.h"
#include "conf_apache.h"





































































































































































































































































































































int lc_process_conf_apache(const char *appname, const char *configfile) {
	return(-1);
}
>



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#include "compat.h"
#include "libconfig.h"
#include "libconfig_private.h"
#include "conf_apache.h"

#ifdef HAVE_CTYPE_H
#include <ctype.h>
#endif

#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif

#ifdef HAVE_STRING_H
#include <string.h>
#endif

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif

static int lc_process_conf_apache_file(const char *configfile, const char *pathprefix);

static int lc_process_conf_apache_include(const char *pathname, const char *pathprefix) {
	struct stat pathinfo;
	struct dirent *dinfo = NULL;
	char includepath[LC_LINEBUF_LEN] = {0};
	DIR *dh = NULL;
	int statret = -1, lcpcafret = -1;
	int retval = 0;

	statret = stat(pathname, &pathinfo);
	if (statret < 0) {
		return(-1);
	}

	if (S_ISDIR(pathinfo.st_mode)) {
		dh = opendir(pathname);
		if (dh == NULL) {
			return(-1);
		}

		while (1) {
			dinfo = readdir(dh);
			if (dinfo == NULL) {
				break;
			}

			/* Skip files that begin with a dot ('.') */
			if (dinfo->d_name[0] == '.') continue;

			snprintf(includepath, sizeof(includepath) - 1, "%s/%s", pathname, dinfo->d_name);
			lcpcafret = lc_process_conf_apache_include(includepath, pathprefix);
			if (lcpcafret < 0) {
				retval = -1;
				/* XXX: should we break here (abort further including of files from a directory if one fails ?) */
			}
		}

		closedir(dh);
	} else {
		lcpcafret = lc_process_conf_apache_file(pathname, pathprefix);
		if (lcpcafret < 0) {
			retval = -1;
		}
	}

	return(retval);
}

static int lc_process_conf_apache_file(const char *configfile, const char *pathprefix) {
	FILE *configfp = NULL;
	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL, *tmp_ptr = NULL;
	char *lastsection = NULL;
	char qualifbuf[LC_LINEBUF_LEN] = {0};
	char *cmd = NULL, *value = NULL, *sep = NULL, *cmdend = NULL;
	char *fgetsret = NULL;
	int lcpvret = -1, lpcafret = -1;
	int invalid_section = 0, ignore_section = 0;
	int retval = 0;
	lc_err_t save_lc_errno = LC_ERR_NONE;

	if (pathprefix != NULL) {
		/* Copy the prefix, if specified. */
		strncpy(qualifbuf, pathprefix, sizeof(qualifbuf) - 1);
	}

	if (configfile == NULL) {
		lc_errno = LC_ERR_INVDATA;
		return(-1);
	}

	configfp = fopen(configfile, "r");

	if (configfp == NULL) {
		lc_errno = LC_ERR_CANTOPEN;
		return(-1);
	}

	while (1) {
		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
		if (fgetsret == NULL) {
			break;
		}
		if (feof(configfp)) {
			break;
		}

		/* Remove trailing crap (but not spaces). */
		linebuf_ptr = &linebuf[strlen(linebuf) - 1];
		while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
			*linebuf_ptr = '\0';
			*linebuf_ptr--;
		}

		/* Remove leading spaces. */
		linebuf_ptr = &linebuf[0];
		while (*linebuf_ptr == ' ' || *linebuf_ptr == '\t') {
			*linebuf_ptr++;
		}

		/* Handle section header. */
		if (linebuf_ptr[0] == '<' && linebuf_ptr[strlen(linebuf_ptr) - 1] == '>') {
			/* Remove < and > from around the data. */
			linebuf_ptr[strlen(linebuf_ptr) - 1] = '\0';
			*linebuf_ptr++;

			/* Lowercase the command part of the section. */
			tmp_ptr = linebuf_ptr;
			while (*tmp_ptr != '\0' && *tmp_ptr != ' ') {
				*tmp_ptr = tolower(*tmp_ptr);
				*tmp_ptr++;
			}

			/* If this is a close section command, handle it */
			if (linebuf_ptr[0] == '/') {
				*linebuf_ptr++;
				cmd = linebuf_ptr; 

				/* Find the last section closed. */
				tmp_ptr = strrchr(qualifbuf, '.');
				if (tmp_ptr == NULL) {
					lastsection = qualifbuf;
					tmp_ptr = qualifbuf;
				} else {
					lastsection = tmp_ptr + 1;
				}

				if (strcmp(cmd, lastsection) != 0) {
					PRINTERR_D("Section closing does not match last opened section.");
					PRINTERR_D("Last opened = \"%s\", Closing = \"%s\"", lastsection, cmd);
					retval = -1;
					lc_errno = LC_ERR_BADFORMAT;

					/* For this error, we abort immediately. */
					break;
				}

				lcpvret = lc_process_var(qualifbuf, NULL, NULL, LC_FLAGS_SECTIONEND);
				if (lcpvret < 0) {
					PRINTERR_D("Invalid section terminating: \"%s\"", qualifbuf);
				}

				/* Remove the "lastsection" part.. */
				*tmp_ptr = '\0';

				/* We just sucessfully closed the last section opened,
				   we must be in a valid section now since we only open
				   sections from within valid sections. */
				invalid_section = 0;
				ignore_section = 0;

				continue;
			}
			/* Otherwise, open a new section. */

			/* Don't open a section from an invalid section. */
			if (invalid_section == 1 || ignore_section == 1) {
				continue;
			}

			/* Parse out any argument passed. */
			sep = strpbrk(linebuf_ptr, " \t");

			if (sep != NULL) {
				cmdend = sep;
				/* Delete space at the end of the command. */
				*cmdend--; /* It currently derefs to the seperator.. */
				while (*cmdend <= ' ') {
					*cmdend = '\0';
					*cmdend--;
				}

				/* Delete the seperator char and any leading space. */
				*sep = '\0';
				*sep++;
				while (*sep == ' ' || *sep == '\t') {
					*sep++;
				}
				value = sep;
			} else {
				/* XXX: should this be "" or NULL ? */
				value = "";
			}

			cmd = linebuf_ptr;

			if (qualifbuf[0] != '\0') {
				strncat(qualifbuf, ".", sizeof(qualifbuf) - strlen(qualifbuf) - 1);
			}
			strncat(qualifbuf, cmd, sizeof(qualifbuf) - strlen(qualifbuf) - 1);

			lcpvret = lc_process_var(qualifbuf, value, NULL, LC_FLAGS_SECTIONSTART);
			if (lcpvret < 0) {
				PRINTERR_D("Invalid section: \"%s\"", qualifbuf);
				invalid_section = 1;
				lc_errno = LC_ERR_INVSECTION;
				retval = -1;
			}
			if (lcpvret == LC_CBRET_IGNORESECTION) {
				ignore_section = 1;
			}
			continue;
		}

		/* Drop comments and blank lines. */
		if (*linebuf_ptr == '#' || *linebuf_ptr == '\0') {
			continue;
		}

		/* Don't handle things for a section that doesn't exist. */
		if (invalid_section == 1) {
			PRINTERR_D("Ignoring line (because invalid section): %s", linebuf);
			continue;
		}
		if (ignore_section == 1) {
			PRINTERR_D("Ignoring line (because ignored section): %s", linebuf);
			continue;
		}

		/* Find the command and the data in the line. */
		sep = strpbrk(linebuf_ptr, " \t");
		if (sep != NULL) {
			cmdend = sep;

			/* Delete space at the end of the command. */
			*cmdend--; /* It currently derefs to the seperator.. */
			while (*cmdend <= ' ') {
				*cmdend = '\0';
				*cmdend--;
			}

			/* Delete the seperator char and any leading space. */
			*sep = '\0';
			*sep++;
			while (*sep == ' ' || *sep == '\t') {
				*sep++;
			}
			value = sep;
		} else {
			value = NULL;
		}

		cmd = linebuf_ptr;

		/* Handle special commands. */
		if (strcasecmp(cmd, "include") == 0) {
			if (value == NULL) {
				lc_errno = LC_ERR_BADFORMAT;
				retval = -1;
				PRINTERR_D("Invalid include command.");
				continue;
			}

			lpcafret = lc_process_conf_apache_include(value, qualifbuf);
			if (lpcafret < 0) {
				PRINTERR_D("Error in included file.");
				retval = -1;
			}
			continue;
		}

		/* Create the fully qualified variable name. */
		if (qualifbuf[0] != '\0') {
			strncat(qualifbuf, ".", sizeof(qualifbuf) - strlen(qualifbuf) - 1);
		}
		strncat(qualifbuf, cmd, sizeof(qualifbuf) - strlen(qualifbuf) - 1);

		/* Call the parent and tell them we have data. */
		save_lc_errno = lc_errno;
		lc_errno = LC_ERR_NONE;
		lcpvret = lc_process_var(qualifbuf, NULL, value, LC_FLAGS_VAR);
		if (lcpvret < 0) {
			if (lc_errno == LC_ERR_NONE) {
				PRINTERR_D("Invalid command: \"%s\"", cmd);
				lc_errno = LC_ERR_INVCMD;
			} else {
				PRINTERR_D("Error processing command (command was valid, but an error occured, errno was set)");
			}
			retval = -1;
		} else {
			lc_errno = save_lc_errno;
		}

		/* Remove the "cmd" part of the buffer. */
		tmp_ptr = strrchr(qualifbuf, '.');
		if (tmp_ptr == NULL) {
			tmp_ptr = qualifbuf;
		}
		*tmp_ptr = '\0';
	}

	fclose(configfp);

	return(retval);
}

int lc_process_conf_apache(const char *appname, const char *configfile) {
	return(lc_process_conf_apache_file(configfile, NULL));
}
15
16
17
18
19
20
21



22
23

24
25
26
27
28
29

30
31
32
33
34
35
36
	FILE *configfp = NULL;
	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
	char qualifbuf[LC_LINEBUF_LEN] = {0};
	char *cmd = NULL, *value = NULL, *sep = NULL, *cmdend = NULL;
	char *currsection = NULL;
	char *fgetsret = NULL;
	int lcpvret = -1;




	if (appname == NULL || configfile == NULL) {

		return(-1);
	}

	configfp = fopen(configfile, "r");

	if (configfp == NULL) {

		return(-1);
	}

	while (1) {
		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
		if (fgetsret == NULL) {
			break;







>
>
>


>






>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
	FILE *configfp = NULL;
	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
	char qualifbuf[LC_LINEBUF_LEN] = {0};
	char *cmd = NULL, *value = NULL, *sep = NULL, *cmdend = NULL;
	char *currsection = NULL;
	char *fgetsret = NULL;
	int lcpvret = -1;
	int invalid_section = 1, ignore_section = 0;
	int retval = 0;
	lc_err_t save_lc_errno = LC_ERR_NONE;

	if (appname == NULL || configfile == NULL) {
		lc_errno = LC_ERR_INVDATA;
		return(-1);
	}

	configfp = fopen(configfile, "r");

	if (configfp == NULL) {
		lc_errno = LC_ERR_CANTOPEN;
		return(-1);
	}

	while (1) {
		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
		if (fgetsret == NULL) {
			break;
61
62
63
64
65
66
67










68
69
70
71
72
73
74
75
76
77
78
79
80
81












82
83
84
85
86
87
88
			}

			/* Open new section. */
			currsection = strdup(linebuf_ptr);
			lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONSTART);
			if (lcpvret < 0) {
				PRINTERR_D("Invalid section: \"%s\"", currsection);










			}
			continue;
		}

		/* Remove leading spaces. */
		linebuf_ptr = &linebuf[0];
		while (*linebuf_ptr == ' ') {
			*linebuf_ptr++;
		}

		/* Drop comments and blank lines. */
		if (*linebuf_ptr == ';' || *linebuf_ptr == '\0') {
			continue;
		}













		/* Find the command and the data in the line. */
		cmdend = sep = strpbrk(linebuf_ptr, "=");
		if (sep == NULL) {
			PRINTERR("Invalid line: \"%s\"", linebuf);
			continue;
		}







>
>
>
>
>
>
>
>
>
>














>
>
>
>
>
>
>
>
>
>
>
>







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
			}

			/* Open new section. */
			currsection = strdup(linebuf_ptr);
			lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONSTART);
			if (lcpvret < 0) {
				PRINTERR_D("Invalid section: \"%s\"", currsection);
				invalid_section = 1;
				lc_errno = LC_ERR_INVSECTION;
				retval = -1;
			} else {
				invalid_section = 0;
				ignore_section = 0;
			}

			if (lcpvret == LC_CBRET_IGNORESECTION) {
				ignore_section = 1;
			}
			continue;
		}

		/* Remove leading spaces. */
		linebuf_ptr = &linebuf[0];
		while (*linebuf_ptr == ' ') {
			*linebuf_ptr++;
		}

		/* Drop comments and blank lines. */
		if (*linebuf_ptr == ';' || *linebuf_ptr == '\0') {
			continue;
		}

		/* Don't handle things for a section that doesn't exist. */
		if (invalid_section == 1) {
			PRINTERR_D("Ignoring line (because invalid section): %s", linebuf);
			continue;
		}

		/* Don't process commands if this section is specifically ignored. */
		if (ignore_section == 1) {
			PRINTERR_D("Ignoring line (because ignored section): %s", linebuf);
			continue;
		}

		/* Find the command and the data in the line. */
		cmdend = sep = strpbrk(linebuf_ptr, "=");
		if (sep == NULL) {
			PRINTERR("Invalid line: \"%s\"", linebuf);
			continue;
		}
108
109
110
111
112
113
114


115
116

117







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
		if (currsection == NULL) {
			strncpy(qualifbuf, cmd, sizeof(qualifbuf) - 1);
		} else {
			snprintf(qualifbuf, sizeof(qualifbuf) - 1, "%s.%s", currsection, cmd);
		}

		/* Call the parent and tell them we have data. */


		lcpvret = lc_process_var(qualifbuf, NULL, value, LC_FLAGS_VAR);
		if (lcpvret < 0) {

			PRINTERR_D("Invalid command: \"%s\"", qualifbuf);







		}
	}

	/* Close any open section, and clean-up. */
	if (currsection != NULL) {
		lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONEND);
		if (lcpvret < 0) {
			PRINTERR_D("Invalid section terminating: \"%s\"", currsection);
		}
		free(currsection);
	}

	fclose(configfp);

	return(0);
}







>
>


>
|
>
>
>
>
>
>
>














|

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
		if (currsection == NULL) {
			strncpy(qualifbuf, cmd, sizeof(qualifbuf) - 1);
		} else {
			snprintf(qualifbuf, sizeof(qualifbuf) - 1, "%s.%s", currsection, cmd);
		}

		/* Call the parent and tell them we have data. */
		save_lc_errno = lc_errno;
		lc_errno = LC_ERR_NONE;
		lcpvret = lc_process_var(qualifbuf, NULL, value, LC_FLAGS_VAR);
		if (lcpvret < 0) {
			if (lc_errno == LC_ERR_NONE) {
				PRINTERR_D("Invalid command: \"%s\"", cmd);
				lc_errno = LC_ERR_INVCMD;
			} else {
				PRINTERR_D("Error processing command (command was valid, but an error occured, errno was set)");
			}
			retval = -1;
		} else {
			lc_errno = save_lc_errno;
		}
	}

	/* Close any open section, and clean-up. */
	if (currsection != NULL) {
		lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONEND);
		if (lcpvret < 0) {
			PRINTERR_D("Invalid section terminating: \"%s\"", currsection);
		}
		free(currsection);
	}

	fclose(configfp);

	return(retval);
}
13
14
15
16
17
18
19


20
21

22
23
24
25
26
27

28
29
30
31
32
33
34

int lc_process_conf_space(const char *appname, const char *configfile) {
	FILE *configfp = NULL;
	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
	char *cmd = NULL, *value = NULL, *sep = NULL;
	char *fgetsret = NULL;
	int lcpvret = -1;



	if (appname == NULL || configfile == NULL) {

		return(-1);
	}

	configfp = fopen(configfile, "r");

	if (configfp == NULL) {

		return(-1);
	}

	while (1) {
		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
		if (fgetsret == NULL) {
			break;







>
>


>






>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

int lc_process_conf_space(const char *appname, const char *configfile) {
	FILE *configfp = NULL;
	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
	char *cmd = NULL, *value = NULL, *sep = NULL;
	char *fgetsret = NULL;
	int lcpvret = -1;
	int retval = 0;
	lc_err_t save_lc_errno = LC_ERR_NONE;

	if (appname == NULL || configfile == NULL) {
		lc_errno = LC_ERR_INVDATA;
		return(-1);
	}

	configfp = fopen(configfile, "r");

	if (configfp == NULL) {
		lc_errno = LC_ERR_CANTOPEN;
		return(-1);
	}

	while (1) {
		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
		if (fgetsret == NULL) {
			break;
62
63
64
65
66
67
68


69
70

71







72
73
74
75
76
77
78
				*sep++;
			}
			value = sep;
		} else {
			value = NULL;
		}



		lcpvret = lc_process_var(cmd, NULL, value, LC_FLAGS_VAR);
		if (lcpvret < 0) {

			PRINTERR_D("Invalid command: \"%s\"", cmd);







		}
	}

	fclose(configfp);

	return(0);
}







>
>


>
|
>
>
>
>
>
>
>





|

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
				*sep++;
			}
			value = sep;
		} else {
			value = NULL;
		}

		save_lc_errno = lc_errno;
		lc_errno = LC_ERR_NONE;
		lcpvret = lc_process_var(cmd, NULL, value, LC_FLAGS_VAR);
		if (lcpvret < 0) {
			if (lc_errno == LC_ERR_NONE) {
				PRINTERR_D("Invalid command: \"%s\"", cmd);
				lc_errno = LC_ERR_INVCMD;
			} else {
				PRINTERR_D("Error processing command (command was valid, but an error occured, errno was set)");
			}
			retval = -1;
		} else {
			lc_errno = save_lc_errno;
		}
	}

	fclose(configfp);

	return(retval);
}
1
2
3
4



5
6
7
8
9
10
11
12
13



14
15
16
17
18
19
20
/* config.h.in.  Generated from configure.in by autoheader.  */

/* Define to 1 if you have the <ctype.h> header file. */
#undef HAVE_CTYPE_H




/* Define to 1 if you have the `getopt' function. */
#undef HAVE_GETOPT

/* Define to 1 if you have the <getopt.h> header file. */
#undef HAVE_GETOPT_H

/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H




/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H

/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H





>
>
>









>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* config.h.in.  Generated from configure.in by autoheader.  */

/* Define to 1 if you have the <ctype.h> header file. */
#undef HAVE_CTYPE_H

/* Define to 1 if you have the <dirent.h> header file. */
#undef HAVE_DIRENT_H

/* Define to 1 if you have the `getopt' function. */
#undef HAVE_GETOPT

/* Define to 1 if you have the <getopt.h> header file. */
#undef HAVE_GETOPT_H

/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H

/* Define to 1 if you have the <libintl.h> header file. */
#undef HAVE_LIBINTL_H

/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H

/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H

Modified configure from [743edb59b5] to [3e2a72d1bf].
1
2
3
4
5
6
7
8
9
10
11
#! /bin/sh
# From configure.in Revision .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.59 for libconfig 0.0.1.
#
# Copyright (C) 2003 Free Software Foundation, Inc.
# This configure script is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.
## --------------------- ##
## M4sh Initialization.  ##
## --------------------- ##



|







1
2
3
4
5
6
7
8
9
10
11
#! /bin/sh
# From configure.in Revision .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.59 for libconfig 0.0.2.
#
# Copyright (C) 2003 Free Software Foundation, Inc.
# This configure script is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.
## --------------------- ##
## M4sh Initialization.  ##
## --------------------- ##
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# This variable seems obsolete.  It should probably be removed, and
# only ac_max_sed_lines should be used.
: ${ac_max_here_lines=38}

# Identity of this package.
PACKAGE_NAME='libconfig'
PACKAGE_TARNAME='libconfig'
PACKAGE_VERSION='0.0.1'
PACKAGE_STRING='libconfig 0.0.1'
PACKAGE_BUGREPORT=''

# Factoring default headers for most tests.
ac_includes_default="\
#include <stdio.h>
#if HAVE_SYS_TYPES_H
# include <sys/types.h>







|
|







264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# This variable seems obsolete.  It should probably be removed, and
# only ac_max_sed_lines should be used.
: ${ac_max_here_lines=38}

# Identity of this package.
PACKAGE_NAME='libconfig'
PACKAGE_TARNAME='libconfig'
PACKAGE_VERSION='0.0.2'
PACKAGE_STRING='libconfig 0.0.2'
PACKAGE_BUGREPORT=''

# Factoring default headers for most tests.
ac_includes_default="\
#include <stdio.h>
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#  include <stdint.h>
# endif
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif"

ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT SET_MAKE INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CPP EGREP AR ac_ct_AR RANLIB ac_ct_RANLIB LIBOBJS SHOBJFLAGS SHOBJLDFLAGS LTLIBOBJS'
ac_subst_files=''

# Initialize some variables set by options.
ac_init_help=
ac_init_version=false
# The variables have the same names as the options, with
# dashes changed to underlines.







|







305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#  include <stdint.h>
# endif
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif"

ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT SET_MAKE INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S RANLIB ac_ct_RANLIB CPP EGREP AR ac_ct_AR LIBOBJS SHOBJFLAGS SHOBJLDFLAGS LTLIBOBJS'
ac_subst_files=''

# Initialize some variables set by options.
ac_init_help=
ac_init_version=false
# The variables have the same names as the options, with
# dashes changed to underlines.
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
#
# Report the --help message.
#
if test "$ac_init_help" = "long"; then
  # Omit some internal or obsolete options to make the list less imposing.
  # This message is too long to be a string in the A/UX 3.1 sh.
  cat <<_ACEOF
\`configure' configures libconfig 0.0.1 to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.







|







774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
#
# Report the --help message.
#
if test "$ac_init_help" = "long"; then
  # Omit some internal or obsolete options to make the list less imposing.
  # This message is too long to be a string in the A/UX 3.1 sh.
  cat <<_ACEOF
\`configure' configures libconfig 0.0.2 to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845

  cat <<\_ACEOF
_ACEOF
fi

if test -n "$ac_init_help"; then
  case $ac_init_help in
     short | recursive ) echo "Configuration of libconfig 0.0.1:";;
   esac
  cat <<\_ACEOF

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a







|







831
832
833
834
835
836
837
838
839
840
841
842
843
844
845

  cat <<\_ACEOF
_ACEOF
fi

if test -n "$ac_init_help"; then
  case $ac_init_help in
     short | recursive ) echo "Configuration of libconfig 0.0.2:";;
   esac
  cat <<\_ACEOF

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
    cd $ac_popdir
  done
fi

test -n "$ac_init_help" && exit 0
if $ac_init_version; then
  cat <<\_ACEOF
libconfig configure 0.0.1
generated by GNU Autoconf 2.59

Copyright (C) 2003 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
_ACEOF
  exit 0
fi
exec 5>config.log
cat >&5 <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by libconfig $as_me 0.0.1, which was
generated by GNU Autoconf 2.59.  Invocation command line was

  $ $0 $@

_ACEOF
{
cat <<_ASUNAME







|













|







942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
    cd $ac_popdir
  done
fi

test -n "$ac_init_help" && exit 0
if $ac_init_version; then
  cat <<\_ACEOF
libconfig configure 0.0.2
generated by GNU Autoconf 2.59

Copyright (C) 2003 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
_ACEOF
  exit 0
fi
exec 5>config.log
cat >&5 <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by libconfig $as_me 0.0.2, which was
generated by GNU Autoconf 2.59.  Invocation command line was

  $ $0 $@

_ACEOF
{
cat <<_ASUNAME
2358
2359
2360
2361
2362
2363
2364



























































































2365
2366
2367
2368
2369
2370
2371
# It thinks the first close brace ends the variable substitution.
test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'

test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'

test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'





























































































ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
# It thinks the first close brace ends the variable substitution.
test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'

test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'

test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'

echo "$as_me:$LINENO: checking whether ln -s works" >&5
echo $ECHO_N "checking whether ln -s works... $ECHO_C" >&6
LN_S=$as_ln_s
if test "$LN_S" = "ln -s"; then
  echo "$as_me:$LINENO: result: yes" >&5
echo "${ECHO_T}yes" >&6
else
  echo "$as_me:$LINENO: result: no, using $LN_S" >&5
echo "${ECHO_T}no, using $LN_S" >&6
fi

if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
set dummy ${ac_tool_prefix}ranlib; ac_word=$2
echo "$as_me:$LINENO: checking for $ac_word" >&5
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
if test "${ac_cv_prog_RANLIB+set}" = set; then
  echo $ECHO_N "(cached) $ECHO_C" >&6
else
  if test -n "$RANLIB"; then
  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  for ac_exec_ext in '' $ac_executable_extensions; do
  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
done

fi
fi
RANLIB=$ac_cv_prog_RANLIB
if test -n "$RANLIB"; then
  echo "$as_me:$LINENO: result: $RANLIB" >&5
echo "${ECHO_T}$RANLIB" >&6
else
  echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi

fi
if test -z "$ac_cv_prog_RANLIB"; then
  ac_ct_RANLIB=$RANLIB
  # Extract the first word of "ranlib", so it can be a program name with args.
set dummy ranlib; ac_word=$2
echo "$as_me:$LINENO: checking for $ac_word" >&5
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then
  echo $ECHO_N "(cached) $ECHO_C" >&6
else
  if test -n "$ac_ct_RANLIB"; then
  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  for ac_exec_ext in '' $ac_executable_extensions; do
  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_RANLIB="ranlib"
    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
done

  test -z "$ac_cv_prog_ac_ct_RANLIB" && ac_cv_prog_ac_ct_RANLIB=":"
fi
fi
ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
if test -n "$ac_ct_RANLIB"; then
  echo "$as_me:$LINENO: result: $ac_ct_RANLIB" >&5
echo "${ECHO_T}$ac_ct_RANLIB" >&6
else
  echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi

  RANLIB=$ac_ct_RANLIB
else
  RANLIB="$ac_cv_prog_RANLIB"
fi


ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
fi

  AR=$ac_ct_AR
else
  AR="$ac_cv_prog_AR"
fi

if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
set dummy ${ac_tool_prefix}ranlib; ac_word=$2
echo "$as_me:$LINENO: checking for $ac_word" >&5
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
if test "${ac_cv_prog_RANLIB+set}" = set; then
  echo $ECHO_N "(cached) $ECHO_C" >&6
else
  if test -n "$RANLIB"; then
  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  for ac_exec_ext in '' $ac_executable_extensions; do
  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
done

fi
fi
RANLIB=$ac_cv_prog_RANLIB
if test -n "$RANLIB"; then
  echo "$as_me:$LINENO: result: $RANLIB" >&5
echo "${ECHO_T}$RANLIB" >&6
else
  echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi

fi
if test -z "$ac_cv_prog_RANLIB"; then
  ac_ct_RANLIB=$RANLIB
  # Extract the first word of "ranlib", so it can be a program name with args.
set dummy ranlib; ac_word=$2
echo "$as_me:$LINENO: checking for $ac_word" >&5
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then
  echo $ECHO_N "(cached) $ECHO_C" >&6
else
  if test -n "$ac_ct_RANLIB"; then
  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  for ac_exec_ext in '' $ac_executable_extensions; do
  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_RANLIB="ranlib"
    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
done

  test -z "$ac_cv_prog_ac_ct_RANLIB" && ac_cv_prog_ac_ct_RANLIB="true"
fi
fi
ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
if test -n "$ac_ct_RANLIB"; then
  echo "$as_me:$LINENO: result: $ac_ct_RANLIB" >&5
echo "${ECHO_T}$ac_ct_RANLIB" >&6
else
  echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi

  RANLIB=$ac_ct_RANLIB
else
  RANLIB="$ac_cv_prog_RANLIB"
fi


cat >>confdefs.h <<\_ACEOF
#define _GNU_SOURCE 1
_ACEOF










<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







2809
2810
2811
2812
2813
2814
2815
















































































2816
2817
2818
2819
2820
2821
2822
fi

  AR=$ac_ct_AR
else
  AR="$ac_cv_prog_AR"
fi


















































































cat >>confdefs.h <<\_ACEOF
#define _GNU_SOURCE 1
_ACEOF



3051
3052
3053
3054
3055
3056
3057
3058





3059
3060
3061
3062
3063
3064
3065







for ac_header in stdlib.h string.h unistd.h time.h sys/time.h getopt.h stdio.h ctype.h





do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
  echo "$as_me:$LINENO: checking for $ac_header" >&5
echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
if eval "test \"\${$as_ac_Header+set}\" = set"; then
  echo $ECHO_N "(cached) $ECHO_C" >&6







|
>
>
>
>
>







3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081












for ac_header in ctype.h dirent.h libintl.h stdio.h stdlib.h string.h strings.h sys/stat.h sys/types.h unistd.h getopt.h time.h sys/time.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
  echo "$as_me:$LINENO: checking for $ac_header" >&5
echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
if eval "test \"\${$as_ac_Header+set}\" = set"; then
  echo $ECHO_N "(cached) $ECHO_C" >&6
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
      conftest$ac_exeext conftest.$ac_ext;
  fi
  LDFLAGS="$OLD_LDFLAGS"
  echo "$as_me:$LINENO: result: $SHOBJLDFLAGS $SHOBJFLAGS" >&5
echo "${ECHO_T}$SHOBJLDFLAGS $SHOBJFLAGS" >&6


          ac_config_files="$ac_config_files Makefile"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
# tests run on this system so they can be shared between configure
# scripts and configure runs, see configure's option --config-cache.
# It is not useful on other systems.  If it contains results you don't
# want to keep, you may remove or edit it.
#







|







16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
      conftest$ac_exeext conftest.$ac_ext;
  fi
  LDFLAGS="$OLD_LDFLAGS"
  echo "$as_me:$LINENO: result: $SHOBJLDFLAGS $SHOBJFLAGS" >&5
echo "${ECHO_T}$SHOBJLDFLAGS $SHOBJFLAGS" >&6


                                                            ac_config_files="$ac_config_files Makefile lc_geterrno.3 lc_process.3 lc_register_var.3 lc_geterrstr.3 lc_register_callback.3"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
# tests run on this system so they can be shared between configure
# scripts and configure runs, see configure's option --config-cache.
# It is not useful on other systems.  If it contains results you don't
# want to keep, you may remove or edit it.
#
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
  echo
  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## Running $as_me. ##
_ASBOX
} >&5
cat >&5 <<_CSEOF

This file was extended by libconfig $as_me 0.0.1, which was
generated by GNU Autoconf 2.59.  Invocation command line was

  CONFIG_FILES    = $CONFIG_FILES
  CONFIG_HEADERS  = $CONFIG_HEADERS
  CONFIG_LINKS    = $CONFIG_LINKS
  CONFIG_COMMANDS = $CONFIG_COMMANDS
  $ $0 $@







|







16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
  echo
  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## Running $as_me. ##
_ASBOX
} >&5
cat >&5 <<_CSEOF

This file was extended by libconfig $as_me 0.0.2, which was
generated by GNU Autoconf 2.59.  Invocation command line was

  CONFIG_FILES    = $CONFIG_FILES
  CONFIG_HEADERS  = $CONFIG_HEADERS
  CONFIG_LINKS    = $CONFIG_LINKS
  CONFIG_COMMANDS = $CONFIG_COMMANDS
  $ $0 $@
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
$config_headers

Report bugs to <bug-autoconf@gnu.org>."
_ACEOF

cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
libconfig config.status 0.0.1
configured by $0, generated by GNU Autoconf 2.59,
  with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"

Copyright (C) 2003 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it."
srcdir=$srcdir







|







16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
$config_headers

Report bugs to <bug-autoconf@gnu.org>."
_ACEOF

cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
libconfig config.status 0.0.2
configured by $0, generated by GNU Autoconf 2.59,
  with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"

Copyright (C) 2003 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it."
srcdir=$srcdir
16697
16698
16699
16700
16701
16702
16703





16704
16705
16706
16707
16708
16709
16710

cat >>$CONFIG_STATUS <<\_ACEOF
for ac_config_target in $ac_config_targets
do
  case "$ac_config_target" in
  # Handling of arguments.
  "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;





  "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
  *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
   { (exit 1); exit 1; }; };;
  esac
done








>
>
>
>
>







16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731

cat >>$CONFIG_STATUS <<\_ACEOF
for ac_config_target in $ac_config_targets
do
  case "$ac_config_target" in
  # Handling of arguments.
  "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
  "lc_geterrno.3" ) CONFIG_FILES="$CONFIG_FILES lc_geterrno.3" ;;
  "lc_process.3" ) CONFIG_FILES="$CONFIG_FILES lc_process.3" ;;
  "lc_register_var.3" ) CONFIG_FILES="$CONFIG_FILES lc_register_var.3" ;;
  "lc_geterrstr.3" ) CONFIG_FILES="$CONFIG_FILES lc_geterrstr.3" ;;
  "lc_register_callback.3" ) CONFIG_FILES="$CONFIG_FILES lc_register_callback.3" ;;
  "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
  *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
   { (exit 1); exit 1; }; };;
  esac
done

16793
16794
16795
16796
16797
16798
16799



16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
s,@ac_ct_CC@,$ac_ct_CC,;t t
s,@EXEEXT@,$EXEEXT,;t t
s,@OBJEXT@,$OBJEXT,;t t
s,@SET_MAKE@,$SET_MAKE,;t t
s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t
s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t
s,@INSTALL_DATA@,$INSTALL_DATA,;t t



s,@CPP@,$CPP,;t t
s,@EGREP@,$EGREP,;t t
s,@AR@,$AR,;t t
s,@ac_ct_AR@,$ac_ct_AR,;t t
s,@RANLIB@,$RANLIB,;t t
s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t
s,@LIBOBJS@,$LIBOBJS,;t t
s,@SHOBJFLAGS@,$SHOBJFLAGS,;t t
s,@SHOBJLDFLAGS@,$SHOBJLDFLAGS,;t t
s,@LTLIBOBJS@,$LTLIBOBJS,;t t
CEOF

_ACEOF







>
>
>




<
<







16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827


16828
16829
16830
16831
16832
16833
16834
s,@ac_ct_CC@,$ac_ct_CC,;t t
s,@EXEEXT@,$EXEEXT,;t t
s,@OBJEXT@,$OBJEXT,;t t
s,@SET_MAKE@,$SET_MAKE,;t t
s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t
s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t
s,@INSTALL_DATA@,$INSTALL_DATA,;t t
s,@LN_S@,$LN_S,;t t
s,@RANLIB@,$RANLIB,;t t
s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t
s,@CPP@,$CPP,;t t
s,@EGREP@,$EGREP,;t t
s,@AR@,$AR,;t t
s,@ac_ct_AR@,$ac_ct_AR,;t t


s,@LIBOBJS@,$LIBOBJS,;t t
s,@SHOBJFLAGS@,$SHOBJFLAGS,;t t
s,@SHOBJLDFLAGS@,$SHOBJLDFLAGS,;t t
s,@LTLIBOBJS@,$LTLIBOBJS,;t t
CEOF

_ACEOF
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
AC_REVISION($Revision $)
AC_INIT(libconfig, 0.0.1)
AC_CONFIG_HEADER(config.h)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_MAKE_SET
AC_PROG_INSTALL


AC_AIX
AC_CHECK_TOOL(AR, ar, true)
AC_CHECK_TOOL(RANLIB, ranlib, true)
AC_GNU_SOURCE

AC_CHECK_HEADERS(stdlib.h string.h unistd.h time.h sys/time.h getopt.h stdio.h ctype.h)
AC_HEADER_TIME

DC_DO_TYPE(uint64_t, unsigned, 8)
DC_DO_TYPE(int64_t, signed, 8)
DC_DO_TYPE(uint32_t, unsigned, 4)
DC_DO_TYPE(int32_t, signed, 4)
DC_DO_TYPE(uint16_t, unsigned, 2)
DC_DO_TYPE(int16_t, signed, 2)

AC_REPLACE_FUNCS(getopt strsep)

dnl Checks for Win32 specific things.
DC_DO_WIN32

DC_GET_SHOBJFLAGS

AC_OUTPUT(Makefile)

|






>
>


<


|









|






|
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
AC_REVISION($Revision $)
AC_INIT(libconfig, 0.0.2)
AC_CONFIG_HEADER(config.h)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_RANLIB
AC_AIX
AC_CHECK_TOOL(AR, ar, true)

AC_GNU_SOURCE

AC_CHECK_HEADERS(ctype.h dirent.h libintl.h stdio.h stdlib.h string.h strings.h sys/stat.h sys/types.h unistd.h time.h sys/time.h)
AC_HEADER_TIME

DC_DO_TYPE(uint64_t, unsigned, 8)
DC_DO_TYPE(int64_t, signed, 8)
DC_DO_TYPE(uint32_t, unsigned, 4)
DC_DO_TYPE(int32_t, signed, 4)
DC_DO_TYPE(uint16_t, unsigned, 2)
DC_DO_TYPE(int16_t, signed, 2)

AC_REPLACE_FUNCS(strsep)

dnl Checks for Win32 specific things.
DC_DO_WIN32

DC_GET_SHOBJFLAGS

AC_OUTPUT(Makefile lc_geterrno.3 lc_process.3 lc_register_var.3 lc_geterrstr.3 lc_register_callback.3)
Deleted getopt.c version [0813078ee0].
Deleted getopt.h version [e07bc96ddb].
Added lc_process.3.in version [da39a3ee5e].
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#endif

#ifdef HAVE_CTYPE_H
#include <ctype.h>
#endif

struct lc_varhandler_st *varhandlers = NULL;

int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra) {
	int retval = -1;

	switch (type) {
		case LC_CONF_SECTION:
			retval = lc_process_conf_section(appname, extra);
			break;
		case LC_CONF_APACHE:
			retval = lc_process_conf_apache(appname, extra);
			break;
		case LC_CONF_COLON:
			retval = lc_process_conf_colon(appname, extra);
			break;
		case LC_CONF_EQUAL:
			retval = lc_process_conf_equal(appname, extra);
			break;
		case LC_CONF_SPACE:
			retval = lc_process_conf_space(appname, extra);
			break;
		case LC_CONF_XML:
			retval = lc_process_conf_xml(appname, extra);
			break;
		default:
			break;
	}

	return(retval);
}

static int lc_process_var_string(void *data, const char *value) {
	char **dataval;

	dataval = data;
	*dataval = strdup(value);








|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







17
18
19
20
21
22
23
24




























25
26
27
28
29
30
31
#endif

#ifdef HAVE_CTYPE_H
#include <ctype.h>
#endif

struct lc_varhandler_st *varhandlers = NULL;
lc_err_t lc_errno = LC_ERR_NONE;





























static int lc_process_var_string(void *data, const char *value) {
	char **dataval;

	dataval = data;
	*dataval = strdup(value);

106
107
108
109
110
111
112

113
114
115
116
117
118
119

120
121

122
123
124
125
126
127
128
129
	if (strcasecmp(value, "enable") == 0 ||
	    strcasecmp(value, "true") == 0 ||
	    strcasecmp(value, "yes") == 0 ||
	    strcasecmp(value, "on") == 0 ||
            strcasecmp(value, "y") == 0 ||
	    strcasecmp(value, "1") == 0) {
		*dataval = 1;

	} else if (strcasecmp(value, "disable") == 0 ||
	    strcasecmp(value, "false") == 0 ||
	    strcasecmp(value, "off") == 0 ||
	    strcasecmp(value, "no") == 0 ||
            strcasecmp(value, "n") == 0 ||
	    strcasecmp(value, "0") == 0) {
		*dataval = 0;

	}


	return(0);
}

static long long lc_process_size(const char *value) {
	long long retval = -1;
	char *mult = NULL;

	retval = strtoull(value, &mult, 10);







>







>


>
|







78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	if (strcasecmp(value, "enable") == 0 ||
	    strcasecmp(value, "true") == 0 ||
	    strcasecmp(value, "yes") == 0 ||
	    strcasecmp(value, "on") == 0 ||
            strcasecmp(value, "y") == 0 ||
	    strcasecmp(value, "1") == 0) {
		*dataval = 1;
		return(0);
	} else if (strcasecmp(value, "disable") == 0 ||
	    strcasecmp(value, "false") == 0 ||
	    strcasecmp(value, "off") == 0 ||
	    strcasecmp(value, "no") == 0 ||
            strcasecmp(value, "n") == 0 ||
	    strcasecmp(value, "0") == 0) {
		*dataval = 0;
		return(0);
	}

	lc_errno = LC_ERR_BADFORMAT;
	return(-1);
}

static long long lc_process_size(const char *value) {
	long long retval = -1;
	char *mult = NULL;

	retval = strtoull(value, &mult, 10);
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237

238
239
240
241
242




























243























































































































































































244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290
291

	dataval = data;
	*dataval = lc_process_size(value);

	return(0);
}

static int lc_handle(struct lc_varhandler_st *handler, const char *value, lc_flags_t flags) {
	switch (handler->mode) {
		case LC_MODE_CALLBACK:
			if (handler->callback != NULL) {
				return(handler->callback(handler->var, value, flags));
			}
			break;
		case LC_MODE_VAR:
			switch (handler->type) {
				case LC_VAR_STRING:
					return(lc_process_var_string(handler->data, value));
					break;
				case LC_VAR_LONG_LONG:
					return(lc_process_var_longlong(handler->data, value));
					break;
				case LC_VAR_LONG:
					return(lc_process_var_long(handler->data, value));
					break;
				case LC_VAR_INT:
					return(lc_process_var_int(handler->data, value));
					break;
				case LC_VAR_SHORT:
					return(lc_process_var_short(handler->data, value));
					break;
				case LC_VAR_BOOL:
					return(lc_process_var_bool(handler->data, value));
					break;
				case LC_VAR_SIZE_LONG_LONG:
					return(lc_process_var_sizelonglong(handler->data, value));
					break;
				case LC_VAR_SIZE_LONG:
					return(lc_process_var_sizelong(handler->data, value));
					break;
				case LC_VAR_SIZE_INT:
					return(lc_process_var_sizeint(handler->data, value));
					break;
				case LC_VAR_SIZE_SHORT:
					return(lc_process_var_sizeshort(handler->data, value));
					break;
				case LC_VAR_TIME:
				case LC_VAR_DATE:
				case LC_VAR_FILENAME:
				case LC_VAR_DIRECTORY:
					PRINTERR_D("Not implemented yet!");
					return(-1);
				case LC_VAR_NONE:
				case LC_VAR_UNKNOWN:

				case LC_VAR_SECTIONSTART:
				case LC_VAR_SECTIONEND:
					return(0);
					break;
			}




























		break;























































































































































































	}

	return(-1);
}

int lc_process_var(const char *var, const char *varargs, const char *value, lc_flags_t flags) {
	struct lc_varhandler_st *handler = NULL;

	for (handler = varhandlers; handler != NULL; handler = handler->_next) {
		if (handler->var != var && (handler->var == NULL || var == NULL)) {
			continue;
		}
		if (handler->var != NULL) {
			if (strcasecmp(handler->var, var) != 0) {
				continue;
			}
		}

		return(lc_handle(handler, value, flags));
	}
	return(-1);
}

int lc_register_callback(const char *var, int (*callback)(const char *, const char *, lc_flags_t)) {
	struct lc_varhandler_st *newhandler = NULL;

	newhandler = malloc(sizeof(*newhandler));

	if (newhandler == NULL) {
		return(-1);
	}

	if (var == NULL) {
		newhandler->var = NULL;
	} else {
		newhandler->var = strdup(var);
	}
	newhandler->callback = callback;
	newhandler->type = LC_VAR_UNKNOWN;

	newhandler->mode = LC_MODE_CALLBACK;
	newhandler->opt = '\0';
	newhandler->_next = varhandlers;

	varhandlers = newhandler;

	return(0);
}








|
|
<
<
<
<
<
<
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<













|
|
>
|
|







159
160
161
162
163
164
165
166
167







168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428


429
















430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454

	dataval = data;
	*dataval = lc_process_size(value);

	return(0);
}

static int lc_handle_type(lc_var_type_t type, const char *value, void *data) {
	switch (type) {







		case LC_VAR_STRING:
			return(lc_process_var_string(data, value));
			break;
		case LC_VAR_LONG_LONG:
			return(lc_process_var_longlong(data, value));
			break;
		case LC_VAR_LONG:
			return(lc_process_var_long(data, value));
			break;
		case LC_VAR_INT:
			return(lc_process_var_int(data, value));
			break;
		case LC_VAR_SHORT:
			return(lc_process_var_short(data, value));
			break;
		case LC_VAR_BOOL:
			return(lc_process_var_bool(data, value));
			break;
		case LC_VAR_SIZE_LONG_LONG:
			return(lc_process_var_sizelonglong(data, value));
			break;
		case LC_VAR_SIZE_LONG:
			return(lc_process_var_sizelong(data, value));
			break;
		case LC_VAR_SIZE_INT:
			return(lc_process_var_sizeint(data, value));
			break;
		case LC_VAR_SIZE_SHORT:
			return(lc_process_var_sizeshort(data, value));
			break;
		case LC_VAR_TIME:
		case LC_VAR_DATE:
		case LC_VAR_FILENAME:
		case LC_VAR_DIRECTORY:
			PRINTERR_D("Not implemented yet!");
			return(-1);
		case LC_VAR_NONE:
		case LC_VAR_UNKNOWN:
		case LC_VAR_SECTION:
		case LC_VAR_SECTIONSTART:
		case LC_VAR_SECTIONEND:
			return(0);
			break;
	}

	return(-1);
}

static int lc_handle(struct lc_varhandler_st *handler, const char *var, const char *varargs, const char *value, lc_flags_t flags) {
	const char *localvar = NULL;
	int retval;

	if (var != NULL) {
		localvar = strrchr(var, '.');
		if (localvar == NULL) {
			localvar = var;
		} else {
			*localvar++;
		}
	} else {
		localvar = NULL;
	}

	switch (handler->mode) {
		case LC_MODE_CALLBACK:
			if (handler->callback != NULL) {
				retval = handler->callback(localvar, var, varargs, value, flags, handler->extra);
				if (retval < 0) {
					lc_errno = LC_ERR_CALLBACK;
				}
				return(retval);
			}
			break;
		case LC_MODE_VAR:
			return(lc_handle_type(handler->type, value, handler->data));
			break;
	}

	return(-1);
}

static int lc_process_environment(const char *appname) {
	/* XXX: write this */
	return(0);
}

static int lc_process_cmdline(int argc, char **argv) {
	struct lc_varhandler_st *handler = NULL;
	char *cmdarg = NULL, *cmdoptarg = NULL;
	char *lastcomponent_handler = NULL;
	int cmdargidx = 0;
	int retval = 0, chkretval = 0;
	int ch = 0;

	for (cmdargidx = 1; cmdargidx < argc; cmdargidx++) {
		cmdarg = argv[cmdargidx];

		/* Make sure we have an argument here. */
		if (cmdarg == NULL) {
			break;
		}

		/* If the argument isn't an option, abort. */
		if (cmdarg[0] != '-') {
			continue;
		}
		*cmdarg++;

		/* Handle long options. */
		if (cmdarg[0] == '-') {
			*cmdarg++;

			/* Don't process arguments after the '--' option. */
			if (cmdarg[0] == '\0') {
				break;
			}

			/* Look for a variable name that matches */
			for (handler = varhandlers; handler != NULL; handler = handler->_next) {
				/* Skip handlers with no variable name. */
				if (handler->var == NULL) {
					continue;
				}
				/* Skip handlers which don't agree with being
				   processed on the command line. */
				if (handler->type == LC_VAR_SECTION ||
				    handler->type == LC_VAR_SECTIONSTART ||
				    handler->type == LC_VAR_SECTIONEND ||
				    handler->type == LC_VAR_UNKNOWN) {
					continue;
				}

				/* Find the last part of the variable and compare it with 
				   the option being processed. */
				lastcomponent_handler = strrchr(handler->var, '.');
				if (lastcomponent_handler == NULL) {
					lastcomponent_handler = handler->var;
				} else {
					*lastcomponent_handler++;
				}

				/* Ignore this handler if they don't match. */
				if (strcasecmp(lastcomponent_handler, cmdarg) != 0) {
					continue;
				}

				if (handler->type == LC_VAR_NONE) {
					cmdoptarg = NULL;
				} else {
					cmdargidx++;
					if (cmdargidx >= argc) {
						PRINTERR("Argument required.");
						lc_errno = LC_ERR_BADFORMAT;
						return(-1);
					}
					cmdoptarg = argv[cmdargidx];
				}

				chkretval = lc_handle(handler, handler->var, NULL, cmdoptarg, LC_FLAGS_CMDLINE);
				if (chkretval < 0) {
					retval = -1;
				}

				break;
			}

			if (handler == NULL) {
				PRINTERR("Unknown option: --%s", cmdarg);
				lc_errno = LC_ERR_INVCMD;
				return(-1);
			}
		} else {
			for (; *cmdarg != '\0'; *cmdarg++) {
				ch = *cmdarg;

				for (handler = varhandlers; handler != NULL; handler = handler->_next) {
					if (handler->opt != ch || handler->opt == '\0') {
						continue;
					}
					/* Skip handlers which don't agree with being
					   processed on the command line. */
					if (handler->type == LC_VAR_SECTION ||
					    handler->type == LC_VAR_SECTIONSTART ||
					    handler->type == LC_VAR_SECTIONEND ||
					    handler->type == LC_VAR_UNKNOWN) {
						continue;
					}

					if (handler->type == LC_VAR_NONE) {
						cmdoptarg = NULL;
					} else {
						cmdargidx++;
						if (cmdargidx >= argc) {
							PRINTERR("Argument required.");
							lc_errno = LC_ERR_BADFORMAT;
							return(-1);
						}
						cmdoptarg = argv[cmdargidx];
					}

					chkretval = lc_handle(handler, handler->var, NULL, cmdoptarg, LC_FLAGS_CMDLINE);
					if (chkretval < 0) {
						retval = -1;
					}

					break;
				}

				if (handler == NULL) {
					PRINTERR("Unknown option: -%c", ch);
					lc_errno = LC_ERR_INVCMD;
					return(-1);
				}
			}
		}
	}

	return(retval);
}


int lc_process_var(const char *var, const char *varargs, const char *value, lc_flags_t flags) {
	struct lc_varhandler_st *handler = NULL;
	const char *lastcomponent_handler = NULL, *lastcomponent_var = NULL;

	lastcomponent_var = strrchr(var, '.');
	if (lastcomponent_var == NULL) {
		lastcomponent_var = var;
	} else {
		*lastcomponent_var++;
	}

	for (handler = varhandlers; handler != NULL; handler = handler->_next) {
		/* If either handler->var or var is NULL, skip, unless both are NULL. */
		if (handler->var != var && (handler->var == NULL || var == NULL)) {
			continue;
		}

		/* If both are not-NULL, compare them. */
		if (handler->var != NULL) {
			/* Wild-card-ish match. */
			if (handler->var[0] == '*' && handler->var[1] == '.') {
				/* Only compare the last components */

				lastcomponent_handler = strrchr(handler->var, '.') + 1; /* strrchr() won't return NULL, because we already checked it. */

				if (strcasecmp(lastcomponent_handler, lastcomponent_var) != 0) {
					continue;
				}
			} else if (strcasecmp(handler->var, var) != 0) {
				/* Exact (case-insensitive comparison) failed. */
				continue;
			}
		}

		return(lc_handle(handler, var, varargs, value, flags));
	}

	return(-1);
}



int lc_register_callback(const char *var, char opt, lc_var_type_t type, int (*callback)(const char *, const char *, const char *, const char *, lc_flags_t, void *), void *extra) {
















	struct lc_varhandler_st *newhandler = NULL;

	newhandler = malloc(sizeof(*newhandler));

	if (newhandler == NULL) {
		return(-1);
	}

	if (var == NULL) {
		newhandler->var = NULL;
	} else {
		newhandler->var = strdup(var);
	}
	newhandler->mode = LC_MODE_CALLBACK;
	newhandler->type = type;
	newhandler->callback = callback;
	newhandler->opt = opt;
	newhandler->extra = extra;
	newhandler->_next = varhandlers;

	varhandlers = newhandler;

	return(0);
}

299
300
301
302
303
304
305
306
307

308
309

310
311
312
313
314
315






























































































	}

	if (var == NULL) {
		newhandler->var = NULL;
	} else {
		newhandler->var = strdup(var);
	}
	newhandler->type = type;
	newhandler->mode = LC_MODE_VAR;

	newhandler->data = data;
	newhandler->opt = opt;

	newhandler->_next = varhandlers;

	varhandlers = newhandler;

	return(0);
}





































































































<

>


>






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
462
463
464
465
466
467
468

469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
	}

	if (var == NULL) {
		newhandler->var = NULL;
	} else {
		newhandler->var = strdup(var);
	}

	newhandler->mode = LC_MODE_VAR;
	newhandler->type = type;
	newhandler->data = data;
	newhandler->opt = opt;
	newhandler->extra = NULL;
	newhandler->_next = varhandlers;

	varhandlers = newhandler;

	return(0);
}

int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra) {
	int retval = 0, chkretval = 0;

	/* XXX Handle config files.  need to handle this in a loop of config files... */
	switch (type) {
		case LC_CONF_SECTION:
			chkretval = lc_process_conf_section(appname, extra);
			break;
		case LC_CONF_APACHE:
			chkretval = lc_process_conf_apache(appname, extra);
			break;
		case LC_CONF_COLON:
			chkretval = lc_process_conf_colon(appname, extra);
			break;
		case LC_CONF_EQUAL:
			chkretval = lc_process_conf_equal(appname, extra);
			break;
		case LC_CONF_SPACE:
			chkretval = lc_process_conf_space(appname, extra);
			break;
		case LC_CONF_XML:
			chkretval = lc_process_conf_xml(appname, extra);
			break;
		default:
			chkretval = -1;
			lc_errno = LC_ERR_INVDATA;
			break;
	}

	if (chkretval < 0) {
		retval = -1;
	}

	/* Handle environment variables.*/
	chkretval = lc_process_environment(appname);
	if (chkretval < 0) {
		retval = -1;
	}

	/* Handle command line arguments */
	chkretval = lc_process_cmdline(argc, argv);
	if (chkretval < 0) {
		retval = -1;
	}

	return(retval);
}


lc_err_t lc_geterrno(void) {
	lc_err_t retval;

	retval = lc_errno;

	lc_errno = LC_ERR_NONE;

	return(retval);
}

char *lc_geterrstr(void) {
	char *retval = NULL;

	switch (lc_errno) {
		case LC_ERR_NONE:
			retval = "Success";
			break;
		case LC_ERR_INVCMD:
			retval = "Invalid command";
			break;
		case LC_ERR_INVSECTION:
			retval = "Invalid section";
			break;
		case LC_ERR_INVDATA:
			retval = "Invalid application data (internal error)";
			break;
		case LC_ERR_BADFORMAT:
			retval = "Bad data specified or incorrect format.";
			break;
		case LC_ERR_CANTOPEN:
			retval = "Can't open file.";
			break;
		case LC_ERR_CALLBACK:
			retval = "Error return from application handler.";
			break;
	}

	lc_errno = LC_ERR_NONE;

	if (retval != NULL) {
		return(retval);
	}
	return("Unknown error");
}
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41

42
43
44
45
46
47












48
49
50








51
52
53
54
        LC_VAR_DIRECTORY,
        LC_VAR_SIZE_LONG_LONG,
        LC_VAR_SIZE_LONG,
        LC_VAR_SIZE_INT,
        LC_VAR_SIZE_SHORT,
        LC_VAR_TIME,
        LC_VAR_DATE,

        LC_VAR_SECTIONSTART,
        LC_VAR_SECTIONEND
} lc_var_type_t;

__BLANK_LINE__

typedef enum {
	LC_FLAGS_VAR,

        LC_FLAGS_SECTIONSTART,
        LC_FLAGS_SECTIONEND
} lc_flags_t;

__BLANK_LINE__













int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra);
int lc_register_callback(const char *var, int (*callback)(const char *, const char *, lc_flags_t));
int lc_register_var(const char *var, lc_var_type_t type, void *data, char opt);









__BLANK_LINE__

!endif







>







|
>






>
>
>
>
>
>
>
>
>
>
>
>

|

>
>
>
>
>
>
>
>




27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
        LC_VAR_DIRECTORY,
        LC_VAR_SIZE_LONG_LONG,
        LC_VAR_SIZE_LONG,
        LC_VAR_SIZE_INT,
        LC_VAR_SIZE_SHORT,
        LC_VAR_TIME,
        LC_VAR_DATE,
        LC_VAR_SECTION,
        LC_VAR_SECTIONSTART,
        LC_VAR_SECTIONEND
} lc_var_type_t;

__BLANK_LINE__

typedef enum {
        LC_FLAGS_VAR,
        LC_FLAGS_CMDLINE,
        LC_FLAGS_SECTIONSTART,
        LC_FLAGS_SECTIONEND
} lc_flags_t;

__BLANK_LINE__

typedef enum {
        LC_ERR_NONE,
        LC_ERR_INVCMD,
        LC_ERR_INVSECTION,
        LC_ERR_INVDATA,
        LC_ERR_BADFORMAT,
        LC_ERR_CANTOPEN,
        LC_ERR_CALLBACK,
} lc_err_t;

__BLANK_LINE__

int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra);
int lc_register_callback(const char *var, char opt, lc_var_type_t type, int (*callback)(const char *, const char *, const char *, const char *, lc_flags_t, void *), void *extra);
int lc_register_var(const char *var, lc_var_type_t type, void *data, char opt);
lc_err_t lc_geterrno(void);
char *lc_geterrstr(void);

__BLANK_LINE__

!define LC_CBRET_IGNORESECTION (255)
!define LC_CBRET_OKAY (0)
!define LC_CBRET_ERROR (-1)

__BLANK_LINE__

!endif
1
2
3
4


5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24
#ifndef _RSK_LIBCONFIG_PRIVATE_H
#define _RSK_LIBCONFIG_PRIVATE_H

#include "libconfig.h"



int lc_process_var(const char *var, const char *varargs, const char *value, lc_flags_t flags);

struct lc_varhandler_st;

struct lc_varhandler_st {
	struct lc_varhandler_st *_next;
	char *var;
	char opt;
	lc_var_type_t type;
	enum {
		LC_MODE_CALLBACK,
		LC_MODE_VAR
	} mode;
	union {
		int (*callback)();
		void *data;
	};

};

#endif




>
>




>









<
|
|
<
>



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

21
22

23
24
25
26
#ifndef _RSK_LIBCONFIG_PRIVATE_H
#define _RSK_LIBCONFIG_PRIVATE_H

#include "libconfig.h"

extern lc_err_t lc_errno;

int lc_process_var(const char *var, const char *varargs, const char *value, lc_flags_t flags);

struct lc_varhandler_st;

struct lc_varhandler_st {
	struct lc_varhandler_st *_next;
	char *var;
	char opt;
	lc_var_type_t type;
	enum {
		LC_MODE_CALLBACK,
		LC_MODE_VAR
	} mode;

	int (*callback)();
	void *data;

	void *extra;
};

#endif
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# Space sperated list of documents, if they exist, they will be
# prefixed with the contents of the DOC_HDR file and substitution
# will occur:
#     @@UTIL@@ becomes the utility name ${UTIL}
#     @@VERS@@ becomes the utility version
#     @@DATE@@ becomes the current date
DOCS="README"
DOC_HDR="HEADER"

# This script is executed immediately after copying the files
# to a temp directory to attempt to compile
BEFORE="build/prep.sh"

# This script is executed immediately prior to creation of the







|







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# Space sperated list of documents, if they exist, they will be
# prefixed with the contents of the DOC_HDR file and substitution
# will occur:
#     @@UTIL@@ becomes the utility name ${UTIL}
#     @@VERS@@ becomes the utility version
#     @@DATE@@ becomes the current date
DOCS="README Docs/USAGE"
DOC_HDR="HEADER"

# This script is executed immediately after copying the files
# to a temp directory to attempt to compile
BEFORE="build/prep.sh"

# This script is executed immediately prior to creation of the
Modified test-lc.c from [49cd7f6cf6] to [9386f962de].
1
2
3



4



5
6
7


















8
9
10
11
12


13


14
15
16
17


18



19

20
21


22
23
24
25
26
27
#include "compat.h"
#include "libconfig.h"




int sally_cmd(const char *arg, const char *val, lc_flags_t flags) {



	PRINTERR_D("%s sets value: \"%s\" (flags=%i)", arg, val, flags);
	return(0);
}



















int main(int argc, char **argv) {
	char *joeval = NULL;
	long long xval = -1;
	int onoff = -1;





	lc_register_var("joe", LC_VAR_STRING, &joeval, 'j');
	lc_register_var("bob", LC_VAR_SIZE_LONG_LONG, &xval, '\0');
	lc_register_var("test", LC_VAR_BOOL, &onoff, '\0');
	lc_register_callback("sally", sally_cmd);


	lc_process(argc, argv, "testapp", LC_CONF_SECTION, "test.cfg");





	if (joeval != NULL) {
		SPOTVAR_S(joeval);


	}
	SPOTVAR_LLU(xval);
	SPOTVAR_I(onoff);

	return(0);
}



>
>
>
|
>
>
>



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





>
>

>
>
|
|
|
|
>
>
|
>
>
>
|
>

|
>
>

|
|



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "compat.h"
#include "libconfig.h"

int help_cmd(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
	printf("Usage info goes here\n");
	printf("\n");

	exit(EXIT_FAILURE);
}
int sally_cmd(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
	PRINTERR_D("%s sets value: \"%s\" (flags=%i)", arg, val, flags);
	return(0);
}

int cmd_ifmodule(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
	if (flags == LC_FLAGS_SECTIONEND) {
		return(LC_CBRET_OKAY);
	}
	if (flags != LC_FLAGS_SECTIONSTART) {
		PRINTERR("IfModule can only be used as a section.");
		return(LC_CBRET_ERROR);
	}
	if (argarg == NULL) {
		PRINTERR("You must specify an argument to IfModule.");
		return(LC_CBRET_ERROR);
	}

	SPOTVAR_S(arg);
	SPOTVAR_S(argarg);
	return(LC_CBRET_IGNORESECTION);
}

int main(int argc, char **argv) {
	char *joeval = NULL;
	long long xval = -1;
	int onoff = -1;
	int lcpret = -1;
	lc_err_t errs;

	lc_register_var("Section", LC_VAR_SECTION, NULL, 0);
	lc_register_var("Somesection", LC_VAR_SECTION, NULL, 0);
	lc_register_var("Section.Test", LC_VAR_STRING, &joeval, 'j');
	lc_register_var("bob", LC_VAR_SIZE_LONG_LONG, &xval, 's');
	lc_register_var("Somesection.Free", LC_VAR_BOOL, &onoff, 0);
	lc_register_callback("sally", 0, LC_VAR_STRING, sally_cmd, NULL);
	lc_register_callback("HELP", 'h', LC_VAR_NONE, help_cmd, NULL);
	lc_register_callback("*.ifmodule", 0, LC_VAR_NONE, cmd_ifmodule, NULL);
	lcpret = lc_process(argc, argv, "testapp", LC_CONF_APACHE, "test.cfg");
	if (lcpret < 0) {
		PRINTERR("Error processing config file: %s", lc_geterrstr());
		return(EXIT_FAILURE);
	}

	if (joeval != NULL) {
		PRINTERR("joeval = \"%s\"", joeval);
	} else {
		PRINTERR("joeval = \"(null)\"");
	}
	PRINTERR("xval = %lli", xval);
	PRINTERR("onoff = %i", onoff);

	return(0);
}