]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/conf-getopt.c
tableprinter: removed some obsolete FIXME, added some comments
[libucw.git] / ucw / conf-getopt.c
index 507c51024cac3226faa0a0f13fe195872cdb5932..bbb81e1119e9cfe66c646897e355400d36247ccf 100644 (file)
@@ -26,8 +26,8 @@ char *cf_def_file = CONFIG_UCW_DEFAULT_CONFIG;
 #endif
 char *cf_env_file = CONFIG_UCW_ENV_VAR_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;
 {
   if (cc->config_loaded++)
     return;
@@ -53,21 +53,19 @@ load_default(struct cf_context *cc)
 }
 
 static void
 }
 
 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();
 }
 
 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)
     {
 
   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')
            {
            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);
            }
              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 */
 #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);
              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 != '?')
        {
          /* unhandled option or end of options */
          if (res != ':' && res != '?')
-           {
-             load_default(cc);
-             final_commit(cc);
-           }
+           end_of_options(cc);
          cc->other_options++;
          return res;
        }
          cc->other_options++;
          return res;
        }