Rupert Swarbrick | 4 Jan 2011 22:27
Picon
Gravatar

[PATCH 0/6] Add links to man pages

The patches below add links in man pages to other man pages and to
http:// urls (not mailto:, since I'm not sure that's a net benefit).

They also change the indenting code to use CSS margins rather than
nonbreaking spaces, which should make copy-paste much nicer.

Rupert Swarbrick (6):
  Fix some compiler warnings.
  Make links from strings of the form "blah(2)" in man pages.
  Add support for http:// urls.
  Do the indents in man pages correctly with CSS and javascript.
  Correctly deal with man links containing newlines.
  Cleverer heuristic on what constitutes a man link.

 libyelp/yelp-man-parser.c   |  435 +++++++++++++++++++++++++++++++++++++++++--
 stylesheets/man2html.xsl.in |   57 ++++++-
 2 files changed, 475 insertions(+), 17 deletions(-)

--

-- 
1.7.2.3
Rupert Swarbrick | 20 Dec 2010 21:53
Picon
Gravatar

[PATCH 1/6] Fix some compiler warnings.

Note: the stray g_next_char() line had no effect.
---
 libyelp/yelp-man-parser.c |   27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/libyelp/yelp-man-parser.c b/libyelp/yelp-man-parser.c
index 68eac81..501b918 100644
--- a/libyelp/yelp-man-parser.c
+++ b/libyelp/yelp-man-parser.c
 <at>  <at>  -28,6 +28,7  <at>  <at> 
 #include <glib/gi18n.h>
 #include <libxml/tree.h>
 #include <gio/gio.h>
+#include <gio/gunixinputstream.h>
 #include <string.h>
 #include <math.h>

 <at>  <at>  -363,8 +364,6  <at>  <at>  yelp_man_parser_parse_file (YelpManParser *parser,
                             GError **error)
 {
     GInputStream *troff_stream;
-    gchar *line;
-    gsize len;
     gboolean ret;
     xmlNodePtr root;

 <at>  <at>  -781,7 +780,7  <at>  <at>  parse_n (YelpManParser *parser, GError **error)

         xmlNewTextChild (parser->header,
                          NULL, BAD_CAST "collection",
(Continue reading)

Rupert Swarbrick | 22 Dec 2010 00:59
Picon
Gravatar

[PATCH 2/6] Make links from strings of the form "blah(2)" in man pages.

Note that there's not a space before the (2): it seems that strings
like that are used for Copyright (C) etc. and not links).
---
 libyelp/yelp-man-parser.c   |  322 +++++++++++++++++++++++++++++++++++++++++++
 stylesheets/man2html.xsl.in |   12 ++-
 2 files changed, 333 insertions(+), 1 deletions(-)

diff --git a/libyelp/yelp-man-parser.c b/libyelp/yelp-man-parser.c
index 501b918..2e381f8 100644
--- a/libyelp/yelp-man-parser.c
+++ b/libyelp/yelp-man-parser.c
 <at>  <at>  -27,6 +27,7  <at>  <at> 
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <libxml/tree.h>
+#include <libxml/xpath.h>
 #include <gio/gio.h>
 #include <gio/gunixinputstream.h>
 #include <string.h>
 <at>  <at>  -191,6 +192,31  <at>  <at>  static void cleanup_parsed_page (YelpManParser *parser);
 static gboolean parse_last_line (YelpManParser *parser, gchar* line);
 static void unicode_strstrip (gchar *str);

+/*
+  A link_inserter takes
+    (1) an array of offsets for the different spans within the string
+    (2) the match info from the regex match
+
+  It's then responsible for mangling the XML tree to insert the actual
+  link. Finally, it should return the offset into the string of the
(Continue reading)

Rupert Swarbrick | 4 Jan 2011 22:18
Picon
Gravatar

[PATCH 6/6] Cleverer heuristic on what constitutes a man link.

---
 libyelp/yelp-man-parser.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/libyelp/yelp-man-parser.c b/libyelp/yelp-man-parser.c
index 680fc89..4001d38 100644
--- a/libyelp/yelp-man-parser.c
+++ b/libyelp/yelp-man-parser.c
 <at>  <at>  -70,6 +70,8  <at>  <at>  struct _YelpManParser {
     gchar            *buffer;    /* The buffer, line at a time */
     gsize             length;    /* The buffer length */

+    gchar            *section;   /* The name of the current section */
+
     /* The width and height of a character according to troff. */
     guint char_width;
     guint char_height;
 <at>  <at>  -443,6 +445,7  <at>  <at>  yelp_man_parser_free (YelpManParser *parser)
     }
     g_string_free (parser->accumulator, TRUE);
     g_free (parser->title_str);
+    g_free (parser->section);
     g_free (parser);
 }

 <at>  <at>  -689,7 +692,7  <at>  <at>  parse_text (YelpManParser *parser, GError **error)
             g_string_truncate (parser->accumulator, 0);

             g_free (text);
-            g_free (section);
(Continue reading)

Rupert Swarbrick | 22 Dec 2010 01:16
Picon
Gravatar

[PATCH 3/6] Add support for http:// urls.

---
 libyelp/yelp-man-parser.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/libyelp/yelp-man-parser.c b/libyelp/yelp-man-parser.c
index 2e381f8..35079d0 100644
--- a/libyelp/yelp-man-parser.c
+++ b/libyelp/yelp-man-parser.c
 <at>  <at>  -216,6 +216,8  <at>  <at>  static void fixup_links (YelpManParser *parser,

 static gsize man_link_inserter (offset_elt_pair *offsets,
                                 const GMatchInfo *match_info);
+static gsize http_link_inserter (offset_elt_pair *offsets,
+                                 const GMatchInfo *match_info);

 /******************************************************************************/
 /* Translations for the 'C' command. This is indeed hackish, but the
 <at>  <at>  -1125,6 +1127,16  <at>  <at>  cleanup_parsed_page (YelpManParser *parser)
     g_return_if_fail (regex);
     fixup_links (parser, regex, man_link_inserter);
     g_regex_unref (regex);
+
+    /* Now for http:// links.
+     */
+    regex = g_regex_new ("https?:\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+"
+                         "([\\w\\-\\., <at> ?^=%&:/~\\+#]*"
+                         "[\\w\\-\\ <at> ?^=%&/~\\+#])?",
+                         0, 0, NULL);
+    g_return_if_fail (regex);
+    fixup_links (parser, regex, http_link_inserter);
(Continue reading)

Rupert Swarbrick | 4 Jan 2011 18:14
Picon
Gravatar

[PATCH 5/6] Correctly deal with man links containing newlines.

---
 libyelp/yelp-man-parser.c |   42 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/libyelp/yelp-man-parser.c b/libyelp/yelp-man-parser.c
index e8d28b2..680fc89 100644
--- a/libyelp/yelp-man-parser.c
+++ b/libyelp/yelp-man-parser.c
 <at>  <at>  -1286,10 +1286,37  <at>  <at>  sheet_fixup_links (xmlNodePtr sheet,

         if (strcmp ((const char*) span->name, "span") != 0) {

-            if ((strcmp ((const char*) span->name, "br") == 0) ||
-                (strcmp ((const char*) span->name, "a") == 0))
+            if (strcmp ((const char*) span->name, "a") == 0)
                 continue;

+            if (strcmp ((const char*) span->name, "br") == 0) {
+                /* If the last character in the accumulator is a
+                 * hyphen, we don't want to include that in the link
+                 * we make. If not, append a newline to the
+                 * accumulator (so we don't mistakenly make links from
+                 * "see\nthis(2)" to seethis(2).
+                 *
+                 * Either way, we add the <br> to the list of pairs
+                 * since we might need to do stuff with it if it's in
+                 * the middle of a link.
+                 */
+                len = strlen (accumulator->str);
+                if (len > 0 && accumulator->str [len-1] == '-') {
(Continue reading)

Rupert Swarbrick | 3 Jan 2011 22:00
Picon
Gravatar

[PATCH 4/6] Do the indents in man pages correctly with CSS and javascript.

---
 libyelp/yelp-man-parser.c   |    6 +++-
 stylesheets/man2html.xsl.in |   45 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/libyelp/yelp-man-parser.c b/libyelp/yelp-man-parser.c
index 35079d0..e8d28b2 100644
--- a/libyelp/yelp-man-parser.c
+++ b/libyelp/yelp-man-parser.c
 <at>  <at>  -976,8 +976,6  <at>  <at>  deal_with_newlines (YelpManParser *parser)
     }

     if (parser->newline) {
-        append_nbsps (parser, dx_to_em_count (parser, parser->hpos));
-
         if ((parser->last_vertical_jump > 0) && (!dont_jump)) {
             jump_lines =
                 parser->last_vertical_jump/parser->char_height;
 <at>  <at>  -990,6 +988,10  <at>  <at>  deal_with_newlines (YelpManParser *parser)
             made_sheet = TRUE;
         }

+        snprintf (tmp, 64, "%u", dx_to_em_count (parser, parser->hpos));
+        xmlNewProp (parser->sheet_node,
+                    BAD_CAST "indent", BAD_CAST tmp);
+
         if (made_sheet) {
             snprintf (tmp, 64, "%u", jump_lines-1);
             xmlNewProp (parser->sheet_node,
diff --git a/stylesheets/man2html.xsl.in b/stylesheets/man2html.xsl.in
(Continue reading)


Gmane