Annotation of libaitcfg/example/test.c, revision 1.6.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:
1.6 misho 18: arr = cfg_getSection(&lst, "ramzamzam !");
19: printf("arr=%p it must be NULL!\n", arr);
20:
1.5 misho 21: arr = cfg_getSection(&lst, "global");
22: printf("arr=%p size=%d\n", arr, array_Size(arr));
23:
24: for (i = 0; i < array_Size(arr); i++)
25: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
26: array_Destroy(&arr);
27:
28: printf("0) ---------------------------------\n");
1.2 misho 29: printf("Find Attribute at position=%d\n", cfg_findAttribute(&lst, NULL, "testattr"));
30: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "", "testattr"));
31: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
32: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
33: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
34: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "att", "0001122277777777"));
35: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "att", "0001122222222222"));
36: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
37: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
38: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "", "att"));
39: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, NULL, "att"));
40: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "a"));
41: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", ""));
42: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, NULL, "att"));
43: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "attr2"));
44: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
45:
46: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "section", "attr3", NULL));
47: printf("LoadValue=%d :: ", cfg_loadAttribute(&lst, "section", "attr3", &v, "iH"));
48: printf("Str=%s\n", AIT_GET_STR(&v));
49: AIT_FREE_VAL(&v);
50: printf("LoadValue=%d :: ", cfg_loadAttribute(&lst, "", "testattr", &v, "iH2"));
51: printf("Str=%s\n", AIT_GET_STR(&v));
52: AIT_FREE_VAL(&v);
53:
1.4 misho 54: printf("GetAttribute multi-lines value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest"));
55: printf("GetAttribute multi-lines w/o \\ value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest_1"));
1.6 misho 56:
57: printf("GetAttribute from %%include file value=%s\n", cfg_getAttribute(&lst, "", "test4ext"));
58: printf("GetAttribute from %%include file [proba] value=%s\n", cfg_getAttribute(&lst, "proba", "test4ext"));
1.2 misho 59: cfgUnloadConfig(&lst);
1.5 misho 60: printf("1) ---------------------------------\n");
1.2 misho 61:
62: printf("size lst=%d tmp=%d %d\n", sizeof lst, sizeof tmp, sizeof(pthread_mutex_t));
63:
1.5 misho 64: tmp = cfgInitConfig();
65: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "BLAHzdf"));
66: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "bzyt", "00", "99999 sdfbj"));
67: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "gniah", "tiiidfsdfsfsiiii"));
68: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, NULL, "att", "0001122777777555"));
69:
70: tmp2 = cfgInitConfig();
71: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, NULL, "zzz", "ZZZ"));
72: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, NULL, "att", "0001122222222222"));
73: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "global", "att", "0001122222222222"));
74: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "global", "attr2", "1111111122222222222"));
1.6.10.1! misho 75: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "global", "dup", "1"));
1.5 misho 76: printf("GetAttribute value=%s\n", cfg_getAttribute(tmp2, "global", "attr2"));
77: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", "a"));
78: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", ""));
79: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, NULL, "att"));
80: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", "attr2"));
81: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "bzyt", "111", "99999"));
82:
83: cfgWriteConfig(stdout, tmp, 0);
84: cfgWriteConfig(stdout, tmp2, 1);
85: printf("2) ---------------------------------\n");
1.2 misho 86:
87: #ifndef SKIP_TEST_CONCAT
1.5 misho 88: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(tmp2, tmp));
89: cfgWriteConfig(stdout, tmp2, 0);
90: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(tmp2, tmp));
91: cfgWriteConfig(stdout, tmp2, 1);
1.2 misho 92: #else
1.5 misho 93: cfgEndConfig(&tmp);
1.2 misho 94: #endif
95:
1.5 misho 96: tmp = cfgInitConfig();
97: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz"));
98: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "bzyt", "00", "99999"));
99: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "gniah", "tiiiiiii"));
100: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, NULL, "att", "0001122777777"));
101: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho"));
102: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho1"));
103: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho2"));
104: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz1"));
105: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz2"));
1.6.10.1! misho 106: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "dup", "2"));
1.2 misho 107:
108: #ifndef SKIP_TEST_MERGE
1.3 misho 109: printf("before_merge ---------------------------------\n");
1.5 misho 110: cfgWriteConfig(stdout, tmp2, 1);
111: printf("after_merge=%d ---------------------------------\n", cfgMergeConfig(tmp2, tmp));
112: cfgWriteConfig(stdout, tmp2, 1);
1.6.10.1! misho 113: printf("END_merge=%d ---------------------------------\n", cfg_getAttributeLong(tmp2, "global", "dup"));
1.2 misho 114: #else
1.5 misho 115: cfgEndConfig(&tmp);
1.2 misho 116: #endif
117:
1.5 misho 118: arr = cfg_getSection(tmp2, "");
119: printf("arr=%p size=%d\n", arr, array_Size(arr));
120:
121: for (i = 0; i < array_Size(arr); i++)
122: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
123: array_Destroy(&arr);
124:
125: arr = cfg_getSection(tmp2, "global");
126: printf("arr=%p size=%d\n", arr, array_Size(arr));
127:
128: for (i = 0; i < array_Size(arr); i++)
129: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
130: array_Destroy(&arr);
131:
132: arr = cfg_getSection(tmp2, NULL);
133: printf("arr=%p size=%d\n", arr, array_Size(arr));
134:
135: for (i = 0; i < array_Size(arr); i++)
136: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
137: array_Destroy(&arr);
138:
139: printf("CreateConfig=%d\n", cfgCreateConfig("test4e.cfg", tmp2, 1));
1.2 misho 140: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
141:
1.5 misho 142: cfgEndConfig(&tmp);
143: cfgEndConfig(&tmp2);
1.2 misho 144: return 0;
145: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>