[BACK]Return to getans CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.bin / top

File: [cvs.NetBSD.org] / src / usr.bin / top / Attic / getans (download)

Revision 1.2, Tue May 22 15:38:22 2001 UTC (18 years, 9 months ago) by christos
Branch: MAIN
CVS Tags: yamt-pf42-baseX, yamt-pf42-base4, yamt-pf42-base3, yamt-pf42-base2, yamt-pf42-base, yamt-pf42, wrstuden-revivesa-base-1, wrstuden-revivesa-base, wrstuden-fixsa-newbase, wrstuden-fixsa-base-1, wrstuden-fixsa-base, wrstuden-fixsa, netbsd-4-base, netbsd-4-0-RELEASE, netbsd-4-0-RC5, netbsd-4-0-RC4, netbsd-4-0-RC3, netbsd-4-0-RC2, netbsd-4-0-RC1, netbsd-4-0-1-RELEASE, netbsd-4-0, netbsd-4, netbsd-3-base, netbsd-3-1-RELEASE, netbsd-3-1-RC4, netbsd-3-1-RC3, netbsd-3-1-RC2, netbsd-3-1-RC1, netbsd-3-1-1-RELEASE, netbsd-3-1, netbsd-3-0-RELEASE, netbsd-3-0-RC6, netbsd-3-0-RC5, netbsd-3-0-RC4, netbsd-3-0-RC3, netbsd-3-0-RC2, netbsd-3-0-RC1, netbsd-3-0-3-RELEASE, netbsd-3-0-2-RELEASE, netbsd-3-0-1-RELEASE, netbsd-3-0, netbsd-3, netbsd-2-base, netbsd-2-1-RELEASE, netbsd-2-1-RC6, netbsd-2-1-RC5, netbsd-2-1-RC4, netbsd-2-1-RC3, netbsd-2-1-RC2, netbsd-2-1-RC1, netbsd-2-1, netbsd-2-0-base, netbsd-2-0-RELEASE, netbsd-2-0-RC5, netbsd-2-0-RC4, netbsd-2-0-RC3, netbsd-2-0-RC2, netbsd-2-0-RC1, netbsd-2-0-3-RELEASE, netbsd-2-0-2-RELEASE, netbsd-2-0-1-RELEASE, netbsd-2-0, netbsd-2, netbsd-1-6-base, netbsd-1-6-RELEASE, netbsd-1-6-RC3, netbsd-1-6-RC2, netbsd-1-6-RC1, netbsd-1-6-PATCH002-RELEASE, netbsd-1-6-PATCH002-RC4, netbsd-1-6-PATCH002-RC3, netbsd-1-6-PATCH002-RC2, netbsd-1-6-PATCH002-RC1, netbsd-1-6-PATCH002, netbsd-1-6-PATCH001-RELEASE, netbsd-1-6-PATCH001-RC3, netbsd-1-6-PATCH001-RC2, netbsd-1-6-PATCH001-RC1, netbsd-1-6-PATCH001, netbsd-1-6, nathanw_sa_end, nathanw_sa_before_merge, nathanw_sa_base, matt-mips64-base, matt-mips64, matt-armv6-prevmlocking, matt-armv6-nbase, matt-armv6-base, matt-armv6, keiichi-mipv6-nbase, keiichi-mipv6-base, keiichi-mipv6, hpcarm-cleanup-nbase, hpcarm-cleanup-base, hpcarm-cleanup, fvdl_fs64_base, cube-autoconf-base, cube-autoconf, chap-midi-nbase, chap-midi-base, chap-midi, abandoned-netbsd-4-base, abandoned-netbsd-4
Branch point for: wrstuden-revivesa, nathanw_sa
Changes since 1.1: +111 -83 lines

bring in fixes from beta12:
	- better error checking for read/write failures
	- new install/configure/Makefile and support scripts (we don't use)
	- don't allow 0 delay for non-root accounts
XXX: Someone needs to coordinate to feed back our prototype fixes to Jeff!

#!/bin/sh
# getans prompt type default  results_filename
#  type is one of 
#   number  
#   integer
#   neginteger
#   file    default=default filename
#   path        
#   yesno   default=0,1 corres yes or no 
#   string (default)

RAWPMPT=$1
TYP=$2
DFLT=$3
OFNM=$4

ny0="no"; ny1="yes"
if [ ${TYP} = "yesno" ]; then
    eval ny=\$ny${DFLT}
    pmpt="${RAWPMPT} [$ny]: "
else
    if [ -z "${DFLT}" ]; then
        pmpt="${RAWPMPT}"
    else
        pmpt="${RAWPMPT} [${DFLT}]: "
    fi
fi
if [ x"`echo -n`" = x-n ]
then
    c=\\c
else
    n=-n
fi

while :
do
    echo $n "$pmpt"$c
    read input
    case "$TYP" in
    number)
	tmp=`echo $input | tr -d 0123456789.`
	if [ -n "$tmp" ]; then
	    echo "Invalid number.  Please try again."
	    continue
	fi
	;;

    integer)
	tmp=`echo $input | tr -d 0123456789`
	if [ -n "$tmp" ]; then
	    echo "Invalid integer.  Please try again."
	    continue
	fi
	;;

    neginteger)
	if [ "x$input" != "x-1" ]; then
	    tmp=`echo $input | tr -d 0123456789`
	    if [ -n "$tmp" ]; then
	        echo "Invalid integer.  Please try again."
	        continue
	    fi
	fi
        ;;

    file)
	if [ -z "$input" ]; then
	    input=${DFLT}
	fi
	if [ ! -f "$input"  -a ! -d "$input" ]; then
	    echo "The file $input does not exist.  Please try again."
	    continue
	fi
	;;

    path)
	if [ -z "$input" ];  then
	    input="${DFLT}"
	fi
	if [ ! -f "$input" ]; then
            path=`echo $PATH | sed -e s'/::/ . /g' -e 's/:/ /g'`
	    x=
            for elt in $path;  do
		if [ -f "$elt/$input" ]; then  x=1; break; fi
	    done
	    if [ -z "$x" ] ;then 
                echo "The command $input was not found.  Please try again."
	        continue
            fi
	fi
	;;

    yesno)
	if [ -z "$input" ];  then  
            input="${DFLT}"
        else
            case $input in 
            y | yes)
                input=1 ;;
            n | no)
                input=0 ;;
            *)
	        echo 'Please answer "yes" or "no".'
	        continue ;;
            esac
        fi
        ;;

    *)	;;
    esac
    break
done

if [ -z "$input" ]; then
    input="${DFLT}"
fi

echo $input > ${OFNM}