diff options
author | David Malone <dwmalone@FreeBSD.org> | 2002-01-24 17:24:16 +0000 |
---|---|---|
committer | David Malone <dwmalone@FreeBSD.org> | 2002-01-24 17:24:16 +0000 |
commit | 4f4f23c1318f0e7d4bef9e7355ae4efa77809fd8 (patch) | |
tree | 01dc9dd59148ee3d2624019bf4a06905463468a9 /contrib/top/getans | |
parent | aee34003d7964653c44c31f5bf6bcf136b32c4f3 (diff) | |
download | src-4f4f23c1318f0e7d4bef9e7355ae4efa77809fd8.tar.gz src-4f4f23c1318f0e7d4bef9e7355ae4efa77809fd8.zip |
import top_3_5beta12vendor/top/3.5beta12
Notes
Notes:
svn path=/vendor/top/dist/; revision=89750
svn path=/vendor/top/3.5beta12/; revision=89752; tag=vendor/top/3.5beta12
Diffstat (limited to 'contrib/top/getans')
-rwxr-xr-x | contrib/top/getans | 178 |
1 files changed, 105 insertions, 73 deletions
diff --git a/contrib/top/getans b/contrib/top/getans index 7c94c37cab98..1b741f7cb7c2 100755 --- a/contrib/top/getans +++ b/contrib/top/getans @@ -1,86 +1,118 @@ -#!/bin/csh -f -set ny = (no yes) -if ($2 == "yesno") then - @ i = $3 + 1 - set pmpt = "$1 [$ny[$i]]: " +#!/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 ("$3" == "") then - set pmpt = "${1}" + if [ -z "${DFLT}" ]; then + pmpt="${RAWPMPT}" else - set pmpt = "$1 [$3]: " - endif -endif -rpt: -echo -n "$pmpt" -set input = $< -switch ($2) - case number: - set tmp = `echo $input | tr -d 0123456789.` - if ("x$tmp" != x) then + 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." - goto rpt - endif - breaksw + continue + fi + ;; - case integer: - set tmp = `echo $input | tr -d 0123456789` - if ("x$tmp" != x) then + integer) + tmp=`echo $input | tr -d 0123456789` + if [ -n "$tmp" ]; then echo "Invalid integer. Please try again." - goto rpt - endif - breaksw + continue + fi + ;; - case neginteger: - if ("x$input" != x-1) then - set tmp = `echo $input | tr -d 0123456789` - if ("x$tmp" != x) then + neginteger) + if [ "x$input" != "x-1" ]; then + tmp=`echo $input | tr -d 0123456789` + if [ -n "$tmp" ]; then echo "Invalid integer. Please try again." - goto rpt - endif - endif - breaksw - - case file: - if ("x$input" == "x") then - set input = $3 - endif - if (! -e "$input") then - echo The file $input "does not exist. Please try again." - goto rpt - endif - breaksw + continue + fi + fi + ;; - case path: - if ("x$input" == "x") then - set input = "$3" - endif - if (! -e "$input") then - foreach elt ($path) - if (-e "$elt/$input") breaksw - end - echo The command $input "was not found. Please try again." - goto rpt - endif - breaksw + 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 + ;; - case yesno: - if ("x$input" == xy || "x$input" == xyes) then - set input = 1 - else if ("x$input" == xn || "x$input" == xno) then - set input = 0 - else if ("x$input" != x) then - echo 'Please answer "yes" or "no".' - goto rpt - endif - breaksw + 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 + ;; - default: - breaksw + 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 + ;; -endsw + *) ;; + esac + break +done -if ("x$input" == x) then - set input = "$3" -endif +if [ -z "$input" ]; then + input="${DFLT}" +fi -echo $input > $4 +echo $input > ${OFNM} |