Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/makemandb With the latest release of mandoc, makema...



details:   https://anonhg.NetBSD.org/src/rev/ad44eb46599c
branches:  trunk
changeset: 818210:ad44eb46599c
user:      abhinav <abhinav%NetBSD.org@localhost>
date:      Mon Oct 03 13:53:39 2016 +0000

description:
With the latest release of mandoc, makemandb(8) started to parse some
sections multiple times. This started to happen because, pmdoc_Sh(), the handler function
responsible for parsing the Sh macros, used to recursively go through all the child
nodes and then the next nodes starting from top level Sh block node.
Now, once it has processed all the child nodes of the top level block node,
it moves to the next node, which is the top level block node of the next section and
in this way one call to pmdoc_Sh() was causing a complete pass through the
man page. Since, mandoc(3) calls pmdoc_Sh() for each .Sh macro in the man
page, it would result in parsing some of the sections multiple times.
This never happened with the previous versions of mandoc, so we never noticed.

I've fixed this by starting the parse sequence of the Sh macro from its body, which gurantees
that we will stop once that section ends.

ok christos@

diffstat:

 usr.sbin/makemandb/makemandb.c |  26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)

diffs (66 lines):

diff -r 0661e76a1f93 -r ad44eb46599c usr.sbin/makemandb/makemandb.c
--- a/usr.sbin/makemandb/makemandb.c    Mon Oct 03 13:36:35 2016 +0000
+++ b/usr.sbin/makemandb/makemandb.c    Mon Oct 03 13:53:39 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makemandb.c,v 1.42 2016/07/17 15:56:14 abhinav Exp $   */
+/*     $NetBSD: makemandb.c,v 1.43 2016/10/03 13:53:39 abhinav Exp $   */
 /*
  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
  * Copyright (c) 2011 Kristaps Dzonsons <kristaps%bsd.lv@localhost>
@@ -17,7 +17,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: makemandb.c,v 1.42 2016/07/17 15:56:14 abhinav Exp $");
+__RCSID("$NetBSD: makemandb.c,v 1.43 2016/10/03 13:53:39 abhinav Exp $");
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -107,6 +107,7 @@
 static void pmdoc_Nm(const struct roff_node *, mandb_rec *);
 static void pmdoc_Nd(const struct roff_node *, mandb_rec *);
 static void pmdoc_Sh(const struct roff_node *, mandb_rec *);
+static void mdoc_parse_Sh(const struct roff_node *, mandb_rec *);
 static void pmdoc_Xr(const struct roff_node *, mandb_rec *);
 static void pmdoc_Pp(const struct roff_node *, mandb_rec *);
 static void pmdoc_macro_handler(const struct roff_node *, mandb_rec *, int);
@@ -1080,13 +1081,26 @@
 
 /*
  * pmdoc_Sh --
- *  Called when a .Sh macro is encountered and loops through its body, calling
+ *  Called when a .Sh macro is encountered and tries to parse its body
+ */
+static void
+pmdoc_Sh(const struct roff_node *n, mandb_rec *rec)
+{
+       if (n == NULL)
+               return;
+
+       if (n->type == ROFFT_BLOCK)
+               mdoc_parse_Sh(n->body, rec);
+}
+
+/*
+ *  Called from pmdoc_Sh to parse body of a .Sh macro. It calls
  *  mdoc_parse_section to append the data to the section specific buffer.
  *  Two special macros which may occur inside the body of Sh are .Nm and .Xr and
  *  they need special handling, thus the separate if branches for them.
  */
 static void
-pmdoc_Sh(const struct roff_node *n, mandb_rec *rec)
+mdoc_parse_Sh(const struct roff_node *n, mandb_rec *rec)
 {
        if (n == NULL || (n->type != ROFFT_TEXT && n->tok == MDOC_MAX))
                return;
@@ -1116,8 +1130,8 @@
         * already been explored by pmdoc_macro_handler.
         */
        if (xr_found == 0)
-               pmdoc_Sh(n->child, rec);
-       pmdoc_Sh(n->next, rec);
+               mdoc_parse_Sh(n->child, rec);
+       mdoc_parse_Sh(n->next, rec);
 }
 
 /*



Home | Main Index | Thread Index | Old Index