#include <ecoli_node_many.h>
#include <ecoli_node_once.h>
+EC_LOG_TYPE_REGISTER(node_once);
+
struct ec_node_once {
struct ec_node gen;
struct ec_node *child;
if (parsed == NULL)
return 0;
- if (parsed->node == node)
+ if (ec_parsed_get_node(parsed) == node)
count++;
- TAILQ_FOREACH(child, &parsed->children, next)
+ EC_PARSED_FOREACH_CHILD(child, parsed)
count += count_node(child, node);
return count;
return ec_node_parse_child(node->child, state, strvec);
}
-static struct ec_completed *
+static int
ec_node_once_complete(const struct ec_node *gen_node,
- struct ec_parsed *state,
+ struct ec_completed *completed,
const struct ec_strvec *strvec)
{
struct ec_node_once *node = (struct ec_node_once *)gen_node;
- struct ec_completed *completed = NULL, *child_completed = NULL;
+ struct ec_parsed *parsed = ec_completed_cur_parse_state(completed);
unsigned int count;
-
- completed = ec_completed();
- if (completed == NULL)
- goto fail;
+ int ret;
/* count the number of occurences of the node: if already parsed,
* do not match
*/
- count = count_node(ec_parsed_get_root(state), node->child); //XXX
+ count = count_node(ec_parsed_get_root(parsed), node->child); //XXX
if (count > 0)
- return completed;
-
- child_completed = ec_node_complete_child(node->child, state, strvec);
- if (child_completed == NULL)
- goto fail;
+ return 0;
- ec_completed_merge(completed, child_completed);
- return completed;
+ ret = ec_node_complete_child(node->child, completed, strvec);
+ if (ret < 0)
+ return ret;
-fail:
- ec_completed_free(completed);
- return NULL;
+ return 0;
}
static void ec_node_once_free_priv(struct ec_node *gen_node)
return gen_node;
}
+/* LCOV_EXCL_START */
static int ec_node_once_testcase(void)
{
struct ec_node *node;
), 0, 0
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_PARSE(node, 0);
ec_node_str(NULL, "titi")
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
- "foo", "bar", "bar2", "toto", "titi", EC_NODE_ENDLIST,
- "");
+ "foo", "bar", "bar2", "toto", "titi", EC_NODE_ENDLIST);
ret |= EC_TEST_CHECK_COMPLETE(node,
"f", EC_NODE_ENDLIST,
- "oo", EC_NODE_ENDLIST,
- "oo");
+ "foo", EC_NODE_ENDLIST);
ec_node_free(node);
#endif
return ret;
}
+/* LCOV_EXCL_STOP */
static struct ec_test ec_node_once_test = {
.name = "node_once",