tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Re: MANPATH and overriding/modifying default paths.
Date: Sat, 24 Dec 2011 23:14:29 +0100	[thread overview]
Message-ID: <20111224221429.GF15148@iris.usta.de> (raw)
In-Reply-To: <4EEDFE12.4020702@bsd.lv>

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

  parent reply	other threads:[~2011-12-24 22:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-18 14:52 Kristaps Dzonsons
2011-12-18 15:08 ` Kristaps Dzonsons
2011-12-18 19:09   ` Ingo Schwarze
2011-12-18 19:50     ` Kristaps Dzonsons
2011-12-24 22:14 ` Ingo Schwarze [this message]
2011-12-24 22:36   ` Kristaps Dzonsons

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=20111224221429.GF15148@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=tech@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).