version 1.1.1.1, 2017/01/24 14:48:56
|
version 1.1.1.2, 2021/03/17 00:49:17
|
Line 3
|
Line 3
|
|
|
int main(void) |
int main(void) |
{ |
{ |
cfg_opt_t section_opts[] = { | static cfg_opt_t section_opts[] = { |
CFG_STR("prop", 0, CFGF_NONE), | CFG_STR("prop", 0, CFGF_NONE), |
CFG_END() | CFG_END() |
}; | }; |
|
|
cfg_opt_t opts[] = { | cfg_opt_t opts[] = { |
CFG_SEC("section", section_opts, CFGF_TITLE | CFGF_MULTI), | CFG_SEC("section", section_opts, CFGF_TITLE | CFGF_MULTI), |
CFG_END() | CFG_END() |
}; | }; |
|
|
cfg_opt_t opts_no_dupes[] = { | cfg_opt_t opts_no_dupes[] = { |
CFG_SEC("section", section_opts, | CFG_SEC("section", section_opts, |
CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES), | CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES), |
CFG_END() | CFG_END() |
}; | }; |
|
|
const char *config_data = | const char *config_data = |
"section title_one { prop = 'value_one' }\n" | "section title_one { prop = 'value_one' }\n" |
"section title_two { prop = 'value_two' }\n" | "section title_two { prop = 'value_two' }\n" |
"section title_one { prop = 'value_one' }\n"; | "section title_one { prop = 'value_one' }\n"; /* Duplicate! */ |
|
|
int rc; | int rc; |
cfg_t *cfg = cfg_init(opts, CFGF_NONE); | cfg_t *cfg = cfg_init(opts, CFGF_NONE); |
fail_unless(cfg); | |
|
|
rc = cfg_parse_buf(cfg, config_data); | fail_unless(cfg); |
|
|
fail_unless(rc == CFG_SUCCESS); | rc = cfg_parse_buf(cfg, config_data); |
| fail_unless(rc == CFG_SUCCESS); |
|
|
fail_unless(cfg_size(cfg, "section") == 2); | fail_unless(cfg_size(cfg, "section") == 2); |
| fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 0)), "title_one") == 0); |
| fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 1)), "title_two") == 0); |
|
|
fail_unless( | cfg_free(cfg); |
strcmp(cfg_title(cfg_getnsec(cfg, "section", 0)), "title_one") == 0); | |
fail_unless( | |
strcmp(cfg_title(cfg_getnsec(cfg, "section", 1)), "title_two") == 0); | |
|
|
cfg_free(cfg); | cfg = cfg_init(opts_no_dupes, CFGF_NONE); |
| fail_unless(cfg); |
|
|
cfg = cfg_init(opts_no_dupes, CFGF_NONE); | rc = cfg_parse_buf(cfg, config_data); |
fail_unless(cfg); | fail_unless(rc == CFG_PARSE_ERROR); |
|
|
rc = cfg_parse_buf(cfg, config_data); | cfg_free(cfg); |
fail_unless(rc == CFG_PARSE_ERROR); | |
|
|
cfg_free(cfg); | return 0; |
| |
return 0; | |
} |
} |
|
|
|
/** |
|
* Local Variables: |
|
* indent-tabs-mode: t |
|
* c-file-style: "linux" |
|
* End: |
|
*/ |