Overview
Comment: | Added a variable type "BOOL_BY_EXISTANCE" that enables things just by being specified. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
307def989939ca19e12b60fe49114d03 |
User & Date: | rkeene on 2004-10-28 21:32:57 |
Other Links: | manifest | tags |
Context
2004-10-28
| ||
22:39 | Added an environment parser. Cleaned up some memory leaks. Made lc_process() cleanup, so calling lc_process() twice will do nothing. check-in: d7ae2bcb59 user: rkeene tags: trunk | |
21:32 | Added a variable type "BOOL_BY_EXISTANCE" that enables things just by being specified. check-in: 307def9899 user: rkeene tags: trunk | |
21:11 | Fixed command line processing and added argument re-ordering. Also, added a global variable lc_optind to indicate where we were in the argv array. check-in: 9d733cc5a2 user: rkeene tags: trunk | |
Changes
Modified libconfig.c from [a80690a998] to [29ab6be894].
︙ | ︙ | |||
80 81 82 83 84 85 86 87 88 89 90 91 92 93 | short *dataval; dataval = data; *dataval = strtoull(value, NULL, 10); return(0); } static int lc_process_var_bool(void *data, const char *value) { int *dataval; dataval = data; *dataval = -1; | > > > > > > > > > > | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | short *dataval; 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; *dataval = -1; |
︙ | ︙ | |||
208 209 210 211 212 213 214 215 216 217 218 219 220 221 | 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: | > > > | 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | 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_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!"); return(-1); case LC_VAR_NONE: |
︙ | ︙ | |||
362 363 364 365 366 367 368 | } /* Ignore this handler if they don't match. */ if (strcasecmp(lastcomponent_handler, cmdarg) != 0) { continue; } | | | 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | } /* Ignore this handler if they don't match. */ if (strcasecmp(lastcomponent_handler, cmdarg) != 0) { continue; } if (handler->type == LC_VAR_NONE || handler->type == LC_VAR_BOOL_BY_EXISTANCE) { cmdoptarg = NULL; } else { cmdargidx++; if (cmdargidx >= argc) { PRINTERR("Argument required."); lc_errno = LC_ERR_BADFORMAT; return(-1); |
︙ | ︙ | |||
406 407 408 409 410 411 412 | if (handler->type == LC_VAR_SECTION || handler->type == LC_VAR_SECTIONSTART || handler->type == LC_VAR_SECTIONEND || handler->type == LC_VAR_UNKNOWN) { continue; } | | | 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | 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 || handler->type == LC_VAR_BOOL_BY_EXISTANCE) { cmdoptarg = NULL; } else { cmdargidx++; if (cmdargidx >= argc) { PRINTERR("Argument required."); lc_errno = LC_ERR_BADFORMAT; return(-1); |
︙ | ︙ | |||
493 494 495 496 497 498 499 500 501 502 503 504 505 506 | /* Exact (case-insensitive comparison) failed. */ continue; } } if (value == NULL && handler->type != LC_VAR_NONE && handler->type != LC_VAR_SECTION && handler->type != LC_VAR_SECTIONSTART && handler->type != LC_VAR_SECTIONEND) { lc_errno = LC_ERR_BADFORMAT; break; } | > | 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | /* Exact (case-insensitive comparison) failed. */ continue; } } 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; } |
︙ | ︙ |
Modified libconfig.h.in from [e26997901c] to [e147fc6e4e].
︙ | ︙ | |||
11 12 13 14 15 16 17 | LC_CONF_SPACE, LC_CONF_XML } lc_conf_type_t; __BLANK_LINE__ typedef enum { | | | | > | 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 | LC_CONF_SPACE, LC_CONF_XML } lc_conf_type_t; __BLANK_LINE__ typedef enum { 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, LC_VAR_BOOL, LC_VAR_FILENAME, 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_BOOL_BY_EXISTANCE /* Requires no arguments. */ } lc_var_type_t; __BLANK_LINE__ typedef enum { LC_FLAGS_VAR, LC_FLAGS_CMDLINE, |
︙ | ︙ |
Modified test-lc.c from [2a94d4df07] to [3e4ac1b9da].
︙ | ︙ | |||
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 | int main(int argc, char **argv) { char *joeval = NULL; long long xval = -1; int onoff = -1; int lcpret = -1; int i = 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_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); for (i = lc_optind; i < argc; i++) { PRINTERR("argv[%i] = \"%s\"", i, argv[i]); } return(0); } | > > > | 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 | 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) { 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); PRINTERR("long = %i", onoff2); for (i = lc_optind; i < argc; i++) { PRINTERR("argv[%i] = \"%s\"", i, argv[i]); } return(0); } |