Subject: man -s
To: Frank van der Linden <frank@wins.uva.nl>
From: Simon Burge <simonb@netbsd.org>
List: tech-userlevel
Date: 06/11/2000 01:17:28
Frank van der Linden wrote:

> On a related note.. I think man(1) should also accept "-s section".
> I often mistype that after spending a day using Solaris. And it's
> more consistent too.

The following allows for "-s section" and retains the current behaviour
if no -s option is used.  I'm not completely happy with the first
paragraph after the options list in the man page (the bit starting "If
the -s option is not specified...") - anyone suggest anything better?
If not, I'll commit this as-is in the next day or so.

It seems that SUSv2 only allows for a -k option to man.  Everything else
is an extension...

Simon.
--

Index: man.1
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/man/man.1,v
retrieving revision 1.10
diff -p -u -r1.10 man.1
--- man.1	2000/05/27 21:33:26	1.10
+++ man.1	2000/06/10 15:12:33
@@ -47,7 +47,10 @@
 .Op Fl M Ar path
 .Op Fl m Ar path
 .Op Fl S Ar srch
-.Op Ar section
+.Oo
+.Op Fl s
+.Ar section
+.Oc
 .Ar name Ar ...
 .Nm ""
 .Op Fl k
@@ -127,6 +130,16 @@ The subdirectories to be searched, and t
 is specified by the ``_subdir'' line in the
 .Nm
 configuration file.
+.It Fl s
+Restrict the directories that
+.Nm
+will search.  The
+.Nm
+configuration file (see
+.Xr man.conf 5 )
+specifies the possible
+.Ar section
+values that are currently available.
 .It Fl S
 Display only man pages that have the specified string in their
 filenames.  This allows the man page search process criteria to be
@@ -142,25 +155,16 @@ and
 combination.
 .El
 .Pp
-The optional
-.Ar section
-argument restricts the directories that
-.Nm
-will search.
-The
-.Nm
-configuration file (see
-.Xr man.conf 5 )
-specifies the possible
-.Ar section
-values that are currently available.
-Except when used with the
+If the
+.Ql Fl s
+option is not specified,
+there is more than one argument,
+the
 .Ql Fl k
-option,
-if only a single argument is specified or if the first argument is
-not a valid section,
-.Nm
-assumes that the argument is the name of a man page to be displayed.
+option is not used and the first argument is a valid section, that
+argument will be used as if specified by the
+.Ql Fl s
+option.
 .Sh ENVIRONMENT
 .Bl -tag -width MANPATHX
 .It Ev MACHINE
Index: man.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/man/man.c,v
retrieving revision 1.23
diff -p -u -r1.23 man.c
--- man.c	2000/05/27 21:33:26	1.23
+++ man.c	2000/06/10 15:12:33
@@ -91,7 +91,7 @@ main(argc, argv)
 	size_t len;
 	int ch, f_cat, f_how, found, abs_section;
 	char **ap, *cmd, *p, *p_add, *p_path;
-	const char *machine, *pager, *conffile, *pathsearch;
+	const char *machine, *pager, *conffile, *pathsearch, *sectionname;
 	char buf[MAXPATHLEN * 2];
 
 #ifdef __GNUC__
@@ -99,9 +99,8 @@ main(argc, argv)
 #endif
 
 	f_cat = f_how = 0;
-	conffile = p_add = p_path = NULL;
-	pathsearch = NULL;
-	while ((ch = getopt(argc, argv, "-aC:cfhkM:m:P:S:w")) != -1)
+	sectionname = pathsearch = conffile = p_add = p_path = NULL;
+	while ((ch = getopt(argc, argv, "-aC:cfhkM:m:P:s:S:w")) != -1)
 		switch (ch) {
 		case 'a':
 			f_all = 1;
@@ -133,6 +132,11 @@ main(argc, argv)
 		case 'k':
 			jump(argv, "-k", "apropos");
 			/* NOTREACHED */
+		case 's':
+			if (sectionname != NULL)
+				usage();
+			sectionname = optarg;
+			break;
 		case 'S':
 			pathsearch = optarg;
 			break;
@@ -188,11 +192,14 @@ main(argc, argv)
 	 * specified a section and it had absolute (rather than
 	 * relative) paths in the man.conf file.
 	 */
-	if (argc > 1 && (section = getlist(*argv)) != NULL) {
-		argv++;
-		argc--;
+	if ((argc > 1 || sectionname != NULL) &&
+	    (section = getlist(sectionname ? sectionname : *argv)) != NULL) {
+		if (sectionname == NULL) {
+			argv++;
+			argc--;
+		}
 		abs_section = (TAILQ_FIRST(&section->list) != NULL &&
-			       *(TAILQ_FIRST(&section->list)->s) == '/');
+		    *(TAILQ_FIRST(&section->list)->s) == '/');
 	} else {
 		section = NULL;
 		abs_section = 0;
@@ -780,8 +787,7 @@ static void
 usage()
 {
 	extern char *__progname;
-	(void)fprintf(stderr,
-    "Usage: %s [-achw] [-C file] [-M path] [-m path] [-S srch] [section] title ...\n",
-	    __progname);
+	(void)fprintf(stderr, "Usage: %s [-achw] [-C file] [-M path] [-m path]"
+	    "[-S srch] [[-s] section] title ...\n", __progname);
 	exit(1);
 }