Annotation of libaitcfg/example/testcfg.c, revision 1.2
1.2 ! misho 1: #include <stdio.h>
! 2: #include <unistd.h>
! 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;
! 12: char ch, *str, *sec, *attr;
! 13: array_t *arr;
! 14: int i, mode = 0;
! 15: struct tagCfg *av;
! 16:
! 17: while ((ch = getopt(argc, argv, "rd")) != -1)
! 18: switch (ch) {
! 19: case 'r':
! 20: mode = 42;
! 21: break;
! 22: case 'd':
! 23: mode = 21;
! 24: break;
! 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");
! 33: return 1;
! 34: } else
! 35: str = argv[1];
! 36:
! 37: if (cfgLoadConfig(argv[0], &cfg)) {
! 38: ELIBERR(cfg);
! 39: return 1;
! 40: } else
! 41: printf("Opened config\n");
! 42:
! 43: if (str) {
! 44: attr = strchr(argv[1], '/');
! 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",
! 66: AIT_ADDR(&av->cfg_attr),
! 67: AIT_GET_STR(&av->cfg_val));
! 68: }
! 69: array_Destroy(&arr);
! 70: }
! 71: }
! 72: } else if (!mode)
! 73: cfgWriteConfig(stdout, &cfg, 1);
! 74: else if (mode == 42)
! 75: cfgWriteConfigRaw(stdout, &cfg, 1);
! 76: else
! 77: cfg_dumpCfg(&cfg);
! 78:
! 79: cfgUnloadConfig(&cfg);
! 80: printf("Closed config\n");
! 81:
! 82: printf("Done.\n");
! 83: return 0;
! 84: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>