1 # Written from scratch by Tom Tromey (tromey@cns.caltech.edu)
3 # manpage -- find and print a manual page.
4 # usage: manpage section name [printing]
14 mp="${MANPATH:-/usr/man}"
15 if [ "$#" -lt 2 ]; then return 1; fi # should print usage
16 if [ "$num" != "" ]; then
17 sec="${num%%[a-zA-Z]*}"
22 for i in $(echo "$mp" | tr : ' '); do
23 if [ ! -d "$i" ]; then continue; fi
24 file="$i"/man"$sec"/"$page"."$num"*
27 if [ -f "$file" ]; then
29 cmd=${MANROFF:-"nroff -man - | col | cat -s"}
31 if [ "$h" != "$zot" ]; then
32 while [ "$h" != "" ]; do
34 *e) cmd="${MANEQN:-neqn} | $cmd";;
35 *r) cmd="refer | $cmd";;
36 *t) cmd="tbl | $cmd";;
37 *v) cmd="vgrind | $cmd";;
38 *) ;; # should print error
43 if [ "$printing" != "" ]; then
44 (cd "$i"; eval "$cmd") < "$file" | ${PAGER:-more}
46 (cd "$i"; eval "$cmd") < "$file" > /tmp/manpage-$$
47 ${PAGER:-more} /tmp/manpage-$$
55 function whatis_internal ()
58 for j in $(echo "$MANPATH" | tr : ' '); do
59 if [ -f "$j/whatis" ]; then
60 eval $2 -i -e "$1" $j/whatis
67 local name=$(basename "$1")
68 whatis_internal "$name" "grep -w"
73 whatis_internal "$1" "grep -F"
76 # Note: "-" and "-t" together not supported. This man could be
77 # made a lot better, but it does everything I want.
80 local PAGER printing mpath MANROFF num
81 mpath="${MANPATH:-/usr/man}"
87 MANROFF=${TROFF:-"ptroff -man -t"}
97 local MANPATH="$mpath"
101 if [ "$1" = "-f" ]; then
108 whatis_internal "$a" "$g"
110 [0-9npol] | [0-9][a-z]* | new | public | old | local)
111 if [ "$1" = "new" ]; then
113 elif [ "$1" = "public" ]; then
115 elif [ "$1" = "old" ]; then
117 elif [ "$1" = "local" ]; then
123 manpage "$num" "$1" "$printing"
126 manpage "$num" "$1" "$printing"