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