source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: In man(1) mode without -a, stop searching after the first manual
@ 2014-11-11 19:04 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-11-11 19:04 UTC (permalink / raw)
  To: source

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-11 19:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-11 19:04 mdocml: In man(1) mode without -a, stop searching after the first manual schwarze

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).