diff options
author | Tatsuya Kinoshita <tats@debian.org> | 2013-07-30 10:49:02 +0000 |
---|---|---|
committer | Tatsuya Kinoshita <tats@debian.org> | 2013-07-30 11:09:33 +0000 |
commit | b61a08fc6465d86d838d30d64c3c61e149e01728 (patch) | |
tree | 757df22698e557900708bad07eb0acee3edf866a /main.c | |
parent | Merge from upstream on 2012-05-22 (diff) | |
download | w3m-b61a08fc6465d86d838d30d64c3c61e149e01728.tar.gz w3m-b61a08fc6465d86d838d30d64c3c61e149e01728.zip |
Sort anchors by sequence number in -dump
Patch from <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=657666>,
provided by Conrad J.C. Hughes.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 27 |
1 files changed, 19 insertions, 8 deletions
@@ -1246,6 +1246,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) { @@ -1266,18 +1272,23 @@ 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; - static Str s = NULL; - if (buf->href->anchors[i].slave) + 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; + static Str s = NULL; + if (in_order[i]->slave) continue; - parseURL2(buf->href->anchors[i].url, &pu, baseURL(buf)); - s = parsedURL2Str(&pu); - if (DecodeURL) + parseURL2(in_order[i]->url, &pu, baseURL(buf)); + s = parsedURL2Str(&pu); + if (DecodeURL) s = Strnew_charp(url_unquote_conv (s->ptr, Currentbuf->document_charset)); - printf("[%d] %s\n", buf->href->anchors[i].hseq + 1, s->ptr); + printf("[%d] %s\n", in_order[i]->hseq + 1, s->ptr); } } } |