X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Freadline%2Fmain.c;h=a64d068b0048296e5c3cb4ad47156dfb5ba97b87;hb=331d87b8f34493ea7eb4db75fa9d90b2e3ed503b;hp=2c81c53c0f69e76d413910bdc1ede305077844cd;hpb=90efcb0b905753a2eac864bc1a869781d7c31919;p=protos%2Flibecoli.git diff --git a/examples/readline/main.c b/examples/readline/main.c index 2c81c53..a64d068 100644 --- a/examples/readline/main.c +++ b/examples/readline/main.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -54,7 +54,7 @@ static char *my_completion_entry(const char *s, int state) return NULL; line[rl_point] = '\0'; - c = ec_node_complete(commands, line); + c = ec_complete(commands, line); free(line); if (c == NULL) return NULL; @@ -70,7 +70,7 @@ static char *my_completion_entry(const char *s, int state) 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) { @@ -106,19 +106,18 @@ static char **my_attempted_completion(const char *text, int start, int end) 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); } @@ -131,6 +130,8 @@ static char *get_node_help(const struct ec_comp_item *item) if (asprintf(&help, "%-20s %s", node_desc, node_help) < 0) return NULL; + ec_free(node_desc); + return help; } @@ -140,9 +141,9 @@ static int show_help(int ignore, int invoking_key) 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; @@ -155,15 +156,15 @@ static int show_help(int ignore, int invoking_key) 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) @@ -212,7 +213,7 @@ static int show_help(int ignore, int invoking_key) fail: ec_comp_iter_free(iter); - ec_parse_free(p); + ec_pnode_free(p); free(line); ec_comp_free(c); if (helps != NULL) { @@ -244,13 +245,13 @@ static int create_commands(void) ); 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; @@ -261,11 +262,11 @@ static int create_commands(void) 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; @@ -275,7 +276,7 @@ static int create_commands(void) "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; @@ -292,7 +293,7 @@ static int create_commands(void) 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; @@ -301,7 +302,7 @@ static int create_commands(void) 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; @@ -310,7 +311,7 @@ static int create_commands(void) 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; @@ -329,7 +330,7 @@ static int create_commands(void) int main(void) { - struct ec_parse *p; + struct ec_pnode *p; char *line; if (ec_init() < 0) { @@ -348,10 +349,10 @@ int main(void) 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); }