]> mj.ucw.cz Git - libucw.git/commitdiff
Opt: State of opt-conf moved to opt_context
authorMartin Mares <mj@ucw.cz>
Mon, 27 Jan 2014 20:03:50 +0000 (21:03 +0100)
committerMartin Mares <mj@ucw.cz>
Mon, 27 Jan 2014 20:03:50 +0000 (21:03 +0100)
It gives a better feeling to get rid of magical static variables
in functions :)

ucw/opt-conf.c
ucw/opt-internal.h

index ccebc013077e426bafa47a4da5636f58b3a91673..25cee0ee1ad339236eef979fb1b9ca51af65d920 100644 (file)
@@ -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:
index 0ac2a77324f05e0998923f69a17e155156931d41..77434d7a63a055208e49cadb77f06f70f3960fd6 100644 (file)
 #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 {