1993-07-07 23:07:02 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# apropos -- search the whatis database for keywords.
|
|
|
|
#
|
1996-08-27 20:04:45 +00:00
|
|
|
# Copyright (c) February 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
|
1993-07-07 23:07:02 +00:00
|
|
|
# Copyright (c) 1990, 1991, John W. Eaton.
|
|
|
|
#
|
|
|
|
# You may distribute under the terms of the GNU General Public
|
|
|
|
# License as specified in the README file that comes with the man
|
|
|
|
# distribution.
|
|
|
|
#
|
|
|
|
# John W. Eaton
|
|
|
|
# jwe@che.utexas.edu
|
|
|
|
# Department of Chemical Engineering
|
|
|
|
# The University of Texas at Austin
|
|
|
|
# Austin, Texas 78712
|
1996-02-25 23:41:46 +00:00
|
|
|
#
|
1999-08-27 23:37:10 +00:00
|
|
|
# $FreeBSD$
|
1993-07-07 23:07:02 +00:00
|
|
|
|
|
|
|
|
1996-02-25 23:41:46 +00:00
|
|
|
PATH=/bin:/usr/bin:$PATH
|
|
|
|
db=whatis # name of whatis data base
|
1996-03-10 18:52:33 +00:00
|
|
|
grepopt=''
|
1993-07-07 23:07:02 +00:00
|
|
|
|
1996-09-14 23:20:33 +00:00
|
|
|
# man -k complain if exit_nomatch=1 and no keyword matched
|
|
|
|
: ${exit_nomatch=0}
|
|
|
|
exit_error=2
|
|
|
|
|
1996-02-25 23:41:46 +00:00
|
|
|
# argument test
|
|
|
|
case $# in 0)
|
|
|
|
echo "usage: `basename $0` keyword ..." >&2
|
1996-09-14 23:20:33 +00:00
|
|
|
exit $exit_error
|
1996-02-25 23:41:46 +00:00
|
|
|
;;
|
|
|
|
esac
|
1993-07-07 23:07:02 +00:00
|
|
|
|
1996-03-10 18:52:33 +00:00
|
|
|
case "$0" in
|
|
|
|
*whatis) grepopt='-w';; # run as whatis(1)
|
|
|
|
*) grepopt='';; # otherwise run as apropos(1)
|
|
|
|
esac
|
|
|
|
|
1996-02-25 23:41:46 +00:00
|
|
|
# test manpath
|
1993-07-07 23:07:02 +00:00
|
|
|
manpath=`%bindir%/manpath -q | tr : '\040'`
|
1996-02-25 23:41:46 +00:00
|
|
|
case X"$manpath" in X)
|
|
|
|
echo "`basename $0`: manpath is null, use \"/usr/share/man\"" >&2
|
|
|
|
manpath=/usr/share/man
|
|
|
|
;;
|
|
|
|
esac
|
1993-07-07 23:07:02 +00:00
|
|
|
|
|
|
|
|
1996-02-25 23:41:46 +00:00
|
|
|
# reset $PAGER if $PAGER is empty
|
|
|
|
case X"$PAGER" in X)
|
|
|
|
PAGER="%pager%"
|
|
|
|
;;
|
|
|
|
esac
|
1993-07-07 23:07:02 +00:00
|
|
|
|
1999-11-23 03:11:54 +00:00
|
|
|
man_locales=`%bindir%/manpath -qL`
|
1999-10-30 21:18:52 +00:00
|
|
|
|
1996-02-25 23:41:46 +00:00
|
|
|
# search for existing */whatis databases
|
|
|
|
mandir=''
|
|
|
|
for d in $manpath
|
1993-07-07 23:07:02 +00:00
|
|
|
do
|
1996-02-25 23:41:46 +00:00
|
|
|
if [ -f "$d/$db" -a -r "$d/$db" ]
|
|
|
|
then
|
|
|
|
mandir="$mandir $d/$db"
|
|
|
|
fi
|
1999-10-30 21:18:52 +00:00
|
|
|
|
2001-03-30 10:31:46 +00:00
|
|
|
# Check for localized manpage subdirectories
|
1999-11-23 03:11:54 +00:00
|
|
|
if [ X"$man_locales" != X ]; then
|
1999-10-30 21:18:52 +00:00
|
|
|
for l in $man_locales
|
|
|
|
do
|
|
|
|
if [ -f "$d/$l/$db" -a -r "$d/$l/$db" ];
|
|
|
|
then
|
|
|
|
mandir="$mandir $d/$l/$db"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
1996-02-25 23:41:46 +00:00
|
|
|
done
|
1993-07-07 23:07:02 +00:00
|
|
|
|
1996-02-25 23:41:46 +00:00
|
|
|
case X"$mandir" in X)
|
|
|
|
echo "`basename $0`: no whatis databases in $manpath" >&2
|
1996-09-14 23:20:33 +00:00
|
|
|
exit $exit_error
|
1996-02-25 23:41:46 +00:00
|
|
|
esac
|
1993-07-07 23:07:02 +00:00
|
|
|
|
1996-02-25 23:41:46 +00:00
|
|
|
|
|
|
|
for manpage
|
|
|
|
do
|
1996-09-27 17:36:50 +00:00
|
|
|
if grep -hi $grepopt -- "$manpage" $mandir; then :
|
1996-02-25 23:41:46 +00:00
|
|
|
else
|
|
|
|
echo "$manpage: nothing appropriate"
|
|
|
|
fi
|
1996-07-08 20:03:18 +00:00
|
|
|
done |
|
1993-07-07 23:07:02 +00:00
|
|
|
|
1996-07-08 20:03:18 +00:00
|
|
|
( # start $PAGER only if we find a manual page
|
|
|
|
while read line
|
|
|
|
do
|
|
|
|
case $line in
|
1996-09-14 23:20:33 +00:00
|
|
|
# collect error(s)
|
1996-07-08 20:03:18 +00:00
|
|
|
*": nothing appropriate") line2="$line2$line\n";;
|
1996-09-14 23:20:33 +00:00
|
|
|
# matched line or EOF
|
1996-07-08 20:03:18 +00:00
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# nothing found, exit
|
2001-03-30 10:44:29 +00:00
|
|
|
if [ -z "$line" -a ! -z "$line2" ]; then
|
1996-09-27 17:36:50 +00:00
|
|
|
printf -- "$line2"
|
1996-09-14 23:20:33 +00:00
|
|
|
exit $exit_nomatch
|
1996-07-08 20:03:18 +00:00
|
|
|
else
|
2001-03-30 10:31:46 +00:00
|
|
|
( printf -- "$line2"; echo "$line"; cat ) | $PAGER
|
1996-07-08 20:03:18 +00:00
|
|
|
fi
|
|
|
|
)
|