-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwtf.in
96 lines (83 loc) · 1.42 KB
/
wtf.in
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
#!/bin/sh
#
# $NetBSD: wtf,v 1.25 2018/08/16 13:31:04 maya Exp $
#
# Public domain
#
PROGNAME="$(basename "$0")"
offensive=false
usage() {
echo "usage: $PROGNAME [-o] [-f dbfile] [is] term ..."
exit 1
}
while getopts f:o f
do
case "$f" in
o) offensive=true
;;
f)
acronyms="$OPTARG $acronyms"
;;
*)
usage
;;
esac
done
shift "$(expr "$OPTIND" - 1)"
if [ "$1" = "is" ]; then
if [ $# -gt 1 ] ; then
shift
fi
fi
if [ -z "$1" ]; then
usage
fi
if [ -z "$acronyms" ]; then
if [ -z "$ACRONYMDB" ]; then
for f in @@ACRONYMSDIR@@/acronyms*; do
case $f in
*-o)
if $offensive; then
acronyms="$acronyms $f"
fi
;;
*)
acronyms="$acronyms $f"
;;
esac
done
else
acronyms="$ACRONYMDB"
fi
fi
if [ -z "$acronyms" ]; then
echo "$PROGNAME: acronym database not found!" >&2
exit 1
fi
for f in $acronyms; do
if [ ! -f "$f" ]; then
echo "$PROGNAME: cannot open acronym database file \`$f'" >&2
exit 1
fi
done
rv=0
for i; do
# Search acronym list first
target="$(echo "$i" | tr '[:lower:]' '[:upper:]')"
ans="$(fgrep -h "$target" $acronyms 2>/dev/null \
| sed -ne "\|^$target[[:space:]]|s|^$target[[:space:]]*||p")"
if [ -n "$ans" ] ; then
echo "$target: $ans"
continue
fi
# Try whatis(1) next
ans="$(whatis "$i" 2>/dev/null)"
if [ $? -eq 0 ]; then
echo "$ans" | sort -u
continue
fi
# Give up!
echo "$PROGNAME: I don't know what \`$i' means!" 1>&2
rv=1
done
exit $rv