1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
Subject: Sort anchors by sequence number in -dump
Origin: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=657666
From: "Conrad J.C. Hughes (for Debian package stuff)" <debbugs@xrad.org>
Resolved merge conflicts by Tatsuya Kinoshita.
--- a/main.c
+++ b/main.c
@@ -1269,6 +1269,12 @@ dump_extra(Buffer *buf)
#endif
}
+static int
+cmp_anchor_hseq(const void *a, const void *b)
+{
+ return (*((const Anchor **) a))->hseq - (*((const Anchor **) b))->hseq;
+}
+
static void
do_dump(Buffer *buf)
{
@@ -1289,15 +1295,20 @@ do_dump(Buffer *buf)
int i;
saveBuffer(buf, stdout, FALSE);
if (displayLinkNumber && buf->href) {
+ int nanchor = buf->href->nanchor;
printf("\nReferences:\n\n");
- for (i = 0; i < buf->href->nanchor; i++) {
- ParsedURL pu;
+ Anchor **in_order = New_N(Anchor *, buf->href->nanchor);
+ for (i = 0; i < nanchor; i++)
+ in_order[i] = buf->href->anchors + i;
+ qsort(in_order, nanchor, sizeof(Anchor *), cmp_anchor_hseq);
+ for (i = 0; i < nanchor; i++) {
+ ParsedURL pu;
char *url;
- if (buf->href->anchors[i].slave)
+ if (in_order[i]->slave)
continue;
- parseURL2(buf->href->anchors[i].url, &pu, baseURL(buf));
+ parseURL2(in_order[i]->url, &pu, baseURL(buf));
url = url_decode2(parsedURL2Str(&pu)->ptr, Currentbuf);
- printf("[%d] %s\n", buf->href->anchors[i].hseq + 1, url);
+ printf("[%d] %s\n", in_order[i]->hseq + 1, url);
}
}
}
|