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");
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 != '?')
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;
*/
#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;