version 1.1, 2017/01/24 14:48:56
|
version 1.1.1.2, 2021/03/17 00:49:17
|
Line 3
|
Line 3
|
|
|
static cfg_t *create_config(void) |
static cfg_t *create_config(void) |
{ |
{ |
cfg_opt_t sec_opts[] = | static cfg_opt_t sec_opts[] = { |
{ | CFG_INT("a", 1, CFGF_NONE), |
CFG_INT("a", 1, CFGF_NONE), | CFG_INT("b", 2, CFGF_NONE), |
CFG_INT("b", 2, CFGF_NONE), | CFG_END() |
CFG_END() | }; |
}; | |
|
|
cfg_opt_t opts[] = | cfg_opt_t opts[] = { |
{ | CFG_SEC("sec", sec_opts, CFGF_MULTI | CFGF_TITLE), |
CFG_SEC("sec", sec_opts, CFGF_MULTI | CFGF_TITLE), | CFG_END() |
CFG_END() | }; |
}; | |
|
|
return cfg_init(opts, 0); | return cfg_init(opts, 0); |
} |
} |
|
|
int | int main(void) |
main(void) | |
{ |
{ |
cfg_t *acfg, *bcfg; | cfg_t *acfg, *bcfg; |
cfg_t *sec; | cfg_t *sec; |
|
|
acfg = create_config(); | acfg = create_config(); |
fail_unless(cfg_parse(acfg, SRC_DIR "/a.conf") == 0); | fail_unless(cfg_parse(acfg, SRC_DIR "/a.conf") == 0); |
|
|
bcfg = create_config(); | bcfg = create_config(); |
fail_unless(cfg_parse(bcfg, SRC_DIR "/b.conf") == 0); | fail_unless(cfg_parse(bcfg, SRC_DIR "/b.conf") == 0); |
|
|
sec = cfg_getnsec(acfg, "sec", 0); | sec = cfg_getnsec(acfg, "sec", 0); |
fail_unless(sec != 0); | fail_unless(sec != 0); |
fail_unless(cfg_size(acfg, "sec") == 1); | fail_unless(cfg_size(acfg, "sec") == 1); |
fail_unless(strcmp(cfg_title(sec), "acfg") == 0); | fail_unless(strcmp(cfg_title(sec), "acfg") == 0); |
fail_unless(cfg_getint(sec, "a") == 5); | fail_unless(cfg_getint(sec, "a") == 5); |
fail_unless(cfg_getint(sec, "b") == 2); | fail_unless(cfg_getint(sec, "b") == 2); |
|
|
sec = cfg_getnsec(bcfg, "sec", 0); | sec = cfg_getnsec(bcfg, "sec", 0); |
fail_unless(sec != 0); | fail_unless(sec != 0); |
fail_unless(cfg_size(bcfg, "sec") == 1); | fail_unless(cfg_size(bcfg, "sec") == 1); |
fail_unless(strcmp(cfg_title(sec), "bcfg") == 0); | fail_unless(strcmp(cfg_title(sec), "bcfg") == 0); |
fail_unless(cfg_getint(sec, "a") == 1); | fail_unless(cfg_getint(sec, "a") == 1); |
fail_unless(cfg_getint(sec, "b") == 9); | fail_unless(cfg_getint(sec, "b") == 9); |
|
|
cfg_free(acfg); | cfg_free(acfg); |
cfg_free(bcfg); | cfg_free(bcfg); |
|
|
return 0; | return 0; |
} |
} |
|
|