1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-23 09:05:31 +02:00

b2/: move basic handling of variables from subex to param

This commit is contained in:
Werner Almesberger 2012-05-21 19:46:42 -03:00
parent c1b6b2a5e4
commit 4a3e517935
4 changed files with 45 additions and 39 deletions

View File

@ -10,8 +10,10 @@
*/
#include <stdlib.h>
#include <glib.h>
#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;
}
}

View File

@ -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 */

View File

@ -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;
}
}

View File

@ -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 */