Package: w3m
Version: 0.5.3-5
Severity: normal
Tags: patch

Dear Maintainer,
*** Please consider answering these questions, where appropriate ***

I recently discovered w3m's "-dump -o display_link_number=1" options,
and find them really useful.  One minor niggle is that the links are
actually listed in an order quite close to, but not the same as, the
number that's displayed.  So for example for one document I have, links
1-10 are presented in the order 1-7,9,10,8 in the References list at the
end of the dump.  I attach a patch which sorts them according to number.

*** End of the template - remove these lines ***


-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (500, 'testing'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.1.0-1-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages w3m depends on:
ii  libbsd0      0.3.0-1
ii  libc6        2.13-24
ii  libgc1c2     1:7.1-8
ii  libgpm2      1.20.4-4
ii  libssl1.0.0  1.0.0g-1
ii  libtinfo5    5.9-4
ii  zlib1g       1:1.2.3.4.dfsg-3

Versions of packages w3m recommends:
ii  ca-certificates  20111211

Versions of packages w3m suggests:
pn  man-db        2.6.0.2-3
pn  menu          2.1.46
pn  migemo        <none>
pn  mime-support  3.51-1
pn  w3m-el        <none>
pn  w3m-img       <none>

-- no debconf information
Description: Sort anchors by sequence number in -dump.
 See above.
 .
 w3m (0.5.3-5.1) unstable; urgency=low
 .
   * Non-maintainer upload.
   * Sort anchors by sequence number in -dump.
Author: Conrad J.C. Hughes (for Debian package stuff) <debb...@xrad.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- w3m-0.5.3.orig/main.c
+++ w3m-0.5.3/main.c
@@ -1258,6 +1258,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)
 {
@@ -1278,18 +1284,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);
 	    }
 	}
     }
  • Bug#657666: w3m: -dump -o di... Conrad J.C. Hughes (for Debian package stuff)

Reply via email to