=================================================================== RCS file: /cvs/mandoc/mandocdb.c,v retrieving revision 1.49.2.6 retrieving revision 1.49.2.18 diff -u -p -r1.49.2.6 -r1.49.2.18 --- mandoc/mandocdb.c 2013/10/01 00:52:58 1.49.2.6 +++ mandoc/mandocdb.c 2014/08/14 04:13:30 1.49.2.18 @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.49.2.6 2013/10/01 00:52:58 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.49.2.18 2014/08/14 04:13:30 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 @@ -34,23 +32,27 @@ #include #include -#if defined(__linux__) || defined(__sun) +#if defined(__APPLE__) +# include +#elif defined(__linux__) || defined(__CYGWIN__) # include +#elif defined(__sun) +# include +# include +#else +# include +#endif + +#if defined(__linux__) || defined(__CYGWIN__) || defined(__sun) # include -#elif defined(__APPLE__) -# include -# include #else # include #endif -#if defined(__sun) -#include -#endif - #include "man.h" #include "mdoc.h" #include "mandoc.h" +#include "mandoc_aux.h" #include "mandocdb.h" #include "manpath.h" @@ -285,6 +287,7 @@ static const struct mdoc_handler mdocs[MDOC_MAX] = { }; static const char *progname; +static int mparse_options; /* abort the parse early */ static int use_all; /* Use all directories and files. */ static int verb; /* Output verbosity level. */ static int warnings; /* Potential problems in manuals. */ @@ -325,8 +328,9 @@ main(int argc, char *argv[]) hash = NULL; op = OP_DEFAULT; dir = NULL; + mparse_options = MPARSE_SO; - while (-1 != (ch = getopt(argc, argv, "aC:d:tu:vW"))) + while (-1 != (ch = getopt(argc, argv, "aC:d:Qtu:vW"))) switch (ch) { case ('a'): use_all = 1; @@ -349,6 +353,9 @@ main(int argc, char *argv[]) dir = optarg; op = OP_UPDATE; break; + case ('Q'): + mparse_options |= MPARSE_QUICK; + break; case ('t'): dup2(STDOUT_FILENO, STDERR_FILENO); if (op) { @@ -391,7 +398,7 @@ main(int argc, char *argv[]) info.lorder = 4321; info.flags = R_DUP; - mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL, NULL); + mp = mparse_alloc(mparse_options, MANDOCLEVEL_FATAL, NULL, NULL); memset(&buf, 0, sizeof(struct buf)); memset(&dbuf, 0, sizeof(struct buf)); @@ -592,7 +599,7 @@ out: usage: fprintf(stderr, - "usage: %s [-avvv] [-C file] | dir ... | -t file ...\n" + "usage: %s [-aQvvv] [-C file] | dir ... | -t file ...\n" " -d dir [file ...] | " "-u dir [file ...]\n", progname); @@ -619,6 +626,8 @@ index_merge(const struct of *of, struct mparse *mp, uint64_t vbuf[2]; char type; + static char emptystring[] = ""; + if (warnings) { files = NULL; hash_reset(&files); @@ -641,7 +650,7 @@ index_merge(const struct of *of, struct mparse *mp, if ((MANDOC_SRC & of->src_form || ! (MANDOC_FORM & of->src_form)) && MANDOCLEVEL_FATAL > mparse_readfd(mp, -1, fn)) - mparse_result(mp, &mdoc, &man); + mparse_result(mp, &mdoc, &man, NULL); if (NULL != mdoc) { msec = mdoc_meta(mdoc)->msec; @@ -731,13 +740,13 @@ index_merge(const struct of *of, struct mparse *mp, } buf_appendb(buf, ")", 2); for (p = buf->cp; '\0' != *p; p++) - *p = tolower(*p); + *p = tolower((unsigned char)*p); key.data = buf->cp; key.size = buf->len; val.data = NULL; val.size = 0; if (0 == skip) - val.data = ""; + val.data = emptystring; else { ch = (*files->get)(files, &key, &val, 0); if (ch < 0) { @@ -973,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; @@ -1372,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); @@ -1393,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! @@ -1455,6 +1426,7 @@ pman_node(MAN_ARGS) * the name parts here. */ + start = title; for ( ;; ) { sz = strcspn(start, " ,"); if ('\0' == start[(int)sz]) @@ -1479,7 +1451,7 @@ pman_node(MAN_ARGS) buf->len = 0; - if (sv == start) { + if (start == title) { buf_append(buf, start); free(title); return(1);