void option_clear(option_list_t *option){ int i; for (i = 0; i < option->option_nb; i++) { option_free(option->options+i); } option->option_nb=0; }
static void options_free(Options o) { while (o) { Options next = ONEXT(o); option_free(o); o = next; } }
/* option_parse(): parse a configuration file * @opts -> the options struct * @path -> an absolute pathname to the file * $return -> 1 on success, 0 otherwise * * This is the exported function to allow caller to parse a configuration * file and populate the provided options structure. */ int option_parse(struct options *opts, char *path) { FILE *fp; int i; if ((fp = fopen(path, "r")) == NULL) { jlog(L_NOTICE, "%s: %s", path, strerror(errno)); return 1; } for (i = 0; opts[i].tag != NULL; i++) *(void **)opts[i].value = NULL; switch(parse(opts, fp)) { case ERR_SYNTAX: jlog(L_NOTICE, "option]> syntax error :: %s:%i", __FILE__, __LINE__); option_free(opts); fclose(fp); return ERR_SYNTAX; case ERR_DUPLICATE: jlog(L_NOTICE, "option]> duplicate :: %s:%i", __FILE__, __LINE__); option_free(opts); fclose(fp); return ERR_DUPLICATE; case ERR_ERRNO: jlog(L_NOTICE, "option]> unexpected error %s :: %s:%i", strerror(errno), __FILE__, __LINE__); option_free(opts); fclose(fp); return ERR_ERRNO; case ERR_TYPE: jlog(L_NOTICE, "option]> invalid option type :: %s:%i", __FILE__, __LINE__); option_free(opts); fclose(fp); return ERR_TYPE; } fclose(fp); return sanity_check(opts); }
static void empty_option_fail(void **state) { args *args = *state; option *opt = option_new("", "", ""); assert_int_equal( ARGPARSE_EMPTY_OPTION, args_add_option(args, opt) ); option_free(opt); }
/** @brief Parse modules. * * @param cur Pointer to the \<modules\> node. */ static void parser_modules(xmlNodePtr cur) { xmlChar *name, *weight, *mandatory; moduleoption *opt; module *dest; while(cur!=NULL) { if (!xmlStrcmp(cur->name, XMLCHAR "module")) { name=parser_getprop_str(cur, XMLCHAR "name"); weight=parser_getprop_str(cur, XMLCHAR "weight"); mandatory=parser_getprop_str(cur, XMLCHAR "mandatory"); opt=option_new(NULL, "weight", CHAR weight); if(!xmlStrcmp(mandatory, XMLCHAR "yes")) { opt=option_new(opt, "mandatory", "1"); } else if(!xmlStrcmp(mandatory, XMLCHAR "no")) { opt=option_new(opt, "mandatory", "0"); } else { FAIL("Property 'mandatory' should be 'yes'" "or 'no'", cur); } opt=parser_options(cur->children, opt); dest=module_load(CHAR name, opt); if(dest==NULL) { fatal(_("Module %s failed to load"), name); } xmlFree(name); xmlFree(weight); xmlFree(mandatory); option_free(opt); } cur=cur->next; } }