summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-09-14 00:26:39 -0400
committerpommicket <pommicket@gmail.com>2025-09-14 00:26:39 -0400
commit1406758a5a2e38392e54cb7ba7a00a0f80ee1567 (patch)
tree4d42477a1b8d8ee3fa7f3251e9e864a9f6a98d2d /examples
parent64c5d7ab942d8f4589f43909497ae07cc69231d0 (diff)
Merging configurations
Diffstat (limited to 'examples')
-rw-r--r--examples/conf.pom19
-rw-r--r--examples/read_conf.c34
2 files changed, 19 insertions, 34 deletions
diff --git a/examples/conf.pom b/examples/conf.pom
index ba10cca..27037d9 100644
--- a/examples/conf.pom
+++ b/examples/conf.pom
@@ -1,17 +1,4 @@
-[0oo.eeee°]
- bar = 10
-# testing
-
-Hello = 5
-
- # here's another comment
-[jibjabjobdsfajkha]
- win = yes
-
[number]
- one = 1
- two = 2
- three = "é
- yippee"
-[]
-thing=yup
+one = 1
+two = 2
+three = 3
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);
}