Annotation of libaitcfg/example/test.c, revision 1.2
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);
! 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"));
! 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"));
! 82:
! 83: #ifndef SKIP_TEST_MERGE
! 84: printf("merge=%d\n---------------------------------\n", cfgMergeConfig(&lst, &tmp));
! 85: cfgWriteConfig(stdout, &lst, 1);
! 86: #else
! 87: cfgUnloadConfig(&tmp);
! 88: #endif
! 89:
! 90: printf("CreateConfig=%d\n", cfgCreateConfig("test4e.cfg", &lst, 1));
! 91: printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
! 92:
! 93: cfgUnloadConfig(&tmp);
! 94: cfgUnloadConfig(&lst);
! 95: return 0;
! 96: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>