1#!/bin/sh
2#
3# apropos -- search the whatis database for keywords.
4# whatis  -- idem, but match only commands (as whole words).
5#
6# Copyright (c) 1990, 1991, John W. Eaton.
7# Copyright (c) 1994-1999, Andries E. Brouwer.
8#
9# You may distribute under the terms of the GNU General Public
10# License as specified in the README file that comes with the man
11# distribution.  
12#
13# apropos/whatis-1.5m aeb 2003-08-01 (from %version%)
14#
15# keep old PATH - 000323 - Bryan Henderson
16# also look in /var/cache/man - 030801 - aeb
17
18program=`basename $0`
19
20# When man pages in your favorite locale look to grep like binary files
21# (and you use GNU grep) you may want to add the 'a' option to *grepopt1.
22aproposgrepopt1='i'
23aproposgrepopt2=''
24whatisgrepopt1='iw'
25whatisgrepopt2=''
26grepopt1=$%apropos_or_whatis%grepopt1
27grepopt2=$%apropos_or_whatis%grepopt2
28
29if [ $# = 0 ]
30then
31    echo "usage: $program keyword ..."
32    exit 1
33fi
34
35manpath=`man %manpathoption% | tr : '\040'`
36
37if [ "$manpath" = "" ]
38then
39    echo "$program: manpath is null"
40    exit 1
41fi
42
43args=
44for arg in $*; do
45    case $arg in
46        --version|-V|-v)
47	    echo "$program from %version%"
48	    exit 0
49	    ;;
50	--help|-h)
51            echo "usage: $program keyword ..."
52	    exit 0
53	    ;;
54	-*)
55	    echo "$program: $arg: unknown option"
56	    exit 1
57	    ;;
58	*)
59	    args="$args $arg"
60    esac
61done
62
63while [ "$1" != "" ]
64do
65    found=0
66    for d in /var/cache/man $manpath /usr/lib
67    do
68        if [ -f $d/whatis ]
69        then
70            if grep -"$grepopt1" "$grepopt2""$1" $d/whatis
71            then
72                found=1
73# Some people are satisfied with a single occurrence
74# But it is better to give all
75#               break
76            fi
77        fi
78    done
79
80    if [ $found = 0 ]
81    then
82        echo "$1: nothing appropriate"
83    fi
84
85    shift
86done | eval ${PAGER:-more -E}
87
88exit
89