};
typedef struct cond_result *(cond_func_t)(
- const struct ec_pnode *state,
+ const struct ec_pnode *pstate,
struct cond_result **in, size_t in_len);
-void cond_result_free(struct cond_result *res)
+static void
+cond_result_free(struct cond_result *res)
{
if (res == NULL)
return;
ec_free(res);
}
-void cond_result_table_free(struct cond_result **table, size_t len)
+static void
+cond_result_table_free(struct cond_result **table, size_t len)
{
size_t i;
errno = EINVAL;
goto fail;
}
- if (!ec_pnode_has_child(p)) {
- errno = EINVAL;
- goto fail;
- }
return p;
}
static struct cond_result *
-eval_root(const struct ec_pnode *state, struct cond_result **in, size_t in_len)
+eval_root(const struct ec_pnode *pstate, struct cond_result **in, size_t in_len)
{
struct cond_result *out = NULL;
const struct ec_pnode *root = NULL;
if (out->htable == NULL)
goto fail;
- root = ec_pnode_get_root(state);
+ root = EC_PNODE_GET_ROOT(pstate);
if (ec_htable_set(out->htable, &root, sizeof(root), NULL, NULL) < 0)
goto fail;
}
static struct cond_result *
-eval_current(const struct ec_pnode *state, struct cond_result **in,
+eval_current(const struct ec_pnode *pstate, struct cond_result **in,
size_t in_len)
{
struct cond_result *out = NULL;
if (out->htable == NULL)
goto fail;
- if (ec_htable_set(out->htable, &state, sizeof(state), NULL, NULL) < 0)
+ if (ec_htable_set(out->htable, &pstate, sizeof(pstate), NULL, NULL) < 0)
goto fail;
cond_result_table_free(in, in_len);
}
static struct cond_result *
-eval_bool(const struct ec_pnode *state, struct cond_result **in, size_t in_len)
+eval_bool(const struct ec_pnode *pstate, struct cond_result **in, size_t in_len)
{
struct cond_result *out = NULL;
- (void)state;
+ (void)pstate;
if (in_len != 1) {
EC_LOG(LOG_ERR, "bool() takes one argument.\n");
}
static struct cond_result *
-eval_or(const struct ec_pnode *state, struct cond_result **in, size_t in_len)
+eval_or(const struct ec_pnode *pstate, struct cond_result **in, size_t in_len)
{
struct cond_result *out = NULL;
size_t i;
- (void)state;
+ (void)pstate;
if (in_len < 2) {
EC_LOG(LOG_ERR, "or() takes at least two arguments\n");
}
static struct cond_result *
-eval_and(const struct ec_pnode *state, struct cond_result **in, size_t in_len)
+eval_and(const struct ec_pnode *pstate, struct cond_result **in, size_t in_len)
{
struct cond_result *out = NULL;
size_t i;
- (void)state;
+ (void)pstate;
if (in_len < 2) {
EC_LOG(LOG_ERR, "or() takes at least two arguments\n");
}
static struct cond_result *
-eval_first_child(const struct ec_pnode *state, struct cond_result **in,
+eval_first_child(const struct ec_pnode *pstate, struct cond_result **in,
size_t in_len)
{
struct cond_result *out = NULL;
const struct ec_pnode * const *pparse;
struct ec_pnode *parse;
- (void)state;
+ (void)pstate;
if (in_len != 1 || in[0]->type != NODESET) {
EC_LOG(LOG_ERR, "first_child() takes one argument of type nodeset.\n");
}
static struct cond_result *
-eval_find(const struct ec_pnode *state, struct cond_result **in,
+eval_find(const struct ec_pnode *pstate, struct cond_result **in,
size_t in_len)
{
struct cond_result *out = NULL;
struct ec_pnode *parse;
const char *id;
- (void)state;
+ (void)pstate;
if (in_len != 2 || in[0]->type != NODESET || in[1]->type != STR) {
EC_LOG(LOG_ERR, "find() takes two arguments (nodeset, str).\n");
}
static struct cond_result *
-eval_cmp(const struct ec_pnode *state, struct cond_result **in,
+eval_cmp(const struct ec_pnode *pstate, struct cond_result **in,
size_t in_len)
{
struct cond_result *out = NULL;
struct ec_htable_elt_ref *iter;
bool eq = false, gt = false;
- (void)state;
+ (void)pstate;
if (in_len != 3 || in[0]->type != STR || in[1]->type != in[2]->type) {
EC_LOG(LOG_ERR, "cmp() takes 3 arguments (str, <type>, <type>).\n");
}
static struct cond_result *
-eval_count(const struct ec_pnode *state, struct cond_result **in, size_t in_len)
+eval_count(const struct ec_pnode *pstate, struct cond_result **in, size_t in_len)
{
struct cond_result *out = NULL;
- (void)state;
+ (void)pstate;
if (in_len != 1 || in[0]->type != NODESET) {
EC_LOG(LOG_ERR, "count() takes one argument of type nodeset.\n");
}
static struct cond_result *
-eval_func(const char *name, const struct ec_pnode *state,
+eval_func(const char *name, const struct ec_pnode *pstate,
struct cond_result **in, size_t in_len)
{
cond_func_t *f;
return NULL;
}
- return f(state, in, in_len);
+ return f(pstate, in, in_len);
}
static struct cond_result *
-eval_condition(const struct ec_pnode *cond, const struct ec_pnode *state)
+eval_condition(const struct ec_pnode *cond, const struct ec_pnode *pstate)
{
const struct ec_pnode *iter;
struct cond_result *res = NULL;
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);
+ args[n_arg] = eval_condition(iter, pstate);
if (args[n_arg] == NULL)
goto fail;
n_arg++;
(void *)iter, "id_arg", 0);
}
- res = eval_func(ec_strvec_val(ec_pnode_strvec(func_name), 0),
- state, args, n_arg);
+ res = eval_func(ec_strvec_val(ec_pnode_get_strvec(func_name), 0),
+ pstate, args, n_arg);
args = NULL;
return res;
}
if (res == NULL)
goto fail;
res->type = STR;
- res->str = ec_strdup(ec_strvec_val(ec_pnode_strvec(value), 0));
+ res->str = ec_strdup(ec_strvec_val(ec_pnode_get_strvec(value), 0));
if (res->str == NULL)
goto fail;
return res;
if (res == NULL)
goto fail;
res->type = INT;
- if (ec_str_parse_llint(ec_strvec_val(ec_pnode_strvec(value), 0),
+ if (ec_str_parse_llint(ec_strvec_val(ec_pnode_get_strvec(value), 0),
0, LLONG_MIN, LLONG_MAX,
&res->int64) < 0)
goto fail;
}
static int
-validate_condition(const struct ec_pnode *cond, const struct ec_pnode *state)
+validate_condition(const struct ec_pnode *cond, const struct ec_pnode *pstate)
{
struct cond_result *res;
int ret;
- res = eval_condition(cond, state);
+ res = eval_condition(cond, pstate);
if (res == NULL)
return -1;
}
static int
-ec_node_cond_parse(const struct ec_node *node, struct ec_pnode *state,
+ec_node_cond_parse(const struct ec_node *node, struct ec_pnode *pstate,
const struct ec_strvec *strvec)
{
struct ec_node_cond *priv = ec_node_priv(node);
struct ec_pnode *child;
int ret, valid;
- ret = ec_parse_child(priv->child, state, strvec);
+ ret = ec_parse_child(priv->child, pstate, strvec);
if (ret <= 0)
return ret;
- valid = validate_condition(priv->parsed_cond, state);
+ valid = validate_condition(priv->parsed_cond, pstate);
if (valid < 0)
return valid;
if (valid == 0) {
- child = ec_pnode_get_last_child(state);
- ec_pnode_unlink_child(state, child);
+ child = ec_pnode_get_last_child(pstate);
+ ec_pnode_unlink_child(child);
ec_pnode_free(child);
return EC_PARSE_NOMATCH;
}