Annotation of libaitcfg/example/test.c, revision 1.4
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:
1.4 ! misho 40: printf("GetAttribute multi-lines value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest"));
! 41: printf("GetAttribute multi-lines w/o \\ value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest_1"));
1.2 misho 42: cfgUnloadConfig(&lst);
43: printf("0) ---------------------------------\n");
44:
45: printf("size lst=%d tmp=%d %d\n", sizeof lst, sizeof tmp, sizeof(pthread_mutex_t));
46:
47: cfgInitConfig(&tmp);
1.3 misho 48: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "BLAHzdf"));
49: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "bzyt", "00", "99999 sdfbj"));
50: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "gniah", "tiiidfsdfsfsiiii"));
51: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, NULL, "att", "0001122777777555"));
1.2 misho 52:
53: cfgInitConfig(&lst);
54: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "zzz", "ZZZ"));
55: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "att", "0001122222222222"));
56: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "att", "0001122222222222"));
57: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222"));
58: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2"));
59: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "a"));
60: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", ""));
61: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, NULL, "att"));
62: printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "attr2"));
63: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "bzyt", "111", "99999"));
64:
65: cfgWriteConfig(stdout, &tmp, 0);
66: cfgWriteConfig(stdout, &lst, 1);
67: printf("1) ---------------------------------\n");
68:
69: #ifndef SKIP_TEST_CONCAT
70: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(&lst, &tmp));
71: cfgWriteConfig(stdout, &lst, 0);
72: printf("concat=%d\n---------------------------------\n", cfgConcatConfig(&lst, &tmp));
73: cfgWriteConfig(stdout, &lst, 1);
74: #else
75: cfgUnloadConfig(&tmp);
76: #endif
77:
78: cfgInitConfig(&tmp);
79: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "blahz"));
80: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "bzyt", "00", "99999"));
81: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "gniah", "tiiiiiii"));
82: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, NULL, "att", "0001122777777"));
1.3 misho 83: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "gruh", "shmink", "ohoboho"));
1.4 ! misho 84: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "gruh", "shmink", "ohoboho1"));
! 85: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "gruh", "shmink", "ohoboho2"));
! 86: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "blahz1"));
! 87: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "blahz2"));
1.2 misho 88:
89: #ifndef SKIP_TEST_MERGE
1.3 misho 90: printf("before_merge ---------------------------------\n");
91: cfgWriteConfig(stdout, &lst, 1);
92: printf("after_merge=%d ---------------------------------\n", cfgMergeConfig(&lst, &tmp));
1.2 misho 93: cfgWriteConfig(stdout, &lst, 1);
94: #else
95: cfgUnloadConfig(&tmp);
96: #endif
97:
98: printf("CreateConfig=%d\n", cfgCreateConfig("test4e.cfg", &lst, 1));
99: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
100:
101: cfgUnloadConfig(&tmp);
102: cfgUnloadConfig(&lst);
103: return 0;
104: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>