summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-03-22 00:56:07 +0000
committerschwarze <schwarze@openbsd.org>2014-03-22 00:56:07 +0000
commitfd5b70b0860c48034dc827d06ba321989b59c8c4 (patch)
tree032ee7f63cf73168358a5a6abc0fcce020b980b7 /usr.bin
parent<sys/agpio.h> is gone; this compiles fine without it (diff)
downloadwireguard-openbsd-fd5b70b0860c48034dc827d06ba321989b59c8c4.tar.xz
wireguard-openbsd-fd5b70b0860c48034dc827d06ba321989b59c8c4.zip
If a man(7) NAME section contains macros, avoid truncated or empty
entries for .Nd in mandocdb(8), instead use the macro content recursively. This improves indexing of more than 200 manuals in Xenocara, i.e. more than 15%, in particular GL and some Xkb.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/man.c42
-rw-r--r--usr.bin/mandoc/man.h4
-rw-r--r--usr.bin/mandoc/mandocdb.c55
3 files changed, 52 insertions, 49 deletions
diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c
index a69c0e36b38..bd1cfd729d4 100644
--- a/usr.bin/mandoc/man.c
+++ b/usr.bin/mandoc/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.75 2014/03/21 22:17:01 schwarze Exp $ */
+/* $Id: man.c,v 1.76 2014/03/22 00:56:07 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <assert.h>
+#include <ctype.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
@@ -702,3 +703,42 @@ man_mparse(const struct man *man)
assert(man && man->parse);
return(man->parse);
}
+
+void
+man_deroff(char **dest, const struct man_node *n)
+{
+ char *cp;
+ size_t sz;
+
+ if (MAN_TEXT != n->type) {
+ for (n = n->child; n; n = n->next)
+ man_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;
+}
diff --git a/usr.bin/mandoc/man.h b/usr.bin/mandoc/man.h
index 54e13433e0d..130a2e06f86 100644
--- a/usr.bin/mandoc/man.h
+++ b/usr.bin/mandoc/man.h
@@ -1,6 +1,7 @@
-/* $Id: man.h,v 1.41 2013/10/17 20:51:29 schwarze Exp $ */
+/* $Id: man.h,v 1.42 2014/03/22 00:56:07 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -111,6 +112,7 @@ struct man;
const struct man_node *man_node(const struct man *);
const struct man_meta *man_meta(const struct man *);
const struct mparse *man_mparse(const struct man *);
+void man_deroff(char **, const struct man_node *);
__END_DECLS
diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c
index cca30fb134b..10363ab1451 100644
--- a/usr.bin/mandoc/mandocdb.c
+++ b/usr.bin/mandoc/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.77 2014/03/21 22:52:21 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.78 2014/03/22 00:56:07 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -1255,9 +1255,9 @@ static void
parse_man(struct mpage *mpage, const struct man_node *n)
{
const struct man_node *head, *body;
- char *start, *sv, *title;
+ char *start, *title;
char byte;
- size_t sz, titlesz;
+ size_t sz;
if (NULL == n)
return;
@@ -1277,11 +1277,7 @@ parse_man(struct mpage *mpage, const struct man_node *n)
NULL != (head = (head->child)) &&
MAN_TEXT == head->type &&
0 == strcmp(head->string, "NAME") &&
- NULL != (body = body->child) &&
- MAN_TEXT == body->type) {
-
- title = NULL;
- titlesz = 0;
+ NULL != body->child) {
/*
* Suck the entire NAME section into memory.
@@ -1290,47 +1286,11 @@ parse_man(struct mpage *mpage, const struct man_node *n)
* NAME sections over many lines.
*/
- for ( ; NULL != body; body = body->next) {
- if (MAN_TEXT != body->type)
- break;
- if (0 == (sz = strlen(body->string)))
- continue;
- title = mandoc_realloc
- (title, titlesz + sz + 1);
- memcpy(title + titlesz, body->string, sz);
- titlesz += sz + 1;
- title[titlesz - 1] = ' ';
- }
+ title = NULL;
+ man_deroff(&title, body);
if (NULL == title)
return;
- title = mandoc_realloc(title, titlesz + 1);
- title[titlesz] = '\0';
-
- /* Skip leading space. */
-
- sv = title;
- while (isspace((unsigned char)*sv))
- sv++;
-
- if (0 == (sz = strlen(sv))) {
- free(title);
- return;
- }
-
- /* Erase trailing space. */
-
- start = &sv[sz - 1];
- while (start > sv && isspace((unsigned char)*start))
- *start-- = '\0';
-
- if (start == sv) {
- free(title);
- return;
- }
-
- start = sv;
-
/*
* Go through a special heuristic dance here.
* Conventionally, one or more manual names are
@@ -1339,6 +1299,7 @@ parse_man(struct mpage *mpage, const struct man_node *n)
* the name parts here.
*/
+ start = title;
for ( ;; ) {
sz = strcspn(start, " ,");
if ('\0' == start[sz])
@@ -1369,7 +1330,7 @@ parse_man(struct mpage *mpage, const struct man_node *n)
start++;
}
- if (sv == start) {
+ if (start == title) {
putkey(mpage, start, TYPE_Nm);
free(title);
return;