* updated accordingly. */
static int
__ec_node_subset_parse(struct parse_result *out, struct ec_node **table,
- size_t table_len, struct ec_parse *state,
+ size_t table_len, struct ec_pnode *pstate,
const struct ec_strvec *strvec)
{
struct ec_node **child_table;
struct ec_strvec *childvec = NULL;
size_t i, j, len = 0;
struct parse_result best_result, result;
- struct ec_parse *best_parse = NULL;
+ struct ec_pnode *best_parse = NULL;
int ret;
if (table_len == 0)
for (i = 0; i < table_len; i++) {
/* try to parse elt i */
- ret = ec_node_parse_child(table[i], state, strvec);
+ ret = ec_parse_child(table[i], pstate, strvec);
if (ret < 0)
goto fail;
memset(&result, 0, sizeof(result));
ret = __ec_node_subset_parse(&result, child_table,
- table_len - 1, state, childvec);
+ table_len - 1, pstate, childvec);
ec_strvec_free(childvec);
childvec = NULL;
if (ret < 0)
/* if result is not the best, ignore */
if (result.parse_len < best_result.parse_len) {
memset(&result, 0, sizeof(result));
- ec_parse_del_last_child(state);
+ ec_pnode_del_last_child(pstate);
continue;
}
/* replace the previous best result */
- ec_parse_free(best_parse);
- best_parse = ec_parse_get_last_child(state);
- ec_parse_unlink_child(state, best_parse);
+ ec_pnode_free(best_parse);
+ best_parse = ec_pnode_get_last_child(pstate);
+ ec_pnode_unlink_child(best_parse);
best_result.parse_len = result.parse_len + 1;
best_result.len = len + result.len;
*out = best_result;
ec_free(child_table);
if (best_parse != NULL)
- ec_parse_link_child(state, best_parse);
+ ec_pnode_link_child(pstate, best_parse);
return 0;
fail:
- ec_parse_free(best_parse);
+ ec_pnode_free(best_parse);
ec_strvec_free(childvec);
ec_free(child_table);
return -1;
static int
ec_node_subset_parse(const struct ec_node *node,
- struct ec_parse *state,
+ struct ec_pnode *pstate,
const struct ec_strvec *strvec)
{
struct ec_node_subset *priv = ec_node_priv(node);
- struct ec_parse *parse = NULL;
+ struct ec_pnode *parse = NULL;
struct parse_result result;
int ret;
memset(&result, 0, sizeof(result));
ret = __ec_node_subset_parse(&result, priv->table,
- priv->len, state, strvec);
+ priv->len, pstate, strvec);
if (ret < 0)
goto fail;
return result.len;
fail:
- ec_parse_free(parse);
+ ec_pnode_free(parse);
return ret;
}
struct ec_comp *comp,
const struct ec_strvec *strvec)
{
- struct ec_parse *parse = ec_comp_get_state(comp);
+ struct ec_pnode *parse = ec_comp_get_cur_pstate(comp);
struct ec_strvec *childvec = NULL;
struct ec_node *save;
size_t i, len;
if (table[i] == NULL)
continue;
- ret = ec_node_complete_child(table[i],
+ ret = ec_complete_child(table[i],
comp, strvec);
if (ret < 0)
goto fail;
if (table[i] == NULL)
continue;
- ret = ec_node_parse_child(table[i], parse, strvec);
+ ret = ec_parse_child(table[i], parse, strvec);
if (ret < 0)
goto fail;
childvec = ec_strvec_ndup(strvec, len,
ec_strvec_len(strvec) - len);
if (childvec == NULL) {
- ec_parse_del_last_child(parse);
+ ec_pnode_del_last_child(parse);
goto fail;
}
table[i] = save;
ec_strvec_free(childvec);
childvec = NULL;
- ec_parse_del_last_child(parse);
+ ec_pnode_del_last_child(parse);
if (ret < 0)
goto fail;
fail = 1;;
for (child = va_arg(ap, struct ec_node *);
- child != EC_NODE_ENDLIST;
+ child != EC_VA_END;
child = va_arg(ap, struct ec_node *)) {
/* on error, don't quit the loop to avoid leaks */
return -1;
}
testres |= EC_TEST_CHECK_COMPLETE(node,
- "", EC_NODE_ENDLIST,
- "foo", "bar", "bar2", "toto", "titi", EC_NODE_ENDLIST);
+ "", EC_VA_END,
+ "foo", "bar", "bar2", "toto", "titi", EC_VA_END);
testres |= EC_TEST_CHECK_COMPLETE(node,
- "", EC_NODE_ENDLIST,
- "bar2", "bar", "foo", "toto", "titi", EC_NODE_ENDLIST);
+ "", EC_VA_END,
+ "bar2", "bar", "foo", "toto", "titi", EC_VA_END);
testres |= EC_TEST_CHECK_COMPLETE(node,
- "bar", "bar2", "", EC_NODE_ENDLIST,
- "foo", "toto", "titi", EC_NODE_ENDLIST);
+ "bar", "bar2", "", EC_VA_END,
+ "foo", "toto", "titi", EC_VA_END);
testres |= EC_TEST_CHECK_COMPLETE(node,
- "f", EC_NODE_ENDLIST,
- "foo", EC_NODE_ENDLIST);
+ "f", EC_VA_END,
+ "foo", EC_VA_END);
testres |= EC_TEST_CHECK_COMPLETE(node,
- "b", EC_NODE_ENDLIST,
- "bar", "bar2", EC_NODE_ENDLIST);
+ "b", EC_VA_END,
+ "bar", "bar2", EC_VA_END);
testres |= EC_TEST_CHECK_COMPLETE(node,
- "bar", EC_NODE_ENDLIST,
- "bar", "bar2", EC_NODE_ENDLIST);
+ "bar", EC_VA_END,
+ "bar", "bar2", EC_VA_END);
testres |= EC_TEST_CHECK_COMPLETE(node,
- "bar", "b", EC_NODE_ENDLIST,
- "bar2", EC_NODE_ENDLIST);
+ "bar", "b", EC_VA_END,
+ "bar2", EC_VA_END);
testres |= EC_TEST_CHECK_COMPLETE(node,
- "t", EC_NODE_ENDLIST,
- "toto", "titi", EC_NODE_ENDLIST);
+ "t", EC_VA_END,
+ "toto", "titi", EC_VA_END);
testres |= EC_TEST_CHECK_COMPLETE(node,
- "to", EC_NODE_ENDLIST,
- "toto", EC_NODE_ENDLIST);
+ "to", EC_VA_END,
+ "toto", EC_VA_END);
testres |= EC_TEST_CHECK_COMPLETE(node,
- "x", EC_NODE_ENDLIST,
- EC_NODE_ENDLIST);
+ "x", EC_VA_END,
+ EC_VA_END);
ec_node_free(node);
return testres;