=================================================================== RCS file: /cvs/mandoc/mansearch.c,v retrieving revision 1.70 retrieving revision 1.74 diff -u -p -r1.70 -r1.74 --- mandoc/mansearch.c 2017/04/17 20:05:08 1.70 +++ mandoc/mansearch.c 2017/07/01 09:47:30 1.74 @@ -1,4 +1,4 @@ -/* $OpenBSD: mansearch.c,v 1.70 2017/04/17 20:05:08 schwarze Exp $ */ +/* $OpenBSD: mansearch.c,v 1.74 2017/07/01 09:47:30 schwarze Exp $ */ /* * Copyright (c) 2012 Kristaps Dzonsons * Copyright (c) 2013-2017 Ingo Schwarze @@ -104,7 +104,8 @@ mansearch(const struct mansearch *search, } cur = maxres = 0; - *res = NULL; + if (res != NULL) + *res = NULL; outkey = KEY_Nd; if (search->outkey != NULL) @@ -155,7 +156,8 @@ mansearch(const struct mansearch *search, chdir_status = 1; if (dbm_open(MANDOC_DB) == -1) { - warn("%s/%s", paths->paths[i], MANDOC_DB); + if (errno != ENOENT) + warn("%s/%s", paths->paths[i], MANDOC_DB); continue; } @@ -172,6 +174,10 @@ mansearch(const struct mansearch *search, lstmatch(search->arch, page->arch) == 0) continue; + if (res == NULL) { + cur = 1; + break; + } if (cur + 1 > maxres) { maxres += 1024; *res = mandoc_reallocarray(*res, @@ -203,12 +209,13 @@ mansearch(const struct mansearch *search, if (cur && search->firstmatch) break; } - qsort(*res, cur, sizeof(struct manpage), manpage_compare); + if (res != NULL) + qsort(*res, cur, sizeof(struct manpage), manpage_compare); if (chdir_status && getcwd_status && chdir(buf) == -1) warn("%s", buf); exprfree(e); *sz = cur; - return 1; + return res != NULL || cur; } /* @@ -516,6 +523,8 @@ buildoutput(size_t im, struct dbm_page *page) output = mandoc_malloc(sz); i = 0; lstcat(output, &i, input, " # "); + output[i++] = '\0'; + assert(i == sz); return output; } @@ -670,6 +679,12 @@ exprterm(const struct mansearch *search, int argc, cha return e; } + if (strcmp("-i", argv[*argi]) == 0 && *argi + 1 < argc) { + cs = 0; + ++*argi; + } else + cs = 1; + e = mandoc_calloc(1, sizeof(*e)); e->type = EXPR_TERM; e->bits = 0; @@ -688,7 +703,6 @@ exprterm(const struct mansearch *search, int argc, cha * If needed, request regular expression handling. */ - cs = 1; if (search->argmode == ARG_WORD) { e->bits = TYPE_Nm; e->match.type = DBM_REGEX;