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