X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fconf-getopt.c;h=bbb81e1119e9cfe66c646897e355400d36247ccf;hb=b8667492cf36a609939ee35ac42900ff0b0cc80f;hp=507c51024cac3226faa0a0f13fe195872cdb5932;hpb=5423d3ec7aa3ff3fec105c49f7ec1a122e82561d;p=libucw.git diff --git a/ucw/conf-getopt.c b/ucw/conf-getopt.c index 507c5102..bbb81e11 100644 --- a/ucw/conf-getopt.c +++ b/ucw/conf-getopt.c @@ -26,8 +26,8 @@ char *cf_def_file = CONFIG_UCW_DEFAULT_CONFIG; #endif char *cf_env_file = CONFIG_UCW_ENV_VAR_CONFIG; -static void -load_default(struct cf_context *cc) +void +cf_load_default(struct cf_context *cc) { if (cc->config_loaded++) return; @@ -53,21 +53,19 @@ load_default(struct cf_context *cc) } static void -final_commit(struct cf_context *cc) +end_of_options(struct cf_context *cc) { - if (cc->postpone_commit) - { - cc->postpone_commit = 0; - if (cf_done_stack(cc)) - die("Cannot commit after the initialization"); - } + cf_load_default(cc); + if (cc->postpone_commit && cf_close_group()) + die("Loading of configuration failed"); } int cf_getopt(int argc, char *const argv[], const char *short_opts, const struct option *long_opts, int *long_index) { struct cf_context *cc = cf_get_context(); - cc->postpone_commit = 1; + if (!cc->postpone_commit) + cf_open_group(); while (1) { @@ -78,7 +76,7 @@ cf_getopt(int argc, char *const argv[], const char *short_opts, const struct opt die("The -S and -C options must precede all other arguments"); if (res == 'S') { - load_default(cc); + cf_load_default(cc); if (cf_set(optarg)) die("Cannot set %s", optarg); } @@ -90,8 +88,7 @@ cf_getopt(int argc, char *const argv[], const char *short_opts, const struct opt #ifdef CONFIG_UCW_DEBUG else { /* --dumpconfig */ - load_default(cc); - final_commit(cc); + end_of_options(cc); struct fastbuf *b = bfdopen(1, 4096); cf_dump_sections(b); bclose(b); @@ -103,10 +100,7 @@ cf_getopt(int argc, char *const argv[], const char *short_opts, const struct opt { /* unhandled option or end of options */ if (res != ':' && res != '?') - { - load_default(cc); - final_commit(cc); - } + end_of_options(cc); cc->other_options++; return res; }