From edcebb2ccc1d9dff61cbd2cf688598e28aa576b0 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Tue, 11 Nov 2014 19:04:55 +0000 Subject: In man(1) mode without -a, stop searching after the first manual tree that contained at least one match in order to not prefer mdoc(1) from ports over mdoc(7). As a bonus, this results in a speedup. --- cgi.c | 3 ++- main.c | 6 +++++- mansearch.c | 10 +++++++++- mansearch.h | 3 ++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cgi.c b/cgi.c index f09aaf67..81166e39 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.100 2014/10/28 17:36:19 schwarze Exp $ */ +/* $Id: cgi.c,v 1.101 2014/11/11 19:04:55 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -977,6 +977,7 @@ pg_search(const struct req *req) search.sec = req->q.sec; search.outkey = "Nd"; search.argmode = req->q.equal ? ARG_NAME : ARG_EXPR; + search.firstmatch = 1; paths.sz = 1; paths.paths = mandoc_malloc(sizeof(char *)); diff --git a/main.c b/main.c index af31a474..63ac45e8 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.198 2014/11/11 02:43:41 schwarze Exp $ */ +/* $Id: main.c,v 1.199 2014/11/11 19:04:55 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze @@ -294,6 +294,10 @@ main(int argc, char *argv[]) if (argc == 0) usage(search.argmode); + if (search.argmode == ARG_NAME && + outmode == OUTMODE_ONE) + search.firstmatch = 1; + /* Access the mandoc database. */ manpath_parse(&paths, conf_file, defpaths, auxpaths); diff --git a/mansearch.c b/mansearch.c index 9c88fac8..938d48c4 100644 --- a/mansearch.c +++ b/mansearch.c @@ -1,4 +1,4 @@ -/* $Id: mansearch.c,v 1.48 2014/09/03 18:09:14 schwarze Exp $ */ +/* $Id: mansearch.c,v 1.49 2014/11/11 19:04:55 schwarze Exp $ */ /* * Copyright (c) 2012 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze @@ -352,6 +352,14 @@ mansearch(const struct mansearch *search, sqlite3_finalize(s2); sqlite3_close(db); ohash_delete(&htab); + + /* + * In man(1) mode, prefer matches in earlier trees + * over matches in later trees. + */ + + if (cur && search->firstmatch) + break; } qsort(*res, cur, sizeof(struct manpage), manpage_compare); rc = 1; diff --git a/mansearch.h b/mansearch.h index 0aab4e76..444f6621 100644 --- a/mansearch.h +++ b/mansearch.h @@ -1,4 +1,4 @@ -/* $Id: mansearch.h,v 1.18 2014/09/03 18:09:14 schwarze Exp $ */ +/* $Id: mansearch.h,v 1.19 2014/11/11 19:04:55 schwarze Exp $ */ /* * Copyright (c) 2012 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze @@ -94,6 +94,7 @@ struct mansearch { const char *sec; /* mansection/NULL */ const char *outkey; /* show content of this macro */ enum argmode argmode; /* interpretation of arguments */ + int firstmatch; /* first matching database only */ }; __BEGIN_DECLS -- cgit v1.2.3