#!/bin/sh
PATH=/bin:/usr/bin:$PATH
db=whatis.db grepopt=''
: ${exit_nomatch=0}
exit_error=2
case $ echo "usage: `basename $0` keyword ..." >&2
exit $exit_error
;;
esac
case "$0" in
*whatis) grepopt='-w';; *) grepopt='';; esac
manpath=`/usr/bin/manpath -q | tr : '\040'`
case X"$manpath" in X)
echo "`basename $0`: manpath is null, use \"/usr/share/man\"" >&2
manpath=/usr/share/man
;;
esac
case X"$PAGER" in X)
PAGER="less -se"
;;
esac
man_locales=`/usr/bin/manpath -qL`
mandir=''
for d in $manpath
do
if [ -f "$d/$db" -a -r "$d/$db" ]
then
mandir="$mandir $d/$db"
fi
if [ X"$man_locales" != X ]; then
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
done
case X"$mandir" in X)
echo "`basename $0`: no whatis databases in $manpath" >&2
exit $exit_error
esac
for manpage
do
if grep -hi $grepopt -- "$manpage" $mandir; then :
else
echo "$manpage: nothing appropriate"
fi
done |
( while read line
do
case $line in
*": nothing appropriate") line2="$line2$line\n";;
*) break;;
esac
done
if [ -z "$line" -a ! -z "$line2" ]; then
printf -- "$line2"
exit $exit_nomatch
else
( printf -- "$line2"; echo "$line"; cat ) | $PAGER
fi
)