return -ENOMEM;
}
- //printf("eval var %s %p\n", str, eval);
+ //printf("eval var %s %p\n", str, eval); //XXX
*result = eval;
return 0;
/* get parsed string vector, it should contain only one str */
vec = ec_parsed_strvec(operator);
- if (ec_strvec_len(vec) != 1)
+ if (ec_strvec_len(vec) > 1)
return -EINVAL;
- if (!strcmp(ec_strvec_val(vec, 0), "|")) {
+ if (ec_strvec_len(vec) == 0) {
+ out = EC_NODE_SEQ(EC_NO_ID, ec_node_clone(in1), ec_node_clone(in2));
+ if (out == NULL)
+ return -EINVAL;
+ ec_node_free(in1);
+ ec_node_free(in2);
+ *result = out;
+ } else if (!strcmp(ec_strvec_val(vec, 0), "|")) {
out = EC_NODE_OR(EC_NO_ID, ec_node_clone(in1), ec_node_clone(in2));
if (out == NULL)
return -EINVAL;
static int ec_node_cmd_build(struct ec_node_cmd *node)
{
struct ec_node *expr = NULL, *lex = NULL, *cmd = NULL;
- struct ec_parsed *p = NULL, *child;
+ struct ec_parsed *p = NULL;
void *result;
int ret;
if (ret < 0)
goto fail;
ret = ec_node_expr_add_bin_op(expr, ec_node_str(EC_NO_ID, "|"));
+ if (ret < 0)
+ goto fail;
+ ret = ec_node_expr_add_bin_op(expr, ec_node("empty", EC_NO_ID));
if (ret < 0)
goto fail;
ret = ec_node_expr_add_post_op(expr, ec_node_str(EC_NO_ID, "+"));
if (ret < 0)
goto fail;
- /* prepend a lexer and a "many" to the expression node */
+ /* prepend a lexer to the expression node */
ret = -ENOMEM;
- lex = ec_node_re_lex(EC_NO_ID,
- ec_node_many(EC_NO_ID, ec_node_clone(expr), 1, 0));
+ lex = ec_node_re_lex(EC_NO_ID, ec_node_clone(expr));
if (lex == NULL)
goto fail;
goto fail;
if (!ec_parsed_has_child(p))
goto fail;
- if (!ec_parsed_has_child(ec_parsed_get_first_child(p)))
- goto fail;
- ret = -ENOMEM;
- cmd = ec_node("seq", EC_NO_ID);
- if (cmd == NULL)
+ ret = ec_node_expr_eval(&result, expr, ec_parsed_get_first_child(p),
+ &test_ops, node);
+ if (ret < 0)
goto fail;
- EC_PARSED_FOREACH_CHILD(child, ec_parsed_get_first_child(p)) {
- ret = ec_node_expr_eval(&result, expr, child,
- &test_ops, node);
- if (ret < 0)
- goto fail;
- ret = ec_node_seq_add(cmd, result);
- if (ret < 0)
- goto fail;
- }
ec_parsed_free(p);
p = NULL;
node->expr = expr;
node->lex = lex;
- node->cmd = cmd;
+ node->cmd = result;
return 0;
ec_node_free(node);
+ node = EC_NODE_CMD(EC_NO_ID, "[foo [bar]]");
+ if (node == NULL) {
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
+ return -1;
+ }
+ ret |= EC_TEST_CHECK_PARSE(node, 0);
+ ret |= EC_TEST_CHECK_PARSE(node, 1, "foo");
+ ret |= EC_TEST_CHECK_PARSE(node, 2, "foo", "bar");
+ ret |= EC_TEST_CHECK_PARSE(node, 0, "x");
+ ec_node_free(node);
+
return ret;
}
/* LCOV_EXCL_STOP */
size_t new_size = size + sizeof(*hdr) + sizeof(*ftr);
void *ret;
int r = random();
+ static int seq;
if (alloc_fail_proba != 0 && (r % 100) < alloc_fail_proba)
hdr = NULL;
ftr->cookie = 0x87654321;
}
- EC_LOG(EC_LOG_DEBUG, "%s:%d: info: malloc(%zd) -> %p [rand=%d]\n",
- file, line, size, ret, r);
- if (r == 976499400)
+ EC_LOG(EC_LOG_DEBUG, "%s:%d: info: malloc(%zd) -> %p seq=%d\n",
+ file, line, size, ret, seq++);
+ if (seq == 100)
printf("here\n");
if (ret)