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