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