mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-26 10:57:32 +02:00
gencat/: keep "struct entry" ptr in "struct node" instead of duplicating content
This commit is contained in:
parent
6e0015cdd6
commit
1b6bf60c56
@ -21,21 +21,15 @@
|
||||
#include "libs.h"
|
||||
|
||||
|
||||
const char *lookup_sym(const struct lib *lib, const char *name,
|
||||
const struct name **names, int *units)
|
||||
const struct entry *lookup_sym(const struct lib *lib, const char *name)
|
||||
{
|
||||
const struct file *file;
|
||||
const struct entry *e;
|
||||
|
||||
for (file = lib->files; file; file = file->next)
|
||||
for (e = file->entries; e; e = e->next)
|
||||
if (!strcasecmp(e->names->s, name)) {
|
||||
if (names)
|
||||
*names = e->names;
|
||||
if (units)
|
||||
*units = e->units;
|
||||
return file->path;
|
||||
}
|
||||
if (!strcasecmp(e->names->s, name))
|
||||
return e;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,7 @@ struct lib {
|
||||
extern struct lib comp_lib;
|
||||
|
||||
|
||||
const char *lookup_sym(const struct lib *lib, const char *name,
|
||||
const struct name **names, int *units);
|
||||
const struct entry *lookup_sym(const struct lib *lib, const char *name);
|
||||
void add_name(struct entry *e, char *s);
|
||||
struct entry *new_entry(struct lib *lib, int units);
|
||||
void add_lib(struct lib *lib, const char *path);
|
||||
|
17
gencat/pdf.c
17
gencat/pdf.c
@ -117,7 +117,7 @@ static void collect_names(const struct node *node, const char ***idx, int *n)
|
||||
if (node->child)
|
||||
collect_names(node->child, idx, n);
|
||||
else {
|
||||
for (name = node->names; name; name = name->next) {
|
||||
for (name = node->e->names; name; name = name->next) {
|
||||
(*n)++;
|
||||
*idx = realloc(*idx, *n*sizeof(char *));
|
||||
if (!*idx)
|
||||
@ -224,8 +224,8 @@ 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);
|
||||
for (name = node->names; name; name = name->next) {
|
||||
if (name != node->names)
|
||||
for (name = node->e->names; name; name = name->next) {
|
||||
if (name != node->e->names)
|
||||
fprintf(file, "(, ) show 0.5 setgray\n");
|
||||
ps_string(file, name->s);
|
||||
fprintf(file, " show\n");
|
||||
@ -235,7 +235,7 @@ static void make_title(FILE *file, const struct node *node, int unit)
|
||||
free(s);
|
||||
}
|
||||
fprintf(file, "0 setgray\n");
|
||||
if (node->units > 1)
|
||||
if (node->e->units > 1)
|
||||
fprintf(file, " ( \\(%c\\)) show\n", 'A'+unit);
|
||||
|
||||
fprintf(file, "/%s findfont %d scalefont setfont\n",
|
||||
@ -246,7 +246,7 @@ static void make_title(FILE *file, const struct node *node, int unit)
|
||||
fprintf(file, "/%s findfont %d scalefont setfont\n",
|
||||
format.lib.font, format.lib.size);
|
||||
fprintf(file, "%d %d moveto\n", format.left, -format.lib.y);
|
||||
ps_string(file, node->lib);
|
||||
ps_string(file, node->e->file->path);
|
||||
fprintf(file, " show\n");
|
||||
|
||||
fprintf(file, "grestore\n");
|
||||
@ -313,7 +313,7 @@ static void convert_comp(const struct node *node, FILE *out)
|
||||
char *tmp;
|
||||
int i, res;
|
||||
|
||||
for (i = 0; i != node->units; i++) {
|
||||
for (i = 0; i != node->e->units; i++) {
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "\r%u/%u", ++done, total);
|
||||
fflush(stderr);
|
||||
@ -322,7 +322,8 @@ 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->names->s, i+1, "tmp", "tmp.ps") < 0) {
|
||||
node->e->file->path, node->e->names->s, i+1,
|
||||
"tmp", "tmp.ps") < 0) {
|
||||
perror("asprintf");
|
||||
exit(1);
|
||||
}
|
||||
@ -367,7 +368,7 @@ static int count_tree(const struct node *node)
|
||||
if (node->child)
|
||||
sum += count_tree(node->child);
|
||||
else
|
||||
sum += node->units;
|
||||
sum += node->e->units;
|
||||
node = node->next;
|
||||
}
|
||||
return sum;
|
||||
|
@ -68,7 +68,7 @@ next:
|
||||
name[e-s+1] = 0;
|
||||
node = alloc_type(struct node);
|
||||
node->name = name;
|
||||
node->lib = NULL;
|
||||
node->e = NULL;
|
||||
node->comment = NULL;
|
||||
node->indent = n;
|
||||
node->child = node->next = NULL;
|
||||
@ -208,9 +208,8 @@ void set_libs(struct node *node)
|
||||
{
|
||||
while (node) {
|
||||
if (!node->child) {
|
||||
node->lib = lookup_sym(&comp_lib, node->name,
|
||||
&node->names, &node->units);
|
||||
if (!node->lib) {
|
||||
node->e = lookup_sym(&comp_lib, node->name);
|
||||
if (!node->e) {
|
||||
fprintf(stderr, "symbol %s not found\n",
|
||||
node->name);
|
||||
exit(1);
|
||||
@ -230,10 +229,10 @@ static void dump_tree_level(const struct node *tree, int level)
|
||||
|
||||
for (n = tree; n; n = n->next) {
|
||||
printf("%*s%s", 4*level, "", n->name);
|
||||
if (n->lib) {
|
||||
for (name = n->names; name; name = name->next)
|
||||
if (n->e) {
|
||||
for (name = n->e->names; name; name = name->next)
|
||||
printf("%s%s",
|
||||
name == n->names ? " (" : ", ", name->s);
|
||||
name == n->e->names ? " (" : ", ", name->s);
|
||||
printf(")");
|
||||
}
|
||||
printf("\n");
|
||||
@ -255,8 +254,8 @@ static void dump_comp_level(const struct node *tree)
|
||||
const struct node *n;
|
||||
|
||||
for (n = tree; n; n = n->next) {
|
||||
if (n->lib)
|
||||
printf("%s\n", n->names->s);
|
||||
if (n->e)
|
||||
printf("%s\n", n->e->names->s);
|
||||
dump_comp_level(n->child);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,9 @@
|
||||
#ifndef TREE_H
|
||||
#define TREE_H
|
||||
|
||||
#include "libs.h"
|
||||
|
||||
|
||||
struct line {
|
||||
char *s;
|
||||
struct line *next;
|
||||
@ -19,10 +22,7 @@ struct line {
|
||||
|
||||
struct node {
|
||||
const char *name;
|
||||
const char *lib; /* NULL if intermediate node */
|
||||
const struct name *names;
|
||||
/* canonical name and aliases of component */
|
||||
int units; /* number of units; undefined if intermediate */
|
||||
const struct entry *e; /* NULL if intermediate node */
|
||||
struct line *comment; /* NULL if intermediate node */
|
||||
int indent; /* level of indentation (characters) */
|
||||
struct node *parent;
|
||||
|
Loading…
Reference in New Issue
Block a user