BSD style man (plus another apropos for the 4D)
Bevis Ip
ip at me.utoronto.ca
Fri Mar 10 11:40:25 AEST 1989
Here are three shell scripts I wrote quite a while ago for BSD style "man".
This "man" runs much faster than SGI's own but you have to run
"makemanpaths" (and "makewhatis", although not really necessary) whenever you
have new man page entries. This version of "makewhatis" is more efficient
(in my opinion) than the one Dave Ciemiewicz (ciemo at bananapc.SGI.COM) just
posted, although it still takes about 10 minutes to finish. The scripts are
geared at IRIS 4D running IRIX 3.1 (evolved from those I wrote back in IRIX
2.2 days). Sorry, no man page either.
bevis
------------CUT-----------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# makemanpaths
# makewhatis
# man
# This archive created: Thu Mar 9 19:06:38 1989
export PATH; PATH=/bin:$PATH
if test -f 'makemanpaths'
then
echo shar: will not over-write existing file "'makemanpaths'"
else
cat << \SHAR_EOF > 'makemanpaths'
#!/bin/sh
# Build man pages path for faster location.
#
# CopyRight (C) 1989 by Bevis Ip, all rights reserved.
#
# Email: ip at me.toronto.edu, uunet!utai!me!ip
#
# Everyone is granted the permission to copy, modify and redistribute
# this program provided that this notice is remain attached. The
# authour assumes no liability of any kind in connection with the
# usage of this code. Use it at your own risk.
#
MANPATHS=${1-/usr/local/lib/manpaths}
cd /usr/catman
trap '' 1 2 3 15
rm -f $MANPATHS
find . ! -type directory -print | sed 's/^.\///' | sort -t/ -2 > $MANPATHS
chmod 444 $MANPATHS
SHAR_EOF
chmod +x 'makemanpaths'
fi # end of overwriting check
if test -f 'makewhatis'
then
echo shar: will not over-write existing file "'makewhatis'"
else
cat << \SHAR_EOF > 'makewhatis'
#!/bin/sh
# Build BSD style whatis database for whatis (man -f) and apropos (man -k).
#
# This is a hack; worked backward from the formatted, packed catman pages.
# (3G) man pages had been formatted strangely and require special treatment.
#
# CopyRight (C) 1989 by Bevis Ip, all rights reserved.
#
# Email: ip at me.toronto.edu, uunet!utai!me!ip
#
# Everyone is granted the permission to copy, modify and redistribute
# this program provided that this notice is remain attached. The
# authour assumes no liability of any kind in connection with the
# usage of this code. Use it at your own risk.
#
WHATIS=${1-/usr/local/lib/whatis}
TMP=/tmp/whatis
MANDIR=/usr/catman
> $TMP
for i in `find $MANDIR -type d -print`
do
cd $i
if [ "`echo *.z`" = "*.z" ]
then
continue
fi
case $i in
$MANDIR/g_man/cat3/*) # no section info @#$%^&*(
pcat `find . ! -type l -name \*.z -print` | col -b | \
sed -n -e '/^ *$/d' \
-e '/^ *NAME$/b getname' -e b \
-e :getname -e n -e h -e :getmore -e n \
-e '/.*SY.*SIS/b gotit' \
-e '/.*DESC/b gotit' \
-e '/.*SPEC/b gotit' \
-e H -e "b getmore" \
-e :gotit -e x \
-e 's/\n/(3G) /' -e 's/\n/ /g' \
-e 's/[ ][ ]*/ /g;p' \
>> $TMP
continue
;;
esac
pcat `find . ! -type l -name \*.z -print` | col -b | \
sed -n -e '/^ *$/d' \
-e '/^ *.*([0-9].*) *.*([0-9].*)$/b getsect' \
-e '/^ *NAME$/b getname' -e b -e :getname -e n \
-e '/.*SY.*SIS/b gotit' \
-e '/.*DESC/b gotit' \
-e '/.*SPEC/b gotit' \
-e H -e "b getname" \
-e :gotit -e x \
-e 's/\n/ /g' -e 's/[ ][ ]*/ /g;p;b' \
-e :getsect -e 's/^ *.*(/(/' \
-e 's/ *.*$//;h' \
>> $TMP
done
trap '' 1 2
rm -f $WHATIS
awk '{ gotit=0
printf "%s", $2
for (i = 3; i <= NF; i++) {
if ($i == "-") {
if (gotit++ == 0)
printf " %s\t-", $1
else
printf " -"
} else {
if ($i ~ /.*-$/) {
# end=length($i)-1
# printf " %s", substr($i, 1, end)
printf " %s", $i
if (++i <= NF)
printf "%s", $i
} else
printf " %s", $i
}
}
if (gotit == 0)
printf " %s", $1
printf "\n"
}' $TMP | sort -u > $WHATIS
chmod 444 $WHATIS
SHAR_EOF
chmod +x 'makewhatis'
fi # end of overwriting check
if test -f 'man'
then
echo shar: will not over-write existing file "'man'"
else
cat << \SHAR_EOF > 'man'
#!/bin/sh
# This is model to BSD man; quick and dirty but fast.
#
# CopyRight (C) 1989 by Bevis Ip, all rights reserved.
#
# Email: ip at me.toronto.edu, uunet!utai!me!ip
#
# Everyone is granted the permission to copy, modify and redistribute
# this program provided that this notice is remain attached. The
# authour assumes no liability of any kind in connection with the
# usage of this code. Use it at your own risk.
#
#MAKEMANPATHS=/usr/local/bin/makemanpaths
REALMAN=/usr/bin/man
MANPATHS=/usr/local/lib/manpaths
WHATIS=/usr/local/lib/whatis
PAGER=${MANPAGER-${PAGER-'less -sbp50'}}
args="$@"
for i
do
case $i in
[1-8][Cc])
std=1
case $i in
1?) sec="cat1.*" ;; 2?) sec="cat2.*" ;;
3?) sec="cat3.*" ;; 4?) sec="cat4.*" ;;
5?) sec="cat5.*" ;; 6?) sec="cat6.*" ;;
7?) sec="cat7.*" ;; 8?) sec="cat8.*" ;;
esac ;;
[1-8][Ff])
ftn=1
case $i in
1?) sec="cat1.*" ;; 2?) sec="cat2.*" ;;
3?) sec="cat3.*" ;; 4?) sec="cat4.*" ;;
5?) sec="cat5.*" ;; 6?) sec="cat6.*" ;;
7?) sec="cat7.*" ;; 8?) sec="cat8.*" ;;
esac ;;
[1-8]) sec="cat$i.*" ;;
-w) path=1 ;;
-T*) TERM="`echo $i | sed 's/-T//'`" ; export TERM ;;
-k) apropos=1 ;;
-f) whatis=1 ;;
-*) usage=1 ; break ;;
*) break ;;
esac
shift
done
if test -n "$usage" -o $# -eq 0
then
echo "Usage: man [-w] [sec] name ..." >&2
echo " man [-k] key ..." >&2
exit 1
fi
if test -n "$apropos"
then
for i in "$@"
do grep -i "$i" $WHATIS
done
exit 0
elif test -n "$whatis"
then
for i in "$@"
do egrep "^$i[ ,]|, $i" $WHATIS
done
exit 0
fi
if test ! -s $MANPATHS
then
# echo "Building manpaths, hang on..."
# exec $MAKEMANPATHS $MANPATHS
echo "No manpaths, starting up $REALMAN..."
exec $REALMAN $args
fi
cd $MANDIR
for target
do
manpages="$manpages `grep \"$sec/$target.z\$\" $MANPATHS 2>&-`"
done
# make fortran pages last (usually not what people's looking for)
for i in $manpages
do
case $i in
*/ftn/*) ftnpages="$ftnpages $i" ;;
*) stdpages="$stdpages $i" ;;
esac
done
if test -n "$std"
then
manpages=$stdpages
elif test -n "$ftn"
then
manpages=$ftnpages
else
manpages=$stdpages$ftnpages
fi
if test -z "$manpages"
then
if test -n "$sec"
then
set $args; sec=$1; shift
echo "No entry for $* in section $sec of the manual."
else
echo "No manual entry for $*."
fi
exit 1
fi
if test -n "$path"
then
echo $manpages
exit 0
fi
bold=`tput smso`
boldoff=`tput rmso`
set $manpages
trap '' 2
pcat $1 | col | eval $PAGER
trap 2
while :
do
shift
if test $# -eq 0
then
exit 0
fi
echo "${bold}----> $1 [$#] <---- (More?) ${boldoff}\c"
read cmd
case "$cmd" in
n*|N*) continue ;;
q*|Q*) exit 0 ;;
esac
trap '' 2
pcat $1 | col | eval $PAGER
trap 2
done
SHAR_EOF
chmod +x 'man'
fi # end of overwriting check
# End of shell archive
exit 0
--
Bevis Ip University of Toronto Mechanical Engineering
CSNET : ip at me.toronto.edu BITNET: ip at me.UTORONTO
Internet: ip%me.toronto.edu at relay.cs.net
UUCP : {allegra,decwrl,decvax}!utcsri!me!ip _OR_ {pyramid,uunet}!utai!me!ip
More information about the Comp.sys.sgi
mailing list