git.droids-corp.org
/
protos
/
libecoli.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
api doc and minor changes
[protos/libecoli.git]
/
src
/
ecoli_editline.c
diff --git
a/src/ecoli_editline.c
b/src/ecoli_editline.c
index
2610bf5
..
e3e53cf
100644
(file)
--- a/
src/ecoli_editline.c
+++ b/
src/ecoli_editline.c
@@
-311,16
+311,11
@@
void ec_editline_free_completions(char **matches, size_t len)
ssize_t
ec_editline_get_completions(const struct ec_comp *cmpl, char ***matches_out)
{
ssize_t
ec_editline_get_completions(const struct ec_comp *cmpl, char ***matches_out)
{
- const struct ec_comp_item *item;
- struct ec_comp_iter *iter = NULL;
+ struct ec_comp_item *item;
char **matches = NULL;
size_t count = 0;
char **matches = NULL;
size_t count = 0;
- iter = ec_comp_iter(cmpl, EC_COMP_FULL | EC_COMP_PARTIAL);
- if (iter == NULL)
- goto fail;
-
- while ((item = ec_comp_iter_next(iter)) != NULL) {
+ EC_COMP_FOREACH(item, cmpl, EC_COMP_FULL | EC_COMP_PARTIAL) {
char **tmp;
tmp = realloc(matches, (count + 1) * sizeof(char *));
char **tmp;
tmp = realloc(matches, (count + 1) * sizeof(char *));
@@
-339,24
+334,18
@@
ec_editline_get_completions(const struct ec_comp *cmpl, char ***matches_out)
fail:
ec_editline_free_completions(matches, count);
*matches_out = NULL;
fail:
ec_editline_free_completions(matches, count);
*matches_out = NULL;
- ec_comp_iter_free(iter);
return -1;
}
char *
ec_editline_append_chars(const struct ec_comp *cmpl)
{
return -1;
}
char *
ec_editline_append_chars(const struct ec_comp *cmpl)
{
- const struct ec_comp_item *item;
- struct ec_comp_iter *iter = NULL;
+ struct ec_comp_item *item;
const char *append;
char *ret = NULL;
size_t n;
const char *append;
char *ret = NULL;
size_t n;
- iter = ec_comp_iter(cmpl, EC_COMP_FULL | EC_COMP_PARTIAL);
- if (iter == NULL)
- goto fail;
-
- while ((item = ec_comp_iter_next(iter)) != NULL) {
+ EC_COMP_FOREACH(item, cmpl, EC_COMP_FULL | EC_COMP_PARTIAL) {
append = ec_comp_item_get_completion(item);
if (ret == NULL) {
ret = ec_strdup(append);
append = ec_comp_item_get_completion(item);
if (ret == NULL) {
ret = ec_strdup(append);
@@
-367,12
+356,10
@@
ec_editline_append_chars(const struct ec_comp *cmpl)
ret[n] = '\0';
}
}
ret[n] = '\0';
}
}
- ec_comp_iter_free(iter);
return ret;
fail:
return ret;
fail:
- ec_comp_iter_free(iter);
ec_free(ret);
return NULL;
ec_free(ret);
return NULL;
@@
-383,34
+370,34
@@
static int get_node_help(const struct ec_comp_item *item,
struct ec_editline_help *help)
{
const struct ec_comp_group *grp;
struct ec_editline_help *help)
{
const struct ec_comp_group *grp;
- const struct ec_p
arse *
state;
+ const struct ec_p
node *p
state;
const struct ec_node *node;
const char *node_help = NULL;
const struct ec_node *node;
const char *node_help = NULL;
- c
onst c
har *node_desc = NULL;
+ char *node_desc = NULL;
help->desc = NULL;
help->help = NULL;
grp = ec_comp_item_get_grp(item);
help->desc = NULL;
help->help = NULL;
grp = ec_comp_item_get_grp(item);
- for (
state = ec_comp_group_get_state(grp);
state != NULL;
-
state = ec_parse_get_parent(
state)) {
- node = ec_p
arse_get_node(
state);
+ for (
pstate = ec_comp_group_get_pstate(grp); p
state != NULL;
+
pstate = ec_pnode_get_parent(p
state)) {
+ node = ec_p
node_get_node(p
state);
if (node_help == NULL)
node_help = ec_dict_get(ec_node_attrs(node), "help");
if (node_help == NULL)
node_help = ec_dict_get(ec_node_attrs(node), "help");
- if (node_desc == NULL)
+ if (node_desc == NULL)
{
node_desc = ec_node_desc(node);
node_desc = ec_node_desc(node);
+ if (node_desc == NULL)
+ goto fail;
+ }
}
}
- if (node_help == NULL)
- node_help = "";
if (node_desc == NULL)
goto fail;
if (node_desc == NULL)
goto fail;
+ if (node_help == NULL)
+ node_help = "";
- help->desc = ec_strdup(node_desc);
- if (help->desc == NULL)
- goto fail;
-
+ help->desc = node_desc;
help->help = ec_strdup(node_help);
if (help->help == NULL)
goto fail;
help->help = ec_strdup(node_help);
if (help->help == NULL)
goto fail;
@@
-418,6
+405,7
@@
static int get_node_help(const struct ec_comp_item *item,
return 0;
fail:
return 0;
fail:
+ ec_free(node_desc);
ec_free(help->desc);
ec_free(help->help);
return -1;
ec_free(help->desc);
ec_free(help->help);
return -1;
@@
-427,34
+415,27
@@
ssize_t
ec_editline_get_helps(const struct ec_editline *editline, const char *line,
const char *full_line, struct ec_editline_help **helps_out)
{
ec_editline_get_helps(const struct ec_editline *editline, const char *line,
const char *full_line, struct ec_editline_help **helps_out)
{
- struct ec_comp_iter *iter = NULL;
const struct ec_comp_group *grp, *prev_grp = NULL;
const struct ec_comp_group *grp, *prev_grp = NULL;
-
const
struct ec_comp_item *item;
+ struct ec_comp_item *item;
struct ec_comp *cmpl = NULL;
struct ec_comp *cmpl = NULL;
- struct ec_p
ars
e *parse = NULL;
+ struct ec_p
nod
e *parse = NULL;
unsigned int count = 0;
struct ec_editline_help *helps = NULL;
*helps_out = NULL;
/* check if the current line matches */
unsigned int count = 0;
struct ec_editline_help *helps = NULL;
*helps_out = NULL;
/* check if the current line matches */
- parse = ec_
node_
parse(editline->node, full_line);
- if (ec_p
ars
e_matches(parse))
+ parse = ec_parse(editline->node, full_line);
+ if (ec_p
nod
e_matches(parse))
count = 1;
count = 1;
- ec_p
ars
e_free(parse);
+ ec_p
nod
e_free(parse);
parse = NULL;
/* complete at current cursor position */
parse = NULL;
/* complete at current cursor position */
- cmpl = ec_
node_
complete(editline->node, line);
+ cmpl = ec_complete(editline->node, line);
if (cmpl == NULL) //XXX log error
goto fail;
if (cmpl == NULL) //XXX log error
goto fail;
- /* let's display one contextual help per node */
- iter = ec_comp_iter(cmpl,
- EC_COMP_UNKNOWN | EC_COMP_FULL | EC_COMP_PARTIAL);
- if (iter == NULL)
- goto fail;
-
helps = ec_calloc(1, sizeof(*helps));
if (helps == NULL)
goto fail;
helps = ec_calloc(1, sizeof(*helps));
if (helps == NULL)
goto fail;
@@
-467,7
+448,9
@@
ec_editline_get_helps(const struct ec_editline *editline, const char *line,
goto fail;
}
goto fail;
}
- while ((item = ec_comp_iter_next(iter)) != NULL) {
+ /* let's display one contextual help per node */
+ EC_COMP_FOREACH(item, cmpl,
+ EC_COMP_UNKNOWN | EC_COMP_FULL | EC_COMP_PARTIAL) {
struct ec_editline_help *tmp = NULL;
/* keep one help per group, skip other items */
struct ec_editline_help *tmp = NULL;
/* keep one help per group, skip other items */
@@
-486,15
+469,13
@@
ec_editline_get_helps(const struct ec_editline *editline, const char *line,
count++;
}
count++;
}
- ec_comp_iter_free(iter);
ec_comp_free(cmpl);
*helps_out = helps;
return count;
fail:
ec_comp_free(cmpl);
*helps_out = helps;
return count;
fail:
- ec_comp_iter_free(iter);
- ec_parse_free(parse);
+ ec_pnode_free(parse);
ec_comp_free(cmpl);
if (helps != NULL) {
while (count--) {
ec_comp_free(cmpl);
if (helps != NULL) {
while (count--) {
@@
-551,7
+532,7
@@
ec_editline_complete(EditLine *el, int c)
goto fail;
}
goto fail;
}
- cmpl = ec_
node_
complete(editline->node, line);
+ cmpl = ec_complete(editline->node, line);
if (cmpl == NULL)
goto fail;
if (cmpl == NULL)
goto fail;
@@
-653,11
+634,11
@@
fail:
return NULL;
}
return NULL;
}
-struct ec_p
ars
e *
+struct ec_p
nod
e *
ec_editline_parse(struct ec_editline *editline, const struct ec_node *node)
{
char *line = NULL;
ec_editline_parse(struct ec_editline *editline, const struct ec_node *node)
{
char *line = NULL;
- struct ec_p
ars
e *parse = NULL;
+ struct ec_p
nod
e *parse = NULL;
/* XXX add sh_lex automatically? This node is required, parse and
* complete are based on it. */
/* XXX add sh_lex automatically? This node is required, parse and
* complete are based on it. */
@@
-668,7
+649,7
@@
ec_editline_parse(struct ec_editline *editline, const struct ec_node *node)
if (line == NULL)
goto fail;
if (line == NULL)
goto fail;
- parse = ec_
node_
parse(node, line);
+ parse = ec_parse(node, line);
if (parse == NULL)
goto fail;
if (parse == NULL)
goto fail;
@@
-677,7
+658,7
@@
ec_editline_parse(struct ec_editline *editline, const struct ec_node *node)
fail:
ec_free(line);
fail:
ec_free(line);
- ec_p
ars
e_free(parse);
+ ec_p
nod
e_free(parse);
return NULL;
}
return NULL;
}