tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Kristaps Dzonsons <kristaps@bsd.lv>
To: tech@mdocml.bsd.lv
Subject: MANPATH and overriding/modifying default paths.
Date: Sun, 18 Dec 2011 15:52:02 +0100	[thread overview]
Message-ID: <4EEDFE12.4020702@bsd.lv> (raw)

[-- Attachment #1: Type: text/plain, Size: 1392 bytes --]

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

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 5985 bytes --]

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

             reply	other threads:[~2011-12-18 14:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-18 14:52 Kristaps Dzonsons [this message]
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
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=4EEDFE12.4020702@bsd.lv \
    --to=kristaps@bsd.lv \
    --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).