Annotation of libaitcfg/example/test.c, revision 1.4.8.5
1.2 misho 1: #include <stdio.h>
2: #include <sys/types.h>
3: #include <aitcfg.h>
4:
5:
6: int main()
7: {
1.4.8.5 ! misho 8: cfg_root_t lst, *tmp, *tmp2;
1.2 misho 9: char szStr[256];
10: struct tagCfg *av;
11: ait_val_t v;
1.4.8.1 misho 12: array_t *arr;
1.4.8.2 misho 13: register int i;
1.2 misho 14:
15: printf("LoadConfig=%d\n", cfgLoadConfig("test.conf", &lst));
16: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
1.4.8.1 misho 17:
18: arr = cfg_getSection(&lst, "global");
19: printf("arr=%p size=%d\n", arr, array_Size(arr));
20:
21: for (i = 0; i < array_Size(arr); i++)
1.4.8.2 misho 22: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
1.4.8.1 misho 23: array_Destroy(&arr);
24:
1.4.8.3 misho 25: printf("0) ---------------------------------\n");
1.2 misho 26: printf("Find Attribute at position=%d\n", cfg_findAttribute(&lst, NULL, "testattr"));
27: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "", "testattr"));
28: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
29: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
30: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
31: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "att", "0001122277777777"));
32: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "att", "0001122222222222"));
33: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
34: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
35: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "", "att"));
36: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, NULL, "att"));
37: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "a"));
38: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", ""));
39: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, NULL, "att"));
40: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "attr2"));
41: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
42:
43: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "section", "attr3", NULL));
44: printf("LoadValue=%d :: ", cfg_loadAttribute(&lst, "section", "attr3", &v, "iH"));
45: printf("Str=%s\n", AIT_GET_STR(&v));
46: AIT_FREE_VAL(&v);
47: printf("LoadValue=%d :: ", cfg_loadAttribute(&lst, "", "testattr", &v, "iH2"));
48: printf("Str=%s\n", AIT_GET_STR(&v));
49: AIT_FREE_VAL(&v);
50:
1.4 misho 51: printf("GetAttribute multi-lines value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest"));
52: printf("GetAttribute multi-lines w/o \\ value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest_1"));
1.2 misho 53: cfgUnloadConfig(&lst);
1.4.8.3 misho 54: printf("1) ---------------------------------\n");
1.2 misho 55:
56: printf("size lst=%d tmp=%d %d\n", sizeof lst, sizeof tmp, sizeof(pthread_mutex_t));
57:
1.4.8.4 misho 58: tmp = cfgInitConfig();
1.4.8.5 ! misho 59: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "BLAHzdf"));
! 60: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "bzyt", "00", "99999 sdfbj"));
! 61: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "gniah", "tiiidfsdfsfsiiii"));
! 62: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, NULL, "att", "0001122777777555"));
! 63:
! 64: tmp2 = cfgInitConfig();
! 65: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, NULL, "zzz", "ZZZ"));
! 66: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, NULL, "att", "0001122222222222"));
! 67: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "global", "att", "0001122222222222"));
! 68: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "global", "attr2", "1111111122222222222"));
! 69: printf("GetAttribute value=%s\n", cfg_getAttribute(tmp2, "global", "attr2"));
! 70: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", "a"));
! 71: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", ""));
! 72: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, NULL, "att"));
! 73: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", "attr2"));
! 74: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "bzyt", "111", "99999"));
1.2 misho 75:
1.4.8.5 ! misho 76: cfgWriteConfig(stdout, tmp, 0);
! 77: cfgWriteConfig(stdout, tmp2, 1);
1.4.8.3 misho 78: printf("2) ---------------------------------\n");
1.2 misho 79:
80: #ifndef SKIP_TEST_CONCAT
1.4.8.5 ! misho 81: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(tmp2, tmp));
! 82: cfgWriteConfig(stdout, tmp2, 0);
! 83: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(tmp2, tmp));
! 84: cfgWriteConfig(stdout, tmp2, 1);
1.2 misho 85: #else
1.4.8.5 ! misho 86: cfgEndConfig(&tmp);
1.2 misho 87: #endif
88:
1.4.8.5 ! misho 89: tmp = cfgInitConfig();
! 90: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz"));
! 91: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "bzyt", "00", "99999"));
! 92: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "gniah", "tiiiiiii"));
! 93: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, NULL, "att", "0001122777777"));
! 94: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho"));
! 95: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho1"));
! 96: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho2"));
! 97: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz1"));
! 98: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz2"));
1.2 misho 99:
100: #ifndef SKIP_TEST_MERGE
1.3 misho 101: printf("before_merge ---------------------------------\n");
1.4.8.5 ! misho 102: cfgWriteConfig(stdout, tmp2, 1);
! 103: printf("after_merge=%d ---------------------------------\n", cfgMergeConfig(tmp2, tmp));
! 104: cfgWriteConfig(stdout, tmp2, 1);
1.2 misho 105: #else
1.4.8.5 ! misho 106: cfgEndConfig(&tmp);
1.2 misho 107: #endif
108:
1.4.8.5 ! misho 109: // arr = cfg_getSection(tmp2, NULL);
! 110: arr = cfg_getSection(tmp2, "");
! 111: printf("arr=%p size=%d\n", arr, array_Size(arr));
! 112:
! 113: for (i = 0; i < array_Size(arr); i++)
! 114: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
! 115: array_Destroy(&arr);
! 116:
! 117: printf("CreateConfig=%d\n", cfgCreateConfig("test4e.cfg", tmp2, 1));
1.2 misho 118: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
119:
1.4.8.5 ! misho 120: cfgEndConfig(&tmp);
! 121: cfgEndConfig(&tmp2);
1.2 misho 122: return 0;
123: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>