Annotation of libaitcfg/example/test.c, revision 1.4.8.3
1.2 misho 1: #include <stdio.h>
2: #include <sys/types.h>
3: #include <aitcfg.h>
4:
5:
6: int main()
7: {
8: cfg_root_t lst, tmp;
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:
58: cfgInitConfig(&tmp);
1.3 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"));
1.2 misho 63:
64: cfgInitConfig(&lst);
65: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "zzz", "ZZZ"));
66: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "att", "0001122222222222"));
67: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "att", "0001122222222222"));
68: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
69: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
70: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "a"));
71: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", ""));
72: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, NULL, "att"));
73: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "attr2"));
74: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "bzyt", "111", "99999"));
75:
76: cfgWriteConfig(stdout, &tmp, 0);
77: cfgWriteConfig(stdout, &lst, 1);
1.4.8.3 ! misho 78: printf("2) ---------------------------------\n");
1.2 misho 79:
80: #ifndef SKIP_TEST_CONCAT
81: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(&lst, &tmp));
82: cfgWriteConfig(stdout, &lst, 0);
83: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(&lst, &tmp));
84: cfgWriteConfig(stdout, &lst, 1);
85: #else
86: cfgUnloadConfig(&tmp);
87: #endif
88:
89: cfgInitConfig(&tmp);
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"));
1.3 misho 94: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "gruh", "shmink", "ohoboho"));
1.4 misho 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");
102: cfgWriteConfig(stdout, &lst, 1);
103: printf("after_merge=%d ---------------------------------\n", cfgMergeConfig(&lst, &tmp));
1.2 misho 104: cfgWriteConfig(stdout, &lst, 1);
105: #else
106: cfgUnloadConfig(&tmp);
107: #endif
108:
109: printf("CreateConfig=%d\n", cfgCreateConfig("test4e.cfg", &lst, 1));
110: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
111:
112: cfgUnloadConfig(&tmp);
113: cfgUnloadConfig(&lst);
114: return 0;
115: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>