=================================================================== RCS file: /cvs/mandoc/mandocdb.c,v retrieving revision 1.49.2.13 retrieving revision 1.49.2.17 diff -u -p -r1.49.2.13 -r1.49.2.17 --- mandoc/mandocdb.c 2014/03/19 22:24:12 1.49.2.13 +++ mandoc/mandocdb.c 2014/08/11 00:31:13 1.49.2.17 @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.49.2.13 2014/03/19 22:24:12 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.49.2.17 2014/08/11 00:31:13 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011, 2012 Ingo Schwarze @@ -15,9 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include @@ -54,6 +52,7 @@ #include "man.h" #include "mdoc.h" #include "mandoc.h" +#include "mandoc_aux.h" #include "mandocdb.h" #include "manpath.h" @@ -983,8 +982,8 @@ index_prune(const struct of *ofile, struct mdb *mdb, s cont: if (recs->cur >= recs->size) { recs->size += MANDOC_SLOP; - recs->stack = mandoc_realloc(recs->stack, - recs->size * sizeof(recno_t)); + recs->stack = mandoc_reallocarray(recs->stack, + recs->size, sizeof(recno_t)); } recs->stack[(int)recs->cur] = recs->last; @@ -1382,8 +1381,8 @@ static int pman_node(MAN_ARGS) { const struct man_node *head, *body; - char *start, *sv, *title; - size_t sz, titlesz; + char *start, *title; + size_t sz; if (NULL == n) return(0); @@ -1403,58 +1402,20 @@ pman_node(MAN_ARGS) NULL != (head = (head->child)) && MAN_TEXT == head->type && 0 == strcmp(head->string, "NAME") && - NULL != (body = body->child) && - MAN_TEXT == body->type) { + NULL != body->child) { - title = NULL; - titlesz = 0; /* * Suck the entire NAME section into memory. * Yes, we might run away. * But too many manuals have big, spread-out * 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[(int)titlesz - 1] = ' '; - } + + title = NULL; + man_deroff(&title, body); if (NULL == title) return(0); - title = mandoc_realloc(title, titlesz + 1); - title[(int)titlesz] = '\0'; - - /* Skip leading space. */ - - sv = title; - while (isspace((unsigned char)*sv)) - sv++; - - if (0 == (sz = strlen(sv))) { - free(title); - return(0); - } - - /* Erase trailing space. */ - - start = &sv[sz - 1]; - while (start > sv && isspace((unsigned char)*start)) - *start-- = '\0'; - - if (start == sv) { - free(title); - return(0); - } - - start = sv; - /* * Go through a special heuristic dance here. * This is why -man manuals are great! @@ -1465,6 +1426,7 @@ pman_node(MAN_ARGS) * the name parts here. */ + start = title; for ( ;; ) { sz = strcspn(start, " ,"); if ('\0' == start[(int)sz]) @@ -1489,7 +1451,7 @@ pman_node(MAN_ARGS) buf->len = 0; - if (sv == start) { + if (start == title) { buf_append(buf, start); free(title); return(1);