freebsd-skq/contrib/top/getans
Joerg Wunsch aee34003d7 This is the long-awaited import of top into the base system (actually,
the src/contrib/top part right now).  This tools is simply too system-
dependant to maintain it in the ports collection.
1997-03-23 18:51:21 +00:00

87 lines
1.6 KiB
Tcsh
Executable File

#!/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