diff --git a/b2/param.c b/b2/param.c index ef9bf89..64855cc 100644 --- a/b2/param.c +++ b/b2/param.c @@ -10,8 +10,10 @@ */ +#include #include +#include "util.h" #include "lang.h" #include "param.h" @@ -113,3 +115,42 @@ MKOPS(name); MKOPS(set); MKOPS(abs); MKOPS(rel); + + +/* ----- Parameters as general-purpose (string) variables ------------------ */ + + +struct param *make_var(const char *name, enum relop op, const char *val) +{ + struct param *var; + + var = alloc_type(struct param); + var->u.name = unique(name); + var->op = op; + var->value.u.s = unique(val); + var->next = NULL; + return var; +} + + +const char *var_lookup(const struct param *vars, const char *name) +{ + while (vars) { + if (vars->u.name == name) + return vars->value.u.s; + vars = vars->next; + } + return NULL; +} + + +void free_vars(struct param *vars) +{ + struct param *next; + + while (vars) { + next = vars->next; + free(vars); + vars = next; + } +} diff --git a/b2/param.h b/b2/param.h index 8369ffd..09561d8 100644 --- a/b2/param.h +++ b/b2/param.h @@ -116,4 +116,8 @@ extern const struct param_ops param_ops_set; extern const struct param_ops param_ops_abs; extern const struct param_ops param_ops_rel; +struct param *make_var(const char *name, enum relop op, const char *val); +const char *var_lookup(const struct param *vars, const char *name); +void free_vars(struct param *vars); + #endif /* !PARAM_H */ diff --git a/b2/subex.c b/b2/subex.c index 7826460..97b8342 100644 --- a/b2/subex.c +++ b/b2/subex.c @@ -135,19 +135,6 @@ static char *compose(const struct chunk *c, } -struct param *make_var(const char *name, enum relop op, const char *val) -{ - struct param *var; - - var = alloc_type(struct param); - var->u.name = unique(name); - var->op = op; - var->value.u.s = unique(val); - var->next = NULL; - return var; -} - - static void do_assign(const char *name, struct param **out, enum relop op, const char *val) { @@ -250,26 +237,3 @@ struct param *substitute(const struct subst *sub, const struct param *in) recurse_sub(sub, in, NULL, NULL, NULL, &out); return out; } - - -const char *var_lookup(const struct param *vars, const char *name) -{ - while (vars) { - if (vars->u.name == name) - return vars->value.u.s; - vars = vars->next; - } - return NULL; -} - - -void free_vars(struct param *vars) -{ - struct param *next; - - while (vars) { - next = vars->next; - free(vars); - vars = next; - } -} diff --git a/b2/subex.h b/b2/subex.h index cd2f090..e280bdc 100644 --- a/b2/subex.h +++ b/b2/subex.h @@ -18,8 +18,5 @@ struct param *substitute(const struct subst *sub, const struct param *in); -struct param *make_var(const char *name, enum relop op, const char *val); -const char *var_lookup(const struct param *vars, const char *name); -void free_vars(struct param *vars); #endif /* !SUBEX_H */