summaryrefslogtreecommitdiffstats
path: root/contrib/top/getans
diff options
context:
space:
mode:
authordwmalone <dwmalone@FreeBSD.org>2002-01-24 17:24:16 +0000
committerdwmalone <dwmalone@FreeBSD.org>2002-01-24 17:24:16 +0000
commit6d85e91806136ccf94d20612be2f8cc4d2590a8a (patch)
tree01dc9dd59148ee3d2624019bf4a06905463468a9 /contrib/top/getans
parent1b9d0472b72177a604d3c5dd26d25eec00049bd2 (diff)
downloadFreeBSD-src-6d85e91806136ccf94d20612be2f8cc4d2590a8a.zip
FreeBSD-src-6d85e91806136ccf94d20612be2f8cc4d2590a8a.tar.gz
import top_3_5beta12
Diffstat (limited to 'contrib/top/getans')
-rwxr-xr-xcontrib/top/getans178
1 files changed, 105 insertions, 73 deletions
diff --git a/contrib/top/getans b/contrib/top/getans
index 7c94c37..1b741f7 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}
OpenPOWER on IntegriCloud