]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - wtf/wtf
d1167a9cba77e0035c94636a52d2512c60a3f7f7
[bsdgames-darwin.git] / wtf / wtf
1 #!/bin/sh
2 #
3 # $NetBSD: wtf,v 1.18 2012/10/03 19:50:06 wiz Exp $
4 #
5 # Public domain
6 #
7
8 PROGNAME="$(basename "$0")"
9
10 usage() {
11 echo "usage: $PROGNAME [-f dbfile] [is] <acronym> ..."
12 exit 1
13 }
14
15 while getopts f: f
16 do
17 case "$f" in
18 f)
19 acronyms="$OPTARG $acronyms"
20 ;;
21 *)
22 usage
23 ;;
24 esac
25 done
26
27 shift "$(expr "$OPTIND" - 1)"
28
29 if [ "$1" = "is" ]; then
30 shift
31 fi
32
33 if [ -z "$1" ]; then
34 usage
35 fi
36
37 if [ -z "$acronyms" ]; then
38 acronyms=${ACRONYMDB:-$(ls /usr/share/misc/acronyms* 2>/dev/null)}
39 fi
40
41 if [ -z "$acronyms" ]; then
42 echo "$PROGNAME: acronym database not found!" >&2
43 exit 1
44 fi
45
46
47 for f in $acronyms; do
48 if [ ! -f $f ]; then
49 echo "$PROGNAME: cannot open acronym database file \`$f'" >&2
50 exit 1
51 fi
52 done
53
54 rv=0
55 for i; do
56 # Search acronym list first
57 target="$(echo "$i" | tr '[a-z]' '[A-Z]')"
58 ans="$(fgrep -h "$target" $acronyms 2>/dev/null \
59 | sed -ne "\|^$target[[:space:]]|s|^$target[[:space:]]*||p")"
60 if [ -n "$ans" ] ; then
61 echo "$target: $ans"
62 continue
63 fi
64
65 # Try whatis(1) next
66 ans="$(whatis "$i" 2>/dev/null)"
67 if [ $? -eq 0 ]; then
68 echo "$ans" | sort -u
69 continue
70 fi
71
72 # Try pkg_info(1) next
73 ans="$(pkg_info -qc "$i" 2> /dev/null)"
74 if [ $? -eq 0 ]; then
75 echo "$i: $ans"
76 continue
77 fi
78
79 # Try querying pkgsrc's help facility next
80 if [ -f ../../mk/bsd.pkg.mk ]; then
81 ans="$(make help topic="$i")"
82 if [ $? -eq 0 ]; then
83 echo "$i: $ans"
84 continue
85 fi
86 fi
87
88 # Give up!
89 echo "$PROGNAME: I don't know what \`$i' means!" 1>&2
90 rv=1
91 done
92 exit $rv