if (completed == NULL)
goto fail;
+ completed->attrs = ec_keyval();
+ if (completed->attrs == NULL)
+ goto fail;
+
TAILQ_INIT(&completed->groups);
completed->cur_state = state;
return completed;
fail:
+ if (completed != NULL)
+ ec_keyval_free(completed->attrs);
ec_free(completed);
return NULL;
}
int
-ec_node_complete_child(struct ec_node *node, struct ec_completed *completed,
- const struct ec_strvec *strvec)
+ec_node_complete_child(const struct ec_node *node,
+ struct ec_completed *completed,
+ const struct ec_strvec *strvec)
{
struct ec_parsed *child_state, *cur_state;
struct ec_completed_group *cur_group;
int ret;
- /* build the node if required */
- if (node->type->build != NULL) {
- if ((node->flags & EC_NODE_F_BUILT) == 0) {
- ret = node->type->build(node);
- if (ret < 0)
- return ret;
- }
- }
- node->flags |= EC_NODE_F_BUILT;
-
if (node->type->complete == NULL)
return -ENOTSUP;
/* save previous parse state, prepare child state */
cur_state = completed->cur_state;
- child_state = ec_parsed();
+ child_state = ec_parsed(node);
if (child_state == NULL)
return -ENOMEM;
if (cur_state != NULL)
ec_parsed_add_child(cur_state, child_state);
- ec_parsed_set_node(child_state, node);
completed->cur_state = child_state;
cur_group = completed->cur_group;
completed->cur_group = NULL;
if (ret < 0)
return ret;
-#if 0 // XXX dump
- printf("----------------------------------------------------------\n");
- ec_node_dump(stdout, node);
- ec_strvec_dump(stdout, strvec);
- ec_completed_dump(stdout, completed);
-#endif
-
return 0;
}
-struct ec_completed *ec_node_complete_strvec(struct ec_node *node,
+struct ec_completed *ec_node_complete_strvec(const struct ec_node *node,
const struct ec_strvec *strvec)
{
struct ec_completed *completed = NULL;
return NULL;
}
-struct ec_completed *ec_node_complete(struct ec_node *node,
+struct ec_completed *ec_node_complete(const struct ec_node *node,
const char *str)
{
struct ec_strvec *strvec = NULL;
return item;
fail:
- ec_keyval_free(item->attrs);
+ ec_keyval_free(attrs);
ec_free(comp_cp);
ec_free(start_cp);
ec_free(full_cp);
switch (item->type) {
case EC_COMP_UNKNOWN:
+ completed->count_unknown++;
break;
case EC_COMP_FULL:
+ completed->count_full++;
+ break;
case EC_COMP_PARTIAL:
- completed->count_match++; //XXX
+ completed->count_partial++;
break;
default:
return -EINVAL;
TAILQ_REMOVE(&completed->groups, grp, next);
ec_completed_group_free(grp);
}
+ ec_keyval_free(completed->attrs);
ec_free(completed);
}
return;
}
- fprintf(out, "completion: count=%u match=%u\n",
- completed->count, completed->count_match);
+ fprintf(out, "completion: count=%u full=%u partial=%u unknown=%u\n",
+ completed->count, completed->count_full,
+ completed->count_partial, completed->count_unknown);
TAILQ_FOREACH(grp, &completed->groups, next) {
fprintf(out, "node=%p, node_type=%s\n",
TAILQ_INSERT_TAIL(&to->groups, grp, next);
}
to->count += from->count;
- to->count_match += from->count_match;
+ to->count_full += from->count_full;
+ to->count_partial += from->count_partial;
+ to->count_unknown += from->count_unknown;
ec_completed_free(from);
return 0;
return count;
if (type & EC_COMP_FULL)
- count += completed->count_match;
+ count += completed->count_full;
+ if (type & EC_COMP_PARTIAL)
+ count += completed->count_partial;
if (type & EC_COMP_UNKNOWN)
- count += (completed->count - completed->count_match); //XXX
+ count += completed->count_unknown;
return count;
}
struct ec_completed_item *ec_completed_iter_next(
struct ec_completed_iter *iter)
{
- struct ec_completed *completed = iter->completed;
+ struct ec_completed *completed;
struct ec_completed_group *cur_node;
struct ec_completed_item *cur_match;
+ if (iter == NULL)
+ return NULL;
+ completed = iter->completed;
if (completed == NULL)
return NULL;