diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-03-23 12:44:19 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-03-23 12:44:19 +0000 |
commit | 7c80f808f2a6f2f74648b2456aa6b00cbb3691b8 (patch) | |
tree | 9cc53d9f59ec93fa7cdb8a0f057dd6a91fb01984 /usr.bin | |
parent | 08c44f701bf55ff1d7e25f33192a9d4ac8588ffe (diff) |
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')
-rw-r--r-- | usr.bin/mandoc/mandocdb.c | 30 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.c | 42 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.h | 3 |
3 files changed, 47 insertions, 28 deletions
diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c index 10363ab1451..0d40470eff2 100644 --- a/usr.bin/mandoc/mandocdb.c +++ b/usr.bin/mandoc/mandocdb.c @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.78 2014/03/22 00:56:07 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.79 2014/03/23 12:44:18 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -1498,32 +1498,10 @@ parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_node *n) 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 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; +} diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h index 763cc2a9c95..cd2a18dd141 100644 --- a/usr.bin/mandoc/mdoc.h +++ b/usr.bin/mandoc/mdoc.h @@ -1,4 +1,4 @@ -/* $Id: mdoc.h,v 1.49 2013/12/24 19:10:34 schwarze Exp $ */ +/* $Id: mdoc.h,v 1.50 2014/03/23 12:44:18 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -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 |