#include <ecoli_node.h>
#include <ecoli_parse.h>
#include <ecoli_complete.h>
-#include <ecoli_keyval.h>
+#include <ecoli_dict.h>
#include <ecoli_node_str.h>
#include <ecoli_node_seq.h>
#include <ecoli_node_space.h>
return NULL;
line[rl_point] = '\0';
- c = ec_node_complete(commands, line);
+ c = ec_complete(commands, line);
free(line);
if (c == NULL)
return NULL;
return NULL;
item_str = ec_comp_item_get_str(item);
- if (c->count_full == 1) {
+ if (ec_comp_count(c, EC_COMP_FULL) == 1) {
/* don't add the trailing space for partial completions */
if (state == 0) {
static char *get_node_help(const struct ec_comp_item *item)
{
const struct ec_comp_group *grp;
- const struct ec_parse *state;
+ const struct ec_pnode *pstate;
const struct ec_node *node;
char *help = NULL;
const char *node_help = NULL;
- const char *node_desc = NULL;
+ char *node_desc = NULL;
grp = ec_comp_item_get_grp(item);
- state = grp->state;
- for (state = grp->state; state != NULL;
- state = ec_parse_get_parent(state)) {
- node = ec_parse_get_node(state);
+ for (pstate = ec_comp_group_get_pstate(grp); pstate != NULL;
+ pstate = ec_pnode_get_parent(pstate)) {
+ node = ec_pnode_get_node(pstate);
if (node_help == NULL)
- node_help = ec_keyval_get(ec_node_attrs(node), "help");
+ node_help = ec_dict_get(ec_node_attrs(node), "help");
if (node_desc == NULL)
node_desc = ec_node_desc(node);
}
if (asprintf(&help, "%-20s %s", node_desc, node_help) < 0)
return NULL;
+ ec_free(node_desc);
+
return help;
}
const struct ec_comp_group *grp, *prev_grp = NULL;
const struct ec_comp_item *item;
struct ec_comp *c = NULL;
- struct ec_parse *p = NULL;
+ struct ec_pnode *p = NULL;
char *line = NULL;
- unsigned int count;
+ size_t count;
char **helps = NULL;
int match = 0;
int cols;
goto fail;
/* check if the current line matches */
- p = ec_node_parse(commands, line);
- if (ec_parse_matches(p))
+ p = ec_parse(commands, line);
+ if (ec_pnode_matches(p))
match = 1;
- ec_parse_free(p);
+ ec_pnode_free(p);
p = NULL;
/* complete at current cursor position */
line[rl_point] = '\0';
- c = ec_node_complete(commands, line);
+ c = ec_complete(commands, line);
free(line);
line = NULL;
if (c == NULL)
fail:
ec_comp_iter_free(iter);
- ec_parse_free(p);
+ ec_pnode_free(p);
free(line);
ec_comp_free(c);
if (helps != NULL) {
);
if (cmd == NULL)
goto fail;
- ec_keyval_set(ec_node_attrs(cmd), "help",
+ ec_dict_set(ec_node_attrs(cmd), "help",
"say hello to someone several times", NULL);
- ec_keyval_set(ec_node_attrs(ec_node_find(cmd, "john")),
+ ec_dict_set(ec_node_attrs(ec_node_find(cmd, "john")),
"help", "specific help for john", NULL);
- ec_keyval_set(ec_node_attrs(ec_node_find(cmd, "name")),
+ ec_dict_set(ec_node_attrs(ec_node_find(cmd, "name")),
"help", "the name of the person", NULL);
- ec_keyval_set(ec_node_attrs(ec_node_find(cmd, "int")),
+ ec_dict_set(ec_node_attrs(ec_node_find(cmd, "int")),
"help", "an integer (0-10)", NULL);
if (ec_node_or_add(cmdlist, cmd) < 0)
goto fail;
ec_node_int("count", 0, 10, 10));
if (cmd == NULL)
goto fail;
- ec_keyval_set(ec_node_attrs(cmd), "help",
+ ec_dict_set(ec_node_attrs(cmd), "help",
"say good morning to someone several times", NULL);
- ec_keyval_set(ec_node_attrs(ec_node_find(cmd, "name")), "help",
+ ec_dict_set(ec_node_attrs(ec_node_find(cmd, "name")), "help",
"the person to greet", NULL);
- ec_keyval_set(ec_node_attrs(ec_node_find(cmd, "count")), "help",
+ ec_dict_set(ec_node_attrs(ec_node_find(cmd, "count")), "help",
"how many times to greet (0-10)", NULL);
if (ec_node_or_add(cmdlist, cmd) < 0)
goto fail;
"buy potatoes,carrots,pumpkins");
if (cmd == NULL)
goto fail;
- ec_keyval_set(ec_node_attrs(cmd), "help",
+ ec_dict_set(ec_node_attrs(cmd), "help",
"buy some vegetables", NULL);
if (ec_node_or_add(cmdlist, cmd) < 0)
goto fail;
1, 0));
if (cmd == NULL)
goto fail;
- ec_keyval_set(ec_node_attrs(cmd), "help",
+ ec_dict_set(ec_node_attrs(cmd), "help",
"eat vegetables (take some more potatoes)", NULL);
if (ec_node_or_add(cmdlist, cmd) < 0)
goto fail;
cmd = EC_NODE_SEQ(EC_NO_ID,
ec_node_str(EC_NO_ID, "bye")
);
- ec_keyval_set(ec_node_attrs(cmd), "help", "say bye", NULL);
+ ec_dict_set(ec_node_attrs(cmd), "help", "say bye", NULL);
if (ec_node_or_add(cmdlist, cmd) < 0)
goto fail;
ec_node_str(EC_NO_ID, "load"),
ec_node("file", EC_NO_ID)
);
- ec_keyval_set(ec_node_attrs(cmd), "help", "load a file", NULL);
+ ec_dict_set(ec_node_attrs(cmd), "help", "load a file", NULL);
if (ec_node_or_add(cmdlist, cmd) < 0)
goto fail;
int main(void)
{
- struct ec_parse *p;
+ struct ec_pnode *p;
char *line;
if (ec_init() < 0) {
if (line == NULL)
break;
- p = ec_node_parse(commands, line);
- ec_parse_dump(stdout, p);
+ p = ec_parse(commands, line);
+ ec_pnode_dump(stdout, p);
add_history(line);
- ec_parse_free(p);
+ ec_pnode_free(p);
}