Annotation of libaitcfg/example/test.c, revision 1.5.10.1
1.2 misho 1: #include <stdio.h>
2: #include <sys/types.h>
3: #include <aitcfg.h>
4:
5:
6: int main()
7: {
1.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.5 misho 12: array_t *arr;
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.5 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++)
22: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
23: array_Destroy(&arr);
24:
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.5.10.1! misho 53:
! 54: printf("GetAttribute from %%include file value=%s\n", cfg_getAttribute(&lst, "", "test4ext"));
! 55: printf("GetAttribute from %%include file [proba] value=%s\n", cfg_getAttribute(&lst, "proba", "test4ext"));
1.2 misho 56: cfgUnloadConfig(&lst);
1.5 misho 57: printf("1) ---------------------------------\n");
1.2 misho 58:
59: printf("size lst=%d tmp=%d %d\n", sizeof lst, sizeof tmp, sizeof(pthread_mutex_t));
60:
1.5 misho 61: tmp = cfgInitConfig();
62: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "BLAHzdf"));
63: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "bzyt", "00", "99999 sdfbj"));
64: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "gniah", "tiiidfsdfsfsiiii"));
65: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, NULL, "att", "0001122777777555"));
66:
67: tmp2 = cfgInitConfig();
68: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, NULL, "zzz", "ZZZ"));
69: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, NULL, "att", "0001122222222222"));
70: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "global", "att", "0001122222222222"));
71: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "global", "attr2", "1111111122222222222"));
72: printf("GetAttribute value=%s\n", cfg_getAttribute(tmp2, "global", "attr2"));
73: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", "a"));
74: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", ""));
75: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, NULL, "att"));
76: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", "attr2"));
77: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "bzyt", "111", "99999"));
78:
79: cfgWriteConfig(stdout, tmp, 0);
80: cfgWriteConfig(stdout, tmp2, 1);
81: printf("2) ---------------------------------\n");
1.2 misho 82:
83: #ifndef SKIP_TEST_CONCAT
1.5 misho 84: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(tmp2, tmp));
85: cfgWriteConfig(stdout, tmp2, 0);
86: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(tmp2, tmp));
87: cfgWriteConfig(stdout, tmp2, 1);
1.2 misho 88: #else
1.5 misho 89: cfgEndConfig(&tmp);
1.2 misho 90: #endif
91:
1.5 misho 92: tmp = cfgInitConfig();
93: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz"));
94: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "bzyt", "00", "99999"));
95: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "gniah", "tiiiiiii"));
96: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, NULL, "att", "0001122777777"));
97: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho"));
98: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho1"));
99: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho2"));
100: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz1"));
101: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz2"));
1.2 misho 102:
103: #ifndef SKIP_TEST_MERGE
1.3 misho 104: printf("before_merge ---------------------------------\n");
1.5 misho 105: cfgWriteConfig(stdout, tmp2, 1);
106: printf("after_merge=%d ---------------------------------\n", cfgMergeConfig(tmp2, tmp));
107: cfgWriteConfig(stdout, tmp2, 1);
1.2 misho 108: #else
1.5 misho 109: cfgEndConfig(&tmp);
1.2 misho 110: #endif
111:
1.5 misho 112: arr = cfg_getSection(tmp2, "");
113: printf("arr=%p size=%d\n", arr, array_Size(arr));
114:
115: for (i = 0; i < array_Size(arr); i++)
116: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
117: array_Destroy(&arr);
118:
119: arr = cfg_getSection(tmp2, "global");
120: printf("arr=%p size=%d\n", arr, array_Size(arr));
121:
122: for (i = 0; i < array_Size(arr); i++)
123: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
124: array_Destroy(&arr);
125:
126: arr = cfg_getSection(tmp2, NULL);
127: printf("arr=%p size=%d\n", arr, array_Size(arr));
128:
129: for (i = 0; i < array_Size(arr); i++)
130: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
131: array_Destroy(&arr);
132:
133: printf("CreateConfig=%d\n", cfgCreateConfig("test4e.cfg", tmp2, 1));
1.2 misho 134: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
135:
1.5 misho 136: cfgEndConfig(&tmp);
137: cfgEndConfig(&tmp2);
1.2 misho 138: return 0;
139: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>