Check-in [67a12fd87a]
Overview
Comment:Updated libconfig
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 67a12fd87aa23392fcd41f89e22a843d7bc78284
User & Date: rkeene on 2004-11-17 09:49:52
Other Links: manifest | tags
Context
2004-11-22
02:00
Added a .spec file Changed license to MIT libconfig 0.1.3 check-in: 4596d49a10 user: rkeene tags: 0.1.3, trunk
2004-11-17
09:49
Updated libconfig check-in: 67a12fd87a user: rkeene tags: trunk
2004-10-31
20:46
Changed to `strtoull' to `strtoll' and updated code. Changed URL in header Added TODO libconfig 0.1.1 check-in: 59af3f328b user: rkeene tags: 0.1.1, trunk
Changes

Modified .cvsignore from [a1cfe0d8d0] to [3ec037ded0].

9
10
11
12
13
14
15

test.cfg
.*.swp
lc_geterrstr.3
lc_register_var.3
lc_register_callback.3
lc_process.3
lc_geterrno.3








>
9
10
11
12
13
14
15
16
test.cfg
.*.swp
lc_geterrstr.3
lc_register_var.3
lc_register_callback.3
lc_process.3
lc_geterrno.3
libconfig.3

Modified .fossil-settings/ignore-glob from [e33f8b5756] to [f46eab9da1].

14
15
16
17
18
19
20


21
22
23
24
25
26
27
28
29
30
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
test-lc/*
test.cfg
test.cfg/*







>
>










14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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.3
libconfig.3/*
libconfig.a
libconfig.a/*
libconfig.h
libconfig.h/*
libconfig.so
libconfig.so/*
test-lc
test-lc/*
test.cfg
test.cfg/*

Modified configure.in from [eed6770815] to [4479b835cc].

1
2
3
4
5
6
7
8
9
AC_REVISION($Revision $)
AC_INIT(libconfig, 0.1.1)
AC_CONFIG_HEADER(config.h)

dnl Find out about the host OS
DC_CHK_OS_INFO

dnl Checks for programs.
AC_PROG_CC

|







1
2
3
4
5
6
7
8
9
AC_REVISION($Revision $)
AC_INIT(libconfig, 0.1.2)
AC_CONFIG_HEADER(config.h)

dnl Find out about the host OS
DC_CHK_OS_INFO

dnl Checks for programs.
AC_PROG_CC

Modified lc_register_callback.3.in from [43854d99e9] to [0102cb6d66].

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.RE

.TP
.IR "lc_var_type_t type"
.RS
The
.IR type
parameter indicates the type of values that are acceptable for this callback.  Currently only LC_VAR_NONE is acceptable, since callbacks may not have values (though they may have arguments).
.RE

.TP
.IR "int (*callback)(...)"
.RS
The
.IR callback







|







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.RE

.TP
.IR "lc_var_type_t type"
.RS
The
.IR type
parameter indicates the type of values that are acceptable for this callback.  A value of LC_VAR_NONE means that the command will accept no arguments, while a value of LC_VAR_UNKNOWN indicates that it's not known whether or not an argument is applicable, this will also disable command line processing.  Any other value is currently ignored.
.RE

.TP
.IR "int (*callback)(...)"
.RS
The
.IR callback

Modified lc_register_var.3.in from [33f89d18c6] to [ed1d29b572].

63
64
65
66
67
68
69



70
71
72
73
74
75
76
77






78
79
80
81
82
83
84
.TP
LC_VAR_SIZE_INT
For a "int" integer type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type "int *".
.TP
LC_VAR_SIZE_SHORT
For a "short" integer type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type "short *".
.TP



LC_VAR_TIME
Not implemented.
.TP
LC_VAR_DATE
Not implemented.
.TP
LC_VAR_BOOL_BY_EXISTANCE
This type of variable takes no arguments, it is set to true (1) by its existance in a configuration file, environment variable, or on the command line.  If it is not specified, the value of the data passed is not changed.  The data passed should be of type "int *".







.SH "RETURN VALUE"
On success 0 is returned, otherwise -1 is returned.

.SH EXAMPLE
.nf
#include <libconfig.h>







>
>
>








>
>
>
>
>
>







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
.TP
LC_VAR_SIZE_INT
For a "int" integer type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type "int *".
.TP
LC_VAR_SIZE_SHORT
For a "short" integer type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type "short *".
.TP
LC_VAR_SIZE_SIZE_T
For a "size_t" data type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type "size_t *".
.TP
LC_VAR_TIME
Not implemented.
.TP
LC_VAR_DATE
Not implemented.
.TP
LC_VAR_BOOL_BY_EXISTANCE
This type of variable takes no arguments, it is set to true (1) by its existance in a configuration file, environment variable, or on the command line.  If it is not specified, the value of the data passed is not changed.  The data passed should be of type "int *".
.TP
LC_VAR_CIDR
XXX: blah
.TP
LC_VAR_IP
XXX: blah

.SH "RETURN VALUE"
On success 0 is returned, otherwise -1 is returned.

.SH EXAMPLE
.nf
#include <libconfig.h>

Modified libconfig.c from [0729e92710] to [65d4398d3f].

46
47
48
49
50
51
52







































53
54
55
56
57
58
59
	char **dataval;

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

	return(0);
}








































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

	dataval = data;
	*dataval = strtoll(value, NULL, 10);








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







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
	char **dataval;

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

	return(0);
}

static int lc_process_var_cidr(void *data, const char *value) {
	

	return(0);
}

static int lc_process_var_ip(void *data, const char *value) {
	uint32_t *dataval = NULL, retval = 0;
	const char *dotptr = NULL;
	int tmpval = -1;

	dataval = data;

	dotptr = value;

	while (1) {
		tmpval = atoi(dotptr);
		if (tmpval < 0) {
			break;
		}

		retval <<= 8;
		retval |= tmpval;

		dotptr = strpbrk(dotptr, "./ \t");
		if (dotptr == NULL) {
			break;
		}
		if (*dotptr != '.') {
			break;
		}
		dotptr++;
	}

	*dataval = retval;

	return(0);
}

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

	dataval = data;
	*dataval = strtoll(value, NULL, 10);

187
188
189
190
191
192
193










194
195
196
197
198
199
200
	short *dataval;

	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:







>
>
>
>
>
>
>
>
>
>







226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
	short *dataval;

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

	return(0);
}

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

	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:
223
224
225
226
227
228
229






230
231
232
233
234
235
236
			break;
		case LC_VAR_SIZE_SHORT:
			return(lc_process_var_sizeshort(data, value));
			break;
		case LC_VAR_BOOL_BY_EXISTANCE:
			return(lc_process_var_bool_byexistance(data, value));
			break;






		case LC_VAR_TIME:
		case LC_VAR_DATE:
		case LC_VAR_FILENAME:
		case LC_VAR_DIRECTORY:
#ifdef DEBUG
			fprintf(stderr, "Not implemented yet!\n");
#endif







>
>
>
>
>
>







272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
			break;
		case LC_VAR_SIZE_SHORT:
			return(lc_process_var_sizeshort(data, value));
			break;
		case LC_VAR_BOOL_BY_EXISTANCE:
			return(lc_process_var_bool_byexistance(data, value));
			break;
		case LC_VAR_SIZE_SIZE_T:
			return(lc_process_var_sizesizet(data, value));
			break;
		case LC_VAR_IP:
			return(lc_process_var_ip(data, value));
			break;
		case LC_VAR_TIME:
		case LC_VAR_DATE:
		case LC_VAR_FILENAME:
		case LC_VAR_DIRECTORY:
#ifdef DEBUG
			fprintf(stderr, "Not implemented yet!\n");
#endif

Modified libconfig.h.in from [6db6e4f548] to [f10199222d].

33
34
35
36
37
38
39
40



41
42
43
44
45
46
47
        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_BOOL_BY_EXISTANCE



} lc_var_type_t;

__BLANK_LINE__

typedef enum {
        LC_FLAGS_VAR,
        LC_FLAGS_CMDLINE,







|
>
>
>







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        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_BOOL_BY_EXISTANCE,
        LC_VAR_SIZE_SIZE_T,
	LC_VAR_CIDR,
	LC_VAR_IP,
} lc_var_type_t;

__BLANK_LINE__

typedef enum {
        LC_FLAGS_VAR,
        LC_FLAGS_CMDLINE,

Modified test-lc.c from [d4be221f35] to [0d1d1a962e].

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

	fprintf(stderr, "IfModule (%s)\n", argarg);
	return(LC_CBRET_IGNORESECTION);
}

int main(int argc, char **argv) {
	char *joeval = NULL;
	long long xval = -1;
	int onoff = -1;
	int lcpret = -1;
	int i = 0;
	int onoff2 = 0;
	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_var("long", LC_VAR_BOOL_BY_EXISTANCE, &onoff2, 'l');

	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) {
		fprintf(stderr, "Error processing config file: %s\n", lc_geterrstr());
		return(EXIT_FAILURE);
	}

	if (joeval != NULL) {
		fprintf(stderr, "joeval = \"%s\"\n", joeval);
	} else {
		fprintf(stderr, "joeval = \"(null)\"\n");
	}
	fprintf(stderr, "xval = %lli\n", xval);
	fprintf(stderr, "onoff = %i\n", onoff);
	fprintf(stderr, "long = %i\n", onoff2);

	for (i = lc_optind; i < argc; i++) {
		fprintf(stderr, "argv[%i] = \"%s\"\n", i, argv[i]);
	}

	return(0);
}







|




|




|


>














|


>






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

	fprintf(stderr, "IfModule (%s)\n", argarg);
	return(LC_CBRET_IGNORESECTION);
}

int main(int argc, char **argv) {
	char *joeval = NULL;
	size_t xval = -1;
	int onoff = -1;
	int lcpret = -1;
	int i = 0;
	int onoff2 = 0;
	uint32_t ipaddr;

	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_SIZE_T, &xval, 's');
	lc_register_var("Somesection.Free", LC_VAR_BOOL, &onoff, 0);
	lc_register_var("long", LC_VAR_BOOL_BY_EXISTANCE, &onoff2, 'l');
	lc_register_var("ipaddr", LC_VAR_IP, &ipaddr, 'i');
	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) {
		fprintf(stderr, "Error processing config file: %s\n", lc_geterrstr());
		return(EXIT_FAILURE);
	}

	if (joeval != NULL) {
		fprintf(stderr, "joeval = \"%s\"\n", joeval);
	} else {
		fprintf(stderr, "joeval = \"(null)\"\n");
	}
	fprintf(stderr, "xval = %llu\n", (unsigned long long) xval);
	fprintf(stderr, "onoff = %i\n", onoff);
	fprintf(stderr, "long = %i\n", onoff2);
	fprintf(stderr, "ip = %08lx\n", (unsigned long) ipaddr);
	for (i = lc_optind; i < argc; i++) {
		fprintf(stderr, "argv[%i] = \"%s\"\n", i, argv[i]);
	}

	return(0);
}