blob: 4f68263ce4ec489bd917e348ebf2660f41f94333 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#!/bin/sh
#
# apropos -- search the whatis database for keywords.
#
# Copyright (c) February 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
# 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
#
# $FreeBSD$
PATH=/bin:/usr/bin:$PATH
db=whatis # name of whatis data base
grepopt=''
# man -k complain if exit_nomatch=1 and no keyword matched
: ${exit_nomatch=0}
exit_error=2
# argument test
case $# in 0)
echo "usage: `basename $0` keyword ..." >&2
exit $exit_error
;;
esac
case "$0" in
*whatis) grepopt='-w';; # run as whatis(1)
*) grepopt='';; # otherwise run as apropos(1)
esac
# test manpath
manpath=`%bindir%/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
# reset $PAGER if $PAGER is empty
case X"$PAGER" in X)
PAGER="%pager%"
;;
esac
# search for existing */whatis databases
mandir=''
for d in $manpath
do
if [ -f "$d/$db" -a -r "$d/$db" ]
then
mandir="$mandir $d/$db"
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 |
( # start $PAGER only if we find a manual page
while read line
do
case $line in
# collect error(s)
*": nothing appropriate") line2="$line2$line\n";;
# matched line or EOF
*) break;;
esac
done
# nothing found, exit
if test -z "$line" -a ! -z "$line2"; then
printf -- "$line2"
exit $exit_nomatch
else
( printf -- "$line2"; echo $line; cat ) | $PAGER
fi
)
|