Date:2012-07-12 04:52:54 (11 years 8 months ago)
Author:Werner Almesberger
Commit:463e8dcac4a2f724a58dae7ea57dd600b8f8a2ef
Message: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.
Files: gencat/pdf.c (5 diffs)

Change Details

gencat/pdf.c
8989/* ----- Alphabetic index -------------------------------------------------- */
9090
9191
92static void collect_names(const struct node *node, const char ***idx, int *n)
92struct index {
93    const char *s;
94    const struct node *node;
95};
96
97
98static void collect_names(const struct node *node, struct index **idx, int *n)
9399{
94100    const struct name *name;
95101
...... 
99105        else {
100106            for (name = node->e->names; name; name = name->next) {
101107                (*n)++;
102                *idx = realloc(*idx, *n*sizeof(char *));
108                *idx = realloc(*idx, *n*sizeof(struct entry));
103109                if (!*idx)
104110                    abort();
105                (*idx)[*n-1] = name->s;
111                (*idx)[*n-1].s = name->s;
112                (*idx)[*n-1].node = node;
106113            }
107114        }
108115        node = node->next;
...... 
112119
113120static int comp(const void *a, const void *b)
114121{
115    return strcmp(*(const char **) a, *(const char **) b);
122    const struct index *ai = a;
123    const struct index *bi = b;
124
125    return strcmp(ai->s, bi->s);
116126}
117127
118128
119129static void make_index(FILE *file, const struct node *node)
120130{
121    const char **idx = NULL, **p;
131    struct index *idx = NULL;
132    const struct index *p;
122133    int n = 0;
123134    int line = 0, col = 0;
124135
125136    collect_names(node, &idx, &n);
126    qsort(idx, n, sizeof(char *), comp);
137    qsort(idx, n, sizeof(struct index), comp);
127138
128139    fprintf(file, "[ /Title (Index) /Count 0 /OUT pdfmark\n");
129140
...... 
147158            format.index.y+line*format.index_line_skip);
148159
149160        fprintf(file, "[ /Rect [ ");
150        ps_string(file, *p);
161        ps_string(file, p->s);
151162        fprintf(file, " false charpath flattenpath pathbbox ]\n");
152163        fprintf(file, " /Subtype /Link\n");
153164        fprintf(file, " /Border [ 0 0 0 ]\n");
154        fprintf(file, " /Action << /Subtype /GoTo /Dest /%p >>\n", *p);
165        fprintf(file, " /Action << /Subtype /GoTo /Dest /%p%p >>\n",
166            p->node, p->s);
155167        fprintf(file, " /ANN pdfmark\n");
156168
157169        fprintf(file, "moveto ");
158        ps_string(file, *p);
170        ps_string(file, p->s);
159171        fprintf(file, " show\n");
160172        line++;
161173    }
...... 
206218        ps_string(file, name->s);
207219        fprintf(file, " show\n");
208220        if (!unit)
209            fprintf(file, "[ /Dest /%p /DEST pdfmark\n", name->s);
221            fprintf(file, "[ /Dest /%p%p /DEST pdfmark\n",
222                node, name->s);
210223    }
211224    fprintf(file, "0 setgray\n");
212225    if (node->e->units > 1)

Archive Download the corresponding diff file

Branches:
master



interactive