diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2014-03-23 12:26:58 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2014-03-23 12:26:58 +0000 |
commit | 85c9ebb82f6cfd81fa04de4344ca2948d174c95c (patch) | |
tree | 41ef55146b8889119eb7ff8d05a6cbc38f264b82 /man.c | |
parent | a1867979c4c9ee59f1a222e80a1cd3a578c560ea (diff) | |
download | mandoc-85c9ebb82f6cfd81fa04de4344ca2948d174c95c.tar.gz |
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 'man.c')
-rw-r--r-- | man.c | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -23,6 +23,7 @@ #include <sys/types.h> #include <assert.h> +#include <ctype.h> #include <stdarg.h> #include <stdlib.h> #include <stdio.h> @@ -706,3 +707,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; +} |