--- libaitcfg/example/test.c 2012/04/02 09:31:20 1.1.2.1 +++ libaitcfg/example/test.c 2012/04/03 12:54:49 1.1.2.10 @@ -2,56 +2,71 @@ #include #include + int main() { cfg_root_t lst, tmp; char szStr[256]; + struct tagCfg *av; + ait_val_t v; printf("LoadConfig=%d\n", cfgLoadConfig("test.conf", &lst)); printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError()); - /* - printf("Find Attribute at position=%d\n", FindAttribute(&lst, NULL, "testattr")); - printf("GetAttribute value=%s\n", GetAttribute(&lst, "", "testattr")); - printf("GetAttribute value=%s\n", GetAttribute(&lst, "global", "attr2")); - printf("SetAttribute=%d\n", SetAttribute(&lst, "global", "attr2", "1111111122222222222")); - printf("GetAttribute value=%s\n", GetAttribute(&lst, "global", "attr2")); - printf("SetAttribute=%d\n", SetAttribute(&lst, NULL, "att", "0001122222222222")); - printf("SetAttribute=%d\n", SetAttribute(&lst, "global", "att", "0001122222222222")); - printf("SetAttribute=%d\n", SetAttribute(&lst, "global", "attr2", "1111111122222222222")); - printf("GetAttribute value=%s\n", GetAttribute(&lst, "global", "attr2")); - printf("UnsetAttribute=%d\n", UnsetAttribute(&lst, "global", "a")); - printf("UnsetAttribute=%d\n", UnsetAttribute(&lst, "global", "")); - printf("UnsetAttribute=%d\n", UnsetAttribute(&lst, NULL, "att")); - printf("UnsetAttribute=%d\n", UnsetAttribute(&lst, "global", "attr2")); - printf("GetAttribute value=%s\n", GetAttribute(&lst, "global", "attr2")); + printf("Find Attribute at position=%d\n", cfg_findAttribute(&lst, NULL, "testattr")); + printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "", "testattr")); + printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2")); + printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222")); + printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2")); + printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "att", "0001122277777777")); + printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "att", "0001122222222222")); + printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222")); + printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2")); + printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "", "att")); + printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, NULL, "att")); + printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "a")); + printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "")); + printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, NULL, "att")); + printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "attr2")); + printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2")); - printf("SetAttribute=%d\n", SetAttribute(&lst, "section", "attr3", NULL)); - printf("LoadValue=%d :: ", LoadAttribute(&lst, "section", "attr3", szStr, 255, "iH")); - printf("Str=%s\n", szStr); - */ -#if 0 - InitConfig(&tmp); - printf("tmp: SetAttribute=%d\n", cfg_SetAttribute(&tmp, "global", "piuk", "blahz")); - printf("tmp: SetAttribute=%d\n", cfg_SetAttribute(&tmp, "bzyt", "00", "99999")); - printf("tmp: SetAttribute=%d\n", cfg_SetAttribute(&tmp, "global", "gniah", "tiiiiiii")); - printf("tmp: SetAttribute=%d\n", cfg_SetAttribute(&tmp, NULL, "att", "0001122777777")); - InitConfig(&lst); - printf("SetAttribute=%d\n", cfg_SetAttribute(&lst, NULL, "zzz", "ZZZ")); - printf("SetAttribute=%d\n", cfg_SetAttribute(&lst, NULL, "att", "0001122222222222")); - printf("SetAttribute=%d\n", cfg_SetAttribute(&lst, "global", "att", "0001122222222222")); - printf("SetAttribute=%d\n", cfg_SetAttribute(&lst, "global", "attr2", "1111111122222222222")); - printf("GetAttribute value=%s\n", cfg_GetAttribute(&lst, "global", "attr2")); - printf("UnsetAttribute=%d\n", cfg_UnsetAttribute(&lst, "global", "a")); - printf("UnsetAttribute=%d\n", cfg_UnsetAttribute(&lst, "global", "")); - printf("UnsetAttribute=%d\n", cfg_UnsetAttribute(&lst, NULL, "att")); - printf("UnsetAttribute=%d\n", cfg_UnsetAttribute(&lst, "global", "attr2")); - printf("tmp: SetAttribute=%d\n", cfg_SetAttribute(&lst, "bzyt", "111", "99999")); + printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "section", "attr3", NULL)); + printf("LoadValue=%d :: ", cfg_loadAttribute(&lst, "section", "attr3", &v, "iH")); + printf("Str=%s\n", AIT_GET_STR(&v)); + AIT_FREE_VAL(&v); + printf("LoadValue=%d :: ", cfg_loadAttribute(&lst, "", "testattr", &v, "iH2")); + printf("Str=%s\n", AIT_GET_STR(&v)); + AIT_FREE_VAL(&v); - WriteConfig(stdout, &tmp); - WriteConfig(stdout, &lst); - printf("---------------------------------\n"); - printf("%d\n---------------------------------\n", MergeConfig(&lst, &tmp)); - WriteConfig(stdout, &lst); + printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest")); + cfgUnloadConfig(&lst); + printf("0) ---------------------------------\n"); + + printf("size lst=%d tmp=%d %d\n", sizeof lst, sizeof tmp, sizeof(pthread_mutex_t)); + + cfgInitConfig(&tmp); + printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "piuk", "blahz")); + printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "bzyt", "00", "99999")); + printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, "global", "gniah", "tiiiiiii")); + printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&tmp, NULL, "att", "0001122777777")); + + cfgInitConfig(&lst); + printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "zzz", "ZZZ")); + printf("SetAttribute=%d\n", cfg_setAttribute(&lst, NULL, "att", "0001122222222222")); + printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "att", "0001122222222222")); + printf("SetAttribute=%d\n", cfg_setAttribute(&lst, "global", "attr2", "1111111122222222222")); + printf("GetAttribute value=%s\n", cfg_getAttribute(&lst, "global", "attr2")); + printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "a")); + printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "")); + printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, NULL, "att")); + printf("UnsetAttribute=%d\n", cfg_unsetAttribute(&lst, "global", "attr2")); + printf("tmp: SetAttribute=%d\n", cfg_setAttribute(&lst, "bzyt", "111", "99999")); + + cfgWriteConfig(stdout, &tmp, 0); + cfgWriteConfig(stdout, &lst, 1); + printf("1) ---------------------------------\n"); + printf("%d\n---------------------------------\n", cfgMergeConfig(&lst, &tmp)); + cfgWriteConfig(stdout, &lst, 1); +#if 0 // printf("%d\n---------------------------------\n", ConcatConfig(&lst, &tmp)); // WriteConfig(stdout, &lst); printf("%d\n---------------------------------\n", ConcatConfig(&lst, &tmp)); @@ -61,5 +76,6 @@ int main() printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError()); #endif cfgUnloadConfig(&lst); + cfgUnloadConfig(&tmp); return 0; }