X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fopt-conf.c;h=3db998b9848f7064054cfd60512460d17e1852c7;hb=f1155256f7a168f5e2c0097cb4e7197b79c4f041;hp=d306db98dc4dab6322e7e96b5200c58ef7b39d04;hpb=924caf6f42990dc99c1d7e4a954da1533e37e537;p=libucw.git diff --git a/ucw/opt-conf.c b/ucw/opt-conf.c index d306db98..3db998b9 100644 --- a/ucw/opt-conf.c +++ b/ucw/opt-conf.c @@ -17,7 +17,6 @@ #include #include -#include static void opt_conf_end_of_options(struct cf_context *cc) { cf_load_default(cc); @@ -25,14 +24,32 @@ static void opt_conf_end_of_options(struct cf_context *cc) { opt_failure("Loading of configuration failed"); } -void opt_handle_config(struct opt_item * opt UNUSED, const char * value, void * data UNUSED) +static void opt_conf_check(struct opt_context *oc) { + switch (oc->conf_state) { + case OPT_CONF_HOOK_BEGIN: + oc->conf_state = OPT_CONF_HOOK_CONFIG; + break; + case OPT_CONF_HOOK_CONFIG: + break; + case OPT_CONF_HOOK_OTHERS: + opt_failure("Config options must stand before other options."); + break; + default: + ASSERT(0); + } +} + +void opt_handle_config(struct opt_item * opt UNUSED, const char * value, void * data) +{ + opt_conf_check(data); if (cf_load(value)) exit(1); // Error message is already printed by cf_load() } -void opt_handle_set(struct opt_item * opt UNUSED, const char * value, void * data UNUSED) +void opt_handle_set(struct opt_item * opt UNUSED, const char * value, void * data) { + opt_conf_check(data); struct cf_context *cc = cf_get_context(); cf_load_default(cc); if (cf_set(value)) @@ -49,33 +66,27 @@ void opt_handle_dumpconfig(struct opt_item * opt UNUSED, const char * value UNUS exit(0); } -void opt_conf_hook_internal(struct opt_item * opt, const char * value UNUSED, void * data UNUSED) { - static enum { - OPT_CONF_HOOK_BEGIN, - OPT_CONF_HOOK_CONFIG, - OPT_CONF_HOOK_OTHERS - } state = OPT_CONF_HOOK_BEGIN; +void opt_conf_hook_internal(struct opt_item * opt, uint event, const char * value UNUSED, void * data) { + struct opt_context *oc = data; + struct cf_context *cc = cf_get_context(); + + if (event == OPT_HOOK_FINAL) { + opt_conf_end_of_options(cc); + return; + } + + ASSERT(event == OPT_HOOK_BEFORE_VALUE); - bool confopt = opt->flags & OPT_BEFORE_CONFIG; + if (opt->flags & OPT_BEFORE_CONFIG) + return; - switch (state) { + switch (oc->conf_state) { case OPT_CONF_HOOK_BEGIN: - if (confopt) - state = OPT_CONF_HOOK_CONFIG; - else { - opt_conf_end_of_options(cf_get_context()); - state = OPT_CONF_HOOK_OTHERS; - } - break; case OPT_CONF_HOOK_CONFIG: - if (!confopt) { - opt_conf_end_of_options(cf_get_context()); - state = OPT_CONF_HOOK_OTHERS; - } + opt_conf_end_of_options(cc); + oc->conf_state = OPT_CONF_HOOK_OTHERS; break; case OPT_CONF_HOOK_OTHERS: - if (confopt) - opt_failure("Config options must stand before other options."); break; default: ASSERT(0);