--- libaitcfg/example/testcfg.c 2021/11/25 22:31:10 1.1.2.1 +++ libaitcfg/example/testcfg.c 2021/11/25 23:44:52 1.1.2.2 @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -8,25 +9,36 @@ int main(int argc, char **argv) { cfg_root_t cfg; - char *str, *sec, *attr; + char ch, *str, *sec, *attr; array_t *arr; - int i; + int i, mode = 0; struct tagCfg *av; - if (argc < 2) { - printf("Error:: missing config.\n\ntestcfg [section/attribute]\n"); + while ((ch = getopt(argc, argv, "r")) != -1) + switch (ch) { + case 'r': + mode = 42; + break; + default: + printf("Error:: missing config.\n\ntestcfg [-r] [section/attribute]\n"); + return 1; + } + argc -= optind; + argv += optind; + if (!argc) { + printf("Error:: missing config.\n\ntestcfg [-r] [section/attribute]\n"); return 1; } else - str = argv[2]; + str = argv[1]; - if (cfgLoadConfig(argv[1], &cfg)) { + if (cfgLoadConfig(argv[0], &cfg)) { ELIBERR(cfg); return 1; } else printf("Opened config\n"); if (str) { - attr = strchr(argv[2], '/'); + attr = strchr(argv[1], '/'); if (!attr) { attr = str; sec = NULL; @@ -48,14 +60,16 @@ main(int argc, char **argv) av = array(arr, i, struct tagCfg*); if (av) printf("%s = %s\n", - AIT_GET_STR(&av->cfg_attr), + AIT_ADDR(&av->cfg_attr), AIT_GET_STR(&av->cfg_val)); } array_Destroy(&arr); } } - } else + } else if (!mode) cfgWriteConfig(stdout, &cfg, 1); + else + cfgWriteConfigRaw(stdout, &cfg, 1); cfgUnloadConfig(&cfg); printf("Closed config\n");