summaryrefslogtreecommitdiffstats
path: root/mdoc.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-03-23 12:44:56 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-03-23 12:44:56 +0000
commit527d07ef48406d7e7b0e3f84aab2251ff33a4599 (patch)
treef4a45e7bd3dcaf382d63a61ac12fb852ca40b00e /mdoc.c
parent85c9ebb82f6cfd81fa04de4344ca2948d174c95c (diff)
downloadmandoc-527d07ef48406d7e7b0e3f84aab2251ff33a4599.tar.gz
If an .Nd block contains macros, avoid fragmented entries in mandocdb(8),
instead use the .Nd content recursively.
Diffstat (limited to 'mdoc.c')
-rw-r--r--mdoc.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/mdoc.c b/mdoc.c
index 814e43b5..c3f84c4a 100644
--- a/mdoc.c
+++ b/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>
@@ -1020,3 +1021,42 @@ mdoc_isdelim(const char *p)
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;
+}