]> mj.ucw.cz Git - libucw.git/commitdiff
If CONFIG_DEBUG is enabled, all programs support a --dumpconfig switch,
authorMartin Mares <mj@ucw.cz>
Wed, 26 Apr 2006 09:38:39 +0000 (11:38 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 26 Apr 2006 09:38:39 +0000 (11:38 +0200)
which dumps the current configuration.

lib/conf2.c
lib/conf2.h

index 0d6d4eb53fb1248e664ce39528b3cca9c4ff0d12..92cc7f3ba31ec49bf9510b7914e24a4cf3857030 100644 (file)
@@ -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 != '?')
index 0021f3f26e07e743f04a5ba38124e281b02b0ccd..f59bd648cfedb950ccdbc081a1df14cd663d21d5 100644 (file)
@@ -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 <getopt.h>
 struct option;