diff options
Diffstat (limited to 'contrib/top/getans')
-rwxr-xr-x | contrib/top/getans | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/contrib/top/getans b/contrib/top/getans new file mode 100755 index 0000000..7c94c37 --- /dev/null +++ b/contrib/top/getans @@ -0,0 +1,86 @@ +#!/bin/csh -f +set ny = (no yes) +if ($2 == "yesno") then + @ i = $3 + 1 + set pmpt = "$1 [$ny[$i]]: " +else + if ("$3" == "") then + set pmpt = "${1}" + 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 + echo "Invalid number. Please try again." + goto rpt + endif + breaksw + + case integer: + set tmp = `echo $input | tr -d 0123456789` + if ("x$tmp" != x) then + echo "Invalid integer. Please try again." + goto rpt + endif + breaksw + + case neginteger: + if ("x$input" != x-1) then + set tmp = `echo $input | tr -d 0123456789` + if ("x$tmp" != x) 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 + + 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 + + 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 + + default: + breaksw + +endsw + +if ("x$input" == x) then + set input = "$3" +endif + +echo $input > $4 |