mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-25 22:55:20 +02:00
b2/param.c: new function merge_vars to merge prioritized lists of variables
This commit is contained in:
parent
5fb156ab93
commit
1e21ea8a40
32
b2/param.c
32
b2/param.c
@ -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)
|
void free_vars(struct param *vars)
|
||||||
{
|
{
|
||||||
struct param *next;
|
struct param *next;
|
||||||
|
@ -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);
|
struct param *make_var(const char *name, enum relop op, const char *val);
|
||||||
const char *var_lookup(const struct param *vars, const char *name);
|
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);
|
void free_vars(struct param *vars);
|
||||||
|
|
||||||
#endif /* !PARAM_H */
|
#endif /* !PARAM_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user