From: Martin Mares Date: Wed, 26 Apr 2006 09:38:39 +0000 (+0200) Subject: If CONFIG_DEBUG is enabled, all programs support a --dumpconfig switch, X-Git-Tag: holmes-import~645^2~11^2~33 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=83d55cc96eff953e26ea0696dd69c2400108db7b;p=libucw.git If CONFIG_DEBUG is enabled, all programs support a --dumpconfig switch, which dumps the current configuration. --- diff --git a/lib/conf2.c b/lib/conf2.c index 0d6d4eb5..92cc7f3b 100644 --- a/lib/conf2.c +++ b/lib/conf2.c @@ -1383,7 +1383,7 @@ cf_get_opt(int argc, char * const argv[], const char *short_opts, const struct o static int other_options = 0; while (1) { int res = getopt_long (argc, argv, short_opts, long_opts, long_index); - if (res == 'S' || res == 'C') + if (res == 'S' || res == 'C' || res == 0x64436667) { if (other_options) die("The -S and -C options must precede all other arguments"); @@ -1391,10 +1391,18 @@ cf_get_opt(int argc, char * const argv[], const char *short_opts, const struct o load_default(); if (cf_set(optarg)) die("Cannot set %s", optarg); - } else { + } else if (res == 'C') { if (cf_load(optarg)) die("Cannot load config file %s", optarg); } +#ifdef CONFIG_DEBUG + else { /* --dumpconfig */ + load_default(); + struct fastbuf *b = bfdopen(1, 4096); + cf_dump_sections(b); + bclose(b); + } +#endif } else { /* unhandled option or end of options */ if (res != ':' && res != '?') diff --git a/lib/conf2.h b/lib/conf2.h index 0021f3f2..f59bd648 100644 --- a/lib/conf2.h +++ b/lib/conf2.h @@ -54,7 +54,7 @@ typedef void *cf_dumper1(struct fastbuf *fb, void *ptr); struct cf_user_type { uns size; // of the parsed attribute cf_parser1 *parser; // how to parse it - cf_dumper1 *dumper; // optional and for debugging purposes only + cf_dumper1 *dumper; // how to dump the type }; struct cf_section; @@ -189,14 +189,22 @@ void cf_dump_sections(struct fastbuf *fb); */ #define CF_SHORT_OPTS "C:S:" -#define CF_LONG_OPTS {"config", 1, 0, 'C'}, {"set", 1, 0, 'S'}, +#define CF_LONG_OPTS {"config", 1, 0, 'C'}, {"set", 1, 0, 'S'}, CF_LONG_OPTS_DEBUG #define CF_NO_LONG_OPTS (const struct option []) { CF_LONG_OPTS { NULL, 0, 0, 0 } } #ifndef CF_USAGE_TAB #define CF_USAGE_TAB "" #endif #define CF_USAGE \ "-C, --config filename\t" CF_USAGE_TAB "Override the default configuration file\n\ --S, --set sec.item=val\t" CF_USAGE_TAB "Manual setting of a configuration item\n" +-S, --set sec.item=val\t" CF_USAGE_TAB "Manual setting of a configuration item\n" CF_USAGE_DEBUG + +#ifdef CONFIG_DEBUG +#define CF_LONG_OPTS_DEBUG { "dumpconfig", 0, 0, 0x64436667 } , +#define CF_USAGE_DEBUG " --dumpconfig\t" CF_USAGE_TAB "Dump program configuration\n" +#else +#define CF_LONG_OPTS_DEBUG +#define CF_USAGE_DEBUG +#endif #include struct option;