--- wtf/wtf.in.orig 2003-12-16 18:47:37.000000000 -0800 +++ wtf/wtf.in 2010-01-10 10:31:47.000000000 -0800 @@ -1,18 +1,25 @@ #!/bin/sh # -# $NetBSD: wtf,v 1.11 2003/04/25 19:08:31 jmmv Exp $ +# $NetBSD: wtf,v 1.15 2007/08/06 21:14:36 hubertf Exp $ # # Public domain # +PROGNAME=`basename $0` + usage() { - echo "usage: `basename $0` [-f dbfile] [-t type] [is] " + echo "usage: $PROGNAME [-f dbfile] [is] " exit 1 } -acronyms=${ACRONYMDB:-@wtf_acronymfile@} +acronyms=${ACRONYMDB:-`ls @wtf_acronymfile@* 2>/dev/null`} + +if [ "$acronyms" = "" ]; then + echo "$PROGNAME: acronyms database not found!" >&2 + exit 1 +fi -args=`getopt f:t: $*` +args=`getopt f: $*` if [ $? -ne 0 ]; then usage fi @@ -22,9 +29,6 @@ -f) acronyms=$2; shift ;; - -t) - acronyms=@wtf_acronymfile@.$2; shift - ;; --) shift; break ;; @@ -32,7 +36,7 @@ shift done -if [ X"$1" = X"is" ] ; then +if [ "$1" = "is" ] ; then shift fi @@ -40,27 +44,52 @@ usage fi -if [ ! -f $acronyms ]; then - echo "`basename $0`: cannot open acronyms database file \`$acronyms'" - exit 1 -fi +for f in $acronyms +do + if [ ! -f $f ]; then + echo "$PROGNAME: cannot open acronyms database file \`$f'" >&2 + exit 1 + fi +done rv=0 while [ $# -gt 0 ] ; do + # Search acronyms list first target=`echo $1 | tr '[a-z]' '[A-Z]'` - ans=`fgrep $target < $acronyms 2>/dev/null \ - | sed -ne "\|^$target[[:space:]]|s|^$target[[:space:]]*||p"` + ans=`fgrep -h $target $acronyms 2>/dev/null \ + | sed -ne "\|^$target[[:space:]]|s|^$target[[:space:]]*||p"` if [ "$ans" != "" ] ; then echo "$target: $ans" - else - ans=`whatis $1 2> /dev/null | egrep "^$1[, ]" 2> /dev/null` + shift ; continue + fi + + # Try whatis(1) next + ans=`whatis $1 2>/dev/null` + if [ $? -eq 0 ] ; then + echo "$ans" | sort -u + shift ; continue + fi + + # Try pkg_info(1) next + ans=`pkg_info -qc $1 2> /dev/null` + if [ $? -eq 0 ] ; then + echo "$1: $ans" + shift ; continue + fi + + # Try querying pkgsrc's help facility next + if [ -f ../../mk/bsd.pkg.mk ] ; then + ans=`make help topic="$1"` if [ $? -eq 0 ] ; then echo "$1: $ans" - else - echo "Gee... I don't know what $1 means..." 1>&2 - rv=1 + shift ; continue fi fi + + # Give up! + echo "$PROGNAME: I don't know what $1 means!" 1>&2 + rv=1 + shift done exit $rv