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.
This commit is contained in:
Tatsuya Kinoshita
2013-07-30 19:49:02 +09:00
parent dbd52ac2ca
commit b61a08fc64
+19 -8
View File
@@ -1246,6 +1246,12 @@ dump_extra(Buffer *buf)
#endif #endif
} }
static int
cmp_anchor_hseq(const void *a, const void *b)
{
return (*((const Anchor **) a))->hseq - (*((const Anchor **) b))->hseq;
}
static void static void
do_dump(Buffer *buf) do_dump(Buffer *buf)
{ {
@@ -1266,18 +1272,23 @@ do_dump(Buffer *buf)
int i; int i;
saveBuffer(buf, stdout, FALSE); saveBuffer(buf, stdout, FALSE);
if (displayLinkNumber && buf->href) { if (displayLinkNumber && buf->href) {
int nanchor = buf->href->nanchor;
printf("\nReferences:\n\n"); printf("\nReferences:\n\n");
for (i = 0; i < buf->href->nanchor; i++) { Anchor **in_order = New_N(Anchor *, buf->href->nanchor);
ParsedURL pu; for (i = 0; i < nanchor; i++)
static Str s = NULL; in_order[i] = buf->href->anchors + i;
if (buf->href->anchors[i].slave) 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; continue;
parseURL2(buf->href->anchors[i].url, &pu, baseURL(buf)); parseURL2(in_order[i]->url, &pu, baseURL(buf));
s = parsedURL2Str(&pu); s = parsedURL2Str(&pu);
if (DecodeURL) if (DecodeURL)
s = Strnew_charp(url_unquote_conv s = Strnew_charp(url_unquote_conv
(s->ptr, Currentbuf->document_charset)); (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);
} }
} }
} }