diff --git a/gencat/pdf.c b/gencat/pdf.c index bb411a5..8aa4378 100644 --- a/gencat/pdf.c +++ b/gencat/pdf.c @@ -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)