3 # apropos -- search the whatis database for keywords.
5 # Copyright (c) February 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
6 # Copyright (c) 1990, 1991, John W. Eaton.
8 # You may distribute under the terms of the GNU General Public
9 # License as specified in the README file that comes with the man
14 # Department of Chemical Engineering
15 # The University of Texas at Austin
21 db=whatis # name of whatis data base
24 # man -k complains if exit_nomatch=1 and no keyword matched
30 echo "usage: `basename $0` keyword ..." >&2
36 *whatis) grepopt='-w';; # run as whatis(1)
37 *) grepopt='';; # otherwise run as apropos(1)
41 manpath=`%bindir%/manpath -q | tr : '\040'`
42 case X"$manpath" in X)
43 echo "`basename $0`: manpath is null, using \"/usr/share/man\"" >&2
44 manpath=/usr/share/man
49 # reset $PAGER if $PAGER is empty
55 man_locales=`%bindir%/manpath -qL`
57 # search for existing */whatis databases
61 if [ -f "$d/$db" -a -r "$d/$db" ]
63 mandir="$mandir $d/$db"
66 # Check for localized manpage subdirectories
67 if [ X"$man_locales" != X ]; then
70 if [ -f "$d/$l/$db" -a -r "$d/$l/$db" ];
72 mandir="$mandir $d/$l/$db"
79 echo "`basename $0`: no whatis databases in $manpath" >&2
86 if grep -Ehi $grepopt -- "$manpage" $mandir; then :
88 echo "$manpage: nothing appropriate"
92 ( # start $PAGER only if we find a manual page
97 *": nothing appropriate") line2="$line2$line\n";;
103 # nothing found, exit
104 if [ -z "$line" -a ! -z "$line2" ]; then
108 ( printf -- "$line2"; echo "$line"; cat ) | $PAGER