Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/wtf use modern shell constructs



details:   https://anonhg.NetBSD.org/src/rev/175ee3b198ae
branches:  trunk
changeset: 779024:175ee3b198ae
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Apr 26 03:16:13 2012 +0000

description:
use modern shell constructs

diffstat:

 games/wtf/wtf |  83 +++++++++++++++++++++++++++-------------------------------
 1 files changed, 39 insertions(+), 44 deletions(-)

diffs (140 lines):

diff -r 8f729ef944fe -r 175ee3b198ae games/wtf/wtf
--- a/games/wtf/wtf     Thu Apr 26 03:04:54 2012 +0000
+++ b/games/wtf/wtf     Thu Apr 26 03:16:13 2012 +0000
@@ -1,53 +1,50 @@
 #!/bin/sh
 #
-#      $NetBSD: wtf,v 1.16 2012/04/26 01:55:14 jschauma Exp $
+#      $NetBSD: wtf,v 1.17 2012/04/26 03:16:13 christos Exp $
 #
 # Public domain
 #
 
-PROGNAME=`basename $0`
+PROGNAME="$(basename "$0")"
 
 usage() {
-       echo "usage: $PROGNAME [-f dbfile] [is] <acronym>"
+       echo "Usage: $PROGNAME [-f dbfile] [is] <acronym>"
        exit 1
 }
 
-args=`getopt f: $*`
-if [ $? -ne 0 ]; then
-       usage
-fi
-set -- $args
-while [ $# -gt 0 ]; do
-       case "$1" in
-               -f)
-                       acronyms="$2 $acronyms"; shift
-                       ;;
-               --)
-                       shift; break
-                       ;;
+while getopts f: f
+do
+       case "$f" in
+       f)
+               acronyms="$OPTARG $acronyms"
+               ;;
+       *)
+               usage
+               ;;
        esac
-       shift
 done
 
-if [ "$1" = "is" ] ; then
+shift "$(expr "$OPTIND" - 1)"
+
+if [ "$1" = "is" ]; then
        shift
 fi
 
-if [ $# -lt 1 ] ; then
+if [ -z "$1" ]; then
        usage
 fi
 
-if [ "$acronyms" = "" ]; then
-       acronyms=${ACRONYMDB:-`ls /usr/share/misc/acronyms* 2>/dev/null`}
+if [ -z "$acronyms" ]; then
+       acronyms=${ACRONYMDB:-$(ls /usr/share/misc/acronyms* 2>/dev/null)}
 fi
 
-if [ "$acronyms" = "" ]; then
+if [ -z "$acronyms" ]; then
        echo "$PROGNAME: acronyms database not found!" >&2
        exit 1
 fi
 
 
-for f in $acronyms ; do
+for f in $acronyms; do
        if [ ! -f $f ]; then
                echo "$PROGNAME: cannot open acronyms database file \`$f'" >&2
                exit 1
@@ -55,43 +52,41 @@
 done
 
 rv=0
-while [ $# -gt 0 ] ; do
+for i; do
        # Search acronyms list first
-       target=`echo $1 | tr '[a-z]' '[A-Z]'`
-       ans=`fgrep -h $target $acronyms 2>/dev/null \
-            | sed -ne "\|^$target[[:space:]]|s|^$target[[:space:]]*||p"`
-       if [ "$ans" != "" ] ; then
+       target="$(echo "$i" | tr '[a-z]' '[A-Z]')"
+       ans="$(fgrep -h "$target" $acronyms 2>/dev/null \
+            | sed -ne "\|^$target[[:space:]]|s|^$target[[:space:]]*||p")"
+       if [ -n "$ans" ] ; then
                echo "$target: $ans"
-               shift ; continue
+               continue
        fi
 
        # Try whatis(1) next
-       ans=`whatis $1 2>/dev/null`
-       if [ $? -eq 0 ] ; then
+       ans="$(whatis "$i" 2>/dev/null)"
+       if [ $? -eq 0 ]; then
                echo "$ans" | sort -u
-               shift ; continue
+               continue
        fi
 
        # Try pkg_info(1) next
-       ans=`pkg_info -qc $1 2> /dev/null`
-       if [ $? -eq 0 ] ; then
-               echo "$1: $ans"
-               shift ; continue
+       ans="$(pkg_info -qc "$i" 2> /dev/null)"
+       if [ $? -eq 0 ]; then
+               echo "$i: $ans"
+               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"
-                       shift ; continue
+       if [ -f ../../mk/bsd.pkg.mk ]; then
+               ans="$(make help topic="$i")"
+               if [ $? -eq 0 ]; then
+                       echo "$i: $ans"
+                       continue
                fi
        fi
 
        # Give up!
-       echo "$PROGNAME: I don't know what $1 means!" 1>&2
+       echo "$PROGNAME: I don't know what \`$i' means!" 1>&2
        rv=1
-       
-       shift
 done
 exit $rv



Home | Main Index | Thread Index | Old Index