#include <ecoli_assert.h>
#include <ecoli_malloc.h>
#include <ecoli_strvec.h>
-#include <ecoli_keyval.h>
+#include <ecoli_dict.h>
#include <ecoli_log.h>
#include <ecoli_test.h>
#include <ecoli_node.h>
struct ec_parse *parent;
const struct ec_node *node;
struct ec_strvec *strvec;
- struct ec_keyval *attrs;
+ struct ec_dict *attrs;
};
static int __ec_node_parse_child(const struct ec_node *node,
TAILQ_INIT(&parse->children);
parse->node = node;
- parse->attrs = ec_keyval();
+ parse->attrs = ec_dict();
if (parse->attrs == NULL)
goto fail;
fail:
if (parse != NULL)
- ec_keyval_free(parse->attrs);
+ ec_dict_free(parse->attrs);
ec_free(parse);
return NULL;
{
struct ec_parse *dup = NULL;
struct ec_parse *child, *dup_child;
- struct ec_keyval *attrs = NULL;
+ struct ec_dict *attrs = NULL;
if (root == NULL)
return NULL;
if (root == ref)
*new_ref = dup;
- attrs = ec_keyval_dup(root->attrs);
+ attrs = ec_dict_dup(root->attrs);
if (attrs == NULL)
goto fail;
- ec_keyval_free(dup->attrs);
+ ec_dict_free(dup->attrs);
dup->attrs = attrs;
if (root->strvec != NULL) {
ec_parse_free_children(parse);
ec_strvec_free(parse->strvec);
- ec_keyval_free(parse->attrs);
+ ec_dict_free(parse->attrs);
ec_free(parse);
}
/* node can be null when parsing is incomplete */
if (parse->node != NULL) {
- id = parse->node->id;
+ id = ec_node_id(parse->node);
typename = ec_node_type(parse->node)->name;
}
return TAILQ_LAST(&parse->children, ec_parse_list);
}
-struct ec_parse *ec_parse_get_next(const struct ec_parse *parse)
+struct ec_parse *ec_parse_next(const struct ec_parse *parse)
{
return TAILQ_NEXT(parse, next);
}
return parse->parent;
}
-struct ec_parse *ec_parse_iter_next(struct ec_parse *parse)
+struct ec_parse *__ec_parse_iter_next(const struct ec_parse *root,
+ struct ec_parse *parse, bool iter_children)
{
struct ec_parse *child, *parent, *next;
- child = TAILQ_FIRST(&parse->children);
- if (child != NULL)
- return child;
+ if (iter_children) {
+ child = TAILQ_FIRST(&parse->children);
+ if (child != NULL)
+ return child;
+ }
parent = parse->parent;
- while (parent != NULL) {
+ while (parent != NULL && parse != root) {
next = TAILQ_NEXT(parse, next);
if (next != NULL)
return next;
return NULL;
}
-struct ec_parse *ec_parse_find_first(struct ec_parse *parse,
- const char *id)
+struct ec_parse *
+ec_parse_find_next(struct ec_parse *root, struct ec_parse *start,
+ const char *id, bool iter_children)
{
struct ec_parse *iter;
- if (parse == NULL)
+ if (root == NULL)
return NULL;
+ if (start == NULL)
+ start = root;
+ else
+ start = EC_PARSE_ITER_NEXT(root, start, iter_children);
- for (iter = parse; iter != NULL; iter = ec_parse_iter_next(iter)) {
+ for (iter = start; iter != NULL;
+ iter = EC_PARSE_ITER_NEXT(root, iter, 1)) {
if (iter->node != NULL &&
- iter->node->id != NULL &&
- !strcmp(iter->node->id, id))
+ !strcmp(ec_node_id(iter->node), id))
return iter;
}
return NULL;
}
-struct ec_keyval *
+struct ec_parse *ec_parse_find(struct ec_parse *parse,
+ const char *id)
+{
+ return ec_parse_find_next(parse, NULL, id, 1);
+}
+
+struct ec_dict *
ec_parse_get_attrs(struct ec_parse *parse)
{
if (parse == NULL)
testres |= EC_TEST_CHECK(
ec_parse_len(p) == 1, "bad parse len\n");
- ret = ec_keyval_set(ec_parse_get_attrs(p), "key", "val", NULL);
+ ret = ec_dict_set(ec_parse_get_attrs(p), "key", "val", NULL);
testres |= EC_TEST_CHECK(ret == 0,
"cannot set parse attribute\n");
ec_parse_free(p2);
p2 = NULL;
- pc = ec_parse_find_first(p, "id_x");
+ pc = ec_parse_find(p, "id_x");
testres |= EC_TEST_CHECK(pc != NULL, "cannot find id_x");
testres |= EC_TEST_CHECK(pc != NULL &&
ec_parse_get_parent(pc) != NULL &&
ec_parse_get_parent(ec_parse_get_parent(pc)) == p,
"invalid parent\n");
- pc = ec_parse_find_first(p, "id_y");
+ pc = ec_parse_find(p, "id_y");
testres |= EC_TEST_CHECK(pc != NULL, "cannot find id_y");
- pc = ec_parse_find_first(p, "id_dezdezdez");
+ pc = ec_parse_find(p, "id_dezdezdez");
testres |= EC_TEST_CHECK(pc == NULL, "should not find bad id");