apropos version B 3000-series
Stephen Smith
ssmith at eos
Wed Mar 15 09:47:23 AEST 1989
I changed the format of apropos to avoid problems with split()
and to make it appear a true clone.
Installation as /usr/local/bin/apropos. The index by default points
at /usr/local/lib/index.
Steve Smith
comments/complaints/compliments to:
ssmith at eos.arc.nas.gov
============================ snip snip ================================
#!/bin/sh
#
# BSD apropos clone -- lookup manual pages by keyword
#
# Usage: apropos [-i] | [ key words... ]
# -i builds the index used for the keyword lookups.
#
# Notes:
# It is not advisable to build the index and do keyword lookups simultaneously.
# We use cron to build the index once a week at night.
#
#
# $Header: /usr/u/ssmith/RCS/apropos,v 1.3 88/08/12 10:00:15 ssmith Exp $
#
# $Log: apropos,v $
# Revision 1.3 88/08/12 10:00:15 ssmith
# New rcs file
#
# Revision 1.3 88/06/13 12:32:15 ssmith
# Exit with message if no arguments (used to hang grep).
# 'Unknown flag' message ( from "Usage....").
# Handle multiple args. ( 'for' loop ).
# Use of grep's exit codes--message if nothing found.
# grep flag from '-w' to '-i' (doug).
# Eliminated pipe to 'more' ( screwed up $?). If desired, run grep in
# a subshell then filter output, e.g., '| fold | more'.
# Awk properly eliminates .B's from SGI graphics manual pages.
#
# Revision 1.2 88/06/13 12:27:37 ssmith
# test for su added 11/9/87
#
# Revision 1.1 88/06/13 12:21:05 ssmith
# Initial revision
#
#
# Database:
index=/usr/local/lib/index
build=0 # don't build
if [ 0 -eq $# ]
then
echo $0 What?;
exit; # echo "Usage: $0 [-i] [word]";
fi
for i
do
case "$i"
in
-i) if [ ! -w /bin/su ]
then
echo $USER: You must be root to build index.
exit 1
else
build=1
fi
break ;;
-*) echo Unknown flag $i;
exit ;;
*) (if grep -i $i $index
then
: ok;
else
echo "$i: Nothing appropriate.";
fi) | fold
esac
done
if [ $build -eq 0 ]; then exit ; fi
#
# Build data base (-i). Each entry consists of man page and section, and a
# brief description of the command.
#
PATH=/bin:/usr/bin:
root=/usr/man ; sec=[au]_man ; lsec=local ; subsec=man[0-9] ;
files="$root/$sec/$subsec/*"; lfiles="$root/$lsec/$subsec/*" ;
for x in $files $lfiles
do
awk '
/^\.TH/ { sec="("$3")"; }
/^\.SH NAME/ {
for( getline ; $1 !~ /^.SH/ ; getline ) {
$1 = substr($1, 1, length($0));
if($1 == ".B") { $1 = $2; $2=""; };
str = str $0 " ";
}
d = index(str, "-");
printf("%-20s %s\n", substr(str, 1, d-2)sec, substr( str, d));
exit;
} ' $x
done 2> $index.errs | deroff -mm > $index
if [ ! -s $index.errs ] ; then rm -f $index.errs ; fi ;
exit 0;
# Note:
# deroff doesn't handle leading '.B's (gl pages), they're stripped first.
# Acknowledgements: The APROPOS clone was developed by
# G. "Murdock" Helms on behest of Doug Kerr, with thanks to
# Doug Kerr, Khanh Nguyen, Steve Philipson and Steve Smith
# for their help and suggestions. (Thanks guys!)
More information about the Comp.sys.sgi
mailing list