remove node build
[protos/libecoli.git] / lib / ecoli_node_or.c
index dcd811b..ddf8281 100644 (file)
@@ -42,6 +42,8 @@
 #include <ecoli_node_str.h>
 #include <ecoli_test.h>
 
+EC_LOG_TYPE_REGISTER(node_or);
+
 struct ec_node_or {
        struct ec_node gen;
        struct ec_node **table;
@@ -67,30 +69,23 @@ ec_node_or_parse(const struct ec_node *gen_node,
        return EC_PARSED_NOMATCH;
 }
 
-static struct ec_completed *
+static int
 ec_node_or_complete(const struct ec_node *gen_node,
-               struct ec_parsed *state,
+               struct ec_completed *completed,
                const struct ec_strvec *strvec)
 {
        struct ec_node_or *node = (struct ec_node_or *)gen_node;
-       struct ec_completed *completed, *child_completed;
+       int ret;
        size_t n;
 
-       completed = ec_completed();
-       if (completed == NULL)
-               return NULL;
-
        for (n = 0; n < node->len; n++) {
-               child_completed = ec_node_complete_child(node->table[n],
-                       state, strvec);
-
-               if (child_completed == NULL) // XXX fail instead?
-                       continue;
-
-               ec_completed_merge(completed, child_completed);
+               ret = ec_node_complete_child(node->table[n],
+                                       completed, strvec);
+               if (ret < 0)
+                       return ret;
        }
 
-       return completed;
+       return 0;
 }
 
 static size_t ec_node_or_get_max_parse_len(const struct ec_node *gen_node)
@@ -127,8 +122,6 @@ int ec_node_or_add(struct ec_node *gen_node, struct ec_node *child)
        if (child == NULL)
                return -EINVAL;
 
-       gen_node->flags &= ~EC_NODE_F_BUILT;
-
        table = ec_realloc(node->table, (node->len + 1) * sizeof(*node->table));
        if (table == NULL) {
                ec_node_free(child);
@@ -201,12 +194,12 @@ static int ec_node_or_testcase(void)
        struct ec_node *node;
        int ret = 0;
 
-       node = EC_NODE_OR(NULL,
-               ec_node_str(NULL, "foo"),
-               ec_node_str(NULL, "bar")
+       node = EC_NODE_OR(EC_NO_ID,
+               ec_node_str(EC_NO_ID, "foo"),
+               ec_node_str(EC_NO_ID, "bar")
        );
        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, 1, "foo");
@@ -219,45 +212,38 @@ static int ec_node_or_testcase(void)
        ec_node_free(node);
 
        /* test completion */
-       node = EC_NODE_OR(NULL,
-               ec_node_str(NULL, "foo"),
-               ec_node_str(NULL, "bar"),
-               ec_node_str(NULL, "bar2"),
-               ec_node_str(NULL, "toto"),
-               ec_node_str(NULL, "titi")
+       node = EC_NODE_OR(EC_NO_ID,
+               ec_node_str(EC_NO_ID, "foo"),
+               ec_node_str(EC_NO_ID, "bar"),
+               ec_node_str(EC_NO_ID, "bar2"),
+               ec_node_str(EC_NO_ID, "toto"),
+               ec_node_str(EC_NO_ID, "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);
        ret |= EC_TEST_CHECK_COMPLETE(node,
                "b", EC_NODE_ENDLIST,
-               "ar", "ar2", EC_NODE_ENDLIST,
-               "ar");
+               "bar", "bar2", EC_NODE_ENDLIST);
        ret |= EC_TEST_CHECK_COMPLETE(node,
                "bar", EC_NODE_ENDLIST,
-               "", "2", EC_NODE_ENDLIST,
-               "");
+               "bar", "bar2", EC_NODE_ENDLIST);
        ret |= EC_TEST_CHECK_COMPLETE(node,
                "t", EC_NODE_ENDLIST,
-               "oto", "iti", EC_NODE_ENDLIST,
-               "");
+               "toto", "titi", EC_NODE_ENDLIST);
        ret |= EC_TEST_CHECK_COMPLETE(node,
                "to", EC_NODE_ENDLIST,
-               "to", EC_NODE_ENDLIST,
-               "to");
+               "toto", EC_NODE_ENDLIST);
        ret |= EC_TEST_CHECK_COMPLETE(node,
                "x", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST,
-               "");
+               EC_NODE_ENDLIST);
        ec_node_free(node);
 
        return ret;