Handle failing rs_context_create().
[libradsec.git] / catgconf.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <stdlib.h>
5 #include "debug.h"
6 #include "gconfig.h"
7
8 void listconfig(struct gconffile **cf, char *block, int compact) {
9     char *opt = NULL, *val = NULL;
10     int conftype;
11
12     for (;;) {
13         free(opt);
14         free(val);
15         getconfigline(cf, block, &opt, &val, &conftype);
16         if (!opt)
17             return;
18
19         if (conftype == CONF_STR && !strcasecmp(opt, "include")) {
20             if (!pushgconfpaths(cf, val))
21                 debugx(1, DBG_ERR, "failed to include config file %s", val);
22             continue;
23         }
24
25         switch (conftype) {
26         case CONF_STR:
27             if (block)
28                 printf(compact ? "%s=%s;" : "\t%s=%s\n", opt, val);
29             else
30                 printf("%s=%s\n", opt, val);
31             break;
32         case CONF_CBK:
33             printf("%s %s {%s", opt, val, compact ? "" : "\n");
34             listconfig(cf, val, compact);
35             printf("}\n");
36             break;
37         default:
38             printf("Unsupported config type\n");
39         }
40     }
41 }
42
43 int main(int argc, char **argv) {
44     int c, compact = 0;
45     struct gconffile *cfs;
46
47     debug_init("catgconf");
48     debug_set_level(DBG_WARN);
49
50     while ((c = getopt(argc, argv, "c")) != -1) {
51         switch (c) {
52         case 'c':
53             compact = 1;
54             break;
55         default:
56             goto usage;
57         }
58     }
59     if (argc - optind != 1)
60         goto usage;
61
62     cfs = openconfigfile(argv[optind]);
63     listconfig(&cfs, NULL, compact);
64     return 0;
65
66 usage:
67     debug(DBG_ERR, "Usage:\n%s [ -c ] configfile", argv[0]);
68     exit(1);
69 }
70
71 /* Local Variables: */
72 /* c-file-style: "stroustrup" */
73 /* End: */