Annotation of libaitcfg/example/testcfg.c, revision 1.1.2.3
1.1.2.1 misho 1: #include <stdio.h>
1.1.2.2 misho 2: #include <unistd.h>
1.1.2.1 misho 3: #include <string.h>
4: #include <elwix.h>
5: #include <aitcfg.h>
6:
7:
8: int
9: main(int argc, char **argv)
10: {
11: cfg_root_t cfg;
1.1.2.2 misho 12: char ch, *str, *sec, *attr;
1.1.2.1 misho 13: array_t *arr;
1.1.2.2 misho 14: int i, mode = 0;
1.1.2.1 misho 15: struct tagCfg *av;
16:
1.1.2.3 ! misho 17: while ((ch = getopt(argc, argv, "rd")) != -1)
1.1.2.2 misho 18: switch (ch) {
19: case 'r':
20: mode = 42;
21: break;
1.1.2.3 ! misho 22: case 'd':
! 23: mode = 21;
! 24: break;
1.1.2.2 misho 25: default:
26: printf("Error:: missing config.\n\ntestcfg [-r] <config> [section/attribute]\n");
27: return 1;
28: }
29: argc -= optind;
30: argv += optind;
31: if (!argc) {
32: printf("Error:: missing config.\n\ntestcfg [-r] <config> [section/attribute]\n");
1.1.2.1 misho 33: return 1;
34: } else
1.1.2.2 misho 35: str = argv[1];
1.1.2.1 misho 36:
1.1.2.2 misho 37: if (cfgLoadConfig(argv[0], &cfg)) {
1.1.2.1 misho 38: ELIBERR(cfg);
39: return 1;
40: } else
41: printf("Opened config\n");
42:
43: if (str) {
1.1.2.2 misho 44: attr = strchr(argv[1], '/');
1.1.2.1 misho 45: if (!attr) {
46: attr = str;
47: sec = NULL;
48: } else {
49: *attr++ = 0;
50: sec = str;
51: }
52: if (sec && !*sec)
53: sec = NULL;
54: printf("Section=%s Attribute=%s\n", sec, attr);
55:
56: if (attr && *attr)
57: printf("%s = %s\n", attr, cfg_getAttribute(&cfg, sec, attr));
58: else {
59: arr = cfg_getSection(&cfg, sec);
60: if (arr) {
61: printf("[%s]\n", sec);
62: for (i = 0; i < array_Size(arr); i++) {
63: av = array(arr, i, struct tagCfg*);
64: if (av)
65: printf("%s = %s\n",
1.1.2.2 misho 66: AIT_ADDR(&av->cfg_attr),
1.1.2.1 misho 67: AIT_GET_STR(&av->cfg_val));
68: }
69: array_Destroy(&arr);
70: }
71: }
1.1.2.2 misho 72: } else if (!mode)
1.1.2.1 misho 73: cfgWriteConfig(stdout, &cfg, 1);
1.1.2.3 ! misho 74: else if (mode == 42)
1.1.2.2 misho 75: cfgWriteConfigRaw(stdout, &cfg, 1);
1.1.2.3 ! misho 76: else
! 77: cfg_dumpCfg(&cfg);
1.1.2.1 misho 78:
79: cfgUnloadConfig(&cfg);
80: printf("Closed config\n");
81:
82: printf("Done.\n");
83: return 0;
84: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>