From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-1.sys.kth.se (smtp-1.sys.kth.se [130.237.32.175]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id pBIEqA8G008523 for ; Sun, 18 Dec 2011 09:52:11 -0500 (EST) Received: from mailscan-1.sys.kth.se (mailscan-1.sys.kth.se [130.237.32.91]) by smtp-1.sys.kth.se (Postfix) with ESMTP id 14394156B5C for ; Sun, 18 Dec 2011 15:52:05 +0100 (CET) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-1.sys.kth.se ([130.237.32.175]) by mailscan-1.sys.kth.se (mailscan-1.sys.kth.se [130.237.32.91]) (amavisd-new, port 10024) with LMTP id oaD4n8BZdN+e for ; Sun, 18 Dec 2011 15:52:03 +0100 (CET) X-KTH-Auth: kristaps [83.250.6.251] X-KTH-mail-from: kristaps@bsd.lv X-KTH-rcpt-to: tech@mdocml.bsd.lv Received: from macky.local (c83-250-6-251.bredband.comhem.se [83.250.6.251]) by smtp-1.sys.kth.se (Postfix) with ESMTP id 27BDD156B6B for ; Sun, 18 Dec 2011 15:52:02 +0100 (CET) Message-ID: <4EEDFE12.4020702@bsd.lv> Date: Sun, 18 Dec 2011 15:52:02 +0100 From: Kristaps Dzonsons User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0 X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 To: tech@mdocml.bsd.lv Subject: MANPATH and overriding/modifying default paths. Content-Type: multipart/mixed; boundary="------------080103050408050209080604" This is a multi-part message in MIME format. --------------080103050408050209080604 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, 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. Objections? I personally like this, as on shared machines I usually have a scattering of utilities in my ~/bin and would love a ~/man with the manuals showing up by default (i.e., manually running mandocdb(8) to generate databases then setting MANPATH in my .profile). It has always, always annoyed me that I can't do this. Take care, Kristaps --------------080103050408050209080604 Content-Type: text/plain; name="patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch.txt" Index: apropos.1 =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/apropos.1,v retrieving revision 1.13 diff -u -r1.13 apropos.1 --- apropos.1 12 Dec 2011 02:00:49 -0000 1.13 +++ apropos.1 18 Dec 2011 14:48:27 -0000 @@ -239,11 +239,22 @@ .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: catman.8 =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/catman.8,v retrieving revision 1.2 diff -u -r1.2 catman.8 --- catman.8 4 Dec 2011 22:52:50 -0000 1.2 +++ catman.8 18 Dec 2011 14:48:27 -0000 @@ -23,6 +23,7 @@ .Sh SYNOPSIS .Nm catman .Op Fl fv +.Op Fl C Ar file .Op Fl M Ar manpath .Op Fl m Ar manpath .Op Fl o Ar path @@ -37,6 +38,12 @@ Force an update to all files. .It Fl v Print each file being updated. +.It Fl C Ar file +Specify an alternative configuration +.Ar file +in +.Xr man.conf 5 +format. .It Fl M Ar manpath Use the colon-separated path instead of the default list of paths searched for @@ -44,7 +51,7 @@ databases. Invalid paths, or paths without manual databases, are ignored. .It Fl m Ar manpath -Append the colon-separated paths to the list of paths searched +Prepend the colon-separated paths to the list of paths searched for .Xr mandocdb 8 databases. @@ -70,6 +77,26 @@ If .Fl f is specified, all files are updated. +.Sh ENVIRONMENT +.Bl -tag -width Ds +.It Ev MANPATH +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 EXIT STATUS .Ex -std .Sh SEE ALSO Index: catman.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/catman.c,v retrieving revision 1.7 diff -u -r1.7 catman.c --- catman.c 16 Dec 2011 12:06:35 -0000 1.7 +++ catman.c 18 Dec 2011 14:48:27 -0000 @@ -66,7 +66,7 @@ main(int argc, char *argv[]) { int ch; - char *aux, *base; + char *aux, *base, *conf_file; struct manpaths dirs; char buf[MAXPATHLEN]; extern char *optarg; @@ -81,8 +81,11 @@ aux = base = NULL; xstrlcpy(buf, "/var/www/cache/man.cgi", MAXPATHLEN); - while (-1 != (ch = getopt(argc, argv, "fm:M:o:v"))) + while (-1 != (ch = getopt(argc, argv, "C:fm:M:o:v"))) switch (ch) { + case ('C'): + conf_file = optarg; + break; case ('f'): force = 1; break; @@ -112,7 +115,7 @@ } memset(&dirs, 0, sizeof(struct manpaths)); - manpath_parse(&dirs, NULL, base, aux); + manpath_parse(&dirs, conf_file, base, aux); ch = manup(&dirs, buf); manpath_free(&dirs); return(ch ? EXIT_SUCCESS : EXIT_FAILURE); @@ -124,6 +127,7 @@ fprintf(stderr, "usage: %s " "[-fv] " + "[-C file] " "[-o path] " "[-m manpath] " "[-M manpath]\n", Index: manpath.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/manpath.c,v retrieving revision 1.7 diff -u -r1.7 manpath.c --- manpath.c 13 Dec 2011 21:09:01 -0000 1.7 +++ manpath.c 18 Dec 2011 14:48:27 -0000 @@ -87,15 +87,40 @@ free(buf); pclose(stream); #else - manpath_parseline(dirs, auxp); + int append, prepend; + char *insert; - if (NULL == defp) - defp = getenv("MANPATH"); + insert = NULL; + append = prepend = 0; + file = NULL == file ? MAN_CONF_FILE : file; - if (NULL == defp) - manpath_manconf(dirs, file ? file : MAN_CONF_FILE); - else + if (NULL == defp && NULL != (defp = getenv("MANPATH"))) { + append = ':' == defp[0]; + if ( ! append && '\0' != defp[0]) + if (':' == defp[(int)strlen(defp) - 1]) + prepend = 1; + if ( ! append && ! prepend) + insert = strstr(defp, "::"); + } + + if (NULL == defp) { + manpath_manconf(dirs, file); + return; + } + + if (prepend) + manpath_manconf(dirs, file); + + if (NULL != insert) { + *insert++ = '\0'; manpath_parseline(dirs, defp); + manpath_manconf(dirs, file); + manpath_parseline(dirs, insert + 1); + } else + manpath_parseline(dirs, defp); + + if (append) + manpath_manconf(dirs, file); #endif } Index: whatis.1 =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/whatis.1,v retrieving revision 1.4 diff -u -r1.4 whatis.1 --- whatis.1 12 Dec 2011 02:00:49 -0000 1.4 +++ whatis.1 18 Dec 2011 14:48:27 -0000 @@ -111,11 +111,22 @@ .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 --------------080103050408050209080604-- -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv