diff --git a/genex/comp.c b/genex/comp.c index 8c8496f..253b2be 100644 --- a/genex/comp.c +++ b/genex/comp.c @@ -200,13 +200,13 @@ void read_desc(FILE *file) void set_libs(struct node *node, - const char *(*find_lib)(const char *sym, const char **canon, + const char *(*find_lib)(const char *sym, const struct name **names, int *units)) { while (node) { if (!node->child) { node->lib = - find_lib(node->name, &node->canon, &node->units); + find_lib(node->name, &node->names, &node->units); if (!node->lib) { fprintf(stderr, "symbol %s not found\n", node->name); @@ -223,9 +223,17 @@ static void dump_level(const struct node *tree, int level) { const struct node *n; const struct line *line; + const struct name *name; for (n = tree; n; n = n->next) { - printf("%*s%s\n", 4*level, "", n->name); + printf("%*s%s", 4*level, "", n->name); + if (n->lib) { + for (name = n->names; name; name = name->next) + printf("%s%s", + name == n->names ? " (" : ", ", name->s); + printf(")"); + } + printf("\n"); for (line = n->comment; line; line = line->next) printf("%*s\"%s\"\n", 4*level+2, "", line->s); dump_level(n->child, level+1); diff --git a/genex/comp.h b/genex/comp.h index d40bc69..e31338a 100644 --- a/genex/comp.h +++ b/genex/comp.h @@ -12,6 +12,9 @@ #ifndef COMP_H #define COMP_H +#include "libs.h" + + struct line { char *s; struct line *next; @@ -20,7 +23,8 @@ struct line { struct node { const char *name; const char *lib; /* NULL if intermediate node */ - const char *canon; /* canonical name of component */ + const struct name *names; + /* canonical name and aliases of component */ int units; /* number of units; undefined if intermediate */ struct line *comment; /* NULL if intermediate node */ int indent; /* level of indentation (characters) */ @@ -36,7 +40,7 @@ extern struct node *tree; void read_tree(FILE *file); void read_desc(FILE *file); void set_libs(struct node *node, - const char *(*find_lib)(const char *sym, const char **canon, + const char *(*find_lib)(const char *sym, const struct name **names, int *units)); void dump_tree(void); diff --git a/genex/libs.c b/genex/libs.c index 0588fcb..58c287d 100644 --- a/genex/libs.c +++ b/genex/libs.c @@ -22,7 +22,7 @@ struct entry { - const char *name; + struct name *names; int units; struct entry *next; }; @@ -34,16 +34,16 @@ static struct lib { } *libs = NULL; -const char *lookup_sym(const char *name, const char **canon, int *units) +const char *lookup_sym(const char *name, const struct name **names, int *units) { const struct lib *lib; const struct entry *e; for (lib = libs; lib; lib = lib->next) for (e = lib->comps; e; e = e->next) - if (!strcasecmp(e->name, name)) { - if (canon) - *canon = e->name; + if (!strcasecmp(e->names->s, name)) { + if (names) + *names = e->names; if (units) *units = e->units; return lib->path; @@ -64,11 +64,26 @@ static const char *field(const char *s, int n) } +static void add_name(struct entry *e, char *s) +{ + char *nl; + struct name **p; + + nl = strchr(s, '\n'); + if (nl) + *nl = 0; + for (p = &e->names; *p; p = &(*p)->next); + *p = alloc_type(struct name); + (*p)->s = stralloc(s); + (*p)->next = NULL; +} + + void add_lib(const char *path) { FILE *file; struct lib *lib; - struct entry *e; + struct entry *e = NULL; char buf[1024]; /* @@@ */ char *spc; const char *s; @@ -86,6 +101,8 @@ void add_lib(const char *path) libs = lib; while (fgets(buf, sizeof(buf), file)) { + if (!strncmp(buf, "ALIAS ", 6) && e) + add_name(e, buf+6); if (strncmp(buf, "DEF ", 4)) continue; s = field(buf, 7); @@ -101,7 +118,8 @@ void add_lib(const char *path) } *spc = 0; e = alloc_type(struct entry); - e->name = stralloc(buf+4); + e->names = NULL; + add_name(e, buf+4); e->units = atoi(s); if (!e->units) { fprintf(stderr, "invalid number of units in %s\n", diff --git a/genex/libs.h b/genex/libs.h index 71ba1a0..35a7b46 100644 --- a/genex/libs.h +++ b/genex/libs.h @@ -12,7 +12,12 @@ #ifndef LIBS_H #define LIBS_H -const char *lookup_sym(const char *name, const char **canon, int *units); +struct name { + const char *s; + struct name *next; +}; + +const char *lookup_sym(const char *name, const struct name **names, int *units); void add_lib(const char *path); void add_libdir(const char *path); diff --git a/genex/pdf.c b/genex/pdf.c index 9a9f5a8..a464007 100644 --- a/genex/pdf.c +++ b/genex/pdf.c @@ -95,7 +95,7 @@ static void make_title(FILE *file, const struct node *node, int unit) fprintf(file, "/%s findfont %d scalefont setfont\n", format.name.font, format.name.size); fprintf(file, "%d %d moveto\n", format.left, -format.name.y); - ps_string(file, node->canon); + ps_string(file, node->names->s); fprintf(file, " show\n"); if (node->units > 1) fprintf(file, " ( \\(%c\\)) show\n", 'A'+unit); @@ -177,7 +177,7 @@ static void convert_comp(const struct node *node, FILE *out) if (!i && node->comment) print_comment(out, node->comment); if (asprintf(&tmp, "./sym2xps '%s' '%s' %d '%s' '%s'", - node->lib, node->canon, i+1, "tmp", "tmp.ps") < 0) { + node->lib, node->names->s, i+1, "tmp", "tmp.ps") < 0) { perror("asprintf"); exit(1); }