summaryrefslogtreecommitdiff
path: root/examples/read_conf.c
blob: 78e48472c9e4c915db1c7ac73b01c079a05f9044 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

#include "pom.h"

int main(int argc, char **argv) {
	pom_error *error;
	pom_conf *conf = pom_load_path(argc >= 2 ? argv[1] : "conf.pom", &error);
	if (!conf) {
		pom_error_print(error);
		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);
	}
	const pom_item *item;
	pom_item_iter *iter = NULL;
	while ((item = pom_conf_next_item(conf, &iter))) {
		printf("Key: %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);
	}
	pom_conf_free(conf);
}