-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
48 lines (41 loc) · 1.13 KB
/
Copy pathexample.c
File metadata and controls
48 lines (41 loc) · 1.13 KB
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
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <config_parser.h>
int main(void) {
ConfigParser p;
ConfigTable *root = config_parse(&p, "./test.config");
if(!root) {
puts("Failed to parse config file!");
return 1;
}
ConfigValue val = config_get_string(root, "a");
if(val.ok) {
printf("a = %s\n", val.as.string);
} else {
puts("Error getting 'a' key!");
}
ConfigTable *test = config_get_table(&p, "test");
if(!test) {
puts("Error getting 'test' table");
goto end;
}
val = config_get_boolean(test, "valid");
if(val.ok) {
printf("test::valid = %s\n", val.as.boolean ? "true" : "false");
} else {
puts("Error getting 'valid' key in table 'test'");
}
ConfigTable *test2 = config_get_table(&p, "test2");
if(!test2) {
puts("Error getting 'test2' table");
goto end;
}
val = config_get_boolean(test2, "valid");
if(val.ok) {
printf("test2::valid = %s\n", val.as.boolean ? "true" : "false");
} else {
puts("Error getting 'valid' key in table 'test2'");
}
end:
config_end(&p);
return 0;
}