From: Martin Mares Date: Sun, 29 Apr 2012 09:52:53 +0000 (+0200) Subject: Conf: Updated conf-test X-Git-Tag: v5.99~170 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=712d4ad76dc6ba3a2dbd591165debfe0ac0c8a71;p=libucw.git Conf: Updated conf-test --- diff --git a/ucw/conf-test.c b/ucw/conf-test.c index 34d1f36b..fb353f91 100644 --- a/ucw/conf-test.c +++ b/ucw/conf-test.c @@ -15,6 +15,8 @@ #include 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 \n\ +Usage: conf-test [ctxt] \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; } diff --git a/ucw/conf-test.cf b/ucw/conf-test.cf index d533af4c..448ccfcb 100644 --- a/ucw/conf-test.cf +++ b/ucw/conf-test.cf @@ -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 \