Annotation of libaitcfg/example/test.c, revision 1.1.2.11
1.1.2.1 misho 1: #include <stdio.h>
2: #include <sys/types.h>
3: #include <aitcfg.h>
4:
1.1.2.9 misho 5:
1.1.2.1 misho 6: int main()
7: {
8: cfg_root_t lst, tmp;
9: char szStr[256];
1.1.2.3 misho 10: struct tagCfg *av;
1.1.2.6 misho 11: ait_val_t v;
1.1.2.1 misho 12:
13: printf("LoadConfig=%d\n", cfgLoadConfig("test.conf", &lst));
14: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
1.1.2.2 misho 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"));
1.1.2.4 misho 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"));
1.1.2.5 misho 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"));
1.1.2.1 misho 31:
1.1.2.9 misho 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);
1.1.2.6 misho 39:
1.1.2.9 misho 40: printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest"));
1.1.2.8 misho 41: cfgUnloadConfig(&lst);
42: printf("0) ---------------------------------\n");
1.1.2.5 misho 43:
1.1.2.9 misho 44: printf("size lst=%d tmp=%d %d\n", sizeof lst, sizeof tmp, sizeof(pthread_mutex_t));
45:
1.1.2.8 misho 46: cfgInitConfig(&tmp);
47: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "blahz"));
48: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "bzyt", "00", "99999"));
49: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "gniah", "tiiiiiii"));
50: printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, NULL, "att", "0001122777777"));
1.1.2.9 misho 51:
1.1.2.8 misho 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"));
1.1.2.11! misho 62: printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "bzyt", "111", "99999"));
1.1.2.1 misho 63:
1.1.2.8 misho 64: cfgWriteConfig(stdout, &tmp, 0);
65: cfgWriteConfig(stdout, &lst, 1);
66: printf("1) ---------------------------------\n");
1.1.2.11! misho 67:
1.1.2.8 misho 68: #if 0
1.1.2.1 misho 69: // printf("%d\n---------------------------------\n", ConcatConfig(&lst, &tmp));
70: // WriteConfig(stdout, &lst);
71: printf("%d\n---------------------------------\n", ConcatConfig(&lst, &tmp));
72: WriteConfig(stdout, &lst);
73:
74: printf("CreateConfig=%d\n", CreateConfig("test4e.cfg", &lst));
75: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
76: #endif
1.1.2.11! misho 77:
! 78: #ifndef SKIP_TEST_MERGE
! 79: printf("merge=%d\n---------------------------------\n", cfgMergeConfig(&lst, &tmp));
! 80: cfgWriteConfig(stdout, &lst, 1);
! 81: #else
1.1.2.8 misho 82: cfgUnloadConfig(&tmp);
1.1.2.11! misho 83: #endif
! 84: cfgUnloadConfig(&lst);
1.1.2.1 misho 85: return 0;
86: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>