summaryrefslogtreecommitdiffstats
path: root/usr.bin/mandoc/mdoc.c
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-03-23 12:44:18 +0000
committerschwarze <schwarze@openbsd.org>2014-03-23 12:44:18 +0000
commit6cd765898bac97447e73a4a42f82a2ac3783d780 (patch)
tree532f8269b9567ee0155f092ab8ff8dfd43652f6f /usr.bin/mandoc/mdoc.c
parentkill(1) doesn't use getopt() due to its non-standard option processing. (diff)
downloadwireguard-openbsd-6cd765898bac97447e73a4a42f82a2ac3783d780.tar.xz
wireguard-openbsd-6cd765898bac97447e73a4a42f82a2ac3783d780.zip
If an .Nd block contains macros, avoid fragmented entries in mandocdb(8),
instead use the .Nd content recursively. Improves a couple of index entries in base.
Diffstat (limited to 'usr.bin/mandoc/mdoc.c')
-rw-r--r--usr.bin/mandoc/mdoc.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c
index f13b9704500..b732e82b00a 100644
--- a/usr.bin/mandoc/mdoc.c
+++ b/usr.bin/mandoc/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.100 2014/03/21 22:52:21 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.101 2014/03/23 12:44:18 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -18,6 +18,7 @@
#include <sys/types.h>
#include <assert.h>
+#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -1016,3 +1017,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;
+}