return -ENOMEM;
if (cur_state != NULL)
- ec_parsed_add_child(cur_state, child_state);
+ ec_parsed_link_child(cur_state, child_state);
completed->cur_state = child_state;
cur_group = completed->cur_group;
completed->cur_group = NULL;
/* restore parent parse state */
if (cur_state != NULL) {
- ec_parsed_del_child(cur_state, child_state);
+ ec_parsed_unlink_child(cur_state, child_state);
assert(!ec_parsed_has_child(child_state));
}
ec_parsed_free(child_state);
* code */
struct ec_node *__ec_node(const struct ec_node_type *type, const char *id);
-/* create a_new node node */
+/* create a new node */
struct ec_node *ec_node(const char *typename, const char *id);
struct ec_node *ec_node_clone(struct ec_node *node);
#include <ecoli_node.h>
-/* XXX remove the _new for all other nodes */
-
/**
* Callback function type for evaluating a variable
*
/* it matches an empty strvec, no need to continue */
if (ret == 0) {
child_parsed = ec_parsed_get_last_child(state);
- ec_parsed_del_child(state, child_parsed);
+ ec_parsed_unlink_child(state, child_parsed);
ec_parsed_free(child_parsed);
break;
}
ret = 1;
} else if (ret != EC_PARSED_NOMATCH) {
child_parsed = ec_parsed_get_last_child(state);
- ec_parsed_del_child(state, child_parsed);
+ ec_parsed_unlink_child(state, child_parsed);
ec_parsed_free(child_parsed);
ret = EC_PARSED_NOMATCH;
}
ret = 1;
} else if (ret != EC_PARSED_NOMATCH) {
child_parsed = ec_parsed_get_last_child(state);
- ec_parsed_del_child(state, child_parsed);
+ ec_parsed_unlink_child(state, child_parsed);
ec_parsed_free(child_parsed);
ret = EC_PARSED_NOMATCH;
}
struct ec_completed_item *item = NULL;
char *new_str = NULL;
const char *str;
- char missing_quote;
+ char missing_quote = '\0';
int ret;
if (ec_strvec_len(strvec) != 1)
/* replace the previous best result */
ec_parsed_free(best_parsed);
best_parsed = ec_parsed_get_last_child(state);
- ec_parsed_del_child(state, best_parsed);
+ ec_parsed_unlink_child(state, best_parsed);
best_result.parsed_len = result.parsed_len + 1;
best_result.len = len + result.len;
*out = best_result;
ec_free(child_table);
if (best_parsed != NULL)
- ec_parsed_add_child(state, best_parsed);
+ ec_parsed_link_child(state, best_parsed);
return 0;
if (child == NULL)
return -ENOMEM;
- ec_parsed_add_child(state, child);
+ ec_parsed_link_child(state, child);
} else {
child = state;
}
free:
if (!is_root) {
- ec_parsed_del_child(state, child);
+ ec_parsed_unlink_child(state, child);
ec_parsed_free(child);
}
return ret;
dup_child = __ec_parsed_dup(child, ref, new_ref);
if (dup_child == NULL)
goto fail;
- ec_parsed_add_child(dup, dup_child);
+ ec_parsed_link_child(dup, dup_child);
}
return dup;
return NULL;
}
-struct ec_parsed *ec_parsed_dup(struct ec_parsed *parsed) //XXX const
+struct ec_parsed *ec_parsed_dup(const struct ec_parsed *parsed)
{
- struct ec_parsed *root, *dup_root, *dup = NULL;
+ const struct ec_parsed *root;
+ struct ec_parsed *dup_root, *dup = NULL;
root = ec_parsed_get_root(parsed);
dup_root = __ec_parsed_dup(root, parsed, &dup);
__ec_parsed_dump(out, parsed, 0);
}
-void ec_parsed_add_child(struct ec_parsed *parsed,
+void ec_parsed_link_child(struct ec_parsed *parsed,
struct ec_parsed *child)
{
TAILQ_INSERT_TAIL(&parsed->children, child, next);
child->parent = parsed;
}
-// XXX we can remove the first arg ? parsed == child->parent ?
-void ec_parsed_del_child(struct ec_parsed *parsed, // XXX rename del in unlink?
+void ec_parsed_unlink_child(struct ec_parsed *parsed,
struct ec_parsed *child)
{
TAILQ_REMOVE(&parsed->children, child, next);
return parsed->node;
}
-void ec_parsed_del_last_child(struct ec_parsed *parsed) // rename in free
+void ec_parsed_del_last_child(struct ec_parsed *parsed)
{
struct ec_parsed *child;
child = ec_parsed_get_last_child(parsed);
- ec_parsed_del_child(parsed, child);
+ ec_parsed_unlink_child(parsed, child);
ec_parsed_free(child);
}
-struct ec_parsed *ec_parsed_get_root(struct ec_parsed *parsed)
+struct ec_parsed *__ec_parsed_get_root(struct ec_parsed *parsed)
{
if (parsed == NULL)
return NULL;
return parsed;
}
-struct ec_parsed *ec_parsed_get_parent(struct ec_parsed *parsed)
+struct ec_parsed *ec_parsed_get_parent(const struct ec_parsed *parsed)
{
if (parsed == NULL)
return NULL;
*
*
*/
-struct ec_parsed *ec_parsed_dup(struct ec_parsed *parsed);
+struct ec_parsed *ec_parsed_dup(const struct ec_parsed *parsed);
/**
*
*
*
*/
-void ec_parsed_add_child(struct ec_parsed *parsed,
+void ec_parsed_link_child(struct ec_parsed *parsed,
struct ec_parsed *child);
/**
*
*
*
*/
-void ec_parsed_del_child(struct ec_parsed *parsed,
+void ec_parsed_unlink_child(struct ec_parsed *parsed,
struct ec_parsed *child);
+/* keep the const */
+#define ec_parsed_get_root(parsed) ({ \
+ const struct ec_parsed *p_ = parsed; /* check type */ \
+ struct ec_parsed *parsed_ = (struct ec_parsed *)parsed; \
+ typeof(parsed) res_; \
+ (void)p_; \
+ res_ = __ec_parsed_get_root(parsed_); \
+ res_; \
+})
+
/**
*
*
*
*/
-struct ec_parsed *ec_parsed_get_root(struct ec_parsed *parsed);
+struct ec_parsed *__ec_parsed_get_root(struct ec_parsed *parsed);
/**
*
*
*
*/
-struct ec_parsed *ec_parsed_get_parent(struct ec_parsed *parsed);
+struct ec_parsed *ec_parsed_get_parent(const struct ec_parsed *parsed);
/**
* Get the first child of a tree.
static char *get_node_help(const struct ec_completed_item *item)
{
const struct ec_completed_group *grp;
- struct ec_parsed *state; // XXX keep const with macro
+ const struct ec_parsed *state;
const struct ec_node *node;
char *help = NULL;
const char *node_help = NULL;