Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Jul 2003 18:34:50 -0400
From:      Chuck Swiger <cswiger@mac.com>
To:        stable@FreeBSD.ORG, jwe@che.utexas.edu
Subject:   A patch to man to handle "man.1"...
Message-ID:  <3F19C78A.7030008@mac.com>

next in thread | raw e-mail | index | archive | help
Hi, all--

I've always thought that specifying sections via "man -s 1 man" or "man 1 man" 
was ugly, and didn't work very well with filename completion.  Diff relative to 
/usr/src/gnu/usr.bin/man to also handle the syntax of "man man.1":

--- man_old/man.c       Sat Jul 19 17:17:13 2003
+++ man/man.c   Sat Jul 19 18:08:23 2003
@@ -149,6 +149,8 @@
    void do_apropos ();
    void do_whatis ();
    int man ();
+  int arglength = 0;
+  int i;

    prognam = mkprogname (argv[0]);
    longsec = NULL;
@@ -200,6 +202,23 @@

           continue;
         }
+
+      /* handle a section specified as "man.1" */
+      arglength = strlen(nextarg);
+
+      for (i = arglength; i > 0 ; i--) {
+        if (nextarg[i] == '.') {
+          tmp = is_section (&(nextarg[i + 1]), manp);
+          if (tmp != NULL) {
+            shortsec = tmp;
+            nextarg[i] = '\0';
+
+            if (debug)
+              fprintf (stderr, "\nsection (via suffix): %s\n", shortsec);
+          }
+          break;
+        }
+      }

        if (apropos) {
         do_apropos (nextarg);
--- man_old/version.h   Sat Jul 19 17:17:13 2003
+++ man/version.h       Sat Jul 19 18:28:07 2003
@@ -14,4 +14,4 @@
   * Austin, Texas  78712
   */

-static char version[] = "1.1";
+static char version[] = "1.2";

	--

This patch seems to handle boundary cases like rc.i386 (which at least somewhat 
resembles a section number :-) properly.

-- 
-Chuck

PS: People using ZSH will find the following completion script very handy in 
conjunction with the above, as it provides tab-based completion for manpages:

# Manual page completion
man_glob () {
   local a
   read -cA a
   if [[ $a[2] = [0-9]* ]] then
     reply=( $^manpath/man$a[2]/$1*$2(N:t:r) )
   else
     reply=( $^manpath/man*/$1*$2(N:t:r) )
   fi
}

compctl -K man_glob man




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3F19C78A.7030008>