summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--delta.c19
-rw-r--r--lib-parse.c40
-rw-r--r--lib-render.c7
-rw-r--r--lib.h6
4 files changed, 65 insertions, 7 deletions
diff --git a/delta.c b/delta.c
index 6e309ba..f407019 100644
--- a/delta.c
+++ b/delta.c
@@ -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);
}
diff --git a/lib-parse.c b/lib-parse.c
index 0a19728..955454a 100644
--- a/lib-parse.c
+++ b/lib-parse.c
@@ -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);
}
}
diff --git a/lib-render.c b/lib-render.c
index fe20c9a..297f60b 100644
--- a/lib-render.c
+++ b/lib-render.c
@@ -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);
}
diff --git a/lib.h b/lib.h
index 4a902fe..e04c05f 100644
--- a/lib.h
+++ b/lib.h
@@ -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 */