From 3badd3809645529046513f8ee2835f7949cbcde9 Mon Sep 17 00:00:00 2001 From: venaas Date: Fri, 9 May 2008 09:15:30 +0000 Subject: added catgconf utility git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@250 e88ac4ed-0b26-0410-9574-a7f39faa03bf --- catgconf.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 catgconf.c (limited to 'catgconf.c') diff --git a/catgconf.c b/catgconf.c new file mode 100644 index 0000000..dc0f312 --- /dev/null +++ b/catgconf.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include "debug.h" +#include "gconfig.h" + +void listconfig(struct gconffile **cf, char *block, int compact) { + char *opt, *val; + int conftype; + + for (;;) { + getconfigline(cf, block, &opt, &val, &conftype); + if (!opt) + return; + + if (conftype == CONF_STR && !strcasecmp(opt, "include")) { + if (!pushgconffiles(cf, val)) + debugx(1, DBG_ERR, "failed to include config file %s", val); + continue; + } + + switch (conftype) { + case CONF_STR: + if (block) + printf(compact ? "%s=%s;" : "\t%s=%s\n", opt, val); + else + printf("%s=%s\n", opt, val); + break; + case CONF_CBK: + printf("%s %s {%s", opt, val, compact ? "" : "\n"); + listconfig(cf, val, compact); + printf("}\n"); + break; + default: + printf("Unsupported config type\n"); + } + } +} + +int main(int argc, char **argv) { + int c, compact = 0; + struct gconffile *cfs; + + debug_init("catgconf"); + debug_set_level(DBG_WARN); + + while ((c = getopt(argc, argv, "c")) != -1) { + switch (c) { + case 'c': + compact = 1; + break; + default: + goto usage; + } + } + if (argc - optind != 1) + goto usage; + + cfs = openconfigfile(argv[optind]); + listconfig(&cfs, NULL, compact); + return 0; + +usage: + debug(DBG_ERR, "Usage:\n%s [ -c ] configfile", argv[0]); + exit(1); +} -- cgit v1.2.3