#include <stdio.h>
#include <sys/types.h>
#include <aitcfg.h>
int main()
{
cfg_root_t lst, *tmp, *tmp2;
char szStr[256];
struct tagCfg *av;
ait_val_t v;
array_t *arr;
register int i;
printf("LoadConfig=%d\n", cfgLoadConfig("test.conf", &lst));
printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
arr = cfg_getSection(&lst, "ramzamzam !");
printf("arr=%p it must be NULL!\n", arr);
arr = cfg_getSection(&lst, "global");
printf("arr=%p size=%d\n", arr, array_Size(arr));
for (i = 0; i < array_Size(arr); i++)
printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
array_Destroy(&arr);
printf("0) ---------------------------------\n");
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", 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);
printf("GetAttribute multi-lines value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest"));
printf("GetAttribute multi-lines w/o \\ value=%s\n", cfg_getAttribute(&lst, "section1", "attrtest_1"));
printf("GetAttribute from %%include file value=%s\n", cfg_getAttribute(&lst, "", "test4ext"));
printf("GetAttribute from %%include file [proba] value=%s\n", cfg_getAttribute(&lst, "proba", "test4ext"));
cfgUnloadConfig(&lst);
printf("1) ---------------------------------\n");
printf("size lst=%d tmp=%d %d\n", sizeof lst, sizeof tmp, sizeof(pthread_mutex_t));
tmp = cfgInitConfig();
printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "BLAHzdf"));
printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "bzyt", "00", "99999 sdfbj"));
printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "gniah", "tiiidfsdfsfsiiii"));
printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, NULL, "att", "0001122777777555"));
tmp2 = cfgInitConfig();
printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, NULL, "zzz", "ZZZ"));
printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, NULL, "att", "0001122222222222"));
printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "global", "att", "0001122222222222"));
printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "global", "attr2", "1111111122222222222"));
printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "global", "dup", "1"));
printf("GetAttribute value=%s\n", cfg_getAttribute(tmp2, "global", "attr2"));
printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", "a"));
printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", ""));
printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, NULL, "att"));
printf("UnsetAttribute=%d\n", cfg_unsetAttribute(tmp2, "global", "attr2"));
printf("SetAttribute=%d\n", cfg_setAttribute(tmp2, "bzyt", "111", "99999"));
cfgWriteConfig(stdout, tmp, 0);
cfgWriteConfig(stdout, tmp2, 1);
printf("2) ---------------------------------\n");
#ifndef SKIP_TEST_CONCAT
printf("concat=%d\n---------------------------------\n", cfgConcatConfig(tmp2, tmp));
cfgWriteConfig(stdout, tmp2, 0);
printf("concat=%d\n---------------------------------\n", cfgConcatConfig(tmp2, tmp));
cfgWriteConfig(stdout, tmp2, 1);
#else
cfgEndConfig(&tmp);
#endif
tmp = cfgInitConfig();
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"));
printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho"));
printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho1"));
printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "gruh", "shmink", "ohoboho2"));
printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz1"));
printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "piuk", "blahz2"));
printf("tmp: SetAttribute=%d\n", cfg_setAttribute(tmp, "global", "dup", "2"));
#ifndef SKIP_TEST_MERGE
printf("before_merge ---------------------------------\n");
cfgWriteConfig(stdout, tmp2, 1);
printf("after_merge=%d ---------------------------------\n", cfgMergeConfig(tmp2, tmp));
cfgWriteConfig(stdout, tmp2, 1);
printf("END_merge=%d ---------------------------------\n", cfg_getAttributeLong(tmp2, "global", "dup"));
#else
cfgEndConfig(&tmp);
#endif
arr = cfg_getSection(tmp2, "");
printf("arr=%p size=%d\n", arr, array_Size(arr));
for (i = 0; i < array_Size(arr); i++)
printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
array_Destroy(&arr);
arr = cfg_getSection(tmp2, "global");
printf("arr=%p size=%d\n", arr, array_Size(arr));
for (i = 0; i < array_Size(arr); i++)
printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
array_Destroy(&arr);
arr = cfg_getSection(tmp2, NULL);
printf("arr=%p size=%d\n", arr, array_Size(arr));
for (i = 0; i < array_Size(arr); i++)
printf("%s\\%s=%s\n", CFG_SECTION(array_Get(arr, i)), CFG_ATTRIBUTE(array_Get(arr, i)), CFG_VALUE(array_Get(arr, i)));
array_Destroy(&arr);
printf("CreateConfig=%d\n", cfgCreateConfig("test4e.cfg", tmp2, 1));
printf("errno=%d error=%s\n", cfg_GetErrno(), cfg_GetError());
cfgEndConfig(&tmp);
cfgEndConfig(&tmp2);
return 0;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>