]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/conf-input.c
Resources for file descriptors and memory blocks.
[libucw.git] / ucw / conf-input.c
index 86a092c1024b223136c9ec7a1c838e1bcdbcc914..fffc6d57e5cd5d8088755bb9c0730768c63cc421 100644 (file)
@@ -223,7 +223,7 @@ parse_fastbuf(const char *name_fb, struct fastbuf *fb, uns depth)
       else if (depth > 8)
        err = "Too many nested files";
       else if (*line && *line != '#')          // because the contents of line_buf is not re-entrant and will be cleared
-       err = "The input command must be the last one on a line";
+       err = "The include command must be the last one on a line";
       if (err)
        goto error;
       struct fastbuf *new_fb = bopen_try(pars[0], O_RDONLY, 1<<14);
@@ -255,7 +255,7 @@ parse_fastbuf(const char *name_fb, struct fastbuf *fb, uns depth)
                    default: op = OP_ALL;
                  }; break;
        case 'p': op = OP_PREPEND; break;
-       case 'r': op = OP_REMOVE; break;
+       case 'r': op = (c[1] && Clocase(c[2]) == 'm') ? OP_REMOVE : OP_RESET; break;
        case 'e': op = OP_EDIT; break;
        case 'b': op = OP_BEFORE; break;
        default: op = OP_SET; break;
@@ -285,6 +285,7 @@ error:
 #define DEFAULT_CONFIG NULL
 #endif
 char *cf_def_file = DEFAULT_CONFIG;
+static int cf_def_loaded;
 
 #ifndef ENV_VAR_CONFIG
 #define ENV_VAR_CONFIG NULL
@@ -408,7 +409,7 @@ cf_load(const char *file)
   if (!err) {
     cf_journal_commit_transaction(1, oldj);
     cf_remember_entry(CE_FILE, file);
-    cf_def_file = NULL;
+    cf_def_loaded = 1;
   } else
     cf_journal_rollback_transaction(1, oldj);
   return err;
@@ -432,6 +433,8 @@ cf_set(const char *string)
 static void
 load_default(void)
 {
+  if (cf_def_loaded++)
+    return;
   if (cf_def_file)
     {
       char *env;
@@ -445,8 +448,11 @@ load_default(void)
     }
   else
     {
-      // We need to create an empty pool
-      cf_journal_commit_transaction(1, cf_journal_new_transaction(1));
+      // We need to create an empty pool and initialize all configuration items
+      struct cf_journal_item *oldj = cf_journal_new_transaction(1);
+      cf_init_stack();
+      done_stack();
+      cf_journal_commit_transaction(1, oldj);
     }
 }
 
@@ -493,9 +499,10 @@ cf_getopt(int argc, char * const argv[], const char *short_opts, const struct op
 #endif
     } else {
       /* unhandled option or end of options */
-      if (res != ':' && res != '?')
+      if (res != ':' && res != '?') {
        load_default();
-      final_commit();
+       final_commit();
+      }
       other_options++;
       return res;
     }