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
installation
user_guide
architecture
- api
contributing
}
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;
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);
}
}
static int
-dump_as_shell(const struct ec_parse *parse)
+dump_as_shell(const struct ec_pnode *parse)
{
FILE *f;
size_t seq = 0;
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;
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);
if (strvec == NULL)
goto fail;
- comp = ec_node_complete_strvec(node, strvec);
+ comp = ec_complete_strvec(node, strvec);
if (comp == NULL)
goto fail;
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!"
return NULL;
line[rl_point] = '\0';
- c = ec_node_complete(commands, line);
+ c = ec_complete(commands, line);
free(line);
if (c == NULL)
return NULL;
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;
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)
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;
goto fail;
/* check if the current line matches */
- p = ec_node_parse(commands, line);
- if (ec_parse_matches(p))
+ p = ec_parse(commands, line);
+ if (ec_pnode_matches(p))
match = 1;
- ec_parse_free(p);
+ ec_pnode_free(p);
p = NULL;
/* complete at current cursor position */
line[rl_point] = '\0';
- c = ec_node_complete(commands, line);
+ c = ec_complete(commands, line);
free(line);
line = NULL;
if (c == NULL)
fail:
ec_comp_iter_free(iter);
- ec_parse_free(p);
+ ec_pnode_free(p);
free(line);
ec_comp_free(c);
if (helps != NULL) {
int main(void)
{
- struct ec_parse *p;
+ struct ec_pnode *p;
char *line;
if (ec_init() < 0) {
if (line == NULL)
break;
- p = ec_node_parse(commands, line);
- ec_parse_dump(stdout, p);
+ p = ec_parse(commands, line);
+ ec_pnode_dump(stdout, p);
add_history(line);
- ec_parse_free(p);
+ ec_pnode_free(p);
}
* 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.
*
/**
* 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
* 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);
/**
* 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);
/**
* 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);
*
*
*/
-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.
* 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.
*
*
*/
-const struct ec_parse *
+const struct ec_pnode *
ec_comp_group_get_state(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);
struct ec_editline;
struct ec_node;
-struct ec_parse;
+struct ec_pnode;
struct ec_comp;
struct ec_editline_help {
* 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
*/
#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;
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 *);
* (.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;
#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, ...);
#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);
*/
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
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)(
};
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
* 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.
#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() */
#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() */
#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() */
* @}
*/
-#ifndef ECOLI_PARSE_
-#define ECOLI_PARSE_
+#ifndef ECOLI_PNODE_
+#define ECOLI_PNODE_
#include <sys/queue.h>
#include <sys/types.h>
#include <stdbool.h>
struct ec_node;
-struct ec_parse;
+struct ec_pnode;
/**
* Create an empty parse tree.
* @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);
/**
*
*
*/
// _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
*
*
*/
-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);
/**
/* 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
* 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);
/**
*
*
*/
-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_; \
})
*
*
*/
-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);
/**
*
*
*/
-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_; \
})
*
*
*/
-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
#include <sys/queue.h>
#include <ecoli_log.h>
+#include <ecoli_utils.h>
struct ec_node;
enum ec_comp_type;
/* 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_; \
(new_type)__x; \
})
+/**
+ * Mark the end of the arguments list in some functions.
+ */
+#define EC_VA_END ((void *)1)
+
#endif
/** @} */
}
# $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'}')
# $1: node sequence number (ex: ec_node4)
# $2: index in strvec
-ec_parse_get_str()
+ec_pnode_get_str()
{
if [ $# -ne 2 ]; then
return
# $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
}
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;
};
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;
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;
}
}
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;
/* 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;
/* 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;
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;
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;
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;
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;
}
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;
if (grp->attrs == NULL)
goto fail;
- grp->state = ec_parse_dup(parse);
+ grp->state = ec_pnode_dup(parse);
if (grp->state == NULL)
goto fail;
fail:
if (grp != NULL) {
- ec_parse_free(grp->state);
+ ec_pnode_free(grp->state);
ec_dict_free(grp->attrs);
}
ec_free(grp);
/* 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)
{
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);
}
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;
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");
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;
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)
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;
fail:
ec_comp_iter_free(iter);
- ec_parse_free(parse);
+ ec_pnode_free(parse);
ec_comp_free(cmpl);
if (helps != NULL) {
while (count--) {
goto fail;
}
- cmpl = ec_node_complete(editline->node, line);
+ cmpl = ec_complete(editline->node, line);
if (cmpl == NULL)
goto 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. */
if (line == NULL)
goto fail;
- parse = ec_node_parse(node, line);
+ parse = ec_parse(node, line);
if (parse == NULL)
goto fail;
fail:
ec_free(line);
- ec_parse_free(parse);
+ ec_pnode_free(parse);
return NULL;
}
};
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);
.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,
};
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;
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
{
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)
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;
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;
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;
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;
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;;
(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;
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;
(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;
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;
(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;
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
{
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)
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);
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. */
};
};
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)
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;
}
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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,
}
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;
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);
}
}
}
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;
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;
}
}
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;
}
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;
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;
}
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;
}
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;
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;
}
// 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)
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);
}
{
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;
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;
return 0;
fail:
- ec_parse_free(parsed_cond);
+ ec_pnode_free(parsed_cond);
ec_free(cond_str);
return -1;
}
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);
/* 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);
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];
goto fail;
}
- return ec_node_complete_child(child, comp, strvec);
+ return ec_complete_child(child, comp, strvec);
fail:
ec_node_free(child);
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++;
}
/* 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);
};
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;
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),
};
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;
};
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);
return -1;
}
- return ec_node_parse_child(priv->child, state, strvec);
+ return ec_parse_child(priv->child, state, strvec);
}
static int
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)
struct result {
bool has_val;
void *val;
- const struct ec_parse *op;
+ const struct ec_pnode *op;
enum expr_node_type op_type;
};
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;
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;
}
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;
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;
}
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;
(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;
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;;
(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;
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;;
(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;
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;
(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;
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;
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;
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;
/* 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);
#include <stddef.h>
#include <errno.h>
+#include <ecoli_utils.h>
#include <ecoli_malloc.h>
#include <ecoli_config.h>
#include <ecoli_node.h>
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;
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);
}
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);
.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,
};
.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),
};
/* 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;
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);
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);
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;
};
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;
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;
/* 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;
}
}
if (count < priv->min) {
- ec_parse_free_children(state);
+ ec_pnode_free_children(state);
return EC_PARSE_NOMATCH;
}
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;
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;
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;
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;
};
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;
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;
};
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;
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);
/* 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
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;
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;
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;
{
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)
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;
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);
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;
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;
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;
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 */
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;
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);
.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,
};
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;
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;
}
.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,
/* no completion */
testres |= EC_TEST_CHECK_COMPLETE(node,
- "", EC_NODE_ENDLIST,
- EC_NODE_ENDLIST);
+ "", EC_VA_END,
+ EC_VA_END);
ec_node_free(node);
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);
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;
childvec = NULL;
if (ret == EC_PARSE_NOMATCH) {
- ec_parse_free_children(state);
+ ec_pnode_free_children(state);
return EC_PARSE_NOMATCH;
}
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 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;
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;
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;
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;
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 */
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;
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;
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;
}
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;
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;
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;
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),
};
}
/* 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;
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);
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;
* 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)
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;
/* 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;
*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;
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;
return result.len;
fail:
- ec_parse_free(parse);
+ ec_pnode_free(parse);
return ret;
}
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;
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;
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;
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;
}
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;
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 */
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;
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
}
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;
}
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;
}
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();
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;
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)
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;
}
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);
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;
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";
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");
* 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;
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;
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;
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);
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;
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;
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;
}
/* 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;
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;
}
/* 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;
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;
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;
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);
}
/* 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);
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;
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;
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) {
match, expected);
}
- ec_parse_free(p);
+ ec_pnode_free(p);
out:
ec_strvec_free(vec);
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;
goto out;
}
- c = ec_node_complete_strvec(tk, vec);
+ c = ec_complete_strvec(tk, vec);
if (c == NULL) {
ret = -1;
goto out;
/* 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;
X remove weakref?
- sh_lex to provide offsets in attributes
- accessors for all structs
+- private vs user attributes?
dependencies
============
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_*()
+