Fix up mix of man(7)/mdoc(7).
[netbsd-mini2440.git] / games / wtf / wtf
blob2c44a6be5663b376eb2d749f59e24c83f9e69797
1 #!/bin/sh
3 # $NetBSD: wtf,v 1.14 2007/01/24 13:17:42 hubertf Exp $
5 # Public domain
8 PROGNAME=`basename $0`
10 usage() {
11 echo "usage: $PROGNAME [-f dbfile] [is] <acronym>"
12 exit 1
15 acronyms=${ACRONYMDB:-`ls /usr/share/misc/acronyms* 2>/dev/null`}
17 if [ "$acronyms" = "" ]; then
18 echo "$PROGNAME: acronyms database not found!" >&2
19 exit 1
22 args=`getopt f: $*`
23 if [ $? -ne 0 ]; then
24 usage
26 set -- $args
27 while [ $# -gt 0 ]; do
28 case "$1" in
29 -f)
30 acronyms=$2; shift
32 --)
33 shift; break
35 esac
36 shift
37 done
39 if [ "$1" = "is" ] ; then
40 shift
43 if [ $# -lt 1 ] ; then
44 usage
47 for f in $acronyms
49 if [ ! -f $f ]; then
50 echo "$PROGNAME: cannot open acronyms database file \`$f'" >&2
51 exit 1
53 done
55 rv=0
56 while [ $# -gt 0 ] ; do
57 # Search acronyms list first
58 target=`echo $1 | tr '[a-z]' '[A-Z]'`
59 ans=`fgrep -h $target $acronyms 2>/dev/null \
60 | sed -ne "\|^$target[[:space:]]|s|^$target[[:space:]]*||p"`
61 if [ "$ans" != "" ] ; then
62 echo "$target: $ans"
63 shift ; continue
66 # Try whatis(1) next
67 ans=`whatis $1 2>/dev/null`
68 if [ $? -eq 0 ] ; then
69 echo "$ans" | sort -u
70 shift ; continue
73 # Try pkg_info(1) next
74 ans=`pkg_info -qc $1 2> /dev/null`
75 if [ $? -eq 0 ] ; then
76 echo "$1: $ans"
77 shift ; continue
80 # Try querying pkgsrc's help facility next
81 if [ -f ../../mk/bsd.pkg.mk ] ; then
82 ans=`make help topic="$1"`
83 if [ $? -eq 0 ] ; then
84 echo "$1: $ans"
85 shift ; continue
89 # Give up!
90 echo "$PROGNAME: I don't know what $1 means!" 1>&2
91 rv=1
93 shift
94 done
95 exit $rv