1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-09-29 01:00:44 +03:00

genex: add parsing and dumping of alias names

This commit is contained in:
Werner Almesberger 2012-04-17 08:45:20 -03:00
parent 72846f1879
commit db903c10ba
5 changed files with 50 additions and 15 deletions

View File

@ -200,13 +200,13 @@ void read_desc(FILE *file)
void set_libs(struct node *node, 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)) int *units))
{ {
while (node) { while (node) {
if (!node->child) { if (!node->child) {
node->lib = node->lib =
find_lib(node->name, &node->canon, &node->units); find_lib(node->name, &node->names, &node->units);
if (!node->lib) { if (!node->lib) {
fprintf(stderr, "symbol %s not found\n", fprintf(stderr, "symbol %s not found\n",
node->name); node->name);
@ -223,9 +223,17 @@ static void dump_level(const struct node *tree, int level)
{ {
const struct node *n; const struct node *n;
const struct line *line; const struct line *line;
const struct name *name;
for (n = tree; n; n = n->next) { 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) for (line = n->comment; line; line = line->next)
printf("%*s\"%s\"\n", 4*level+2, "", line->s); printf("%*s\"%s\"\n", 4*level+2, "", line->s);
dump_level(n->child, level+1); dump_level(n->child, level+1);

View File

@ -12,6 +12,9 @@
#ifndef COMP_H #ifndef COMP_H
#define COMP_H #define COMP_H
#include "libs.h"
struct line { struct line {
char *s; char *s;
struct line *next; struct line *next;
@ -20,7 +23,8 @@ struct line {
struct node { struct node {
const char *name; const char *name;
const char *lib; /* NULL if intermediate node */ 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 */ int units; /* number of units; undefined if intermediate */
struct line *comment; /* NULL if intermediate node */ struct line *comment; /* NULL if intermediate node */
int indent; /* level of indentation (characters) */ int indent; /* level of indentation (characters) */
@ -36,7 +40,7 @@ extern struct node *tree;
void read_tree(FILE *file); void read_tree(FILE *file);
void read_desc(FILE *file); void read_desc(FILE *file);
void set_libs(struct node *node, 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)); int *units));
void dump_tree(void); void dump_tree(void);

View File

@ -22,7 +22,7 @@
struct entry { struct entry {
const char *name; struct name *names;
int units; int units;
struct entry *next; struct entry *next;
}; };
@ -34,16 +34,16 @@ static struct lib {
} *libs = NULL; } *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 lib *lib;
const struct entry *e; const struct entry *e;
for (lib = libs; lib; lib = lib->next) for (lib = libs; lib; lib = lib->next)
for (e = lib->comps; e; e = e->next) for (e = lib->comps; e; e = e->next)
if (!strcasecmp(e->name, name)) { if (!strcasecmp(e->names->s, name)) {
if (canon) if (names)
*canon = e->name; *names = e->names;
if (units) if (units)
*units = e->units; *units = e->units;
return lib->path; 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) void add_lib(const char *path)
{ {
FILE *file; FILE *file;
struct lib *lib; struct lib *lib;
struct entry *e; struct entry *e = NULL;
char buf[1024]; /* @@@ */ char buf[1024]; /* @@@ */
char *spc; char *spc;
const char *s; const char *s;
@ -86,6 +101,8 @@ void add_lib(const char *path)
libs = lib; libs = lib;
while (fgets(buf, sizeof(buf), file)) { while (fgets(buf, sizeof(buf), file)) {
if (!strncmp(buf, "ALIAS ", 6) && e)
add_name(e, buf+6);
if (strncmp(buf, "DEF ", 4)) if (strncmp(buf, "DEF ", 4))
continue; continue;
s = field(buf, 7); s = field(buf, 7);
@ -101,7 +118,8 @@ void add_lib(const char *path)
} }
*spc = 0; *spc = 0;
e = alloc_type(struct entry); e = alloc_type(struct entry);
e->name = stralloc(buf+4); e->names = NULL;
add_name(e, buf+4);
e->units = atoi(s); e->units = atoi(s);
if (!e->units) { if (!e->units) {
fprintf(stderr, "invalid number of units in %s\n", fprintf(stderr, "invalid number of units in %s\n",

View File

@ -12,7 +12,12 @@
#ifndef LIBS_H #ifndef LIBS_H
#define 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_lib(const char *path);
void add_libdir(const char *path); void add_libdir(const char *path);

View File

@ -95,7 +95,7 @@ static void make_title(FILE *file, const struct node *node, int unit)
fprintf(file, "/%s findfont %d scalefont setfont\n", fprintf(file, "/%s findfont %d scalefont setfont\n",
format.name.font, format.name.size); format.name.font, format.name.size);
fprintf(file, "%d %d moveto\n", format.left, -format.name.y); 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"); fprintf(file, " show\n");
if (node->units > 1) if (node->units > 1)
fprintf(file, " ( \\(%c\\)) show\n", 'A'+unit); 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) if (!i && node->comment)
print_comment(out, node->comment); print_comment(out, node->comment);
if (asprintf(&tmp, "./sym2xps '%s' '%s' %d '%s' '%s'", 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"); perror("asprintf");
exit(1); exit(1);
} }