diff options
Diffstat (limited to 'examples/read_conf.c')
-rw-r--r-- | examples/read_conf.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/examples/read_conf.c b/examples/read_conf.c index f153c15..45a6520 100644 --- a/examples/read_conf.c +++ b/examples/read_conf.c @@ -12,26 +12,24 @@ int main(int argc, char **argv) { free(error); return EXIT_FAILURE; } - printf("number.one: %s\n", pom_conf_get(conf, "number.one")); - printf("number.tow: %s\n", pom_conf_get_or_default(conf, "number.tow", "(none)")); - printf("has thing? %d\n", pom_conf_has(conf, "thing")); - const char *file; uint64_t line; - if (pom_conf_location(conf, "thing", &file, &line)) { - printf("\tthing location: %s:%" PRIu64 "\n", file,line); + pom_conf *conf2 = pom_load_string("<inline>", "foo=bar\r\n[j.number]\n" + "one = I\n" + "five = V\n", &error); + if (!conf2) { + pom_conf_free(conf); + pom_error_print(error); + free(error); + return EXIT_FAILURE; } - const pom_item *item; pom_item_iter *iter = NULL; - while ((item = pom_conf_next_item(pom_conf_section(conf, "number"), &iter))) { - printf("Number: %s, Value: %s\n", item->key, item->value); - } - pom_unread_key_iter *unread = NULL; - const char *key; - while ((key = pom_conf_next_unread_key(conf, &unread))) { - printf("Unrecognized key: %s\n", key); - } - pom_key_iter *keys = NULL; - while ((key = pom_conf_next_key(conf, &keys))) { - printf("Top-level key: %s\n", key); + const pom_item *item; + pom_conf_merge(conf,pom_conf_section(conf2,"j")); + while ((item = pom_conf_next_item(conf, &iter))) { + printf("Key: %s, Value: %s\n", item->key, item->value); + const char *file; uint64_t line; + pom_conf_location(conf,item->key,&file,&line); + printf(" Defined at %s:%" PRIu64 "\n",file,line); } pom_conf_free(conf); + pom_conf_free(conf2); } |