source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: If an .Nd block contains macros, avoid fragmented entries in
@ 2014-03-23 12:44 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-03-23 12:44 UTC (permalink / raw)
  To: source

Log Message:
-----------
If an .Nd block contains macros, avoid fragmented entries in mandocdb(8), 
instead use the .Nd content recursively.

Modified Files:
--------------
    mdocml:
        mandocdb.c
        mdoc.c
        mdoc.h

Revision Data
-------------
Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.121 -r1.122
--- mandocdb.c
+++ mandocdb.c
@@ -1506,32 +1506,10 @@ parse_mdoc_Xr(struct mpage *mpage, const
 static int
 parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_node *n)
 {
-	size_t		 sz;
 
-	if (MDOC_BODY != n->type)
-		return(0);
-
-	/*
-	 * Special-case the `Nd' because we need to put the description
-	 * into the document table.
-	 */
-
-	for (n = n->child; NULL != n; n = n->next) {
-		if (MDOC_TEXT == n->type) {
-			if (NULL != mpage->desc) {
-				sz = strlen(mpage->desc) +
-				     strlen(n->string) + 2;
-				mpage->desc = mandoc_realloc(
-				    mpage->desc, sz);
-				strlcat(mpage->desc, " ", sz);
-				strlcat(mpage->desc, n->string, sz);
-			} else
-				mpage->desc = mandoc_strdup(n->string);
-		}
-		if (NULL != n->child)
-			parse_mdoc_Nd(mpage, n);
-	}
-	return(1);
+	if (MDOC_BODY == n->type)
+		mdoc_deroff(&mpage->desc, n);
+	return(0);
 }
 
 static int
Index: mdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.h,v
retrieving revision 1.125
retrieving revision 1.126
diff -Lmdoc.h -Lmdoc.h -u -p -r1.125 -r1.126
--- mdoc.h
+++ mdoc.h
@@ -389,6 +389,7 @@ struct	mdoc;
 
 const struct mdoc_node *mdoc_node(const struct mdoc *);
 const struct mdoc_meta *mdoc_meta(const struct mdoc *);
+void mdoc_deroff(char **, const struct mdoc_node *);
 
 __END_DECLS
 
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.210
retrieving revision 1.211
diff -Lmdoc.c -Lmdoc.c -u -p -r1.210 -r1.211
--- mdoc.c
+++ mdoc.c
@@ -22,6 +22,7 @@
 #include <sys/types.h>
 
 #include <assert.h>
+#include <ctype.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -1019,4 +1020,43 @@ mdoc_isdelim(const char *p)
 		return(DELIM_MIDDLE);
 
 	return(DELIM_NONE);
+}
+
+void
+mdoc_deroff(char **dest, const struct mdoc_node *n)
+{
+	char	*cp;
+	size_t	 sz;
+
+	if (MDOC_TEXT != n->type) {
+		for (n = n->child; n; n = n->next)
+			mdoc_deroff(dest, n);
+		return;
+	}
+
+	/* Skip leading whitespace. */
+
+	for (cp = n->string; '\0' != *cp; cp++)
+		if (0 == isspace((unsigned char)*cp))
+			break;
+
+	/* Skip trailing whitespace. */
+
+	for (sz = strlen(cp); sz; sz--)
+		if (0 == isspace((unsigned char)cp[sz-1]))
+			break;
+
+	/* Skip empty strings. */
+
+	if (0 == sz)
+		return;
+
+	if (NULL == *dest) {
+		*dest = mandoc_strndup(cp, sz);
+		return;
+	}
+
+	mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp);
+	free(*dest);
+	*dest = cp;
 }
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-03-23 12:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-23 12:44 mdocml: If an .Nd block contains macros, avoid fragmented entries in schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).