check for double test registration
[protos/libecoli.git] / lib / ecoli_node_sh_lex.c
index b51069a..f3dce9e 100644 (file)
@@ -25,7 +25,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#define _GNU_SOURCE /* for asprintf */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -36,6 +35,7 @@
 
 #include <ecoli_malloc.h>
 #include <ecoli_log.h>
+#include <ecoli_string.h>
 #include <ecoli_test.h>
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
@@ -253,7 +253,10 @@ ec_node_sh_lex_parse(const struct ec_node *gen_node,
                new_vec = tokenize(str, 0, 0, NULL);
        }
        if (new_vec == NULL) {
-               ret = -ENOMEM;
+               if (errno == EINVAL)
+                       ret = EC_PARSED_NOMATCH;
+               else
+                       ret = -ENOMEM;
                goto fail;
        }
 
@@ -320,25 +323,25 @@ ec_node_sh_lex_complete(const struct ec_node *gen_node,
                        goto fail;
                while ((item = ec_completed_iter_next(iter)) != NULL) {
                        str = ec_completed_item_get_str(item);
-                       if (asprintf(&new_str, "%c%s%c", missing_quote, str,
+                       if (ec_asprintf(&new_str, "%c%s%c", missing_quote, str,
                                        missing_quote) < 0) {
                                new_str = NULL;
                                goto fail;
                        }
                        if (ec_completed_item_set_str(item, new_str) < 0)
                                goto fail;
-                       free(new_str);
+                       ec_free(new_str);
                        new_str = NULL;
 
                        str = ec_completed_item_get_completion(item);
-                       if (asprintf(&new_str, "%s%c", str,
+                       if (ec_asprintf(&new_str, "%s%c", str,
                                        missing_quote) < 0) {
                                new_str = NULL;
                                goto fail;
                        }
                        if (ec_completed_item_set_completion(item, new_str) < 0)
                                goto fail;
-                       free(new_str);
+                       ec_free(new_str);
                        new_str = NULL;
                }
        }
@@ -354,7 +357,7 @@ ec_node_sh_lex_complete(const struct ec_node *gen_node,
        ec_completed_free(tmp_completed);
        ec_completed_iter_free(iter);
        ec_strvec_free(new_vec);
-       free(new_str);
+       ec_free(new_str);
 
        return -1;
 }
@@ -398,7 +401,7 @@ struct ec_node *ec_node_sh_lex(const char *id, struct ec_node *child)
 static int ec_node_sh_lex_testcase(void)
 {
        struct ec_node *node;
-       int ret = 0;
+       int testres = 0;
 
        node = ec_node_sh_lex(EC_NO_ID,
                EC_NODE_SEQ(EC_NO_ID,
@@ -413,11 +416,11 @@ static int ec_node_sh_lex_testcase(void)
                EC_LOG(EC_LOG_ERR, "cannot create node\n");
                return -1;
        }
-       ret |= EC_TEST_CHECK_PARSE(node, 1, "foo bar");
-       ret |= EC_TEST_CHECK_PARSE(node, 1, "  foo   bar");
-       ret |= EC_TEST_CHECK_PARSE(node, 1, "  'foo' \"bar\"");
-       ret |= EC_TEST_CHECK_PARSE(node, 1, "  'f'oo 'toto' bar");
-       ret |= EC_TEST_CHECK_PARSE(node, -1, "  foo toto bar'");
+       testres |= EC_TEST_CHECK_PARSE(node, 1, "foo bar");
+       testres |= EC_TEST_CHECK_PARSE(node, 1, "  foo   bar");
+       testres |= EC_TEST_CHECK_PARSE(node, 1, "  'foo' \"bar\"");
+       testres |= EC_TEST_CHECK_PARSE(node, 1, "  'f'oo 'toto' bar");
+       testres |= EC_TEST_CHECK_PARSE(node, -1, "  foo toto bar'");
        ec_node_free(node);
 
        /* test completion */
@@ -435,48 +438,48 @@ static int ec_node_sh_lex_testcase(void)
                EC_LOG(EC_LOG_ERR, "cannot create node\n");
                return -1;
        }
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "", EC_NODE_ENDLIST,
                "foo", EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                " ", EC_NODE_ENDLIST,
                "foo", EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "f", EC_NODE_ENDLIST,
                "foo", EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "foo", EC_NODE_ENDLIST,
                "foo", EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "foo ", EC_NODE_ENDLIST,
                "bar", "toto", EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "foo t", EC_NODE_ENDLIST,
                "toto", EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "foo b", EC_NODE_ENDLIST,
                "bar", EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "foo bar", EC_NODE_ENDLIST,
                "bar", EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "foo bar ", EC_NODE_ENDLIST,
                "titi", EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "foo toto bar ", EC_NODE_ENDLIST,
                "titi", EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "x", EC_NODE_ENDLIST,
                EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "foo barx", EC_NODE_ENDLIST,
                EC_NODE_ENDLIST);
-       ret |= EC_TEST_CHECK_COMPLETE(node,
+       testres |= EC_TEST_CHECK_COMPLETE(node,
                "foo 'b", EC_NODE_ENDLIST,
                "'bar'", EC_NODE_ENDLIST);
 
        ec_node_free(node);
-       return ret;
+       return testres;
 }
 /* LCOV_EXCL_STOP */