Annotation of libaitcfg/example/test.c, revision 1.3.8.1
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;
12:
13: printf("LoadConfig=%d\n", cfgLoadConfig("test.conf", &lst));
14: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
15: printf("Find Attribute at position=%d\n", cfg_findAttribute(&lst, NULL, "testattr"));
16: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "", "testattr"));
17: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
18: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
19: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
20: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "att", "0001122277777777"));
21: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "att", "0001122222222222"));
22: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
23: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
24: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "", "att"));
25: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, NULL, "att"));
26: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "a"));
27: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", ""));
28: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, NULL, "att"));
29: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "attr2"));
30: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
31:
32: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "section", "attr3", NULL));
33: printf("LoadValue=%d :: ", cfg_loadAttribute(&lst, "section", "attr3", &v, "iH"));
34: printf("Str=%s\n", AIT_GET_STR(&v));
35: AIT_FREE_VAL(&v);
36: printf("LoadValue=%d :: ", cfg_loadAttribute(&lst, "", "testattr", &v, "iH2"));
37: printf("Str=%s\n", AIT_GET_STR(&v));
38: AIT_FREE_VAL(&v);
39:
40: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest"));
41: cfgUnloadConfig(&lst);
42: printf("0) ---------------------------------\n");
43:
44: printf("size lst=%d tmp=%d %d\n", sizeof lst, sizeof tmp, sizeof(pthread_mutex_t));
45:
46: cfgInitConfig(&tmp);
1.3 misho 47: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "BLAHzdf"));
48: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "bzyt", "00", "99999 sdfbj"));
49: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "gniah", "tiiidfsdfsfsiiii"));
50: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, NULL, "att", "0001122777777555"));
1.2 misho 51:
52: cfgInitConfig(&lst);
53: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "zzz", "ZZZ"));
54: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "att", "0001122222222222"));
55: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "att", "0001122222222222"));
56: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
57: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
58: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "a"));
59: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", ""));
60: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, NULL, "att"));
61: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "attr2"));
62: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "bzyt", "111", "99999"));
63:
64: cfgWriteConfig(stdout, &tmp, 0);
65: cfgWriteConfig(stdout, &lst, 1);
66: printf("1) ---------------------------------\n");
67:
68: #ifndef SKIP_TEST_CONCAT
69: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(&lst, &tmp));
70: cfgWriteConfig(stdout, &lst, 0);
71: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(&lst, &tmp));
72: cfgWriteConfig(stdout, &lst, 1);
73: #else
74: cfgUnloadConfig(&tmp);
75: #endif
76:
77: cfgInitConfig(&tmp);
78: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "blahz"));
79: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "bzyt", "00", "99999"));
80: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "gniah", "tiiiiiii"));
81: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, NULL, "att", "0001122777777"));
1.3 misho 82: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "gruh", "shmink", "ohoboho"));
1.3.8.1 ! misho 83: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "gruh", "shmink", "ohoboho1"));
! 84: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "gruh", "shmink", "ohoboho2"));
! 85: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "blahz1"));
! 86: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "blahz2"));
1.2 misho 87:
88: #ifndef SKIP_TEST_MERGE
1.3 misho 89: printf("before_merge ---------------------------------\n");
90: cfgWriteConfig(stdout, &lst, 1);
91: printf("after_merge=%d ---------------------------------\n", cfgMergeConfig(&lst, &tmp));
1.2 misho 92: cfgWriteConfig(stdout, &lst, 1);
93: #else
94: cfgUnloadConfig(&tmp);
95: #endif
96:
97: printf("CreateConfig=%d\n", cfgCreateConfig("test4e.cfg", &lst, 1));
98: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
99:
100: cfgUnloadConfig(&tmp);
101: cfgUnloadConfig(&lst);
102: return 0;
103: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>