Module Name:    src
Committed By:   abhinav
Date:           Mon Oct  3 13:53:39 UTC 2016

Modified Files:
        src/usr.sbin/makemandb: makemandb.c

Log Message:
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@


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/usr.sbin/makemandb/makemandb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/makemandb/makemandb.c
diff -u src/usr.sbin/makemandb/makemandb.c:1.42 src/usr.sbin/makemandb/makemandb.c:1.43
--- src/usr.sbin/makemandb/makemandb.c:1.42	Sun Jul 17 15:56:14 2016
+++ src/usr.sbin/makemandb/makemandb.c	Mon Oct  3 13:53:39 2016
@@ -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.upadh...@gmail.com>
  * Copyright (c) 2011 Kristaps Dzonsons <krist...@bsd.lv>
@@ -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 proff_node(const struct roff
 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_Pp(const struct roff_node *n, mand
 
 /*
  * 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 @@ pmdoc_Sh(const struct roff_node *n, mand
 	 * 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);
 }
 
 /*

Reply via email to