rename structures and functions
authorOlivier Matz <zer0@droids-corp.org>
Thu, 7 Nov 2019 17:09:29 +0000 (18:09 +0100)
committerOlivier Matz <zer0@droids-corp.org>
Thu, 7 Nov 2019 17:09:29 +0000 (18:09 +0100)
47 files changed:
doc/architecture.rst
doc/index.rst
examples/parse-yaml/parse-yaml.c
examples/parse-yaml/parse-yaml.sh
examples/readline/main.c
include/ecoli_complete.h
include/ecoli_editline.h
include/ecoli_node.h
include/ecoli_node_cmd.h
include/ecoli_node_dynamic.h
include/ecoli_node_expr.h
include/ecoli_node_helper.h
include/ecoli_node_or.h
include/ecoli_node_seq.h
include/ecoli_node_subset.h
include/ecoli_parse.h
include/ecoli_test.h
include/ecoli_utils.h
libshell/libecoli.sh
src/ecoli_complete.c
src/ecoli_editline.c
src/ecoli_node_any.c
src/ecoli_node_bypass.c
src/ecoli_node_cmd.c
src/ecoli_node_cond.c
src/ecoli_node_dynamic.c
src/ecoli_node_empty.c
src/ecoli_node_expr.c
src/ecoli_node_expr_test.c
src/ecoli_node_file.c
src/ecoli_node_helper.c
src/ecoli_node_int.c
src/ecoli_node_many.c
src/ecoli_node_none.c
src/ecoli_node_once.c
src/ecoli_node_option.c
src/ecoli_node_or.c
src/ecoli_node_re.c
src/ecoli_node_re_lex.c
src/ecoli_node_seq.c
src/ecoli_node_sh_lex.c
src/ecoli_node_space.c
src/ecoli_node_str.c
src/ecoli_node_subset.c
src/ecoli_parse.c
src/ecoli_test.c
todo.txt

index 64ecaa8..274873d 100644 (file)
@@ -55,7 +55,7 @@ Parsing an input
 
 When the *libecoli* parses an input, it browses the tree (depth first
 search) and returns an *ecoli parse tree*. Let's decompose what is done
-when ``ec_node_parse_strvec(root_node, input)`` is called, step by step:
+when ``ec_parse_strvec(root_node, input)`` is called, step by step:
 
 1. The initial input is a string vector ``["foo bar"]``.
 2. The *sh_lex* node splits the input as a shell would have done it, in
index a5f8731..6636793 100644 (file)
@@ -41,5 +41,4 @@ Who use it?
    installation
    user_guide
    architecture
-   api
    contributing
index 4f46b22..d1c1a54 100644 (file)
@@ -108,10 +108,10 @@ static int parse_args(int argc, char **argv)
 }
 
 static int
-__dump_as_shell(FILE *f, const struct ec_parse *parse, size_t *seq)
+__dump_as_shell(FILE *f, const struct ec_pnode *parse, size_t *seq)
 {
-       const struct ec_node *node = ec_parse_get_node(parse);
-       struct ec_parse *child;
+       const struct ec_node *node = ec_pnode_get_node(parse);
+       struct ec_pnode *child;
        size_t cur_seq, i, len;
        const char *s;
 
@@ -125,25 +125,25 @@ __dump_as_shell(FILE *f, const struct ec_parse *parse, size_t *seq)
        fprintf(f, "ec_node%zu_type='%s'\n", cur_seq,
                ec_node_type_name(ec_node_type(node)));
 
-       len = ec_strvec_len(ec_parse_strvec(parse));
+       len = ec_strvec_len(ec_pnode_strvec(parse));
        fprintf(f, "ec_node%zu_strvec_len=%zu\n", cur_seq, len);
        for (i = 0; i < len; i++) {
-               s = ec_strvec_val(ec_parse_strvec(parse), i);
+               s = ec_strvec_val(ec_pnode_strvec(parse), i);
                fprintf(f, "ec_node%zu_str%zu='%s'\n", cur_seq, i, s);
        }
 
-       if (ec_parse_get_first_child(parse) != NULL) {
+       if (ec_pnode_get_first_child(parse) != NULL) {
                fprintf(f, "ec_node%zu_first_child='ec_node%zu'\n",
                        cur_seq, cur_seq + 1);
        }
 
-       EC_PARSE_FOREACH_CHILD(child, parse) {
+       EC_PNODE_FOREACH_CHILD(child, parse) {
                fprintf(f, "ec_node%zu_parent='ec_node%zu'\n",
                        *seq + 1, cur_seq);
                __dump_as_shell(f, child, seq);
        }
 
-       if (ec_parse_next(parse) != NULL) {
+       if (ec_pnode_next(parse) != NULL) {
                fprintf(f, "ec_node%zu_next='ec_node%zu'\n",
                        cur_seq, *seq + 1);
        }
@@ -152,7 +152,7 @@ __dump_as_shell(FILE *f, const struct ec_parse *parse, size_t *seq)
 }
 
 static int
-dump_as_shell(const struct ec_parse *parse)
+dump_as_shell(const struct ec_pnode *parse)
 {
        FILE *f;
        size_t seq = 0;
@@ -173,7 +173,7 @@ static int
 interact(struct ec_node *node)
 {
        struct ec_editline *editline = NULL;
-       struct ec_parse *parse = NULL;
+       struct ec_pnode *parse = NULL;
        struct ec_node *shlex = NULL;
        char *line = NULL;
 
@@ -193,23 +193,23 @@ interact(struct ec_node *node)
        if (parse == NULL)
                goto fail;
 
-       if (!ec_parse_matches(parse))
+       if (!ec_pnode_matches(parse))
                goto fail;
 
-       //ec_parse_dump(stdout, parse);
+       //ec_pnode_dump(stdout, parse);
 
        if (dump_as_shell(parse) < 0) {
                fprintf(stderr, "Failed to dump the parsed result\n");
                goto fail;
        }
 
-       ec_parse_free(parse);
+       ec_pnode_free(parse);
        ec_editline_free(editline);
        ec_node_free(shlex);
        return 0;
 
 fail:
-       ec_parse_free(parse);
+       ec_pnode_free(parse);
        ec_editline_free(editline);
        free(line);
        ec_node_free(shlex);
@@ -232,7 +232,7 @@ complete_words(const struct ec_node *node, int argc, char *argv[])
        if (strvec == NULL)
                goto fail;
 
-       comp = ec_node_complete_strvec(node, strvec);
+       comp = ec_complete_strvec(node, strvec);
        if (comp == NULL)
                goto fail;
 
index 9d5a680..2c54cea 100644 (file)
@@ -92,8 +92,8 @@ $parse_yaml -i $yaml -o $output || match=0
 if [ "$match" = "1" ]; then
        cat $output
        . $output
-       name=$(ec_parse_get_str $(ec_parse_find_first ec_node1 name) 0)
-       hello=$(ec_parse_get_str $(ec_parse_find_first ec_node1 hello) 0)
+       name=$(ec_pnode_get_str $(ec_pnode_find_first ec_node1 name) 0)
+       hello=$(ec_pnode_get_str $(ec_pnode_find_first ec_node1 hello) 0)
 
        if [ "$hello" != "" ]; then
                echo "$name says hello to you!"
index 6095808..90a25f0 100644 (file)
@@ -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;
@@ -106,7 +106,7 @@ 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 *state;
        const struct ec_node *node;
        char *help = NULL;
        const char *node_help = NULL;
@@ -114,8 +114,8 @@ static char *get_node_help(const struct ec_comp_item *item)
 
        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_parse_get_node(state);
+            state = ec_pnode_get_parent(state)) {
+               node = ec_pnode_get_node(state);
                if (node_help == NULL)
                        node_help = ec_dict_get(ec_node_attrs(node), "help");
                if (node_desc == NULL)
@@ -139,7 +139,7 @@ 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;
        char **helps = NULL;
@@ -154,15 +154,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)
@@ -211,7 +211,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) {
@@ -328,7 +328,7 @@ static int create_commands(void)
 
 int main(void)
 {
-       struct ec_parse *p;
+       struct ec_pnode *p;
        char *line;
 
        if (ec_init() < 0) {
@@ -347,10 +347,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);
        }
 
 
index b2df5e1..ebb5ad0 100644 (file)
@@ -11,9 +11,9 @@
  * This file provide helpers to list and manipulate the possible
  * completions for a given input.
  *
- * Use @ec_node_complete_strvec() to complete a vector of strings when
+ * Use @ec_complete_strvec() to complete a vector of strings when
  * the input is already split into several tokens. You can use
- * @ec_node_complete() if you know that the size of the vector is
+ * @ec_complete() if you know that the size of the vector is
  * 1. This is common if you grammar tree has a lexer that will tokenize
  * the input.
  *
@@ -50,7 +50,7 @@ enum ec_comp_type {
 /**
  * Get the list of completions from a string input.
  *
- * It is equivalent that calling @ec_node_complete_strvec() with a
+ * It is equivalent that calling @ec_complete_strvec() with a
  * vector that only contains 1 element, the input string. Using this
  * function is often more convenient if you get your input from a
  * buffer, because you won't have to create a vector. Usually, it means
@@ -66,7 +66,7 @@ enum ec_comp_type {
  *   A pointer to the completion list on success, or NULL
  *   on error (errno is set).
  */
-struct ec_comp *ec_node_complete(const struct ec_node *node,
+struct ec_comp *ec_complete(const struct ec_node *node,
        const char *str);
 
 /**
@@ -93,7 +93,7 @@ struct ec_comp *ec_node_complete(const struct ec_node *node,
  *   A pointer to the completion list on success, or NULL
  *   on error (errno is set).
  */
-struct ec_comp *ec_node_complete_strvec(const struct ec_node *node,
+struct ec_comp *ec_complete_strvec(const struct ec_node *node,
        const struct ec_strvec *strvec);
 
 /**
@@ -102,7 +102,7 @@ struct ec_comp *ec_node_complete_strvec(const struct ec_node *node,
  * This function is to be used by ecoli nodes.
  *
  */
-int ec_node_complete_child(const struct ec_node *node,
+int ec_complete_child(const struct ec_node *node,
                        struct ec_comp *comp,
                        const struct ec_strvec *strvec);
 
@@ -111,7 +111,7 @@ int ec_node_complete_child(const struct ec_node *node,
  *
  *
  */
-struct ec_comp *ec_comp(struct ec_parse *state);
+struct ec_comp *ec_comp(struct ec_pnode *state);
 
 /**
  * Free a completion object and all its items.
@@ -140,7 +140,7 @@ int ec_comp_merge(struct ec_comp *to,
  * Get current completion state.
  *
  */
-struct ec_parse *ec_comp_get_state(const struct ec_comp *comp);
+struct ec_pnode *ec_comp_get_state(const struct ec_comp *comp);
 
 /**
  * Get current completion group.
@@ -244,7 +244,7 @@ ec_comp_group_get_node(const struct ec_comp_group *grp);
  *
  *
  */
-const struct ec_parse *
+const struct ec_pnode *
 ec_comp_group_get_state(const struct ec_comp_group *grp);
 
 /**
@@ -262,7 +262,7 @@ ec_comp_group_get_attrs(const struct ec_comp_group *grp);
  *
  */
 int
-ec_node_complete_unknown(const struct ec_node *gen_node,
+ec_complete_unknown(const struct ec_node *gen_node,
                        struct ec_comp *comp,
                        const struct ec_strvec *strvec);
 
index 414d58b..ea86838 100644 (file)
@@ -23,7 +23,7 @@
 
 struct ec_editline;
 struct ec_node;
-struct ec_parse;
+struct ec_pnode;
 struct ec_comp;
 
 struct ec_editline_help {
@@ -159,7 +159,7 @@ char *ec_editline_gets(struct ec_editline *editline);
  * Get a line (managing completion) and parse it with passed node
  * XXX find a better name?
  */
-struct ec_parse *
+struct ec_pnode *
 ec_editline_parse(struct ec_editline *editline, const struct ec_node *node);
 
 int
index 38e25e4..0557dea 100644 (file)
  */
 #define EC_NO_ID "no-id"
 
-#define EC_NODE_ENDLIST ((void *)1)
-
 struct ec_node;
-struct ec_parse;
+struct ec_pnode;
 struct ec_comp;
 struct ec_strvec;
 struct ec_dict;
@@ -79,10 +77,10 @@ TAILQ_HEAD(ec_node_type_list, ec_node_type);
 
 typedef int (*ec_node_set_config_t)(struct ec_node *node,
                                const struct ec_config *config);
-typedef int (*ec_node_parse_t)(const struct ec_node *node,
-                       struct ec_parse *state,
+typedef int (*ec_parse_t)(const struct ec_node *node,
+                       struct ec_pnode *state,
                        const struct ec_strvec *strvec);
-typedef int (*ec_node_complete_t)(const struct ec_node *node,
+typedef int (*ec_complete_t)(const struct ec_node *node,
                                struct ec_comp *comp_state,
                                const struct ec_strvec *strvec);
 typedef const char * (*ec_node_desc_t)(const struct ec_node *);
@@ -102,8 +100,8 @@ struct ec_node_type {
         *  (.type = EC_CONFIG_TYPE_NONE). */
        const struct ec_config_schema *schema;
        ec_node_set_config_t set_config; /* validate/ack a config change */
-       ec_node_parse_t parse;
-       ec_node_complete_t complete;
+       ec_parse_t parse;
+       ec_complete_t complete;
        ec_node_desc_t desc;
        size_t size;
        ec_node_init_priv_t init_priv;
index a605492..1c5c986 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <ecoli_node.h>
 
-#define EC_NODE_CMD(args...) __ec_node_cmd(args, EC_NODE_ENDLIST)
+#define EC_NODE_CMD(args...) __ec_node_cmd(args, EC_VA_END)
 
 struct ec_node *__ec_node_cmd(const char *id, const char *cmd_str, ...);
 
index 65d3085..fd98971 100644 (file)
 #define ECOLI_NODE_DYNAMIC_
 
 struct ec_node;
-struct ec_parse;
+struct ec_pnode;
 
 /* callback invoked by parse() or complete() to build the dynamic node
  * the behavior of the node can depend on what is already parsed */
 typedef struct ec_node *(*ec_node_dynamic_build_t)(
-       struct ec_parse *state, void *opaque);
+       struct ec_pnode *state, void *opaque);
 
 struct ec_node *ec_node_dynamic(const char *id, ec_node_dynamic_build_t build,
                                void *opaque);
index 15f81ae..35eec25 100644 (file)
@@ -29,7 +29,7 @@
  */
 typedef int (*ec_node_expr_eval_var_t)(
        void **result, void *userctx,
-       const struct ec_parse *var);
+       const struct ec_pnode *var);
 
 /**
  * Callback function type for evaluating a prefix-operator
@@ -51,23 +51,23 @@ typedef int (*ec_node_expr_eval_var_t)(
 typedef int (*ec_node_expr_eval_pre_op_t)(
        void **result, void *userctx,
        void *operand,
-       const struct ec_parse *operator);
+       const struct ec_pnode *operator);
 
 typedef int (*ec_node_expr_eval_post_op_t)(
        void **result, void *userctx,
        void *operand,
-       const struct ec_parse *operator);
+       const struct ec_pnode *operator);
 
 typedef int (*ec_node_expr_eval_bin_op_t)(
        void **result, void *userctx,
        void *operand1,
-       const struct ec_parse *operator,
+       const struct ec_pnode *operator,
        void *operand2);
 
 typedef int (*ec_node_expr_eval_parenthesis_t)(
        void **result, void *userctx,
-       const struct ec_parse *open_paren,
-       const struct ec_parse *close_paren,
+       const struct ec_pnode *open_paren,
+       const struct ec_pnode *close_paren,
        void * value);
 
 typedef void (*ec_node_expr_eval_free_t)(
@@ -92,7 +92,7 @@ struct ec_node_expr_eval_ops {
 };
 
 int ec_node_expr_eval(void **result, const struct ec_node *node,
-       struct ec_parse *parse, const struct ec_node_expr_eval_ops *ops,
+       struct ec_pnode *parse, const struct ec_node_expr_eval_ops *ops,
        void *userctx);
 
 #endif
index 9dbf519..f87eeb7 100644 (file)
@@ -38,14 +38,14 @@ ec_node_config_node_list_to_table(const struct ec_config *config,
  * Build a list of config nodes from variable arguments.
  *
  * The va_list argument is a list of pointer to ec_node structures,
- * terminated with EC_NODE_ENDLIST.
+ * terminated with EC_VA_END.
  *
  * This helper is used by nodes that contain a list of nodes,
  * like "seq", "or", ...
  *
  * @param ap
  *   List of pointer to ec_node structures, terminated with
- *   EC_NODE_ENDLIST.
+ *   EC_VA_END.
  * @return
  *   A pointer to an ec_config structure. In this case, the
  *   nodes will be freed when the config structure will be freed.
index 1738af1..92492fb 100644 (file)
 #define ECOLI_NODE_OR_
 
 #include <ecoli_node.h>
+#include <ecoli_utils.h>
 
-#define EC_NODE_OR(args...) __ec_node_or(args, EC_NODE_ENDLIST)
+#define EC_NODE_OR(args...) __ec_node_or(args, EC_VA_END)
 
-/* list must be terminated with EC_NODE_ENDLIST */
+/* list must be terminated with EC_VA_END */
 /* all nodes given in the list will be freed when freeing this one */
 /* avoid using this function directly, prefer the macro EC_NODE_OR() or
  * ec_node_or() + ec_node_or_add() */
index e1f3896..403cabf 100644 (file)
@@ -12,9 +12,9 @@
 
 #include <ecoli_node.h>
 
-#define EC_NODE_SEQ(args...) __ec_node_seq(args, EC_NODE_ENDLIST)
+#define EC_NODE_SEQ(args...) __ec_node_seq(args, EC_VA_END)
 
-/* list must be terminated with EC_NODE_ENDLIST */
+/* list must be terminated with EC_VA_END */
 /* all nodes given in the list will be freed when freeing this one */
 /* avoid using this function directly, prefer the macro EC_NODE_SEQ() or
  * ec_node_seq() + ec_node_seq_add() */
index 6ec3319..6eff1a0 100644 (file)
@@ -12,9 +12,9 @@
 
 #include <ecoli_node.h>
 
-#define EC_NODE_SUBSET(args...) __ec_node_subset(args, EC_NODE_ENDLIST)
+#define EC_NODE_SUBSET(args...) __ec_node_subset(args, EC_VA_END)
 
-/* list must be terminated with EC_NODE_ENDLIST */
+/* list must be terminated with EC_VA_END */
 /* all nodes given in the list will be freed when freeing this one */
 /* avoid using this function directly, prefer the macro EC_NODE_SUBSET() or
  * ec_node_subset() + ec_node_subset_add() */
index a64c0ae..9bd98a3 100644 (file)
@@ -17,8 +17,8 @@
  * @}
  */
 
-#ifndef ECOLI_PARSE_
-#define ECOLI_PARSE_
+#ifndef ECOLI_PNODE_
+#define ECOLI_PNODE_
 
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -27,7 +27,7 @@
 #include <stdbool.h>
 
 struct ec_node;
-struct ec_parse;
+struct ec_pnode;
 
 /**
  * Create an empty parse tree.
@@ -35,28 +35,28 @@ struct ec_parse;
  * @return
  *   The empty parse tree.
  */
-struct ec_parse *ec_parse(const struct ec_node *node);
+struct ec_pnode *ec_pnode(const struct ec_node *node);
 
 /**
  *
  *
  *
  */
-void ec_parse_free(struct ec_parse *parse);
+void ec_pnode_free(struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-void ec_parse_free_children(struct ec_parse *parse);
+void ec_pnode_free_children(struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-struct ec_parse *ec_parse_dup(const struct ec_parse *parse);
+struct ec_pnode *ec_pnode_dup(const struct ec_pnode *pnode);
 
 /**
  *
@@ -64,7 +64,7 @@ struct ec_parse *ec_parse_dup(const struct ec_parse *parse);
  *
  */
 // _get_ XXX
-const struct ec_strvec *ec_parse_strvec(const struct ec_parse *parse);
+const struct ec_strvec *ec_pnode_strvec(const struct ec_pnode *pnode);
 
 /* a NULL return value is an error, with errno set
   ENOTSUP: no ->parse() operation
@@ -74,14 +74,14 @@ const struct ec_strvec *ec_parse_strvec(const struct ec_parse *parse);
  *
  *
  */
-struct ec_parse *ec_node_parse(const struct ec_node *node, const char *str);
+struct ec_pnode *ec_parse(const struct ec_node *node, const char *str);
 
 /**
  *
  *
  *
  */
-struct ec_parse *ec_node_parse_strvec(const struct ec_node *node,
+struct ec_pnode *ec_parse_strvec(const struct ec_node *node,
                                const struct ec_strvec *strvec);
 
 /**
@@ -94,7 +94,7 @@ struct ec_parse *ec_node_parse_strvec(const struct ec_node *node,
 /* internal: used by nodes
  *
  * state is the current parse tree, which is built piece by piece while
- *   parsing the node tree: ec_node_parse_child() creates a new child in
+ *   parsing the node tree: ec_parse_child() creates a new child in
  *   this state parse tree, and calls the parse() method for the child
  *   node, with state pointing to this new child. If it does not match,
  *   the child is removed in the state, else it is kept, with its
@@ -105,8 +105,8 @@ struct ec_parse *ec_node_parse_strvec(const struct ec_node *node,
  * EC_PARSE_NOMATCH (positive) if it does not match
  * -1 on error, and errno is set
  */
-int ec_node_parse_child(const struct ec_node *node,
-                       struct ec_parse *state,
+int ec_parse_child(const struct ec_node *node,
+                       struct ec_pnode *state,
                        const struct ec_strvec *strvec);
 
 /**
@@ -114,23 +114,23 @@ int ec_node_parse_child(const struct ec_node *node,
  *
  *
  */
-void ec_parse_link_child(struct ec_parse *parse,
-                       struct ec_parse *child);
+void ec_pnode_link_child(struct ec_pnode *pnode,
+                       struct ec_pnode *child);
 /**
  *
  *
  *
  */
-void ec_parse_unlink_child(struct ec_parse *parse,
-                       struct ec_parse *child);
+void ec_pnode_unlink_child(struct ec_pnode *pnode,
+                       struct ec_pnode *child);
 
 /* keep the const */
-#define ec_parse_get_root(parse) ({                            \
-       const struct ec_parse *p_ = parse; /* check type */     \
-       struct ec_parse *parse_ = (struct ec_parse *)parse;     \
+#define ec_pnode_get_root(parse) ({                            \
+       const struct ec_pnode *p_ = parse; /* check type */     \
+       struct ec_pnode *pnode_ = (struct ec_pnode *)parse;     \
        typeof(parse) res_;                                     \
        (void)p_;                                               \
-       res_ = __ec_parse_get_root(parse_);                     \
+       res_ = __ec_pnode_get_root(pnode_);                     \
        res_;                                                   \
 })
 
@@ -139,86 +139,86 @@ void ec_parse_unlink_child(struct ec_parse *parse,
  *
  *
  */
-struct ec_parse *__ec_parse_get_root(struct ec_parse *parse);
+struct ec_pnode *__ec_pnode_get_root(struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-struct ec_parse *ec_parse_get_parent(const struct ec_parse *parse);
+struct ec_pnode *ec_pnode_get_parent(const struct ec_pnode *pnode);
 
 /**
  * Get the first child of a tree.
  *
  */
-struct ec_parse *ec_parse_get_first_child(const struct ec_parse *parse);
+struct ec_pnode *ec_pnode_get_first_child(const struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-struct ec_parse *ec_parse_get_last_child(const struct ec_parse *parse);
+struct ec_pnode *ec_pnode_get_last_child(const struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-struct ec_parse *ec_parse_next(const struct ec_parse *parse);
+struct ec_pnode *ec_pnode_next(const struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-#define EC_PARSE_FOREACH_CHILD(child, parse)                   \
-       for (child = ec_parse_get_first_child(parse);           \
+#define EC_PNODE_FOREACH_CHILD(child, parse)                   \
+       for (child = ec_pnode_get_first_child(parse);           \
             child != NULL;                                     \
-            child = ec_parse_next(child))                      \
+            child = ec_pnode_next(child))                      \
 
 /**
  *
  *
  *
  */
-bool ec_parse_has_child(const struct ec_parse *parse);
+bool ec_pnode_has_child(const struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-const struct ec_node *ec_parse_get_node(const struct ec_parse *parse);
+const struct ec_node *ec_pnode_get_node(const struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-void ec_parse_del_last_child(struct ec_parse *parse);
+void ec_pnode_del_last_child(struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-struct ec_dict *ec_parse_get_attrs(struct ec_parse *parse);
+struct ec_dict *ec_pnode_get_attrs(struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-void ec_parse_dump(FILE *out, const struct ec_parse *parse);
+void ec_pnode_dump(FILE *out, const struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-struct ec_parse *ec_parse_find(struct ec_parse *parse,
+struct ec_pnode *ec_pnode_find(struct ec_pnode *pnode,
        const char *id);
 
 /**
@@ -226,26 +226,26 @@ struct ec_parse *ec_parse_find(struct ec_parse *parse,
  *
  *
  */
-struct ec_parse *ec_parse_find_next(struct ec_parse *root,
-                               struct ec_parse *start,
+struct ec_pnode *ec_pnode_find_next(struct ec_pnode *root,
+                               struct ec_pnode *start,
                                const char *id, bool iter_children);
 
 /**
  * Iterate among parse tree
  *
  * Use it with:
- * for (iter = state; iter != NULL; iter = EC_PARSE_ITER_NEXT(state, iter, 1))
+ * for (iter = state; iter != NULL; iter = EC_PNODE_ITER_NEXT(state, iter, 1))
  */
-struct ec_parse *__ec_parse_iter_next(const struct ec_parse *root,
-                               struct ec_parse *parse, bool iter_children);
+struct ec_pnode *__ec_pnode_iter_next(const struct ec_pnode *root,
+                               struct ec_pnode *pnode, bool iter_children);
 
 /* keep the const if any */
-#define EC_PARSE_ITER_NEXT(root, parse, iter_children) ({              \
-       const struct ec_parse *p_ = parse; /* check type */             \
-       struct ec_parse *parse_ = (struct ec_parse *)parse;             \
+#define EC_PNODE_ITER_NEXT(root, parse, iter_children) ({              \
+       const struct ec_pnode *p_ = parse; /* check type */             \
+       struct ec_pnode *pnode_ = (struct ec_pnode *)parse;             \
        typeof(parse) res_;                                             \
        (void)p_;                                                       \
-       res_ = __ec_parse_iter_next(root, parse_, iter_children);       \
+       res_ = __ec_pnode_iter_next(root, pnode_, iter_children);       \
        res_;                                                           \
 })
 
@@ -254,13 +254,13 @@ struct ec_parse *__ec_parse_iter_next(const struct ec_parse *root,
  *
  *
  */
-size_t ec_parse_len(const struct ec_parse *parse);
+size_t ec_pnode_len(const struct ec_pnode *pnode);
 
 /**
  *
  *
  *
  */
-size_t ec_parse_matches(const struct ec_parse *parse);
+size_t ec_pnode_matches(const struct ec_pnode *pnode);
 
 #endif
index e4b091b..0e9475f 100644 (file)
@@ -15,6 +15,7 @@
 #include <sys/queue.h>
 
 #include <ecoli_log.h>
+#include <ecoli_utils.h>
 
 struct ec_node;
 enum ec_comp_type;
@@ -78,7 +79,7 @@ int ec_test_check_parse(struct ec_node *node, int expected, ...);
 
 /* node, input, [expected1, expected2, ...] */
 #define EC_TEST_CHECK_PARSE(node, args...) ({                          \
-       int ret_ = ec_test_check_parse(node, args, EC_NODE_ENDLIST);    \
+       int ret_ = ec_test_check_parse(node, args, EC_VA_END);  \
        if (ret_)                                                       \
                EC_TEST_ERR("parse test failed");                       \
        ret_;                                                           \
index 98bfcc9..7b76c17 100644 (file)
        (new_type)__x;                          \
        })
 
+/**
+ * Mark the end of the arguments list in some functions.
+ */
+#define EC_VA_END ((void *)1)
+
 #endif
 
 /** @} */
index fdb642d..8e14a1e 100644 (file)
@@ -15,39 +15,39 @@ ec_debug()
 }
 
 # $1: node sequence number (ex: ec_node4)
-ec_parse_get_first_child()
+ec_pnode_get_first_child()
 {
        local first_child=${1}_first_child
        ec_echo $(eval 'ec_echo ${'$first_child'}')
 }
 
 # $1: node sequence number (ex: ec_node4)
-ec_parse_get_next()
+ec_pnode_get_next()
 {
        local next=${1}_next
        ec_echo $(eval 'ec_echo ${'$next'}')
 }
 
 # $1: node sequence number (ex: ec_node4)
-ec_parse_iter_next()
+ec_pnode_iter_next()
 {
        local seq=${1#ec_node}
        seq=$((seq+1))
        local next=ec_node${seq}
-       if [ "$(ec_parse_get_id $next)" != "" ]; then
+       if [ "$(ec_pnode_get_id $next)" != "" ]; then
                ec_echo $next
        fi
 }
 
 # $1: node sequence number (ex: ec_node4)
-ec_parse_get_id()
+ec_pnode_get_id()
 {
        local id=${1}_id
        ec_echo $(eval 'ec_echo ${'$id'}')
 }
 
 # $1: node sequence number (ex: ec_node4)
-ec_parse_get_strvec_len()
+ec_pnode_get_strvec_len()
 {
        local strvec_len=${1}_strvec_len
        ec_echo $(eval 'ec_echo ${'$strvec_len'}')
@@ -55,7 +55,7 @@ ec_parse_get_strvec_len()
 
 # $1: node sequence number (ex: ec_node4)
 # $2: index in strvec
-ec_parse_get_str()
+ec_pnode_get_str()
 {
        if [ $# -ne 2 ]; then
                return
@@ -66,18 +66,18 @@ ec_parse_get_str()
 
 # $1: node sequence number (ex: ec_node4)
 # $2: node id (string)
-ec_parse_find_first()
+ec_pnode_find_first()
 {
        if [ $# -ne 2 ]; then
                return
        fi
        local node_seq=$1
        while [ "$node_seq" != "" ]; do
-               local id=$(ec_parse_get_id $node_seq)
+               local id=$(ec_pnode_get_id $node_seq)
                if [ "$id" = "$2" ]; then
                        ec_echo $node_seq
                        return 0
                fi
-               node_seq=$(ec_parse_iter_next $node_seq)
+               node_seq=$(ec_pnode_iter_next $node_seq)
        done
 }
index 1844c62..d1bcbd8 100644 (file)
@@ -41,7 +41,7 @@ struct ec_comp_group {
        TAILQ_ENTRY(ec_comp_group) next;
        const struct ec_node *node;
        struct ec_comp_item_list items;
-       struct ec_parse *state;
+       struct ec_pnode *state;
        struct ec_dict *attrs;
 };
 
@@ -52,13 +52,13 @@ struct ec_comp {
        unsigned count_full;
        unsigned count_partial;
        unsigned count_unknown;
-       struct ec_parse *cur_state;
+       struct ec_pnode *cur_state;
        struct ec_comp_group *cur_group;
        struct ec_comp_group_list groups;
        struct ec_dict *attrs;
 };
 
-struct ec_comp *ec_comp(struct ec_parse *state)
+struct ec_comp *ec_comp(struct ec_pnode *state)
 {
        struct ec_comp *comp = NULL;
 
@@ -84,7 +84,7 @@ struct ec_comp *ec_comp(struct ec_parse *state)
        return NULL;
 }
 
-struct ec_parse *ec_comp_get_state(const struct ec_comp *comp)
+struct ec_pnode *ec_comp_get_state(const struct ec_comp *comp)
 {
        return comp->cur_state;
 }
@@ -100,11 +100,11 @@ struct ec_dict *ec_comp_get_attrs(const struct ec_comp *comp)
 }
 
 int
-ec_node_complete_child(const struct ec_node *node,
+ec_complete_child(const struct ec_node *node,
                struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_parse *child_state, *cur_state;
+       struct ec_pnode *child_state, *cur_state;
        struct ec_comp_group *cur_group;
        int ret;
 
@@ -115,12 +115,12 @@ ec_node_complete_child(const struct ec_node *node,
 
        /* save previous parse state, prepare child state */
        cur_state = comp->cur_state;
-       child_state = ec_parse(node);
+       child_state = ec_pnode(node);
        if (child_state == NULL)
                return -1;
 
        if (cur_state != NULL)
-               ec_parse_link_child(cur_state, child_state);
+               ec_pnode_link_child(cur_state, child_state);
        comp->cur_state = child_state;
        cur_group = comp->cur_group;
        comp->cur_group = NULL;
@@ -130,10 +130,10 @@ ec_node_complete_child(const struct ec_node *node,
 
        /* restore parent parse state */
        if (cur_state != NULL) {
-               ec_parse_unlink_child(cur_state, child_state);
-               assert(!ec_parse_has_child(child_state));
+               ec_pnode_unlink_child(cur_state, child_state);
+               assert(!ec_pnode_has_child(child_state));
        }
-       ec_parse_free(child_state);
+       ec_pnode_free(child_state);
        comp->cur_state = cur_state;
        comp->cur_group = cur_group;
 
@@ -143,7 +143,7 @@ ec_node_complete_child(const struct ec_node *node,
        return 0;
 }
 
-struct ec_comp *ec_node_complete_strvec(const struct ec_node *node,
+struct ec_comp *ec_complete_strvec(const struct ec_node *node,
        const struct ec_strvec *strvec)
 {
        struct ec_comp *comp = NULL;
@@ -153,7 +153,7 @@ struct ec_comp *ec_node_complete_strvec(const struct ec_node *node,
        if (comp == NULL)
                goto fail;
 
-       ret = ec_node_complete_child(node, comp, strvec);
+       ret = ec_complete_child(node, comp, strvec);
        if (ret < 0)
                goto fail;
 
@@ -164,7 +164,7 @@ fail:
        return NULL;
 }
 
-struct ec_comp *ec_node_complete(const struct ec_node *node,
+struct ec_comp *ec_complete(const struct ec_node *node,
        const char *str)
 {
        struct ec_strvec *strvec = NULL;
@@ -178,7 +178,7 @@ struct ec_comp *ec_node_complete(const struct ec_node *node,
        if (ec_strvec_add(strvec, str) < 0)
                goto fail;
 
-       comp = ec_node_complete_strvec(node, strvec);
+       comp = ec_complete_strvec(node, strvec);
        if (comp == NULL)
                goto fail;
 
@@ -191,7 +191,7 @@ struct ec_comp *ec_node_complete(const struct ec_node *node,
 }
 
 static struct ec_comp_group *
-ec_comp_group(const struct ec_node *node, struct ec_parse *parse)
+ec_comp_group(const struct ec_node *node, struct ec_pnode *parse)
 {
        struct ec_comp_group *grp = NULL;
 
@@ -203,7 +203,7 @@ ec_comp_group(const struct ec_node *node, struct ec_parse *parse)
        if (grp->attrs == NULL)
                goto fail;
 
-       grp->state = ec_parse_dup(parse);
+       grp->state = ec_pnode_dup(parse);
        if (grp->state == NULL)
                goto fail;
 
@@ -214,7 +214,7 @@ ec_comp_group(const struct ec_node *node, struct ec_parse *parse)
 
 fail:
        if (grp != NULL) {
-               ec_parse_free(grp->state);
+               ec_pnode_free(grp->state);
                ec_dict_free(grp->attrs);
        }
        ec_free(grp);
@@ -485,7 +485,7 @@ fail:
 
 /* return a completion item of type "unknown" */
 int
-ec_node_complete_unknown(const struct ec_node *gen_node,
+ec_complete_unknown(const struct ec_node *gen_node,
                        struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
@@ -514,7 +514,7 @@ static void ec_comp_group_free(struct ec_comp_group *grp)
                TAILQ_REMOVE(&grp->items, item, next);
                ec_comp_item_free(item);
        }
-       ec_parse_free(ec_parse_get_root(grp->state));
+       ec_pnode_free(ec_pnode_get_root(grp->state));
        ec_dict_free(grp->attrs);
        ec_free(grp);
 }
@@ -525,7 +525,7 @@ ec_comp_group_get_node(const struct ec_comp_group *grp)
        return grp->node;
 }
 
-const struct ec_parse *
+const struct ec_pnode *
 ec_comp_group_get_state(const struct ec_comp_group *grp)
 {
        return grp->state;
@@ -716,19 +716,19 @@ static int ec_comp_testcase(void)
        if (node == NULL)
                goto fail;
 
-       c = ec_node_complete(node, "xcdscds");
+       c = ec_complete(node, "xcdscds");
        testres |= EC_TEST_CHECK(
                c != NULL && ec_comp_count(c, EC_COMP_ALL) == 0,
                "complete count should is not 0\n");
        ec_comp_free(c);
 
-       c = ec_node_complete(node, "x");
+       c = ec_complete(node, "x");
        testres |= EC_TEST_CHECK(
                c != NULL && ec_comp_count(c, EC_COMP_ALL) == 1,
                "complete count should is not 1\n");
        ec_comp_free(c);
 
-       c = ec_node_complete(node, "");
+       c = ec_complete(node, "");
        testres |= EC_TEST_CHECK(
                c != NULL && ec_comp_count(c, EC_COMP_ALL) == 2,
                "complete count should is not 2\n");
index 2610bf5..6a6e23b 100644 (file)
@@ -383,7 +383,7 @@ static int get_node_help(const struct ec_comp_item *item,
                        struct ec_editline_help *help)
 {
        const struct ec_comp_group *grp;
-       const struct ec_parse *state;
+       const struct ec_pnode *state;
        const struct ec_node *node;
        const char *node_help = NULL;
        const char *node_desc = NULL;
@@ -394,8 +394,8 @@ static int get_node_help(const struct ec_comp_item *item,
        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_parse_get_node(state);
+            state = ec_pnode_get_parent(state)) {
+               node = ec_pnode_get_node(state);
                if (node_help == NULL)
                        node_help = ec_dict_get(ec_node_attrs(node), "help");
                if (node_desc == NULL)
@@ -431,21 +431,21 @@ ec_editline_get_helps(const struct ec_editline *editline, const char *line,
        const struct ec_comp_group *grp, *prev_grp = NULL;
        const struct ec_comp_item *item;
        struct ec_comp *cmpl = NULL;
-       struct ec_parse *parse = NULL;
+       struct ec_pnode *parse = NULL;
        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_parse_matches(parse))
+       parse = ec_parse(editline->node, full_line);
+       if (ec_pnode_matches(parse))
                count = 1;
-       ec_parse_free(parse);
+       ec_pnode_free(parse);
        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;
 
@@ -494,7 +494,7 @@ ec_editline_get_helps(const struct ec_editline *editline, const char *line,
 
 fail:
        ec_comp_iter_free(iter);
-       ec_parse_free(parse);
+       ec_pnode_free(parse);
        ec_comp_free(cmpl);
        if (helps != NULL) {
                while (count--) {
@@ -551,7 +551,7 @@ ec_editline_complete(EditLine *el, int c)
                goto fail;
        }
 
-       cmpl = ec_node_complete(editline->node, line);
+       cmpl = ec_complete(editline->node, line);
        if (cmpl == NULL)
                goto fail;
 
@@ -653,11 +653,11 @@ fail:
        return NULL;
 }
 
-struct ec_parse *
+struct ec_pnode *
 ec_editline_parse(struct ec_editline *editline, const struct ec_node *node)
 {
        char *line = NULL;
-       struct ec_parse *parse = NULL;
+       struct ec_pnode *parse = NULL;
 
        /* XXX add sh_lex automatically? This node is required, parse and
         * complete are based on it. */
@@ -668,7 +668,7 @@ ec_editline_parse(struct ec_editline *editline, const struct ec_node *node)
        if (line == NULL)
                goto fail;
 
-       parse = ec_node_parse(node, line);
+       parse = ec_parse(node, line);
        if (parse == NULL)
                goto fail;
 
@@ -677,7 +677,7 @@ ec_editline_parse(struct ec_editline *editline, const struct ec_node *node)
 
 fail:
        ec_free(line);
-       ec_parse_free(parse);
+       ec_pnode_free(parse);
 
        return NULL;
 }
index 8efbec4..43b886a 100644 (file)
@@ -25,7 +25,7 @@ struct ec_node_any {
 };
 
 static int ec_node_any_parse(const struct ec_node *node,
-                       struct ec_parse *state,
+                       struct ec_pnode *state,
                        const struct ec_strvec *strvec)
 {
        struct ec_node_any *priv = ec_node_priv(node);
@@ -91,7 +91,7 @@ static struct ec_node_type ec_node_any_type = {
        .schema = ec_node_any_schema,
        .set_config = ec_node_any_set_config,
        .parse = ec_node_any_parse,
-       .complete = ec_node_complete_unknown,
+       .complete = ec_complete_unknown,
        .size = sizeof(struct ec_node_any),
        .free_priv = ec_node_any_free_priv,
 };
@@ -153,11 +153,11 @@ static int ec_node_any_testcase(void)
                return -1;
        }
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "foo", EC_VA_END,
+               EC_VA_END);
        ec_node_free(node);
 
        return testres;
index de70450..21bb253 100644 (file)
@@ -28,12 +28,12 @@ struct ec_node_bypass {
 
 static int
 ec_node_bypass_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        struct ec_node_bypass *priv = ec_node_priv(node);
 
-       return ec_node_parse_child(priv->child, state, strvec);
+       return ec_parse_child(priv->child, state, strvec);
 }
 
 static int
@@ -43,7 +43,7 @@ ec_node_bypass_complete(const struct ec_node *node,
 {
        struct ec_node_bypass *priv = ec_node_priv(node);
 
-       return ec_node_complete_child(priv->child, comp, strvec);
+       return ec_complete_child(priv->child, comp, strvec);
 }
 
 static void ec_node_bypass_free_priv(struct ec_node *node)
@@ -208,14 +208,14 @@ static int ec_node_bypass_testcase(void)
                return -1;
        }
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               "foo", 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,
-               EC_NODE_ENDLIST);
+               "b", EC_VA_END,
+               EC_VA_END);
        ec_node_free(node);
 
        return testres;
index b6b0720..829c896 100644 (file)
@@ -53,7 +53,7 @@ struct ec_node_cmd_ctx {
 
 static int
 ec_node_cmd_eval_var(void **result, void *userctx,
-       const struct ec_parse *var)
+       const struct ec_pnode *var)
 {
        const struct ec_strvec *vec;
        struct ec_node_cmd_ctx *ctx = userctx;
@@ -62,7 +62,7 @@ ec_node_cmd_eval_var(void **result, void *userctx,
        unsigned int i;
 
        /* get parsed string vector, it should contain only one str */
-       vec = ec_parse_strvec(var);
+       vec = ec_pnode_strvec(var);
        if (ec_strvec_len(vec) != 1) {
                errno = EINVAL;
                return -1;
@@ -96,7 +96,7 @@ ec_node_cmd_eval_var(void **result, void *userctx,
 
 static int
 ec_node_cmd_eval_pre_op(void **result, void *userctx, void *operand,
-       const struct ec_parse *operator)
+       const struct ec_pnode *operator)
 {
        (void)result;
        (void)userctx;
@@ -109,7 +109,7 @@ ec_node_cmd_eval_pre_op(void **result, void *userctx, void *operand,
 
 static int
 ec_node_cmd_eval_post_op(void **result, void *userctx, void *operand,
-       const struct ec_parse *operator)
+       const struct ec_pnode *operator)
 {
        const struct ec_strvec *vec;
        struct ec_node *in = operand;;
@@ -118,7 +118,7 @@ ec_node_cmd_eval_post_op(void **result, void *userctx, void *operand,
        (void)userctx;
 
        /* get parsed string vector, it should contain only one str */
-       vec = ec_parse_strvec(operator);
+       vec = ec_pnode_strvec(operator);
        if (ec_strvec_len(vec) != 1) {
                errno = EINVAL;
                return -1;
@@ -141,7 +141,7 @@ ec_node_cmd_eval_post_op(void **result, void *userctx, void *operand,
 
 static int
 ec_node_cmd_eval_bin_op(void **result, void *userctx, void *operand1,
-       const struct ec_parse *operator, void *operand2)
+       const struct ec_pnode *operator, void *operand2)
 
 {
        const struct ec_strvec *vec;
@@ -152,7 +152,7 @@ ec_node_cmd_eval_bin_op(void **result, void *userctx, void *operand1,
        (void)userctx;
 
        /* get parsed string vector, it should contain only one str */
-       vec = ec_parse_strvec(operator);
+       vec = ec_pnode_strvec(operator);
        if (ec_strvec_len(vec) > 1) {
                errno = EINVAL;
                return -1;
@@ -223,8 +223,8 @@ ec_node_cmd_eval_bin_op(void **result, void *userctx, void *operand1,
 
 static int
 ec_node_cmd_eval_parenthesis(void **result, void *userctx,
-       const struct ec_parse *open_paren,
-       const struct ec_parse *close_paren,
+       const struct ec_pnode *open_paren,
+       const struct ec_pnode *close_paren,
        void *value)
 {
        const struct ec_strvec *vec;
@@ -235,7 +235,7 @@ ec_node_cmd_eval_parenthesis(void **result, void *userctx,
        (void)close_paren;
 
        /* get parsed string vector, it should contain only one str */
-       vec = ec_parse_strvec(open_paren);
+       vec = ec_pnode_strvec(open_paren);
        if (ec_strvec_len(vec) != 1) {
                errno = EINVAL;
                return -1;
@@ -358,45 +358,45 @@ static struct ec_node *
 ec_node_cmd_build(const char *cmd_str, struct ec_node **table, size_t len)
 {
        struct ec_node_cmd_ctx ctx = { table, len };
-       struct ec_parse *p = NULL;
+       struct ec_pnode *p = NULL;
        void *result;
        int ret;
 
        /* parse the command expression */
-       p = ec_node_parse(ec_node_cmd_parser, cmd_str);
+       p = ec_parse(ec_node_cmd_parser, cmd_str);
        if (p == NULL)
                goto fail;
 
-       if (!ec_parse_matches(p)) {
+       if (!ec_pnode_matches(p)) {
                errno = EINVAL;
                goto fail;
        }
-       if (!ec_parse_has_child(p)) {
+       if (!ec_pnode_has_child(p)) {
                errno = EINVAL;
                goto fail;
        }
 
        ret = ec_node_expr_eval(&result, ec_node_cmd_expr,
-                               ec_parse_get_first_child(p),
+                               ec_pnode_get_first_child(p),
                                &expr_ops, &ctx);
        if (ret < 0)
                goto fail;
 
-       ec_parse_free(p);
+       ec_pnode_free(p);
        return result;
 
 fail:
-       ec_parse_free(p);
+       ec_pnode_free(p);
        return NULL;
 }
 
 static int
-ec_node_cmd_parse(const struct ec_node *node, struct ec_parse *state,
+ec_node_cmd_parse(const struct ec_node *node, struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        struct ec_node_cmd *priv = ec_node_priv(node);
 
-       return ec_node_parse_child(priv->cmd, state, strvec);
+       return ec_parse_child(priv->cmd, state, strvec);
 }
 
 static int
@@ -406,7 +406,7 @@ ec_node_cmd_complete(const struct ec_node *node,
 {
        struct ec_node_cmd *priv = ec_node_priv(node);
 
-       return ec_node_complete_child(priv->cmd, comp, strvec);
+       return ec_complete_child(priv->cmd, comp, strvec);
 }
 
 static void ec_node_cmd_free_priv(struct ec_node *node)
@@ -671,14 +671,14 @@ static int ec_node_cmd_testcase(void)
        testres |= EC_TEST_CHECK_PARSE(node, 4, "good", "morning", "1", "bob");
 
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               "good", EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               "good", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "g", EC_NODE_ENDLIST,
-               "good", EC_NODE_ENDLIST);
+               "g", EC_VA_END,
+               "good", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "good", "morning", "", EC_NODE_ENDLIST,
-               "bob", "bobby", "michael", EC_NODE_ENDLIST);
+               "good", "morning", "", EC_VA_END,
+               "bob", "bobby", "michael", EC_VA_END);
 
        ec_node_free(node);
 
index 46d62bd..8ff81dc 100644 (file)
@@ -43,7 +43,7 @@ static struct ec_dict *ec_node_cond_functions; /* functions dictionary */
 
 struct ec_node_cond {
        char *cond_str;                /* the condition string. */
-       struct ec_parse *parsed_cond;  /* the parsed condition. */
+       struct ec_pnode *parsed_cond;  /* the parsed condition. */
        struct ec_node *child;         /* the child node. */
 };
 
@@ -71,7 +71,7 @@ struct cond_result {
 };
 
 typedef struct cond_result *(cond_func_t)(
-       const struct ec_parse *state,
+       const struct ec_pnode *state,
        struct cond_result **in, size_t in_len);
 
 void cond_result_free(struct cond_result *res)
@@ -177,21 +177,21 @@ fail:
        return NULL;
 }
 
-static struct ec_parse *
+static struct ec_pnode *
 ec_node_cond_build(const char *cond_str)
 {
-       struct ec_parse *p = NULL;
+       struct ec_pnode *p = NULL;
 
        /* parse the condition expression */
-       p = ec_node_parse(ec_node_cond_parser, cond_str);
+       p = ec_parse(ec_node_cond_parser, cond_str);
        if (p == NULL)
                goto fail;
 
-       if (!ec_parse_matches(p)) {
+       if (!ec_pnode_matches(p)) {
                errno = EINVAL;
                goto fail;
        }
-       if (!ec_parse_has_child(p)) {
+       if (!ec_pnode_has_child(p)) {
                errno = EINVAL;
                goto fail;
        }
@@ -199,15 +199,15 @@ ec_node_cond_build(const char *cond_str)
        return p;
 
 fail:
-       ec_parse_free(p);
+       ec_pnode_free(p);
        return NULL;
 }
 
 static struct cond_result *
-eval_root(const struct ec_parse *state, struct cond_result **in, size_t in_len)
+eval_root(const struct ec_pnode *state, struct cond_result **in, size_t in_len)
 {
        struct cond_result *out = NULL;
-       const struct ec_parse *root = NULL;
+       const struct ec_pnode *root = NULL;
 
        (void)in;
 
@@ -226,7 +226,7 @@ eval_root(const struct ec_parse *state, struct cond_result **in, size_t in_len)
        if (out->htable == NULL)
                goto fail;
 
-       root = ec_parse_get_root(state);
+       root = ec_pnode_get_root(state);
        if (ec_htable_set(out->htable, &root, sizeof(root), NULL, NULL) < 0)
                goto fail;
 
@@ -240,7 +240,7 @@ fail:
 }
 
 static struct cond_result *
-eval_current(const struct ec_parse *state, struct cond_result **in,
+eval_current(const struct ec_pnode *state, struct cond_result **in,
        size_t in_len)
 {
        struct cond_result *out = NULL;
@@ -292,7 +292,7 @@ boolean_value(const struct cond_result *res)
 }
 
 static struct cond_result *
-eval_bool(const struct ec_parse *state, struct cond_result **in, size_t in_len)
+eval_bool(const struct ec_pnode *state, struct cond_result **in, size_t in_len)
 {
        struct cond_result *out = NULL;
 
@@ -321,7 +321,7 @@ fail:
 }
 
 static struct cond_result *
-eval_or(const struct ec_parse *state, struct cond_result **in, size_t in_len)
+eval_or(const struct ec_pnode *state, struct cond_result **in, size_t in_len)
 {
        struct cond_result *out = NULL;
        size_t i;
@@ -355,7 +355,7 @@ fail:
 }
 
 static struct cond_result *
-eval_and(const struct ec_parse *state, struct cond_result **in, size_t in_len)
+eval_and(const struct ec_pnode *state, struct cond_result **in, size_t in_len)
 {
        struct cond_result *out = NULL;
        size_t i;
@@ -389,13 +389,13 @@ fail:
 }
 
 static struct cond_result *
-eval_first_child(const struct ec_parse *state, struct cond_result **in,
+eval_first_child(const struct ec_pnode *state, struct cond_result **in,
        size_t in_len)
 {
        struct cond_result *out = NULL;
        struct ec_htable_elt_ref *iter;
-       const struct ec_parse * const *pparse;
-       struct ec_parse *parse;
+       const struct ec_pnode * const *pparse;
+       struct ec_pnode *parse;
 
        (void)state;
 
@@ -417,7 +417,7 @@ eval_first_child(const struct ec_parse *state, struct cond_result **in,
        for (iter = ec_htable_iter(in[0]->htable);
             iter != NULL; iter = ec_htable_iter_next(iter)) {
                pparse = ec_htable_iter_get_key(iter);
-               parse = ec_parse_get_first_child(*pparse);
+               parse = ec_pnode_get_first_child(*pparse);
                if (parse == NULL)
                        continue;
                if (ec_htable_set(out->htable, &parse, sizeof(parse), NULL,
@@ -435,13 +435,13 @@ fail:
 }
 
 static struct cond_result *
-eval_find(const struct ec_parse *state, struct cond_result **in,
+eval_find(const struct ec_pnode *state, struct cond_result **in,
        size_t in_len)
 {
        struct cond_result *out = NULL;
        struct ec_htable_elt_ref *iter;
-       struct ec_parse * const *pparse;
-       struct ec_parse *parse;
+       struct ec_pnode * const *pparse;
+       struct ec_pnode *parse;
        const char *id;
 
        (void)state;
@@ -465,13 +465,13 @@ eval_find(const struct ec_parse *state, struct cond_result **in,
        for (iter = ec_htable_iter(in[0]->htable);
             iter != NULL; iter = ec_htable_iter_next(iter)) {
                pparse = ec_htable_iter_get_key(iter);
-               parse = ec_parse_find(*pparse, id);
+               parse = ec_pnode_find(*pparse, id);
                while (parse != NULL) {
                        if (ec_htable_set(out->htable, &parse,
                                                sizeof(parse), NULL,
                                                NULL) < 0)
                                goto fail;
-                       parse = ec_parse_find_next(*pparse, parse, id, 1);
+                       parse = ec_pnode_find_next(*pparse, parse, id, 1);
                }
        }
 
@@ -485,7 +485,7 @@ fail:
 }
 
 static struct cond_result *
-eval_cmp(const struct ec_parse *state, struct cond_result **in,
+eval_cmp(const struct ec_pnode *state, struct cond_result **in,
        size_t in_len)
 {
        struct cond_result *out = NULL;
@@ -529,7 +529,7 @@ eval_cmp(const struct ec_parse *state, struct cond_result **in,
                        if (ec_htable_get(
                                        in[2]->htable,
                                        ec_htable_iter_get_key(iter),
-                                       sizeof(struct ec_parse *)) == NULL) {
+                                       sizeof(struct ec_pnode *)) == NULL) {
                                eq = false;
                                break;
                        }
@@ -568,7 +568,7 @@ fail:
 }
 
 static struct cond_result *
-eval_count(const struct ec_parse *state, struct cond_result **in, size_t in_len)
+eval_count(const struct ec_pnode *state, struct cond_result **in, size_t in_len)
 {
        struct cond_result *out = NULL;
 
@@ -597,7 +597,7 @@ fail:
 }
 
 static struct cond_result *
-eval_func(const char *name, const struct ec_parse *state,
+eval_func(const char *name, const struct ec_pnode *state,
        struct cond_result **in, size_t in_len)
 {
        cond_func_t *f;
@@ -616,63 +616,63 @@ eval_func(const char *name, const struct ec_parse *state,
 
 
 static struct cond_result *
-eval_condition(const struct ec_parse *cond, const struct ec_parse *state)
+eval_condition(const struct ec_pnode *cond, const struct ec_pnode *state)
 {
-       const struct ec_parse *iter;
+       const struct ec_pnode *iter;
        struct cond_result *res = NULL;
        struct cond_result **args = NULL;
-       const struct ec_parse *func = NULL, *func_name = NULL, *arg_list = NULL;
-       const struct ec_parse *value = NULL;
+       const struct ec_pnode *func = NULL, *func_name = NULL, *arg_list = NULL;
+       const struct ec_pnode *value = NULL;
        const char *id;
        size_t n_arg = 0;
 
        // XXX fix cast (x3)
-       func = ec_parse_find((void *)cond, "id_function");
+       func = ec_pnode_find((void *)cond, "id_function");
        if (func != NULL) {
-               EC_PARSE_FOREACH_CHILD(iter, func) {
-                       id = ec_node_id(ec_parse_get_node(iter));
+               EC_PNODE_FOREACH_CHILD(iter, func) {
+                       id = ec_node_id(ec_pnode_get_node(iter));
                        if (!strcmp(id, "id_function_name"))
                                func_name = iter;
                        if (!strcmp(id, "id_arg_list"))
                                arg_list = iter;
                }
 
-               iter = ec_parse_find((void *)arg_list, "id_arg");
+               iter = ec_pnode_find((void *)arg_list, "id_arg");
                while (iter != NULL) {
                        args = ec_realloc(args, (n_arg + 1) * sizeof(*args));
                        args[n_arg] = eval_condition(iter, state);
                        if (args[n_arg] == NULL)
                                goto fail;
                        n_arg++;
-                       iter = ec_parse_find_next((void *)arg_list,
+                       iter = ec_pnode_find_next((void *)arg_list,
                                                (void *)iter, "id_arg", 0);
                }
 
-               res = eval_func(ec_strvec_val(ec_parse_strvec(func_name), 0),
+               res = eval_func(ec_strvec_val(ec_pnode_strvec(func_name), 0),
                                state, args, n_arg);
                args = NULL;
                return res;
        }
 
-       value = ec_parse_find((void *)cond, "id_value_str");
+       value = ec_pnode_find((void *)cond, "id_value_str");
        if (value != NULL) {
                res = ec_malloc(sizeof(*res));
                if (res == NULL)
                        goto fail;
                res->type = STR;
-               res->str = ec_strdup(ec_strvec_val(ec_parse_strvec(value), 0));
+               res->str = ec_strdup(ec_strvec_val(ec_pnode_strvec(value), 0));
                if (res->str == NULL)
                        goto fail;
                return res;
        }
 
-       value = ec_parse_find((void *)cond, "id_value_int");
+       value = ec_pnode_find((void *)cond, "id_value_int");
        if (value != NULL) {
                res = ec_malloc(sizeof(*res));
                if (res == NULL)
                        goto fail;
                res->type = INT;
-               if (ec_str_parse_llint(ec_strvec_val(ec_parse_strvec(value), 0),
+               if (ec_str_parse_llint(ec_strvec_val(ec_pnode_strvec(value), 0),
                                        0, LLONG_MIN, LLONG_MAX,
                                        &res->int64) < 0)
                        goto fail;
@@ -686,7 +686,7 @@ fail:
 }
 
 static int
-validate_condition(const struct ec_parse *cond, const struct ec_parse *state)
+validate_condition(const struct ec_pnode *cond, const struct ec_pnode *state)
 {
        struct cond_result *res;
        int ret;
@@ -702,14 +702,14 @@ validate_condition(const struct ec_parse *cond, const struct ec_parse *state)
 }
 
 static int
-ec_node_cond_parse(const struct ec_node *node, struct ec_parse *state,
+ec_node_cond_parse(const struct ec_node *node, struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        struct ec_node_cond *priv = ec_node_priv(node);
-       struct ec_parse *child;
+       struct ec_pnode *child;
        int ret, valid;
 
-       ret = ec_node_parse_child(priv->child, state, strvec);
+       ret = ec_parse_child(priv->child, state, strvec);
        if (ret <= 0)
                return ret;
 
@@ -718,9 +718,9 @@ ec_node_cond_parse(const struct ec_node *node, struct ec_parse *state,
                return valid;
 
        if (valid == 0) {
-               child = ec_parse_get_last_child(state);
-               ec_parse_unlink_child(state, child);
-               ec_parse_free(child);
+               child = ec_pnode_get_last_child(state);
+               ec_pnode_unlink_child(state, child);
+               ec_pnode_free(child);
                return EC_PARSE_NOMATCH;
        }
 
@@ -737,7 +737,7 @@ ec_node_cond_complete(const struct ec_node *node,
        // XXX eval condition
        // XXX before or after completing ? configurable ?
 
-       return ec_node_complete_child(priv->child, comp, strvec);
+       return ec_complete_child(priv->child, comp, strvec);
 }
 
 static void ec_node_cond_free_priv(struct ec_node *node)
@@ -746,7 +746,7 @@ static void ec_node_cond_free_priv(struct ec_node *node)
 
        ec_free(priv->cond_str);
        priv->cond_str = NULL;
-       ec_parse_free(priv->parsed_cond);
+       ec_pnode_free(priv->parsed_cond);
        priv->parsed_cond = NULL;
        ec_node_free(priv->child);
 }
@@ -772,7 +772,7 @@ static int ec_node_cond_set_config(struct ec_node *node,
 {
        struct ec_node_cond *priv = ec_node_priv(node);
        const struct ec_config *cond = NULL;
-       struct ec_parse *parsed_cond = NULL;
+       struct ec_pnode *parsed_cond = NULL;
        const struct ec_config *child;
        char *cond_str = NULL;
 
@@ -796,7 +796,7 @@ static int ec_node_cond_set_config(struct ec_node *node,
                goto fail;
 
        /* ok, store the config */
-       ec_parse_free(priv->parsed_cond);
+       ec_pnode_free(priv->parsed_cond);
        priv->parsed_cond = parsed_cond;
        ec_free(priv->cond_str);
        priv->cond_str = cond_str;
@@ -806,7 +806,7 @@ static int ec_node_cond_set_config(struct ec_node *node,
        return 0;
 
 fail:
-       ec_parse_free(parsed_cond);
+       ec_pnode_free(parsed_cond);
        ec_free(cond_str);
        return -1;
 }
index e511f68..2ce2e32 100644 (file)
@@ -30,7 +30,7 @@ struct ec_node_dynamic {
 
 static int
 ec_node_dynamic_parse(const struct ec_node *node,
-               struct ec_parse *parse,
+               struct ec_pnode *parse,
                const struct ec_strvec *strvec)
 {
        struct ec_node_dynamic *priv = ec_node_priv(node);
@@ -46,14 +46,14 @@ ec_node_dynamic_parse(const struct ec_node *node,
        /* add the node pointer in the attributes, so it will be freed
         * when parse is freed */
        snprintf(key, sizeof(key), "_dyn_%p", child);
-       ret = ec_dict_set(ec_parse_get_attrs(parse), key, child,
+       ret = ec_dict_set(ec_pnode_get_attrs(parse), key, child,
                        (void *)node_free);
        if (ret < 0) {
                child = NULL; /* already freed */
                goto fail;
        }
 
-       return ec_node_parse_child(child, parse, strvec);
+       return ec_parse_child(child, parse, strvec);
 
 fail:
        ec_node_free(child);
@@ -66,7 +66,7 @@ ec_node_dynamic_complete(const struct ec_node *node,
                const struct ec_strvec *strvec)
 {
        struct ec_node_dynamic *priv = ec_node_priv(node);
-       struct ec_parse *parse;
+       struct ec_pnode *parse;
        struct ec_node *child = NULL;
        void (*node_free)(struct ec_node *) = ec_node_free;
        char key[64];
@@ -87,7 +87,7 @@ ec_node_dynamic_complete(const struct ec_node *node,
                goto fail;
        }
 
-       return ec_node_complete_child(child, comp, strvec);
+       return ec_complete_child(child, comp, strvec);
 
 fail:
        ec_node_free(child);
@@ -131,18 +131,18 @@ fail:
 EC_NODE_TYPE_REGISTER(ec_node_dynamic_type);
 
 static struct ec_node *
-build_counter(struct ec_parse *parse, void *opaque)
+build_counter(struct ec_pnode *parse, void *opaque)
 {
        const struct ec_node *node;
-       struct ec_parse *root, *iter;
+       struct ec_pnode *root, *iter;
        unsigned int count = 0;
        char buf[32];
 
        (void)opaque;
-       root = ec_parse_get_root(parse);
+       root = ec_pnode_get_root(parse);
        for (iter = root; iter != NULL;
-            iter = EC_PARSE_ITER_NEXT(root, iter, 1)) {
-               node = ec_parse_get_node(iter);
+            iter = EC_PNODE_ITER_NEXT(root, iter, 1)) {
+               node = ec_pnode_get_node(iter);
                if (!strcmp(ec_node_id(node), "my-id"))
                        count++;
        }
@@ -171,11 +171,11 @@ static int ec_node_dynamic_testcase(void)
        /* test completion */
 
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "c", EC_NODE_ENDLIST,
-               "count-0", EC_NODE_ENDLIST);
+               "c", EC_VA_END,
+               "count-0", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "count-0", "", EC_NODE_ENDLIST,
-               "count-1", EC_NODE_ENDLIST,
+               "count-0", "", EC_VA_END,
+               "count-1", EC_VA_END,
                "count-1");
        ec_node_free(node);
 
index af3bae1..090808e 100644 (file)
@@ -22,7 +22,7 @@ struct ec_node_empty {
 };
 
 static int ec_node_empty_parse(const struct ec_node *node,
-                       struct ec_parse *state,
+                       struct ec_pnode *state,
                        const struct ec_strvec *strvec)
 {
        (void)node;
@@ -34,7 +34,7 @@ static int ec_node_empty_parse(const struct ec_node *node,
 static struct ec_node_type ec_node_empty_type = {
        .name = "empty",
        .parse = ec_node_empty_parse,
-       .complete = ec_node_complete_unknown,
+       .complete = ec_complete_unknown,
        .size = sizeof(struct ec_node_empty),
 };
 
@@ -63,11 +63,11 @@ static int ec_node_empty_testcase(void)
                return -1;
        }
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "foo", EC_VA_END,
+               EC_VA_END);
        ec_node_free(node);
 
        return testres;
index 2ca0ed3..ff654ef 100644 (file)
@@ -43,7 +43,7 @@ struct ec_node_expr {
 };
 
 static int ec_node_expr_parse(const struct ec_node *node,
-                       struct ec_parse *state,
+                       struct ec_pnode *state,
                        const struct ec_strvec *strvec)
 {
        struct ec_node_expr *priv = ec_node_priv(node);
@@ -53,7 +53,7 @@ static int ec_node_expr_parse(const struct ec_node *node,
                return -1;
        }
 
-       return ec_node_parse_child(priv->child, state, strvec);
+       return ec_parse_child(priv->child, state, strvec);
 }
 
 static int
@@ -68,7 +68,7 @@ ec_node_expr_complete(const struct ec_node *node,
                return -1;
        }
 
-       return ec_node_complete_child(priv->child, comp, strvec);
+       return ec_complete_child(priv->child, comp, strvec);
 }
 
 static void ec_node_expr_free_priv(struct ec_node *node)
@@ -463,7 +463,7 @@ static enum expr_node_type get_node_type(const struct ec_node *expr_node,
 struct result {
        bool has_val;
        void *val;
-       const struct ec_parse *op;
+       const struct ec_pnode *op;
        enum expr_node_type op_type;
 };
 
@@ -520,18 +520,18 @@ static int eval_expression(struct result *result,
        void *userctx,
        const struct ec_node_expr_eval_ops *ops,
        const struct ec_node *expr_node,
-       const struct ec_parse *parse)
+       const struct ec_pnode *parse)
 
 {
-       struct ec_parse *open = NULL, *close = NULL;
+       struct ec_pnode *open = NULL, *close = NULL;
        struct result child_result;
-       struct ec_parse *child;
+       struct ec_pnode *child;
        enum expr_node_type type;
 
        memset(result, 0, sizeof(*result));
        memset(&child_result, 0, sizeof(child_result));
 
-       type = get_node_type(expr_node, ec_parse_get_node(parse));
+       type = get_node_type(expr_node, ec_pnode_get_node(parse));
        if (type == VAL) {
                if (ops->eval_var(&result->val, userctx, parse) < 0)
                        goto fail;
@@ -541,9 +541,9 @@ static int eval_expression(struct result *result,
                result->op_type = type;
        }
 
-       EC_PARSE_FOREACH_CHILD(child, parse) {
+       EC_PNODE_FOREACH_CHILD(child, parse) {
 
-               type = get_node_type(expr_node, ec_parse_get_node(child));
+               type = get_node_type(expr_node, ec_pnode_get_node(child));
                if (type == PAREN_OPEN) {
                        open = child;
                        continue;
@@ -581,7 +581,7 @@ fail:
 }
 
 int ec_node_expr_eval(void **user_result, const struct ec_node *node,
-       struct ec_parse *parse, const struct ec_node_expr_eval_ops *ops,
+       struct ec_pnode *parse, const struct ec_node_expr_eval_ops *ops,
        void *userctx)
 {
        struct result result;
@@ -597,7 +597,7 @@ int ec_node_expr_eval(void **user_result, const struct ec_node *node,
        if (ec_node_check_type(node, &ec_node_expr_type) < 0)
                return -1;
 
-       if (!ec_parse_matches(parse)) {
+       if (!ec_pnode_matches(parse)) {
                errno = EINVAL;
                return -1;
        }
index e3a0c79..c2096ed 100644 (file)
@@ -25,7 +25,7 @@ struct my_eval_result {
 
 static int
 ec_node_expr_test_eval_var(void **result, void *userctx,
-       const struct ec_parse *var)
+       const struct ec_pnode *var)
 {
        const struct ec_strvec *vec;
        const struct ec_node *node;
@@ -35,13 +35,13 @@ ec_node_expr_test_eval_var(void **result, void *userctx,
        (void)userctx;
 
        /* get parsed string vector, it should contain only one str */
-       vec = ec_parse_strvec(var);
+       vec = ec_pnode_strvec(var);
        if (ec_strvec_len(vec) != 1) {
                errno = EINVAL;
                return -1;
        }
 
-       node = ec_parse_get_node(var);
+       node = ec_pnode_get_node(var);
        if (ec_node_int_getval(node, ec_strvec_val(vec, 0), &val) < 0)
                return -1;
 
@@ -58,7 +58,7 @@ ec_node_expr_test_eval_var(void **result, void *userctx,
 
 static int
 ec_node_expr_test_eval_pre_op(void **result, void *userctx, void *operand,
-       const struct ec_parse *operator)
+       const struct ec_pnode *operator)
 {
        const struct ec_strvec *vec;
        struct my_eval_result *eval = operand;;
@@ -66,7 +66,7 @@ ec_node_expr_test_eval_pre_op(void **result, void *userctx, void *operand,
        (void)userctx;
 
        /* get parsed string vector, it should contain only one str */
-       vec = ec_parse_strvec(operator);
+       vec = ec_pnode_strvec(operator);
        if (ec_strvec_len(vec) != 1) {
                errno = EINVAL;
                return -1;
@@ -88,7 +88,7 @@ ec_node_expr_test_eval_pre_op(void **result, void *userctx, void *operand,
 
 static int
 ec_node_expr_test_eval_post_op(void **result, void *userctx, void *operand,
-       const struct ec_parse *operator)
+       const struct ec_pnode *operator)
 {
        const struct ec_strvec *vec;
        struct my_eval_result *eval = operand;;
@@ -96,7 +96,7 @@ ec_node_expr_test_eval_post_op(void **result, void *userctx, void *operand,
        (void)userctx;
 
        /* get parsed string vector, it should contain only one str */
-       vec = ec_parse_strvec(operator);
+       vec = ec_pnode_strvec(operator);
        if (ec_strvec_len(vec) != 1) {
                errno = EINVAL;
                return -1;
@@ -117,7 +117,7 @@ ec_node_expr_test_eval_post_op(void **result, void *userctx, void *operand,
 
 static int
 ec_node_expr_test_eval_bin_op(void **result, void *userctx, void *operand1,
-       const struct ec_parse *operator, void *operand2)
+       const struct ec_pnode *operator, void *operand2)
 
 {
        const struct ec_strvec *vec;
@@ -127,7 +127,7 @@ ec_node_expr_test_eval_bin_op(void **result, void *userctx, void *operand1,
        (void)userctx;
 
        /* get parsed string vector, it should contain only one str */
-       vec = ec_parse_strvec(operator);
+       vec = ec_pnode_strvec(operator);
        if (ec_strvec_len(vec) != 1) {
                errno = EINVAL;
                return -1;
@@ -151,8 +151,8 @@ ec_node_expr_test_eval_bin_op(void **result, void *userctx, void *operand1,
 
 static int
 ec_node_expr_test_eval_parenthesis(void **result, void *userctx,
-       const struct ec_parse *open_paren,
-       const struct ec_parse *close_paren,
+       const struct ec_pnode *open_paren,
+       const struct ec_pnode *close_paren,
        void *value)
 {
        (void)userctx;
@@ -185,17 +185,17 @@ static int ec_node_expr_test_eval(struct ec_node *lex_node,
        const struct ec_node *expr_node,
        const char *str, int val)
 {
-       struct ec_parse *p;
+       struct ec_pnode *p;
        void *result;
        struct my_eval_result *eval;
        int ret;
 
-       p = ec_node_parse(lex_node, str);
+       p = ec_parse(lex_node, str);
        if (p == NULL)
                return -1;
 
        ret = ec_node_expr_eval(&result, expr_node, p, &test_ops, NULL);
-       ec_parse_free(p);
+       ec_pnode_free(p);
        if (ret < 0)
                return -1;
 
index 9c4f4f5..ff77e01 100644 (file)
@@ -36,7 +36,7 @@ struct ec_node_file {
 
 static int
 ec_node_file_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        (void)node;
@@ -394,20 +394,20 @@ static int ec_node_file_testcase(void)
 
        /* test completion */
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "/tmp/toto/t", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "/tmp/toto/t", EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE_PARTIAL(node,
-               "/tmp/toto/t", EC_NODE_ENDLIST,
-               "/tmp/toto/titi/", "/tmp/toto/tutu/", EC_NODE_ENDLIST);
+               "/tmp/toto/t", EC_VA_END,
+               "/tmp/toto/titi/", "/tmp/toto/tutu/", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "/tmp/toto/f", EC_NODE_ENDLIST,
-               "/tmp/toto/foo", EC_NODE_ENDLIST);
+               "/tmp/toto/f", EC_VA_END,
+               "/tmp/toto/foo", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "/tmp/toto/b", EC_NODE_ENDLIST,
-               "/tmp/toto/bar", "/tmp/toto/bar2", EC_NODE_ENDLIST);
+               "/tmp/toto/b", EC_VA_END,
+               "/tmp/toto/bar", "/tmp/toto/bar2", EC_VA_END);
 
        ec_node_free(node);
 
index 94811f2..7440565 100644 (file)
@@ -8,6 +8,7 @@
 #include <stddef.h>
 #include <errno.h>
 
+#include <ecoli_utils.h>
 #include <ecoli_malloc.h>
 #include <ecoli_config.h>
 #include <ecoli_node.h>
@@ -75,7 +76,7 @@ ec_node_config_node_list_from_vargs(va_list ap)
        if (list == NULL)
                goto fail;
 
-       for (; node != EC_NODE_ENDLIST; node = va_arg(ap, struct ec_node *)) {
+       for (; node != EC_VA_END; node = va_arg(ap, struct ec_node *)) {
                if (node == NULL)
                        goto fail;
 
@@ -86,7 +87,7 @@ ec_node_config_node_list_from_vargs(va_list ap)
        return list;
 
 fail:
-       for (; node != EC_NODE_ENDLIST; node = va_arg(ap, struct ec_node *))
+       for (; node != EC_VA_END; node = va_arg(ap, struct ec_node *))
                ec_node_free(node);
        ec_config_free(list);
 
index 0fdca0b..acad9ed 100644 (file)
@@ -75,7 +75,7 @@ static int parse_ullint(struct ec_node_int_uint *priv, const char *str,
 }
 
 static int ec_node_int_uint_parse(const struct ec_node *node,
-                       struct ec_parse *state,
+                       struct ec_pnode *state,
                        const struct ec_strvec *strvec)
 {
        struct ec_node_int_uint *priv = ec_node_priv(node);
@@ -177,7 +177,7 @@ static struct ec_node_type ec_node_int_type = {
        .schema = ec_node_int_schema,
        .set_config = ec_node_int_set_config,
        .parse = ec_node_int_uint_parse,
-       .complete = ec_node_complete_unknown,
+       .complete = ec_complete_unknown,
        .size = sizeof(struct ec_node_int_uint),
        .init_priv = ec_node_uint_init_priv,
 };
@@ -290,7 +290,7 @@ static struct ec_node_type ec_node_uint_type = {
        .schema = ec_node_uint_schema,
        .set_config = ec_node_uint_set_config,
        .parse = ec_node_int_uint_parse,
-       .complete = ec_node_complete_unknown,
+       .complete = ec_complete_unknown,
        .size = sizeof(struct ec_node_int_uint),
 };
 
@@ -369,7 +369,7 @@ int ec_node_uint_getval(const struct ec_node *node, const char *str,
 /* LCOV_EXCL_START */
 static int ec_node_int_testcase(void)
 {
-       struct ec_parse *p;
+       struct ec_pnode *p;
        struct ec_node *node;
        const char *s;
        int testres = 0;
@@ -393,19 +393,19 @@ static int ec_node_int_testcase(void)
        testres |= EC_TEST_CHECK_PARSE(node, -1, "0x100000000000000000");
        testres |= EC_TEST_CHECK_PARSE(node, -1, "4r");
 
-       p = ec_node_parse(node, "1");
-       s = ec_strvec_val(ec_parse_strvec(p), 0);
+       p = ec_parse(node, "1");
+       s = ec_strvec_val(ec_pnode_strvec(p), 0);
        testres |= EC_TEST_CHECK(s != NULL &&
                ec_node_uint_getval(node, s, &u64) == 0 &&
                u64 == 1, "bad integer value");
-       ec_parse_free(p);
+       ec_pnode_free(p);
 
-       p = ec_node_parse(node, "10");
-       s = ec_strvec_val(ec_parse_strvec(p), 0);
+       p = ec_parse(node, "10");
+       s = ec_strvec_val(ec_pnode_strvec(p), 0);
        testres |= EC_TEST_CHECK(s != NULL &&
                ec_node_uint_getval(node, s, &u64) == 0 &&
                u64 == 10, "bad integer value");
-       ec_parse_free(p);
+       ec_pnode_free(p);
        ec_node_free(node);
 
        node = ec_node_int(EC_NO_ID, -1, LLONG_MAX, 16);
@@ -422,12 +422,12 @@ static int ec_node_int_testcase(void)
        testres |= EC_TEST_CHECK_PARSE(node, -1, "zzz");
        testres |= EC_TEST_CHECK_PARSE(node, -1, "4r");
 
-       p = ec_node_parse(node, "10");
-       s = ec_strvec_val(ec_parse_strvec(p), 0);
+       p = ec_parse(node, "10");
+       s = ec_strvec_val(ec_pnode_strvec(p), 0);
        testres |= EC_TEST_CHECK(s != NULL &&
                ec_node_int_getval(node, s, &i64) == 0 &&
                i64 == 16, "bad integer value");
-       ec_parse_free(p);
+       ec_pnode_free(p);
        ec_node_free(node);
 
        node = ec_node_int(EC_NO_ID, LLONG_MIN, 0, 10);
@@ -449,14 +449,14 @@ static int ec_node_int_testcase(void)
                return -1;
        }
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "x", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "x", EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "1", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "1", EC_VA_END,
+               EC_VA_END);
        ec_node_free(node);
 
        return testres;
index 91a5fbf..d99c2e3 100644 (file)
@@ -30,11 +30,11 @@ struct ec_node_many {
 };
 
 static int ec_node_many_parse(const struct ec_node *node,
-                       struct ec_parse *state,
+                       struct ec_pnode *state,
                        const struct ec_strvec *strvec)
 {
        struct ec_node_many *priv = ec_node_priv(node);
-       struct ec_parse *child_parse;
+       struct ec_pnode *child_parse;
        struct ec_strvec *childvec = NULL;
        size_t off = 0, count;
        int ret;
@@ -45,7 +45,7 @@ static int ec_node_many_parse(const struct ec_node *node,
                if (childvec == NULL)
                        goto fail;
 
-               ret = ec_node_parse_child(priv->child, state, childvec);
+               ret = ec_parse_child(priv->child, state, childvec);
                if (ret < 0)
                        goto fail;
 
@@ -57,9 +57,9 @@ static int ec_node_many_parse(const struct ec_node *node,
 
                /* it matches an empty strvec, no need to continue */
                if (ret == 0) {
-                       child_parse = ec_parse_get_last_child(state);
-                       ec_parse_unlink_child(state, child_parse);
-                       ec_parse_free(child_parse);
+                       child_parse = ec_pnode_get_last_child(state);
+                       ec_pnode_unlink_child(state, child_parse);
+                       ec_pnode_free(child_parse);
                        break;
                }
 
@@ -67,7 +67,7 @@ static int ec_node_many_parse(const struct ec_node *node,
        }
 
        if (count < priv->min) {
-               ec_parse_free_children(state);
+               ec_pnode_free_children(state);
                return EC_PARSE_NOMATCH;
        }
 
@@ -83,13 +83,13 @@ __ec_node_many_complete(struct ec_node_many *priv, unsigned int max,
                        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_state(comp);
        struct ec_strvec *childvec = NULL;
        unsigned int i;
        int ret;
 
        /* first, try to complete with the child node */
-       ret = ec_node_complete_child(priv->child, comp, strvec);
+       ret = ec_complete_child(priv->child, comp, strvec);
        if (ret < 0)
                goto fail;
 
@@ -108,7 +108,7 @@ __ec_node_many_complete(struct ec_node_many *priv, unsigned int max,
                if (childvec == NULL)
                        goto fail;
 
-               ret = ec_node_parse_child(priv->child, parse, childvec);
+               ret = ec_parse_child(priv->child, parse, childvec);
                if (ret < 0)
                        goto fail;
 
@@ -117,18 +117,18 @@ __ec_node_many_complete(struct ec_node_many *priv, unsigned int max,
 
                if ((unsigned int)ret != i) {
                        if (ret != EC_PARSE_NOMATCH)
-                               ec_parse_del_last_child(parse);
+                               ec_pnode_del_last_child(parse);
                        continue;
                }
 
                childvec = ec_strvec_ndup(strvec, i, ec_strvec_len(strvec) - i);
                if (childvec == NULL) {
-                       ec_parse_del_last_child(parse);
+                       ec_pnode_del_last_child(parse);
                        goto fail;
                }
 
                ret = __ec_node_many_complete(priv, max, comp, childvec);
-               ec_parse_del_last_child(parse);
+               ec_pnode_del_last_child(parse);
                ec_strvec_free(childvec);
                childvec = NULL;
 
@@ -382,26 +382,26 @@ static int ec_node_many_testcase(void)
                return -1;
        }
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               "foo", 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,
-               "foo", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "foo", EC_VA_END,
+               "foo", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", "", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "foo", "", EC_VA_END,
+               "foo", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", "foo", "", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "foo", "foo", "", EC_VA_END,
+               "foo", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", "foo", "foo", "", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "foo", "foo", "foo", "", EC_VA_END,
+               "foo", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", "foo", "foo", "foo", "", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "foo", "foo", "foo", "foo", "", EC_VA_END,
+               EC_VA_END);
        ec_node_free(node);
 
        return testres;
index eadcd4c..032a412 100644 (file)
@@ -22,7 +22,7 @@ struct ec_node_none {
 };
 
 static int ec_node_none_parse(const struct ec_node *node,
-                       struct ec_parse *state,
+                       struct ec_pnode *state,
                        const struct ec_strvec *strvec)
 {
        (void)node;
@@ -76,11 +76,11 @@ static int ec_node_none_testcase(void)
                return -1;
        }
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "foo", EC_VA_END,
+               EC_VA_END);
        ec_node_free(node);
 
        return testres;
index 4662a66..e3ed96a 100644 (file)
@@ -29,18 +29,18 @@ struct ec_node_once {
 };
 
 static unsigned int
-count_node(struct ec_parse *parse, const struct ec_node *node)
+count_node(struct ec_pnode *parse, const struct ec_node *node)
 {
-       struct ec_parse *child;
+       struct ec_pnode *child;
        unsigned int count = 0;
 
        if (parse == NULL)
                return 0;
 
-       if (ec_parse_get_node(parse) == node)
+       if (ec_pnode_get_node(parse) == node)
                count++;
 
-       EC_PARSE_FOREACH_CHILD(child, parse)
+       EC_PNODE_FOREACH_CHILD(child, parse)
                count += count_node(child, node);
 
        return count;
@@ -48,7 +48,7 @@ count_node(struct ec_parse *parse, const struct ec_node *node)
 
 static int
 ec_node_once_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        struct ec_node_once *priv = ec_node_priv(node);
@@ -57,11 +57,11 @@ ec_node_once_parse(const struct ec_node *node,
        /* count the number of occurences of the node: if already parsed,
         * do not match
         */
-       count = count_node(ec_parse_get_root(state), priv->child);
+       count = count_node(ec_pnode_get_root(state), priv->child);
        if (count > 0)
                return EC_PARSE_NOMATCH;
 
-       return ec_node_parse_child(priv->child, state, strvec);
+       return ec_parse_child(priv->child, state, strvec);
 }
 
 static int
@@ -70,18 +70,18 @@ ec_node_once_complete(const struct ec_node *node,
                const struct ec_strvec *strvec)
 {
        struct ec_node_once *priv = ec_node_priv(node);
-       struct ec_parse *parse = ec_comp_get_state(comp);
+       struct ec_pnode *parse = ec_comp_get_state(comp);
        unsigned int count;
        int ret;
 
        /* count the number of occurences of the node: if already parsed,
         * do not match
         */
-       count = count_node(ec_parse_get_root(parse), priv->child);
+       count = count_node(ec_pnode_get_root(parse), priv->child);
        if (count > 0)
                return 0;
 
-       ret = ec_node_complete_child(priv->child, comp, strvec);
+       ret = ec_complete_child(priv->child, comp, strvec);
        if (ret < 0)
                return ret;
 
@@ -253,20 +253,20 @@ static int ec_node_once_testcase(void)
        testres |= EC_TEST_CHECK_PARSE(node, 0, "foox");
 
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               "foo", "bar", EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               "foo", "bar", 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", EC_NODE_ENDLIST);
+               "b", EC_VA_END,
+               "bar", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", "", EC_NODE_ENDLIST,
-               "bar", EC_NODE_ENDLIST);
+               "foo", "", EC_VA_END,
+               "bar", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "bar", "", EC_NODE_ENDLIST,
-               "foo", "bar", EC_NODE_ENDLIST);
+               "bar", "", EC_VA_END,
+               "foo", "bar", EC_VA_END);
        ec_node_free(node);
 
        return testres;
index f2f8977..85f3451 100644 (file)
@@ -28,13 +28,13 @@ struct ec_node_option {
 
 static int
 ec_node_option_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        struct ec_node_option *priv = ec_node_priv(node);
        int ret;
 
-       ret = ec_node_parse_child(priv->child, state, strvec);
+       ret = ec_parse_child(priv->child, state, strvec);
        if (ret < 0)
                return ret;
 
@@ -51,7 +51,7 @@ ec_node_option_complete(const struct ec_node *node,
 {
        struct ec_node_option *priv = ec_node_priv(node);
 
-       return ec_node_complete_child(priv->child, comp, strvec);
+       return ec_complete_child(priv->child, comp, strvec);
 }
 
 static void ec_node_option_free_priv(struct ec_node *node)
@@ -216,14 +216,14 @@ static int ec_node_option_testcase(void)
                return -1;
        }
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               "foo", 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,
-               EC_NODE_ENDLIST);
+               "b", EC_VA_END,
+               EC_VA_END);
        ec_node_free(node);
 
        return testres;
index 125b70b..5f26f62 100644 (file)
@@ -31,7 +31,7 @@ struct ec_node_or {
 
 static int
 ec_node_or_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        struct ec_node_or *priv = ec_node_priv(node);
@@ -39,7 +39,7 @@ ec_node_or_parse(const struct ec_node *node,
        int ret;
 
        for (i = 0; i < priv->len; i++) {
-               ret = ec_node_parse_child(priv->table[i], state, strvec);
+               ret = ec_parse_child(priv->table[i], state, strvec);
                if (ret == EC_PARSE_NOMATCH)
                        continue;
                return ret;
@@ -58,7 +58,7 @@ ec_node_or_complete(const struct ec_node *node,
        size_t n;
 
        for (n = 0; n < priv->len; n++) {
-               ret = ec_node_complete_child(priv->table[n],
+               ret = ec_complete_child(priv->table[n],
                                        comp, strvec);
                if (ret < 0)
                        return ret;
@@ -238,7 +238,7 @@ struct ec_node *__ec_node_or(const char *id, ...)
        if (children == NULL)
                goto fail_free_children;
 
-       for (; child != EC_NODE_ENDLIST; child = va_arg(ap, struct ec_node *)) {
+       for (; child != EC_VA_END; child = va_arg(ap, struct ec_node *)) {
                if (child == NULL)
                        goto fail_free_children;
 
@@ -264,7 +264,7 @@ struct ec_node *__ec_node_or(const char *id, ...)
        return node;
 
 fail_free_children:
-       for (; child != EC_NODE_ENDLIST; child = va_arg(ap, struct ec_node *))
+       for (; child != EC_VA_END; child = va_arg(ap, struct ec_node *))
                ec_node_free(child);
 fail:
        ec_node_free(node); /* will also free added children */
@@ -311,26 +311,26 @@ static int ec_node_or_testcase(void)
                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,
-               "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,
-               "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;
index 9e6678c..7d68b77 100644 (file)
@@ -27,7 +27,7 @@ struct ec_node_re {
 
 static int
 ec_node_re_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        struct ec_node_re *priv = ec_node_priv(node);
@@ -116,7 +116,7 @@ static struct ec_node_type ec_node_re_type = {
        .schema = ec_node_re_schema,
        .set_config = ec_node_re_set_config,
        .parse = ec_node_re_parse,
-       .complete = ec_node_complete_unknown,
+       .complete = ec_complete_unknown,
        .size = sizeof(struct ec_node_re),
        .free_priv = ec_node_re_free_priv,
 };
index cff1c8c..48cf749 100644 (file)
@@ -116,12 +116,12 @@ fail:
 
 static int
 ec_node_re_lex_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        struct ec_node_re_lex *priv = ec_node_priv(node);
        struct ec_strvec *new_vec = NULL;
-       struct ec_parse *child_parse;
+       struct ec_pnode *child_parse;
        const char *str;
        int ret;
 
@@ -139,16 +139,16 @@ ec_node_re_lex_parse(const struct ec_node *node,
        if (new_vec == NULL)
                goto fail;
 
-       ret = ec_node_parse_child(priv->child, state, new_vec);
+       ret = ec_parse_child(priv->child, state, new_vec);
        if (ret < 0)
                goto fail;
 
        if ((unsigned)ret == ec_strvec_len(new_vec)) {
                ret = 1;
        } else if (ret != EC_PARSE_NOMATCH) {
-               child_parse = ec_parse_get_last_child(state);
-               ec_parse_unlink_child(state, child_parse);
-               ec_parse_free(child_parse);
+               child_parse = ec_pnode_get_last_child(state);
+               ec_pnode_unlink_child(state, child_parse);
+               ec_pnode_free(child_parse);
                ret = EC_PARSE_NOMATCH;
        }
 
@@ -372,7 +372,7 @@ static struct ec_node_type ec_node_re_lex_type = {
        .schema = ec_node_re_lex_schema,
        .set_config = ec_node_re_lex_set_config,
        .parse = ec_node_re_lex_parse,
-       .complete = ec_node_complete_unknown,
+       .complete = ec_complete_unknown,
        .size = sizeof(struct ec_node_re_lex),
        .free_priv = ec_node_re_lex_free_priv,
        .get_children_count = ec_node_re_lex_get_children_count,
@@ -547,8 +547,8 @@ static int ec_node_re_lex_testcase(void)
 
        /* no completion */
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               EC_VA_END);
 
        ec_node_free(node);
 
index 6b1a2cd..d06b053 100644 (file)
@@ -34,7 +34,7 @@ struct ec_node_seq {
 
 static int
 ec_node_seq_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        struct ec_node_seq *priv = ec_node_priv(node);
@@ -49,7 +49,7 @@ ec_node_seq_parse(const struct ec_node *node,
                if (childvec == NULL)
                        goto fail;
 
-               ret = ec_node_parse_child(priv->table[i], state, childvec);
+               ret = ec_parse_child(priv->table[i], state, childvec);
                if (ret < 0)
                        goto fail;
 
@@ -57,7 +57,7 @@ ec_node_seq_parse(const struct ec_node *node,
                childvec = NULL;
 
                if (ret == EC_PARSE_NOMATCH) {
-                       ec_parse_free_children(state);
+                       ec_pnode_free_children(state);
                        return EC_PARSE_NOMATCH;
                }
 
@@ -76,7 +76,7 @@ __ec_node_seq_complete(struct ec_node **table, size_t table_len,
                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_state(comp);
        struct ec_strvec *childvec = NULL;
        unsigned int i;
        int ret;
@@ -96,7 +96,7 @@ __ec_node_seq_complete(struct ec_node **table, size_t table_len,
         */
 
        /* first, try to complete with the first node of the table */
-       ret = ec_node_complete_child(table[0], comp, strvec);
+       ret = ec_complete_child(table[0], comp, strvec);
        if (ret < 0)
                goto fail;
 
@@ -107,7 +107,7 @@ __ec_node_seq_complete(struct ec_node **table, size_t table_len,
                if (childvec == NULL)
                        goto fail;
 
-               ret = ec_node_parse_child(table[0], parse, childvec);
+               ret = ec_parse_child(table[0], parse, childvec);
                if (ret < 0)
                        goto fail;
 
@@ -116,20 +116,20 @@ __ec_node_seq_complete(struct ec_node **table, size_t table_len,
 
                if ((unsigned int)ret != i) {
                        if (ret != EC_PARSE_NOMATCH)
-                               ec_parse_del_last_child(parse);
+                               ec_pnode_del_last_child(parse);
                        continue;
                }
 
                childvec = ec_strvec_ndup(strvec, i, ec_strvec_len(strvec) - i);
                if (childvec == NULL) {
-                       ec_parse_del_last_child(parse);
+                       ec_pnode_del_last_child(parse);
                        goto fail;
                }
 
                ret = __ec_node_seq_complete(&table[1],
                                        table_len - 1,
                                        comp, childvec);
-               ec_parse_del_last_child(parse);
+               ec_pnode_del_last_child(parse);
                ec_strvec_free(childvec);
                childvec = NULL;
 
@@ -325,7 +325,7 @@ struct ec_node *__ec_node_seq(const char *id, ...)
        if (children == NULL)
                goto fail_free_children;
 
-       for (; child != EC_NODE_ENDLIST; child = va_arg(ap, struct ec_node *)) {
+       for (; child != EC_VA_END; child = va_arg(ap, struct ec_node *)) {
                if (child == NULL)
                        goto fail_free_children;
 
@@ -351,7 +351,7 @@ struct ec_node *__ec_node_seq(const char *id, ...)
        return node;
 
 fail_free_children:
-       for (; child != EC_NODE_ENDLIST; child = va_arg(ap, struct ec_node *))
+       for (; child != EC_VA_END; child = va_arg(ap, struct ec_node *))
                ec_node_free(child);
 fail:
        ec_node_free(node); /* will also free added children */
@@ -400,32 +400,32 @@ static int ec_node_seq_testcase(void)
                return -1;
        }
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               "foo", 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,
-               "foo", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "foo", EC_VA_END,
+               "foo", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", "", EC_NODE_ENDLIST,
-               "bar", "toto", EC_NODE_ENDLIST);
+               "foo", "", EC_VA_END,
+               "bar", "toto", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", "t", EC_NODE_ENDLIST,
-               "toto", EC_NODE_ENDLIST);
+               "foo", "t", EC_VA_END,
+               "toto", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", "b", EC_NODE_ENDLIST,
-               "bar", EC_NODE_ENDLIST);
+               "foo", "b", EC_VA_END,
+               "bar", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", "bar", EC_NODE_ENDLIST,
-               "bar", EC_NODE_ENDLIST);
+               "foo", "bar", EC_VA_END,
+               "bar", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "x", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "x", EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foobarx", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "foobarx", EC_VA_END,
+               EC_VA_END);
        ec_node_free(node);
 
        return testres;
index 9bd06ce..2461620 100644 (file)
@@ -213,12 +213,12 @@ static struct ec_strvec *tokenize(const char *str, int completion,
 
 static int
 ec_node_sh_lex_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        struct ec_node_sh_lex *priv = ec_node_priv(node);
        struct ec_strvec *new_vec = NULL;
-       struct ec_parse *child_parse;
+       struct ec_pnode *child_parse;
        const char *str;
        int ret;
 
@@ -233,16 +233,16 @@ ec_node_sh_lex_parse(const struct ec_node *node,
        if (new_vec == NULL)
                goto fail;
 
-       ret = ec_node_parse_child(priv->child, state, new_vec);
+       ret = ec_parse_child(priv->child, state, new_vec);
        if (ret < 0)
                goto fail;
 
        if ((unsigned)ret == ec_strvec_len(new_vec)) {
                ret = 1;
        } else if (ret != EC_PARSE_NOMATCH) {
-               child_parse = ec_parse_get_last_child(state);
-               ec_parse_unlink_child(state, child_parse);
-               ec_parse_free(child_parse);
+               child_parse = ec_pnode_get_last_child(state);
+               ec_pnode_unlink_child(state, child_parse);
+               ec_pnode_free(child_parse);
                ret = EC_PARSE_NOMATCH;
        }
 
@@ -285,7 +285,7 @@ ec_node_sh_lex_complete(const struct ec_node *node,
        if (tmp_comp == NULL)
                goto fail;
 
-       ret = ec_node_complete_child(priv->child, tmp_comp, new_vec);
+       ret = ec_complete_child(priv->child, tmp_comp, new_vec);
        if (ret < 0)
                goto fail;
 
@@ -440,44 +440,44 @@ static int ec_node_sh_lex_testcase(void)
                return -1;
        }
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               "foo", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               " ", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               " ", EC_VA_END,
+               "foo", 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,
-               "foo", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "foo", EC_VA_END,
+               "foo", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo ", EC_NODE_ENDLIST,
-               "bar", "toto", EC_NODE_ENDLIST);
+               "foo ", EC_VA_END,
+               "bar", "toto", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo t", EC_NODE_ENDLIST,
-               "toto", EC_NODE_ENDLIST);
+               "foo t", EC_VA_END,
+               "toto", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo b", EC_NODE_ENDLIST,
-               "bar", EC_NODE_ENDLIST);
+               "foo b", EC_VA_END,
+               "bar", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo bar", EC_NODE_ENDLIST,
-               "bar", EC_NODE_ENDLIST);
+               "foo bar", EC_VA_END,
+               "bar", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo bar ", EC_NODE_ENDLIST,
-               "titi", EC_NODE_ENDLIST);
+               "foo bar ", EC_VA_END,
+               "titi", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo toto bar ", EC_NODE_ENDLIST,
-               "titi", EC_NODE_ENDLIST);
+               "foo toto bar ", EC_VA_END,
+               "titi", EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "x", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "x", EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo barx", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "foo barx", EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo 'b", EC_NODE_ENDLIST,
-               "'bar'", EC_NODE_ENDLIST);
+               "foo 'b", EC_VA_END,
+               "'bar'", EC_VA_END);
 
        ec_node_free(node);
        return testres;
index c7afed6..4ab6ad3 100644 (file)
@@ -23,7 +23,7 @@ struct ec_node_space {
 
 static int
 ec_node_space_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        const char *str;
@@ -47,7 +47,7 @@ ec_node_space_parse(const struct ec_node *node,
 static struct ec_node_type ec_node_space_type = {
        .name = "space",
        .parse = ec_node_space_parse,
-       .complete = ec_node_complete_unknown,
+       .complete = ec_complete_unknown,
        .size = sizeof(struct ec_node_space),
 };
 
@@ -79,14 +79,14 @@ static int ec_node_space_testcase(void)
        }
        /* never completes whatever the input */
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               " ", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               " ", EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "foo", EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               "foo", EC_VA_END,
+               EC_VA_END);
        ec_node_free(node);
 
        return testres;
index face6d5..88246bd 100644 (file)
@@ -26,7 +26,7 @@ struct ec_node_str {
 
 static int
 ec_node_str_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                const struct ec_strvec *strvec)
 {
        struct ec_node_str *priv = ec_node_priv(node);
@@ -245,20 +245,20 @@ static int ec_node_str_testcase(void)
                return -1;
        }
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               EC_NODE_ENDLIST,
-               EC_NODE_ENDLIST);
+               EC_VA_END,
+               EC_VA_END);
        testres |= EC_TEST_CHECK_COMPLETE(node,
-               "", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "", EC_VA_END,
+               "foo", 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,
-               "foo", EC_NODE_ENDLIST,
-               "foo", EC_NODE_ENDLIST);
+               "foo", EC_VA_END,
+               "foo", 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;
index 2f2fae7..eddef84 100644 (file)
@@ -37,14 +37,14 @@ struct parse_result {
  * 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 *state,
                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)
@@ -58,7 +58,7 @@ __ec_node_subset_parse(struct parse_result *out, struct ec_node **table,
 
        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], state, strvec);
                if (ret < 0)
                        goto fail;
 
@@ -91,14 +91,14 @@ __ec_node_subset_parse(struct parse_result *out, struct ec_node **table,
                /* 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(state);
                        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(state);
+               ec_pnode_unlink_child(state, best_parse);
 
                best_result.parse_len = result.parse_len + 1;
                best_result.len = len + result.len;
@@ -109,12 +109,12 @@ __ec_node_subset_parse(struct parse_result *out, struct ec_node **table,
        *out = best_result;
        ec_free(child_table);
        if (best_parse != NULL)
-               ec_parse_link_child(state, best_parse);
+               ec_pnode_link_child(state, 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;
@@ -122,11 +122,11 @@ __ec_node_subset_parse(struct parse_result *out, struct ec_node **table,
 
 static int
 ec_node_subset_parse(const struct ec_node *node,
-               struct ec_parse *state,
+               struct ec_pnode *state,
                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;
 
@@ -144,7 +144,7 @@ ec_node_subset_parse(const struct ec_node *node,
        return result.len;
 
  fail:
-       ec_parse_free(parse);
+       ec_pnode_free(parse);
        return ret;
 }
 
@@ -153,7 +153,7 @@ __ec_node_subset_complete(struct ec_node **table, size_t table_len,
                        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_state(comp);
        struct ec_strvec *childvec = NULL;
        struct ec_node *save;
        size_t i, len;
@@ -173,7 +173,7 @@ __ec_node_subset_complete(struct ec_node **table, size_t table_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;
@@ -185,7 +185,7 @@ __ec_node_subset_complete(struct ec_node **table, size_t table_len,
                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;
 
@@ -196,7 +196,7 @@ __ec_node_subset_complete(struct ec_node **table, size_t table_len,
                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;
                }
 
@@ -207,7 +207,7 @@ __ec_node_subset_complete(struct ec_node **table, size_t table_len,
                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;
@@ -319,7 +319,7 @@ struct ec_node *__ec_node_subset(const char *id, ...)
                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 */
@@ -384,35 +384,35 @@ static int ec_node_subset_testcase(void)
                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;
index b32dafb..e1b6018 100644 (file)
 
 EC_LOG_TYPE_REGISTER(parse);
 
-TAILQ_HEAD(ec_parse_list, ec_parse);
+TAILQ_HEAD(ec_pnode_list, ec_pnode);
 
-struct ec_parse {
-       TAILQ_ENTRY(ec_parse) next;
-       struct ec_parse_list children;
-       struct ec_parse *parent;
+struct ec_pnode {
+       TAILQ_ENTRY(ec_pnode) next;
+       struct ec_pnode_list children;
+       struct ec_pnode *parent;
        const struct ec_node *node;
        struct ec_strvec *strvec;
        struct ec_dict *attrs;
 };
 
-static int __ec_node_parse_child(const struct ec_node *node,
-                               struct ec_parse *state,
+static int __ec_parse_child(const struct ec_node *node,
+                               struct ec_pnode *state,
                                bool is_root, const struct ec_strvec *strvec)
 {
        struct ec_strvec *match_strvec;
-       struct ec_parse *child = NULL;
+       struct ec_pnode *child = NULL;
        int ret;
 
        // XXX limit max number of recursions to avoid segfault
@@ -50,11 +50,11 @@ static int __ec_node_parse_child(const struct ec_node *node,
        }
 
        if (!is_root) {
-               child = ec_parse(node);
+               child = ec_pnode(node);
                if (child == NULL)
                        return -1;
 
-               ec_parse_link_child(state, child);
+               ec_pnode_link_child(state, child);
        } else {
                child = state;
        }
@@ -64,8 +64,8 @@ static int __ec_node_parse_child(const struct ec_node *node,
 
        if (ret == EC_PARSE_NOMATCH) {
                if (!is_root) {
-                       ec_parse_unlink_child(state, child);
-                       ec_parse_free(child);
+                       ec_pnode_unlink_child(state, child);
+                       ec_pnode_free(child);
                }
                return ret;
        }
@@ -80,42 +80,42 @@ static int __ec_node_parse_child(const struct ec_node *node,
 
 fail:
        if (!is_root) {
-               ec_parse_unlink_child(state, child);
-               ec_parse_free(child);
+               ec_pnode_unlink_child(state, child);
+               ec_pnode_free(child);
        }
        return -1;
 }
 
-int ec_node_parse_child(const struct ec_node *node, struct ec_parse *state,
+int ec_parse_child(const struct ec_node *node, struct ec_pnode *state,
                        const struct ec_strvec *strvec)
 {
        assert(state != NULL);
-       return __ec_node_parse_child(node, state, false, strvec);
+       return __ec_parse_child(node, state, false, strvec);
 }
 
 // XXX what is returned if no match ??
-struct ec_parse *ec_node_parse_strvec(const struct ec_node *node,
+struct ec_pnode *ec_parse_strvec(const struct ec_node *node,
                                const struct ec_strvec *strvec)
 {
-       struct ec_parse *parse = ec_parse(node);
+       struct ec_pnode *parse = ec_pnode(node);
        int ret;
 
        if (parse == NULL)
                return NULL;
 
-       ret = __ec_node_parse_child(node, parse, true, strvec);
+       ret = __ec_parse_child(node, parse, true, strvec);
        if (ret < 0) {
-               ec_parse_free(parse);
+               ec_pnode_free(parse);
                return NULL;
        }
 
        return parse;
 }
 
-struct ec_parse *ec_node_parse(const struct ec_node *node, const char *str)
+struct ec_pnode *ec_parse(const struct ec_node *node, const char *str)
 {
        struct ec_strvec *strvec = NULL;
-       struct ec_parse *parse = NULL;
+       struct ec_pnode *parse = NULL;
 
        errno = ENOMEM;
        strvec = ec_strvec();
@@ -125,7 +125,7 @@ struct ec_parse *ec_node_parse(const struct ec_node *node, const char *str)
        if (ec_strvec_add(strvec, str) < 0)
                goto fail;
 
-       parse = ec_node_parse_strvec(node, strvec);
+       parse = ec_parse_strvec(node, strvec);
        if (parse == NULL)
                goto fail;
 
@@ -134,13 +134,13 @@ struct ec_parse *ec_node_parse(const struct ec_node *node, const char *str)
 
  fail:
        ec_strvec_free(strvec);
-       ec_parse_free(parse);
+       ec_pnode_free(parse);
        return NULL;
 }
 
-struct ec_parse *ec_parse(const struct ec_node *node)
+struct ec_pnode *ec_pnode(const struct ec_node *node)
 {
-       struct ec_parse *parse = NULL;
+       struct ec_pnode *parse = NULL;
 
        parse = ec_calloc(1, sizeof(*parse));
        if (parse == NULL)
@@ -163,18 +163,18 @@ struct ec_parse *ec_parse(const struct ec_node *node)
        return NULL;
 }
 
-static struct ec_parse *
-__ec_parse_dup(const struct ec_parse *root, const struct ec_parse *ref,
-               struct ec_parse **new_ref)
+static struct ec_pnode *
+__ec_pnode_dup(const struct ec_pnode *root, const struct ec_pnode *ref,
+               struct ec_pnode **new_ref)
 {
-       struct ec_parse *dup = NULL;
-       struct ec_parse *child, *dup_child;
+       struct ec_pnode *dup = NULL;
+       struct ec_pnode *child, *dup_child;
        struct ec_dict *attrs = NULL;
 
        if (root == NULL)
                return NULL;
 
-       dup = ec_parse(root->node);
+       dup = ec_pnode(root->node);
        if (dup == NULL)
                return NULL;
 
@@ -194,26 +194,26 @@ __ec_parse_dup(const struct ec_parse *root, const struct ec_parse *ref,
        }
 
        TAILQ_FOREACH(child, &root->children, next) {
-               dup_child = __ec_parse_dup(child, ref, new_ref);
+               dup_child = __ec_pnode_dup(child, ref, new_ref);
                if (dup_child == NULL)
                        goto fail;
-               ec_parse_link_child(dup, dup_child);
+               ec_pnode_link_child(dup, dup_child);
        }
 
        return dup;
 
 fail:
-       ec_parse_free(dup);
+       ec_pnode_free(dup);
        return NULL;
 }
 
-struct ec_parse *ec_parse_dup(const struct ec_parse *parse)
+struct ec_pnode *ec_pnode_dup(const struct ec_pnode *parse)
 {
-       const struct ec_parse *root;
-       struct ec_parse *dup_root, *dup = NULL;
+       const struct ec_pnode *root;
+       struct ec_pnode *dup_root, *dup = NULL;
 
-       root = ec_parse_get_root(parse);
-       dup_root = __ec_parse_dup(root, parse, &dup);
+       root = ec_pnode_get_root(parse);
+       dup_root = __ec_pnode_dup(root, parse, &dup);
        if (dup_root == NULL)
                return NULL;
        assert(dup != NULL);
@@ -221,9 +221,9 @@ struct ec_parse *ec_parse_dup(const struct ec_parse *parse)
        return dup;
 }
 
-void ec_parse_free_children(struct ec_parse *parse)
+void ec_pnode_free_children(struct ec_pnode *parse)
 {
-       struct ec_parse *child;
+       struct ec_pnode *child;
 
        if (parse == NULL)
                return;
@@ -232,28 +232,28 @@ void ec_parse_free_children(struct ec_parse *parse)
                child = TAILQ_FIRST(&parse->children);
                TAILQ_REMOVE(&parse->children, child, next);
                child->parent = NULL;
-               ec_parse_free(child);
+               ec_pnode_free(child);
        }
 }
 
-void ec_parse_free(struct ec_parse *parse)
+void ec_pnode_free(struct ec_pnode *parse)
 {
        if (parse == NULL)
                return;
 
        ec_assert_print(parse->parent == NULL,
-                       "parent not NULL in ec_parse_free()");
+                       "parent not NULL in ec_pnode_free()");
 
-       ec_parse_free_children(parse);
+       ec_pnode_free_children(parse);
        ec_strvec_free(parse->strvec);
        ec_dict_free(parse->attrs);
        ec_free(parse);
 }
 
-static void __ec_parse_dump(FILE *out,
-       const struct ec_parse *parse, size_t indent)
+static void __ec_pnode_dump(FILE *out,
+       const struct ec_pnode *parse, size_t indent)
 {
-       struct ec_parse *child;
+       struct ec_pnode *child;
        const struct ec_strvec *vec;
        const char *id = "none", *typename = "none";
 
@@ -265,14 +265,14 @@ static void __ec_parse_dump(FILE *out,
 
        fprintf(out, "%*s" "type=%s id=%s vec=",
                (int)indent * 4, "", typename, id);
-       vec = ec_parse_strvec(parse);
+       vec = ec_pnode_strvec(parse);
        ec_strvec_dump(out, vec);
 
        TAILQ_FOREACH(child, &parse->children, next)
-               __ec_parse_dump(out, child, indent + 1);
+               __ec_pnode_dump(out, child, indent + 1);
 }
 
-void ec_parse_dump(FILE *out, const struct ec_parse *parse)
+void ec_pnode_dump(FILE *out, const struct ec_pnode *parse)
 {
        fprintf(out, "------------------- parse dump:\n");
 
@@ -285,51 +285,51 @@ void ec_parse_dump(FILE *out, const struct ec_parse *parse)
         * does not have children: an incomplete parse, like those
         * generated by complete() don't match but have children that
         * may match. */
-       if (!ec_parse_matches(parse) && TAILQ_EMPTY(&parse->children)) {
+       if (!ec_pnode_matches(parse) && TAILQ_EMPTY(&parse->children)) {
                fprintf(out, "no match\n");
                return;
        }
 
-       __ec_parse_dump(out, parse, 0);
+       __ec_pnode_dump(out, parse, 0);
 }
 
-void ec_parse_link_child(struct ec_parse *parse,
-       struct ec_parse *child)
+void ec_pnode_link_child(struct ec_pnode *parse,
+       struct ec_pnode *child)
 {
        TAILQ_INSERT_TAIL(&parse->children, child, next);
        child->parent = parse;
 }
 
-void ec_parse_unlink_child(struct ec_parse *parse,
-       struct ec_parse *child)
+void ec_pnode_unlink_child(struct ec_pnode *parse,
+       struct ec_pnode *child)
 {
        TAILQ_REMOVE(&parse->children, child, next);
        child->parent = NULL;
 }
 
-struct ec_parse *
-ec_parse_get_first_child(const struct ec_parse *parse)
+struct ec_pnode *
+ec_pnode_get_first_child(const struct ec_pnode *parse)
 {
        return TAILQ_FIRST(&parse->children);
 }
 
-struct ec_parse *
-ec_parse_get_last_child(const struct ec_parse *parse)
+struct ec_pnode *
+ec_pnode_get_last_child(const struct ec_pnode *parse)
 {
-       return TAILQ_LAST(&parse->children, ec_parse_list);
+       return TAILQ_LAST(&parse->children, ec_pnode_list);
 }
 
-struct ec_parse *ec_parse_next(const struct ec_parse *parse)
+struct ec_pnode *ec_pnode_next(const struct ec_pnode *parse)
 {
        return TAILQ_NEXT(parse, next);
 }
 
-bool ec_parse_has_child(const struct ec_parse *parse)
+bool ec_pnode_has_child(const struct ec_pnode *parse)
 {
        return !TAILQ_EMPTY(&parse->children);
 }
 
-const struct ec_node *ec_parse_get_node(const struct ec_parse *parse)
+const struct ec_node *ec_pnode_get_node(const struct ec_pnode *parse)
 {
        if (parse == NULL)
                return NULL;
@@ -337,16 +337,16 @@ const struct ec_node *ec_parse_get_node(const struct ec_parse *parse)
        return parse->node;
 }
 
-void ec_parse_del_last_child(struct ec_parse *parse)
+void ec_pnode_del_last_child(struct ec_pnode *parse)
 {
-       struct ec_parse *child;
+       struct ec_pnode *child;
 
-       child = ec_parse_get_last_child(parse);
-       ec_parse_unlink_child(parse, child);
-       ec_parse_free(child);
+       child = ec_pnode_get_last_child(parse);
+       ec_pnode_unlink_child(parse, child);
+       ec_pnode_free(child);
 }
 
-struct ec_parse *__ec_parse_get_root(struct ec_parse *parse)
+struct ec_pnode *__ec_pnode_get_root(struct ec_pnode *parse)
 {
        if (parse == NULL)
                return NULL;
@@ -357,7 +357,7 @@ struct ec_parse *__ec_parse_get_root(struct ec_parse *parse)
        return parse;
 }
 
-struct ec_parse *ec_parse_get_parent(const struct ec_parse *parse)
+struct ec_pnode *ec_pnode_get_parent(const struct ec_pnode *parse)
 {
        if (parse == NULL)
                return NULL;
@@ -365,10 +365,10 @@ struct ec_parse *ec_parse_get_parent(const struct ec_parse *parse)
        return parse->parent;
 }
 
-struct ec_parse *__ec_parse_iter_next(const struct ec_parse *root,
-                               struct ec_parse *parse, bool iter_children)
+struct ec_pnode *__ec_pnode_iter_next(const struct ec_pnode *root,
+                               struct ec_pnode *parse, bool iter_children)
 {
-       struct ec_parse *child, *parent, *next;
+       struct ec_pnode *child, *parent, *next;
 
        if (iter_children) {
                child = TAILQ_FIRST(&parse->children);
@@ -386,21 +386,21 @@ struct ec_parse *__ec_parse_iter_next(const struct ec_parse *root,
        return NULL;
 }
 
-struct ec_parse *
-ec_parse_find_next(struct ec_parse *root, struct ec_parse *start,
+struct ec_pnode *
+ec_pnode_find_next(struct ec_pnode *root, struct ec_pnode *start,
                const char *id, bool iter_children)
 {
-       struct ec_parse *iter;
+       struct ec_pnode *iter;
 
        if (root == NULL)
                return NULL;
        if (start == NULL)
                start = root;
        else
-               start = EC_PARSE_ITER_NEXT(root, start, iter_children);
+               start = EC_PNODE_ITER_NEXT(root, start, iter_children);
 
        for (iter = start; iter != NULL;
-            iter = EC_PARSE_ITER_NEXT(root, iter, 1)) {
+            iter = EC_PNODE_ITER_NEXT(root, iter, 1)) {
                if (iter->node != NULL &&
                                !strcmp(ec_node_id(iter->node), id))
                        return iter;
@@ -409,14 +409,14 @@ ec_parse_find_next(struct ec_parse *root, struct ec_parse *start,
        return NULL;
 }
 
-struct ec_parse *ec_parse_find(struct ec_parse *parse,
+struct ec_pnode *ec_pnode_find(struct ec_pnode *parse,
        const char *id)
 {
-       return ec_parse_find_next(parse, NULL, id, 1);
+       return ec_pnode_find_next(parse, NULL, id, 1);
 }
 
 struct ec_dict *
-ec_parse_get_attrs(struct ec_parse *parse)
+ec_pnode_get_attrs(struct ec_pnode *parse)
 {
        if (parse == NULL)
                return NULL;
@@ -424,7 +424,7 @@ ec_parse_get_attrs(struct ec_parse *parse)
        return parse->attrs;
 }
 
-const struct ec_strvec *ec_parse_strvec(const struct ec_parse *parse)
+const struct ec_strvec *ec_pnode_strvec(const struct ec_pnode *parse)
 {
        if (parse == NULL || parse->strvec == NULL)
                return NULL;
@@ -433,7 +433,7 @@ const struct ec_strvec *ec_parse_strvec(const struct ec_parse *parse)
 }
 
 /* number of strings in the parse vector */
-size_t ec_parse_len(const struct ec_parse *parse)
+size_t ec_pnode_len(const struct ec_pnode *parse)
 {
        if (parse == NULL || parse->strvec == NULL)
                return 0;
@@ -441,7 +441,7 @@ size_t ec_parse_len(const struct ec_parse *parse)
        return ec_strvec_len(parse->strvec);
 }
 
-size_t ec_parse_matches(const struct ec_parse *parse)
+size_t ec_pnode_matches(const struct ec_pnode *parse)
 {
        if (parse == NULL)
                return 0;
@@ -453,11 +453,11 @@ size_t ec_parse_matches(const struct ec_parse *parse)
 }
 
 /* LCOV_EXCL_START */
-static int ec_parse_testcase(void)
+static int ec_pnode_testcase(void)
 {
        struct ec_node *node = NULL;
-       struct ec_parse *p = NULL, *p2 = NULL;
-       const struct ec_parse *pc;
+       struct ec_pnode *p = NULL, *p2 = NULL;
+       const struct ec_pnode *pc;
        FILE *f = NULL;
        char *buf = NULL;
        size_t buflen = 0;
@@ -471,15 +471,15 @@ static int ec_parse_testcase(void)
        if (node == NULL)
                goto fail;
 
-       p = ec_node_parse(node, "xcdscds");
+       p = ec_parse(node, "xcdscds");
        testres |= EC_TEST_CHECK(
-               p != NULL && !ec_parse_matches(p),
+               p != NULL && !ec_pnode_matches(p),
                "parse should not match\n");
 
        f = open_memstream(&buf, &buflen);
        if (f == NULL)
                goto fail;
-       ec_parse_dump(f, p);
+       ec_pnode_dump(f, p);
        fclose(f);
        f = NULL;
 
@@ -487,43 +487,43 @@ static int ec_parse_testcase(void)
                strstr(buf, "no match"), "bad dump\n");
        free(buf);
        buf = NULL;
-       ec_parse_free(p);
+       ec_pnode_free(p);
 
-       p = ec_node_parse(node, "x y");
+       p = ec_parse(node, "x y");
        testres |= EC_TEST_CHECK(
-               p != NULL && ec_parse_matches(p),
+               p != NULL && ec_pnode_matches(p),
                "parse should match\n");
        testres |= EC_TEST_CHECK(
-               ec_parse_len(p) == 1, "bad parse len\n");
+               ec_pnode_len(p) == 1, "bad parse len\n");
 
-       ret = ec_dict_set(ec_parse_get_attrs(p), "key", "val", NULL);
+       ret = ec_dict_set(ec_pnode_get_attrs(p), "key", "val", NULL);
        testres |= EC_TEST_CHECK(ret == 0,
                "cannot set parse attribute\n");
 
-       p2 = ec_parse_dup(p);
+       p2 = ec_pnode_dup(p);
        testres |= EC_TEST_CHECK(
-               p2 != NULL && ec_parse_matches(p2),
+               p2 != NULL && ec_pnode_matches(p2),
                "parse should match\n");
-       ec_parse_free(p2);
+       ec_pnode_free(p2);
        p2 = NULL;
 
-       pc = ec_parse_find(p, "id_x");
+       pc = ec_pnode_find(p, "id_x");
        testres |= EC_TEST_CHECK(pc != NULL, "cannot find id_x");
        testres |= EC_TEST_CHECK(pc != NULL &&
-               ec_parse_get_parent(pc) != NULL &&
-               ec_parse_get_parent(ec_parse_get_parent(pc)) == p,
+               ec_pnode_get_parent(pc) != NULL &&
+               ec_pnode_get_parent(ec_pnode_get_parent(pc)) == p,
                "invalid parent\n");
 
-       pc = ec_parse_find(p, "id_y");
+       pc = ec_pnode_find(p, "id_y");
        testres |= EC_TEST_CHECK(pc != NULL, "cannot find id_y");
-       pc = ec_parse_find(p, "id_dezdezdez");
+       pc = ec_pnode_find(p, "id_dezdezdez");
        testres |= EC_TEST_CHECK(pc == NULL, "should not find bad id");
 
 
        f = open_memstream(&buf, &buflen);
        if (f == NULL)
                goto fail;
-       ec_parse_dump(f, p);
+       ec_pnode_dump(f, p);
        fclose(f);
        f = NULL;
 
@@ -536,13 +536,13 @@ static int ec_parse_testcase(void)
        free(buf);
        buf = NULL;
 
-       ec_parse_free(p);
+       ec_pnode_free(p);
        ec_node_free(node);
        return testres;
 
 fail:
-       ec_parse_free(p2);
-       ec_parse_free(p);
+       ec_pnode_free(p2);
+       ec_pnode_free(p);
        ec_node_free(node);
        if (f != NULL)
                fclose(f);
@@ -552,9 +552,9 @@ fail:
 }
 /* LCOV_EXCL_STOP */
 
-static struct ec_test ec_parse_test = {
+static struct ec_test ec_pnode_test = {
        .name = "parse",
-       .test = ec_parse_testcase,
+       .test = ec_pnode_testcase,
 };
 
-EC_TEST_REGISTER(ec_parse_test);
+EC_TEST_REGISTER(ec_pnode_test);
index b090bd3..4429e67 100644 (file)
@@ -46,7 +46,7 @@ int ec_test_register(struct ec_test *test)
 
 int ec_test_check_parse(struct ec_node *tk, int expected, ...)
 {
-       struct ec_parse *p;
+       struct ec_pnode *p;
        struct ec_strvec *vec = NULL;
        const char *s;
        int ret = -1, match;
@@ -60,7 +60,7 @@ int ec_test_check_parse(struct ec_node *tk, int expected, ...)
                goto out;
 
        for (s = va_arg(ap, const char *);
-            s != EC_NODE_ENDLIST;
+            s != EC_VA_END;
             s = va_arg(ap, const char *)) {
                if (s == NULL)
                        goto out;
@@ -69,12 +69,12 @@ int ec_test_check_parse(struct ec_node *tk, int expected, ...)
                        goto out;
        }
 
-       p = ec_node_parse_strvec(tk, vec);
+       p = ec_parse_strvec(tk, vec);
        if (p == NULL) {
                EC_LOG(EC_LOG_ERR, "parse is NULL\n");
        }
-       if (ec_parse_matches(p))
-               match = ec_parse_len(p);
+       if (ec_pnode_matches(p))
+               match = ec_pnode_len(p);
        else
                match = -1;
        if (expected == match) {
@@ -85,7 +85,7 @@ int ec_test_check_parse(struct ec_node *tk, int expected, ...)
                        match, expected);
        }
 
-       ec_parse_free(p);
+       ec_pnode_free(p);
 
 out:
        ec_strvec_free(vec);
@@ -110,7 +110,7 @@ int ec_test_check_complete(struct ec_node *tk, enum ec_comp_type type, ...)
                goto out;
 
        for (s = va_arg(ap, const char *);
-            s != EC_NODE_ENDLIST;
+            s != EC_VA_END;
             s = va_arg(ap, const char *)) {
                if (s == NULL)
                        goto out;
@@ -119,7 +119,7 @@ int ec_test_check_complete(struct ec_node *tk, enum ec_comp_type type, ...)
                        goto out;
        }
 
-       c = ec_node_complete_strvec(tk, vec);
+       c = ec_complete_strvec(tk, vec);
        if (c == NULL) {
                ret = -1;
                goto out;
@@ -127,7 +127,7 @@ int ec_test_check_complete(struct ec_node *tk, enum ec_comp_type type, ...)
 
        /* for each expected completion, check it is there */
        for (s = va_arg(ap, const char *);
-            s != EC_NODE_ENDLIST;
+            s != EC_VA_END;
             s = va_arg(ap, const char *)) {
                struct ec_comp_iter *iter;
                const struct ec_comp_item *item;
index acb7069..16521f0 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -44,6 +44,7 @@ X use vec for strvec
 X remove weakref?
 - sh_lex to provide offsets in attributes
 - accessors for all structs
+- private vs user attributes?
 
 dependencies
 ============
@@ -437,3 +438,81 @@ There are several options:
 3/ one library with core + yaml + edit
    dependency is managed at runtime
 
+
+--------------
+
+current naming: ec_node_parse* and ec_comp_complete* are not
+so good names
+
+struct         ec_comp
+alloc          ec_complete()
+free           ec_complete_free()
+action         ec_comp_complete()
+action         ec_comp_complete_strvec()
+action         ec_comp_dump()
+action         ec_comp_merge()
+accessors      ec_comp_get()
+
+struct         ec_parse
+alloc          ec_parse()
+free           ec_parse_free()
+action         ec_node_parse()
+action         ec_node_parse_strvec()
+accessors      ...
+
+struct         ec_node
+alloc          ec_node()
+free           ec_node_free()
+action         ...
+accessors      ...
+
+struct         ec_strvec
+alloc          ec_strvec()
+free           ec_strvec_free()
+action         ec_strvec_*()
+
+---------
+
+proposal
+
+- struct name must not be a verb (ex: not ec_parse)
+- allocator is the name of struct
+- actions are <structname>_<verb>() except for basic/common actions
+- basic actions are ec_<verb>()
+- accessors (get) are <structname>_<field>()
+- accessors (set) are <structname>_set_<field>()
+
+
+XXX list all functions to be sure
+XXX this could go in documentation (coding rules)
+
+struct         ec_comp
+alloc          ec_comp()
+free           ec_comp_free()
+action         ec_complete()
+action         ec_complete_strvec()
+action         ec_comp_dump()
+action         ec_comp_merge()
+accessors      ec_comp_id()
+accessors      ec_comp_attrs()
+
+(pnode means parsed node)
+struct         ec_pnode
+alloc          ec_pnode()
+free           ec_pnode_free()
+action         ec_parse()
+action         ec_parse_strvec()
+accessors      ...
+
+(node means grammar node)
+struct         ec_node
+alloc          ec_node()
+free           ec_node_free()
+action         ...
+accessors      ec_node_get*()
+
+struct         ec_strvec
+alloc          ec_strvec()
+free           ec_strvec_free()
+action         ec_strvec_*()
+