1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-29 17:10:17 +02:00

gencat/pdf.c: key index entries by the tree node, to distinguish duplicates

Before, duplicate names in the tree always pointed to the same page.
Now they point to the respective locations.

Note that this does not affect handling of duplicate names in libraries,
where still only one "wins" while the other is completely ignored.
This commit is contained in:
Werner Almesberger 2012-07-11 23:52:54 -03:00
parent 605585ffdb
commit 463e8dcac4

View File

@ -89,7 +89,13 @@ static void ps_string(FILE *file, const char *s)
/* ----- Alphabetic index -------------------------------------------------- */
static void collect_names(const struct node *node, const char ***idx, int *n)
struct index {
const char *s;
const struct node *node;
};
static void collect_names(const struct node *node, struct index **idx, int *n)
{
const struct name *name;
@ -99,10 +105,11 @@ static void collect_names(const struct node *node, const char ***idx, int *n)
else {
for (name = node->e->names; name; name = name->next) {
(*n)++;
*idx = realloc(*idx, *n*sizeof(char *));
*idx = realloc(*idx, *n*sizeof(struct entry));
if (!*idx)
abort();
(*idx)[*n-1] = name->s;
(*idx)[*n-1].s = name->s;
(*idx)[*n-1].node = node;
}
}
node = node->next;
@ -112,18 +119,22 @@ static void collect_names(const struct node *node, const char ***idx, int *n)
static int comp(const void *a, const void *b)
{
return strcmp(*(const char **) a, *(const char **) b);
const struct index *ai = a;
const struct index *bi = b;
return strcmp(ai->s, bi->s);
}
static void make_index(FILE *file, const struct node *node)
{
const char **idx = NULL, **p;
struct index *idx = NULL;
const struct index *p;
int n = 0;
int line = 0, col = 0;
collect_names(node, &idx, &n);
qsort(idx, n, sizeof(char *), comp);
qsort(idx, n, sizeof(struct index), comp);
fprintf(file, "[ /Title (Index) /Count 0 /OUT pdfmark\n");
@ -147,15 +158,16 @@ static void make_index(FILE *file, const struct node *node)
format.index.y+line*format.index_line_skip);
fprintf(file, "[ /Rect [ ");
ps_string(file, *p);
ps_string(file, p->s);
fprintf(file, " false charpath flattenpath pathbbox ]\n");
fprintf(file, " /Subtype /Link\n");
fprintf(file, " /Border [ 0 0 0 ]\n");
fprintf(file, " /Action << /Subtype /GoTo /Dest /%p >>\n", *p);
fprintf(file, " /Action << /Subtype /GoTo /Dest /%p%p >>\n",
p->node, p->s);
fprintf(file, " /ANN pdfmark\n");
fprintf(file, "moveto ");
ps_string(file, *p);
ps_string(file, p->s);
fprintf(file, " show\n");
line++;
}
@ -206,7 +218,8 @@ static void make_title(FILE *file, const struct node *node, int unit)
ps_string(file, name->s);
fprintf(file, " show\n");
if (!unit)
fprintf(file, "[ /Dest /%p /DEST pdfmark\n", name->s);
fprintf(file, "[ /Dest /%p%p /DEST pdfmark\n",
node, name->s);
}
fprintf(file, "0 setgray\n");
if (node->e->units > 1)