Index: .cvsignore ================================================================== --- .cvsignore +++ .cvsignore @@ -11,5 +11,6 @@ lc_geterrstr.3 lc_register_var.3 lc_register_callback.3 lc_process.3 lc_geterrno.3 +libconfig.3 Index: .fossil-settings/ignore-glob ================================================================== --- .fossil-settings/ignore-glob +++ .fossil-settings/ignore-glob @@ -16,10 +16,12 @@ 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 Index: configure.in ================================================================== --- configure.in +++ configure.in @@ -1,7 +1,7 @@ AC_REVISION($Revision $) -AC_INIT(libconfig, 0.1.1) +AC_INIT(libconfig, 0.1.2) AC_CONFIG_HEADER(config.h) dnl Find out about the host OS DC_CHK_OS_INFO Index: lc_register_callback.3.in ================================================================== --- lc_register_callback.3.in +++ lc_register_callback.3.in @@ -35,11 +35,11 @@ .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). +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 Index: lc_register_var.3.in ================================================================== --- lc_register_var.3.in +++ lc_register_var.3.in @@ -65,18 +65,27 @@ 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 Index: libconfig.c ================================================================== --- libconfig.c +++ libconfig.c @@ -48,10 +48,49 @@ 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; @@ -189,10 +228,20 @@ 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)); @@ -225,10 +274,16 @@ 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 Index: libconfig.h.in ================================================================== --- libconfig.h.in +++ libconfig.h.in @@ -35,11 +35,14 @@ LC_VAR_TIME, LC_VAR_DATE, LC_VAR_SECTION, LC_VAR_SECTIONSTART, LC_VAR_SECTIONEND, - LC_VAR_BOOL_BY_EXISTANCE + LC_VAR_BOOL_BY_EXISTANCE, + LC_VAR_SIZE_SIZE_T, + LC_VAR_CIDR, + LC_VAR_IP, } lc_var_type_t; __BLANK_LINE__ typedef enum { Index: test-lc.c ================================================================== --- test-lc.c +++ test-lc.c @@ -29,23 +29,24 @@ return(LC_CBRET_IGNORESECTION); } int main(int argc, char **argv) { char *joeval = NULL; - long long xval = -1; + size_t xval = -1; int onoff = -1; int lcpret = -1; int i = 0; int onoff2 = 0; - lc_err_t errs; + 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_LONG_LONG, &xval, 's'); + 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) { @@ -56,14 +57,15 @@ if (joeval != NULL) { fprintf(stderr, "joeval = \"%s\"\n", joeval); } else { fprintf(stderr, "joeval = \"(null)\"\n"); } - fprintf(stderr, "xval = %lli\n", xval); + 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); }