aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTatsuya Kinoshita <tats@debian.org>2013-07-30 11:14:54 +0000
committerTatsuya Kinoshita <tats@debian.org>2013-07-30 11:14:54 +0000
commite3d3c53ac3c3b8f7c8ab227427ea9ff147f9036f (patch)
tree88966004acc26ea238b5414bd569b86aac1b569d
parentMerge branch 'feature/debian-version' (diff)
parentMerge branch 'master' into bug/sort-dump-links (diff)
downloadw3m-e3d3c53ac3c3b8f7c8ab227427ea9ff147f9036f.tar.gz
w3m-e3d3c53ac3c3b8f7c8ab227427ea9ff147f9036f.zip
Merge branch 'bug/sort-dump-links'
Diffstat (limited to '')
-rw-r--r--main.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/main.c b/main.c
index 0fdb175..f6e14a4 100644
--- 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);
}
}
}