]> mj.ucw.cz Git - libucw.git/commitdiff
Conf: Updated conf-test
authorMartin Mares <mj@ucw.cz>
Sun, 29 Apr 2012 09:52:53 +0000 (11:52 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 29 Apr 2012 11:57:30 +0000 (13:57 +0200)
ucw/conf-test.c
ucw/conf-test.cf

index 34d1f36bc9e316350bd8d2eab7194423037144c8..fb353f91bbf924d3af98ed8d10e08385e3b28acb 100644 (file)
@@ -15,6 +15,8 @@
 #include <time.h>
 
 static int verbose;
+static int new_context;
+static int reload;
 
 struct sub_sect_1 {
   cnode n;
@@ -162,19 +164,20 @@ static struct cf_section cf_top = {
   }
 };
 
-static char short_opts[] = CF_SHORT_OPTS "v";
+static char short_opts[] = CF_SHORT_OPTS "rv";
 static struct option long_opts[] = {
        CF_LONG_OPTS
+       {"reload",      0, 0, 'r'},
        {"verbose",     0, 0, 'v'},
        {NULL,          0, 0, 0}
 };
 
 static char *help = "\
-Usage: conf-test <options>\n\
+Usage: conf-test [ctxt] <options>\n\
 \n\
-Options:\n"
-CF_USAGE
-"-v\t\t\tBe verbose\n\
+Options:\n" CF_USAGE "\
+-r, --reload\t\tReload configuration\n\
+-v, --verbose\t\tBe verbose\n\
 ";
 
 static void NONRET
@@ -192,30 +195,43 @@ int
 main(int argc, char *argv[])
 {
   log_init(argv[0]);
+
+  struct cf_context *cc = NULL, *prev = NULL;
+  if (argc > 1 && !strcmp(argv[1], "ctxt")) {
+    cc = cf_new_context();
+    prev = cf_switch_context(cc);
+    argc--, argv++;
+  }
+
   cf_declare_section("top", &cf_top, 0);
   cf_def_file = "ucw/conf-test.cf";
 
   int opt;
   while ((opt = cf_getopt(argc, argv, short_opts, long_opts, NULL)) >= 0)
     switch (opt) {
+      case 'n': new_context++; break;
+      case 'r': reload++; break;
       case 'v': verbose++; break;
       default: usage("unknown option %c\n", opt);
     }
   if (optind < argc)
     usage("too many parameters (%d more)\n", argc-optind);
 
-  /*
-  cf_load("non-existent file");
-  //cf_reload("non-existent file");
-  cf_load("non-existent file");
-  cf_set("top.d1 -1.1; top.master b");
-  cf_reload(NULL);
-  cf_reload(NULL);
-  */
-
-  struct fastbuf *out = bfdopen(1, 1<<14);
-  cf_dump_sections(out);
-  bclose(out);
+  if (reload) {
+    cf_reload(NULL);
+    cf_reload(NULL);
+  }
+
+  if (verbose) {
+    struct fastbuf *out = bfdopen(1, 1<<14);
+    cf_dump_sections(out);
+    bclose(out);
+  }
+
+  if (new_context) {
+    cf_switch_context(prev);
+    cf_free_context(cc);
+  }
 
   return 0;
 }
index d533af4cd81ffe58883d0171481f7ca196fdbd7c..448ccfcb9c1e4cdb50822b15d51202072a5725b3 100644 (file)
@@ -1,8 +1,7 @@
 # test config file
 #include ucw/conf-test.t ; top.xa=1
 #include 'non-existent file'; #top.xa=1
-Top { \
-
+Top {
   nr1=16       #!!!
   nrs1         2 3 5 \
            7 11 13 \