:
#!sh
# @[$]man       1.11
#
# A version of the man command written for the shell: based on old published
# version by S. Bourne.  This extends the system "man" command to the
# ULISP manual pages.  It does not deal with fancy terminals, but its
# speed relative to those man scripts which do, speaks in its favor.
#
# WCH
#

# With no arguments display usage.
case $# in
	0)      /bin/echo 'Usage: man [-w] [-[e]nt] [-p] [section] name'
		/bin/echo 'Sections: [0-6]u   user'
		/bin/echo '          [0-8]l   local'
		/bin/echo '          [0-7]L   LISP'
		/bin/echo '          0,1,7,8a administrative'
		exit 1
esac

# Stipulate default directories for utilitites and ports used.
# default formater is nroff, but troff may be elected.
#
#	THESE PATHS MAY HAVE TO BE CHANGED FOR DIFFERENT FILE SYSTEM LAYOUTS
#	NB Printing avoids queuing - You may want to change this.
MORE=/usr/bin/more
LP=/dev/lp2
N=/usr/bin/nroff
MANDIR=/usr/man

# change the present working directory of the invoked shell.
cd $MANDIR

# Options must preceed the section number.  If no section number is given
# then all sections are searched.  Therfore initialize section to some
# definitly non-existant section.  Watch this if new section is added.
# March 23 1986 - non-existant section below was originally 'X', since
# somebody may add an "experimental" section, the @ seems safer.

section=@

# nroffed file is not sent to the line printer unless -p

print=no

# pathname is not printed unless -w

path=no

# preprocessing by eqn for troff and neqn for nroff is not set initially

pre=notset


# Loop on arguments
for i
do
	case $i in
		[0-8])                           section=$i
						 division=all;;
		[0-6][uU])                       section=$i
			case $section in
				0[uU]) section=0 ;;
				1[uU]) section=1 ;;
				2[uU]) section=2 ;;
				3[uU]) section=3 ;;
				4[uU]) section=4 ;;
				5[uU]) section=5 ;;
			esac
						 division=u;;
		[0-8]l)                          section=$i
			case $section in
				0[l]) section=0 ;;
				1[l]) section=1 ;;
				2[l]) section=2 ;;
				3[l]) section=3 ;;
				4[l]) section=4 ;;
				5[l]) section=5 ;;
				6[l]) section=6 ;;
				7[l]) section=7 ;;
				8[l]) section=8 ;;
			esac
						 division=l;;
		[0178][aA])                      section=$i
			case $section in
				0[aA]) section=0 ;;
				1[aA]) section=1 ;;
				7[aA]) section=7 ;;
				8[aA]) section=8 ;;
			esac
						 division=a;;
		[0-7]L)                           section=$i
			case $section in
				0L) section=0 ;;
				1L) section=1 ;;
				2L) section=2 ;;
				3L) section=3 ;;
				4L) section=4 ;;
				5L) section=5 ;;
				6L) section=6 ;;
			esac
						 division=L;;
		-t)			         N=/usr/bin/troff  ;;
		-te | -et | -e)		         N=/usr/bin/troff
						 pre=eqn ;;
		-n)			         N=/usr/bin/nroff  ;;
		-en | -ne)		         N=/usr/bin/troff
						 pre=neqn ;;
		-w)			         path=yes ;;
		-p)			         print=yes ;;
		-*)			         /bin/echo Unknown flag \'$i\' ;;
		*)
		        if test -f ${division}_man/man$section/$i.$section
			then
				/bin/echo /usr/man/${division}_man/man$section/$i.$section
				case $path in
				yes)
					found=yes
					continue ;;
				esac

				case $pre in
				eqn | neqn)
					$pre ${division}_man/man$section/$i.$section | $N -man | $MORE ;;
				notset)
					${N} -man ${division}_man/man$section/$i.$section | $MORE ;;
				esac

				case $print in
				yes)
					${N} -man ${division}_man/man$section/$i.$section | $LP ;;
				esac
			else
# look through all the manual sections
				found=no
				for division in u l a L
				do
					for j in 0 1 2 3 4 5 6 7 8 M
					do
						if test -f ${division}_man/man$j/$i.$j
						then
							case $path in
							yes)  /bin/echo "/usr/man/${division}_man/man$j/$i.$j"
								found=yes
								continue ;;
							esac

							case $pre in
							eqn | neqn)
								$pre ${division}_man$j/$i.$j | $N -man | $MORE ;;
							notset)
								${N} -man ${division}_man/man$j/$i.$j | $MORE ;;
							esac
						found=yes
						fi
					done
				done
				case $found in
				no) /bin/echo \'$i\': No manual entry
				    /bin/echo "Try apropos."
					;;
				esac
			fi
	esac
done

exit 0


Return to Home Page
Return to Metayoga Page
Return to shell Page


The URL for this document is:
http://graham.main.nc.us/~bhammel/graham/SHELL/man.html
Created: 1997
Last Updated: May 28, 2000 Email me, Bill Hammel at
bhammel@graham.main.nc.us
READ WARNING BEFORE SENDING E-MAIL