From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout.scc.kit.edu (scc-mailout.scc.kit.edu [129.13.185.202]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id pBOMEURS014553 for ; Sat, 24 Dec 2011 17:14:31 -0500 (EST) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by scc-mailout-02.scc.kit.edu with esmtp (Exim 4.72 #1) id 1ReZrJ-0005Ar-4m; Sat, 24 Dec 2011 23:14:29 +0100 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1ReZrJ-0005gd-6H for tech@mdocml.bsd.lv; Sat, 24 Dec 2011 23:14:29 +0100 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1ReZrJ-0006EA-56 for tech@mdocml.bsd.lv; Sat, 24 Dec 2011 23:14:29 +0100 Received: from schwarze by usta.de with local (Exim 4.72) (envelope-from ) id 1ReZrJ-0006bK-4G for tech@mdocml.bsd.lv; Sat, 24 Dec 2011 23:14:29 +0100 Date: Sat, 24 Dec 2011 23:14:29 +0100 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: Re: MANPATH and overriding/modifying default paths. Message-ID: <20111224221429.GF15148@iris.usta.de> References: <4EEDFE12.4020702@bsd.lv> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4EEDFE12.4020702@bsd.lv> User-Agent: Mutt/1.5.21 (2010-09-15) Hi Kristaps, Kristaps Dzonsons wrote on Sun, Dec 18, 2011 at 03:52:02PM +0100: > A while back, I complained to Ingo that MANPATH is heavy-handed: it > doesn't allow us to modify the default search path (in, e.g., > /etc/man.conf), but only override it. > > He mentioned that in manpath(1) used on systems, MANPATH can modify > instead of override by placemen to colons. To wit: > > MANPATH > If $MANPATH is set, manpath displays its value rather than > determining it on the fly. If $MANPATH is prefixed by a colon, then > the value of the variable is appended to the list determined from > the content of the configuration files. If the colon comes at the > end of the value in the variable, then the determined list is > appended to the content of the variable. If the value of the > variable contains a double colon (::), then the determined list is > inserted in the middle of the value, between the two colons. > > The enclosed patch does just this for apropos(1), whatis(1), and > catman(8) (which is also updated with -C like the others). I > modified the explanation above to be (I hope) a little clearer as to > precedence. Yes, your wording is better, very clear and concise. > Objections? First, i misread your patch. You changed the #else clause of the cpp(1) alternative, not the #ifdef clause. Thanks for pointing that out once again. Then, i hesitated for some time whether we really want this, but came to the conclusion that we have MANPATH anyway, it does not change MANPATH semantics that much, the proposed use case makes sense, i could not come up with a better solution, and it improves compatibility a tiny bit. So i have tweaked it and committed it to OpenBSD. At the expense of three additional lines of code - actually, all of them closing braces - i got rid of two local variables, made the code flow much more obvious and got the oportunity of inserting eight comments. While here, i have also put back -m (which got lost) and copied Linux semantics of treating an empty MANPATH the same way as an undefined MANPATH, which obviously is more useful than returning empty results. Feel free to merge to bsd.lv, or tell me to do it; conflict resolution will be trivial. Yours, Ingo CVSROOT: /cvs Module name: src Changes by: schwarze@cvs.openbsd.org 2011/12/24 14:51:40 Modified files: usr.bin/mandoc : apropos.1 manpath.c Log message: Support leading, trailing and double colons in MANPATH to prepend, append or insert the man.conf(5) default path; compatible with GNU manpath(1), implementation by kristaps@, heavily tweaked by me. Index: apropos.1 =================================================================== RCS file: /cvs/src/usr.bin/mandoc/apropos.1,v retrieving revision 1.9 diff -u -p -r1.9 apropos.1 --- apropos.1 12 Dec 2011 01:59:13 -0000 1.9 +++ apropos.1 24 Dec 2011 21:42:07 -0000 @@ -239,11 +239,22 @@ Text production: .Sh ENVIRONMENT .Bl -tag -width Ds .It Ev MANPATH -Colon-separated paths overriding the default list of paths searched for +Colon-separated paths modifying the default list of paths searched for manual databases. Invalid paths, or paths without manual databases, are ignored. Overridden by .Fl M . +If +.Ev MANPATH +begins with a +.Sq \&: , +it is appended to the default list; +else if it ends with +.Sq \&: , +it is prepended to the default list; else if it contains +.Sq \&:: , +the default list is inserted between the colons. +If none of these conditions are met, it overrides the default list. .El .Sh FILES .Bl -tag -width "/etc/man.conf" -compact Index: manpath.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/manpath.c,v retrieving revision 1.3 diff -u -p -r1.3 manpath.c --- manpath.c 19 Dec 2011 02:26:33 -0000 1.3 +++ manpath.c 24 Dec 2011 21:42:07 -0000 @@ -38,16 +38,54 @@ void manpath_parse(struct manpaths *dirs, const char *file, char *defp, char *auxp) { + char *insert; + /* Always prepend -m. */ manpath_parseline(dirs, auxp); - if (NULL == defp) - defp = getenv("MANPATH"); + /* If -M is given, it overrides everything else. */ + if (NULL != defp) { + manpath_parseline(dirs, defp); + return; + } + + /* MANPATH and man.conf(5) cooperate. */ + defp = getenv("MANPATH"); + if (NULL == file) + file = MAN_CONF_FILE; + + /* No MANPATH; use man.conf(5) only. */ + if (NULL == defp || '\0' == defp[0]) { + manpath_manconf(dirs, file); + return; + } + + /* Prepend man.conf(5) to MANPATH. */ + if (':' == defp[0]) { + manpath_manconf(dirs, file); + manpath_parseline(dirs, defp); + return; + } + + /* Append man.conf(5) to MANPATH. */ + if (':' == defp[(int)strlen(defp) - 1]) { + manpath_parseline(dirs, defp); + manpath_manconf(dirs, file); + return; + } - if (NULL == defp) - manpath_manconf(dirs, file ? file : MAN_CONF_FILE); - else + /* Insert man.conf(5) into MANPATH. */ + insert = strstr(defp, "::"); + if (NULL != insert) { + *insert++ = '\0'; manpath_parseline(dirs, defp); + manpath_manconf(dirs, file); + manpath_parseline(dirs, insert + 1); + return; + } + + /* MANPATH overrides man.conf(5) completely. */ + manpath_parseline(dirs, defp); } /* -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv