Annotation of libaitcfg/example/test.c, revision 1.5.10.2
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.5.10.2! 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.5.10.1 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"));
75: printf("GetAttribute value=%s\n", cfg_getAttribute(tmp2, "global", "attr2"));
76: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", "a"));
77: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", ""));
78: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, NULL, "att"));
79: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", "attr2"));
80: printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "bzyt", "111", "99999"));
81:
82: cfgWriteConfig(stdout, tmp, 0);
83: cfgWriteConfig(stdout, tmp2, 1);
84: printf("2) ---------------------------------\n");
1.2 misho 85:
86: #ifndef SKIP_TEST_CONCAT
1.5 misho 87: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(tmp2, tmp));
88: cfgWriteConfig(stdout, tmp2, 0);
89: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(tmp2, tmp));
90: cfgWriteConfig(stdout, tmp2, 1);
1.2 misho 91: #else
1.5 misho 92: cfgEndConfig(&tmp);
1.2 misho 93: #endif
94:
1.5 misho 95: tmp = cfgInitConfig();
96: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz"));
97: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "bzyt", "00", "99999"));
98: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "gniah", "tiiiiiii"));
99: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, NULL, "att", "0001122777777"));
100: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho"));
101: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho1"));
102: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho2"));
103: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz1"));
104: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz2"));
1.2 misho 105:
106: #ifndef SKIP_TEST_MERGE
1.3 misho 107: printf("before_merge ---------------------------------\n");
1.5 misho 108: cfgWriteConfig(stdout, tmp2, 1);
109: printf("after_merge=%d ---------------------------------\n", cfgMergeConfig(tmp2, tmp));
110: cfgWriteConfig(stdout, tmp2, 1);
1.2 misho 111: #else
1.5 misho 112: cfgEndConfig(&tmp);
1.2 misho 113: #endif
114:
1.5 misho 115: arr = cfg_getSection(tmp2, "");
116: printf("arr=%p size=%d\n", arr, array_Size(arr));
117:
118: for (i = 0; i < array_Size(arr); i++)
119: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
120: array_Destroy(&arr);
121:
122: arr = cfg_getSection(tmp2, "global");
123: printf("arr=%p size=%d\n", arr, array_Size(arr));
124:
125: for (i = 0; i < array_Size(arr); i++)
126: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
127: array_Destroy(&arr);
128:
129: arr = cfg_getSection(tmp2, NULL);
130: printf("arr=%p size=%d\n", arr, array_Size(arr));
131:
132: for (i = 0; i < array_Size(arr); i++)
133: printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
134: array_Destroy(&arr);
135:
136: printf("CreateConfig=%d\n", cfgCreateConfig("test4e.cfg", tmp2, 1));
1.2 misho 137: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
138:
1.5 misho 139: cfgEndConfig(&tmp);
140: cfgEndConfig(&tmp2);
1.2 misho 141: return 0;
142: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>