From 95413e056ddbc3f2a2fe101ac7277712e40fc34d Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 27 Jan 2014 21:03:50 +0100 Subject: [PATCH] Opt: State of opt-conf moved to opt_context It gives a better feeling to get rid of magical static variables in functions :) --- ucw/opt-conf.c | 16 ++++++---------- ucw/opt-internal.h | 7 +++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ucw/opt-conf.c b/ucw/opt-conf.c index ccebc013..25cee0ee 100644 --- a/ucw/opt-conf.c +++ b/ucw/opt-conf.c @@ -48,12 +48,8 @@ void opt_handle_dumpconfig(struct opt_item * opt UNUSED, const char * value UNUS exit(0); } -void opt_conf_hook_internal(struct opt_item * opt, uns event, 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, uns event, const char * value UNUSED, void * data) { + struct opt_context *oc = data; struct cf_context *cc = cf_get_context(); if (event == OPT_HOOK_FINAL) { @@ -65,19 +61,19 @@ void opt_conf_hook_internal(struct opt_item * opt, uns event, const char * value bool confopt = opt->flags & OPT_BEFORE_CONFIG; - switch (state) { + switch (oc->conf_state) { case OPT_CONF_HOOK_BEGIN: if (confopt) - state = OPT_CONF_HOOK_CONFIG; + oc->conf_state = OPT_CONF_HOOK_CONFIG; else { opt_conf_end_of_options(cc); - state = OPT_CONF_HOOK_OTHERS; + oc->conf_state = OPT_CONF_HOOK_OTHERS; } break; case OPT_CONF_HOOK_CONFIG: if (!confopt) { opt_conf_end_of_options(cc); - state = OPT_CONF_HOOK_OTHERS; + oc->conf_state = OPT_CONF_HOOK_OTHERS; } break; case OPT_CONF_HOOK_OTHERS: diff --git a/ucw/opt-internal.h b/ucw/opt-internal.h index 0ac2a773..77434d7a 100644 --- a/ucw/opt-internal.h +++ b/ucw/opt-internal.h @@ -15,6 +15,12 @@ #define opt_precompute ucw_opt_precompute #endif +enum opt_conf_state { + OPT_CONF_HOOK_BEGIN, + OPT_CONF_HOOK_CONFIG, + OPT_CONF_HOOK_OTHERS, +}; + struct opt_context { const struct opt_section * options; struct opt_precomputed * opts; @@ -25,6 +31,7 @@ struct opt_context { int positional_max; int positional_count; bool stop_parsing; + enum opt_conf_state conf_state; }; struct opt_precomputed { -- 2.39.2