diff options
author | hubertf <hubertf@NetBSD.org> | 2005-06-22 20:11:03 +0000 |
---|---|---|
committer | hubertf <hubertf@NetBSD.org> | 2005-06-22 20:11:03 +0000 |
commit | ef4d0c168ecc6f29f76a86ed3d1a69c2942c22db (patch) | |
tree | 310407eb5ad7dcc34a9c130412c9865d2933234f /wtf | |
parent | 3e39584b24a73f00df65f1e1711ccc868fc80e5a (diff) | |
download | bsdgames-darwin-ef4d0c168ecc6f29f76a86ed3d1a69c2942c22db.tar.gz bsdgames-darwin-ef4d0c168ecc6f29f76a86ed3d1a69c2942c22db.tar.zst bsdgames-darwin-ef4d0c168ecc6f29f76a86ed3d1a69c2942c22db.zip |
* Change program logic to not nest needlessly
* Search all acronyms databases, and don't force the user to
know in which category to look (-t is gone)
* If an acronym is not found in the database or by whatis(1),
also check pkg_info(1). Per PR bin/30539 by Geert Hendrickx
(geert.hendrickx@ua.ac.be)
OK'd by Julio M. Merino Vidal <jmmv>
Diffstat (limited to 'wtf')
-rw-r--r-- | wtf/wtf | 55 | ||||
-rw-r--r-- | wtf/wtf.6 | 23 |
2 files changed, 44 insertions, 34 deletions
@@ -1,6 +1,6 @@ #!/bin/sh # -# $NetBSD: wtf,v 1.11 2003/04/25 19:08:31 jmmv Exp $ +# $NetBSD: wtf,v 1.12 2005/06/22 20:11:03 hubertf Exp $ # # Public domain # @@ -10,9 +10,9 @@ usage() { exit 1 } -acronyms=${ACRONYMDB:-/usr/share/misc/acronyms} +acronyms=${ACRONYMDB:-`ls /usr/share/misc/acronyms*`} -args=`getopt f:t: $*` +args=`getopt f: $*` if [ $? -ne 0 ]; then usage fi @@ -22,9 +22,6 @@ while [ $# -gt 0 ]; do -f) acronyms=$2; shift ;; - -t) - acronyms=/usr/share/misc/acronyms.$2; shift - ;; --) shift; break ;; @@ -32,7 +29,7 @@ while [ $# -gt 0 ]; do shift done -if [ X"$1" = X"is" ] ; then +if [ "$1" = "is" ] ; then shift fi @@ -40,27 +37,43 @@ if [ $# -lt 1 ] ; then 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 "`basename $0`: cannot open acronyms database file \`$f'" 1>&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=`cat $acronyms | fgrep -h $target 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` - if [ $? -eq 0 ] ; then - echo "$1: $ans" - else - echo "Gee... I don't know what $1 means..." 1>&2 - rv=1 - fi + shift ; continue fi + + # Try whatis(1) next + ans=`whatis $1 2>/dev/null` + if [ $? -eq 0 ] ; then + echo "$ans" | sort | uniq + 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 + + # Give up! + echo "`basename $0`, I don't know what $1 means!" 1>&2 + rv=1 + shift done exit $rv @@ -1,8 +1,8 @@ -.\" $NetBSD: wtf.6,v 1.8 2003/04/25 19:08:31 jmmv Exp $ +.\" $NetBSD: wtf.6,v 1.9 2005/06/22 20:11:03 hubertf Exp $ .\" .\" Public Domain .\" -.Dd April 25, 2003 +.Dd June 22, 2005 .Dt WTF 6 .Os .Sh NAME @@ -11,7 +11,6 @@ .Sh SYNOPSIS .Nm .Op Fl f Ar dbfile -.Op Fl t Ar type .Op Ar is .Ar acronym Ar ... .Sh DESCRIPTION @@ -19,11 +18,13 @@ The .Nm utility displays the expansion of the acronyms specified on the command line. -If the acronym is unknown, +If the acronym is not in any of the acronyms databases, .Nm will check to see if the acronym is known by the .Xr whatis 1 -command. +or the +.Xr pkg_info 1 +commands. .Pp If .Dq is @@ -38,13 +39,6 @@ The following options are available: Overrides the default acronym database, bypassing the value of the .Ev ACRONYMDB variable. -.It Fl t Ar type -Specifies the acronym's type. -Simply put, it makes the program use the acronyms database named -.Pa /usr/share/misc/acronyms.type , -where -.Ar type -is given by the argument. .El .Sh ENVIRONMENT .Bl -tag -width ACRONYMDB @@ -52,7 +46,9 @@ is given by the argument. The default acronym database may be overridden by setting the environment variable .Ev ACRONYMDB -to the name of a file in the proper format (acronym[tab]meaning). +to the name of one or more space-seperated file names of +acronym databases. +The files must be in the proper format (acronym[tab]meaning). .El .Sh FILES .Bl -tag -width /usr/share/misc/acronyms.XXXX -compact @@ -62,6 +58,7 @@ default acronym database. computer-related acronym database. .El .Sh SEE ALSO +.Xr pkg_info 1 , .Xr whatis 1 .Sh HISTORY .Nm |