source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: In man(1) mode without -a, stop searching after the first manual
Date: Tue, 11 Nov 2014 14:04:55 -0500 (EST)	[thread overview]
Message-ID: <201411111904.sABJ4teZ030137@krisdoz.my.domain> (raw)

Log Message:
-----------
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.

Modified Files:
--------------
    mdocml:
        cgi.c
        main.c
        mansearch.c
        mansearch.h

Revision Data
-------------
Index: mansearch.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mansearch.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -Lmansearch.h -Lmansearch.h -u -p -r1.18 -r1.19
--- mansearch.h
+++ mansearch.h
@@ -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
Index: mansearch.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mansearch.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -Lmansearch.c -Lmansearch.c -u -p -r1.48 -r1.49
--- mansearch.c
+++ mansearch.c
@@ -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;
Index: cgi.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/cgi.c,v
retrieving revision 1.100
retrieving revision 1.101
diff -Lcgi.c -Lcgi.c -u -p -r1.100 -r1.101
--- cgi.c
+++ cgi.c
@@ -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 *));
Index: main.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.c,v
retrieving revision 1.198
retrieving revision 1.199
diff -Lmain.c -Lmain.c -u -p -r1.198 -r1.199
--- main.c
+++ main.c
@@ -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);
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-11-11 19:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201411111904.sABJ4teZ030137@krisdoz.my.domain \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).