Index: libconfig.c ================================================================== --- libconfig.c +++ libconfig.c @@ -82,10 +82,20 @@ dataval = data; *dataval = strtoull(value, NULL, 10); return(0); } + +static int lc_process_var_bool_byexistance(void *data, const char *value) { + int *dataval; + + dataval = data; + + *dataval = 1; + + return(0); +} static int lc_process_var_bool(void *data, const char *value) { int *dataval; dataval = data; @@ -210,10 +220,13 @@ return(lc_process_var_sizeint(data, value)); 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: PRINTERR_D("Not implemented yet!"); @@ -364,11 +377,11 @@ /* Ignore this handler if they don't match. */ if (strcasecmp(lastcomponent_handler, cmdarg) != 0) { continue; } - if (handler->type == LC_VAR_NONE) { + if (handler->type == LC_VAR_NONE || handler->type == LC_VAR_BOOL_BY_EXISTANCE) { cmdoptarg = NULL; } else { cmdargidx++; if (cmdargidx >= argc) { PRINTERR("Argument required."); @@ -408,11 +421,11 @@ handler->type == LC_VAR_SECTIONEND || handler->type == LC_VAR_UNKNOWN) { continue; } - if (handler->type == LC_VAR_NONE) { + if (handler->type == LC_VAR_NONE || handler->type == LC_VAR_BOOL_BY_EXISTANCE) { cmdoptarg = NULL; } else { cmdargidx++; if (cmdargidx >= argc) { PRINTERR("Argument required."); @@ -495,10 +508,11 @@ } } if (value == NULL && handler->type != LC_VAR_NONE && + handler->type != LC_VAR_BOOL_BY_EXISTANCE && handler->type != LC_VAR_SECTION && handler->type != LC_VAR_SECTIONSTART && handler->type != LC_VAR_SECTIONEND) { lc_errno = LC_ERR_BADFORMAT; break; Index: libconfig.h.in ================================================================== --- libconfig.h.in +++ libconfig.h.in @@ -13,12 +13,12 @@ } lc_conf_type_t; __BLANK_LINE__ typedef enum { - LC_VAR_UNKNOWN, - LC_VAR_NONE, + LC_VAR_UNKNOWN, /* Requires no arguments. */ + LC_VAR_NONE, /* Requires no arguments. */ LC_VAR_STRING, LC_VAR_LONG_LONG, LC_VAR_LONG, LC_VAR_INT, LC_VAR_SHORT, @@ -31,11 +31,12 @@ LC_VAR_SIZE_SHORT, LC_VAR_TIME, LC_VAR_DATE, LC_VAR_SECTION, LC_VAR_SECTIONSTART, - LC_VAR_SECTIONEND + LC_VAR_SECTIONEND, + LC_VAR_BOOL_BY_EXISTANCE /* Requires no arguments. */ } lc_var_type_t; __BLANK_LINE__ typedef enum { Index: test-lc.c ================================================================== --- test-lc.c +++ test-lc.c @@ -33,17 +33,19 @@ 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) { @@ -56,11 +58,12 @@ } else { PRINTERR("joeval = \"(null)\""); } PRINTERR("xval = %lli", xval); PRINTERR("onoff = %i", onoff); + PRINTERR("long = %i", onoff2); for (i = lc_optind; i < argc; i++) { PRINTERR("argv[%i] = \"%s\"", i, argv[i]); } return(0); }