modules/dwl: new module

This commit is contained in:
Ogromny 2022-12-13 15:18:41 +01:00 committed by Daniel Eklöf
parent 6027b2728b
commit f5cfc103d0
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
10 changed files with 625 additions and 5 deletions

23
yml.c
View file

@ -640,9 +640,11 @@ yml_is_list(const struct yml_node *node)
return node->type == LIST;
}
const struct yml_node *
yml_get_value(const struct yml_node *node, const char *_path)
static struct yml_node const *
yml_get_(struct yml_node const *node, char const *_path, bool value)
{
/* value: true for value, false for key */
if (node != NULL && node->type == ROOT)
node = node->root.root;
@ -662,7 +664,11 @@ yml_get_value(const struct yml_node *node, const char *_path)
if (strcmp(it->item.key->scalar.value, part) == 0) {
if (next_part == NULL) {
free(path);
return it->item.value;
if (value)
return it->item.value;
else
return it->item.key;
}
node = it->item.value;
@ -675,6 +681,17 @@ yml_get_value(const struct yml_node *node, const char *_path)
return NULL;
}
const struct yml_node *
yml_get_value(const struct yml_node *node, const char *_path)
{
return yml_get_(node, _path, true);
}
struct yml_node const *
yml_get_key(struct yml_node const *node, char const *_path) {
return yml_get_(node, _path, false);
}
struct yml_list_iter
yml_list_iter(const struct yml_node *list)
{