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

eeshow/: support component aliases

This commit is contained in:
Werner Almesberger 2016-08-11 02:32:00 -03:00
parent 3e102752f6
commit 06d5a924c6
4 changed files with 65 additions and 7 deletions

View File

@ -36,7 +36,7 @@
/* ----- Components -------------------------------------------------------- */
static bool comp_lib_objs(const struct lib_obj *a, const struct lib_obj *b)
static bool comp_eq_objs(const struct lib_obj *a, const struct lib_obj *b)
{
/*
* @@@ over-simplify a little. We don't search to find objects that
@ -97,6 +97,19 @@ static bool comp_lib_objs(const struct lib_obj *a, const struct lib_obj *b)
}
static bool comp_eq_aliases(const struct comp_alias *a,
const struct comp_alias *b)
{
while (a && b) {
if (strcmp(a->name, b->name))
return 0;
a = a->next;
b = b->next;
}
return a == b;
}
static bool comp_eq(const struct comp *a, const struct comp *b)
{
if (a == b)
@ -113,7 +126,9 @@ static bool comp_eq(const struct comp *a, const struct comp *b)
return 0;
if (a->name_offset != b->name_offset)
return 0;
return comp_lib_objs(a->objs, b->objs);
if (!comp_eq_aliases(a->aliases, b->aliases))
return 0;
return comp_eq_objs(a->objs, b->objs);
}

View File

@ -78,6 +78,7 @@ static bool parse_def(struct lib *lib, const char *line)
s = tmp;
}
lib->curr_comp->name = s;
lib->curr_comp->aliases = NULL;
lib->curr_comp->units = units;
lib->curr_comp->visible = 0;
@ -133,6 +134,20 @@ static bool parse_arc(struct lib_obj *obj, const char *line)
}
/* ----- Aliases ----------------------------------------------------------- */
static void add_alias(struct comp *comp, const char *alias)
{
struct comp_alias *new;
new = alloc_type(struct comp_alias);
new->name = alias;
new->next = comp->aliases;
comp->aliases = new;
}
/* ----- Library parser ---------------------------------------------------- */
@ -143,7 +158,7 @@ static bool lib_parse_line(const struct file *file,
int n = 0;
unsigned points;
struct lib_obj *obj;
char *style;
char *s, *style;
unsigned zero1, zero2;
char vis;
@ -166,6 +181,10 @@ static bool lib_parse_line(const struct file *file,
lib->curr_comp->visible |= 1 << n;
return 1;
}
if (sscanf(line, "ALIAS %ms", &s) == 1) {
add_alias(lib->curr_comp, s);
return 1;
}
/* @@@ explicitly ignore FPLIST */
return 1;
case lib_draw:
@ -309,14 +328,27 @@ static void free_objs(struct lib_obj *objs)
}
static void free_comp(struct comp *comp)
{
struct comp_alias *next;
free((char *) comp->name);
while (comp->aliases) {
next = comp->aliases->next;
free((char *) comp->aliases->name);
comp->aliases = next;
}
free_objs(comp->objs);
free(comp);
}
void lib_free(struct lib *lib)
{
struct comp *comp, *next;
for (comp = lib->comps; comp; comp = next) {
next = comp->next;
free((char *) comp->name);
free_objs(comp->objs);
free(comp);
free_comp(comp);
}
}

View File

@ -367,10 +367,15 @@ static void draw(const struct comp *comp, const struct lib_obj *obj,
const struct comp *lib_find(const struct lib *lib, const char *name)
{
const struct comp *comp;
const struct comp_alias *alias;
for (comp = lib->comps; comp; comp = comp->next)
for (comp = lib->comps; comp; comp = comp->next) {
if (!strcmp(comp->name, name))
return comp;
for (alias = comp->aliases; alias; alias = alias->next)
if (!strcmp(alias->name, name))
return comp;
}
fprintf(stderr, "\"%s\" not found\n", name);
exit(1);
}

View File

@ -87,8 +87,14 @@ struct lib_obj {
struct lib_obj *next;
};
struct comp_alias {
const char *name;
struct comp_alias *next;
};
struct comp {
const char *name;
struct comp_alias *aliases;
unsigned units;
unsigned visible; /* visible fields, bit mask */