=================================================================== RCS file: /cvs/mandoc/mansearch.c,v retrieving revision 1.79 retrieving revision 1.84 diff -u -p -r1.79 -r1.84 --- mandoc/mansearch.c 2018/11/22 12:01:46 1.79 +++ mandoc/mansearch.c 2023/04/28 19:11:03 1.84 @@ -1,4 +1,4 @@ -/* $Id: mansearch.c,v 1.79 2018/11/22 12:01:46 schwarze Exp $ */ +/* $Id: mansearch.c,v 1.84 2023/04/28 19:11:03 schwarze Exp $ */ /* * Copyright (c) 2012 Kristaps Dzonsons * Copyright (c) 2013-2018 Ingo Schwarze @@ -36,7 +36,6 @@ #include #include -#include "mandoc.h" #include "mandoc_aux.h" #include "mandoc_ohash.h" #include "manconf.h" @@ -192,7 +191,7 @@ mansearch(const struct mansearch *search, mpage->file, R_OK) == -1) { warn("%s", mpage->file); warnx("outdated mandoc.db contains " - "bogus %s entry, run makewhatis %s", + "bogus %s entry, run makewhatis %s", page->file + 1, paths->paths[i]); free(mpage->file); free(rp); @@ -200,6 +199,7 @@ mansearch(const struct mansearch *search, } mpage->names = buildnames(page); mpage->output = buildoutput(outkey, page); + mpage->bits = search->firstmatch ? rp->bits : 0; mpage->ipath = i; mpage->sec = *page->sect - '0'; if (mpage->sec < 0 || mpage->sec > 9) @@ -220,7 +220,7 @@ mansearch(const struct mansearch *search, if (cur && search->firstmatch) break; } - if (res != NULL) + if (res != NULL && cur > 1) qsort(*res, cur, sizeof(struct manpage), manpage_compare); if (chdir_status && getcwd_status && chdir(buf) == -1) warn("%s", buf); @@ -295,8 +295,10 @@ manmerge_term(struct expr *e, struct ohash *htab) break; slot = ohash_lookup_memory(htab, (char *)&res, sizeof(res.page), res.page); - if ((rp = ohash_find(htab, slot)) != NULL) + if ((rp = ohash_find(htab, slot)) != NULL) { + rp->bits |= res.bits; continue; + } rp = mandoc_malloc(sizeof(*rp)); *rp = res; ohash_insert(htab, slot, rp); @@ -409,7 +411,8 @@ manpage_compare(const void *vp1, const void *vp2) mp1 = vp1; mp2 = vp2; - if ((diff = mp1->sec - mp2->sec)) + if ((diff = mp2->bits - mp1->bits) || + (diff = mp1->sec - mp2->sec)) return diff; /* Fall back to alphabetic ordering of names. */ @@ -488,7 +491,7 @@ lstlen(const char *cp, size_t sep) /* * Print the NUL-terminated list of NUL-terminated strings - * into the buffer, seperating strings with sep. + * into the buffer, separating strings with sep. */ static void lstcat(char *buf, size_t *i, const char *cp, const char *sep)