1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-22 15:49:22 +02:00

b2/param.c: new function merge_vars to merge prioritized lists of variables

This commit is contained in:
Werner Almesberger 2012-05-24 00:05:21 -03:00
parent 5fb156ab93
commit 1e21ea8a40
2 changed files with 33 additions and 0 deletions

View File

@ -144,6 +144,38 @@ const char *var_lookup(const struct param *vars, const char *name)
}
/*
* The variables in list "a" have lower priority than those in list "b",
* i.e., a variable in "a" is only picked if there is no variable with the
* same name in "b".
*/
struct param *merge_vars(const struct param *a, const struct param *b)
{
const struct param *v;
struct param *res, **last = &res;
while (a) {
for (v = b; v; v = v->next)
if (a->u.name == v->u.name)
break;
if (!v) {
*last = alloc_type(struct param);
**last = *a;
last = &(*last)->next;
}
a = a->next;
}
for (v = b; v; v = v->next) {
*last = alloc_type(struct param);
**last = *v;
last = &(*last)->next;
}
*last = NULL;
return res;
}
void free_vars(struct param *vars)
{
struct param *next;

View File

@ -120,6 +120,7 @@ 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);
struct param *merge_vars(const struct param *a, const struct param *b);
void free_vars(struct param *vars);
#endif /* !PARAM_H */