{
size_t i = 0;
- /* skip spaces */
- while (!isblank(str[i]) && str[i] != '\0')
+ /* eat chars until we find a quote, space, or end of string */
+ while (!isblank(str[i]) && str[i] != '\0' &&
+ str[i] != '"' && str[i] != '\'')
i++;
return i;
return ret;
}
-static struct ec_completed *ec_node_sh_lex_complete(const struct ec_node *gen_node,
- const struct ec_strvec *strvec)
+static int
+ec_node_sh_lex_complete(const struct ec_node *gen_node,
+ struct ec_completed *completed,
+ struct ec_parsed *parsed,
+ const struct ec_strvec *strvec)
{
struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
- struct ec_completed *completed, *child_completed = NULL;
struct ec_strvec *new_vec = NULL;
const char *str;
char missing_quote;
-
-// printf("==================\n");
- completed = ec_completed();
- if (completed == NULL)
- return NULL;
+ int ret;
if (ec_strvec_len(strvec) != 1)
- return completed;
+ return 0;
str = ec_strvec_val(strvec, 0);
+// printf("\nold:%s\n", str);
new_vec = tokenize(str, 1, 1, &missing_quote);
if (new_vec == NULL)
goto fail;
+// printf("new:%s\n", ec_strvec_val(new_vec, 0));
-// ec_strvec_dump(new_vec, stdout);
-
- child_completed = ec_node_complete_strvec(node->child, new_vec);
- if (child_completed == NULL)
+ // XXX: complete should add the quotes for !EC_PARTIAL: use another
+ // completed object
+ ret = ec_node_complete_child(node->child, completed, parsed, new_vec);
+ if (ret < 0)
goto fail;
ec_strvec_free(new_vec);
- new_vec = NULL;
- ec_completed_merge(completed, child_completed);
- return completed;
+ return 0;
fail:
ec_strvec_free(new_vec);
- ec_completed_free(completed);
- return NULL;
+ return -1;
}
static void ec_node_sh_lex_free_priv(struct ec_node *gen_node)
return &node->gen;
}
+/* LCOV_EXCL_START */
static int ec_node_sh_lex_testcase(void)
{
struct ec_node *node;
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'");
ec_node_free(node);
/* test completion */
}
ret |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
- "foo", EC_NODE_ENDLIST,
- "foo");
+ "foo", EC_NODE_ENDLIST);
ret |= EC_TEST_CHECK_COMPLETE(node,
" ", EC_NODE_ENDLIST,
- "foo", EC_NODE_ENDLIST,
- "foo");
+ "foo", 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,
"foo", EC_NODE_ENDLIST,
- "", EC_NODE_ENDLIST,
- "");
+ "foo", EC_NODE_ENDLIST);
ret |= EC_TEST_CHECK_COMPLETE(node,
"foo ", EC_NODE_ENDLIST,
- "bar", "toto", EC_NODE_ENDLIST,
- "");
+ "bar", "toto", EC_NODE_ENDLIST);
ret |= EC_TEST_CHECK_COMPLETE(node,
"foo t", EC_NODE_ENDLIST,
- "oto", EC_NODE_ENDLIST,
- "oto");
+ "toto", EC_NODE_ENDLIST);
ret |= EC_TEST_CHECK_COMPLETE(node,
"foo b", EC_NODE_ENDLIST,
- "ar", EC_NODE_ENDLIST,
- "ar");
+ "bar", EC_NODE_ENDLIST);
ret |= EC_TEST_CHECK_COMPLETE(node,
"foo bar", EC_NODE_ENDLIST,
- "", EC_NODE_ENDLIST,
- "");
+ "bar", EC_NODE_ENDLIST);
ret |= EC_TEST_CHECK_COMPLETE(node,
"foo bar ", EC_NODE_ENDLIST,
- "titi", EC_NODE_ENDLIST,
- "titi");
+ "titi", EC_NODE_ENDLIST);
ret |= EC_TEST_CHECK_COMPLETE(node,
"foo toto bar ", EC_NODE_ENDLIST,
- "titi", EC_NODE_ENDLIST,
- "titi");
+ "titi", EC_NODE_ENDLIST);
ret |= EC_TEST_CHECK_COMPLETE(node,
"x", EC_NODE_ENDLIST,
- EC_NODE_ENDLIST,
- "");
+ EC_NODE_ENDLIST);
ret |= EC_TEST_CHECK_COMPLETE(node,
"foo barx", EC_NODE_ENDLIST,
- EC_NODE_ENDLIST,
- "");
+ EC_NODE_ENDLIST);
ec_node_free(node);
return ret;
}
+/* LCOV_EXCL_STOP */
static struct ec_test ec_node_sh_lex_test = {
.name = "node_sh_lex",