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