summaryrefslogtreecommitdiffstats
path: root/contrib/top/getans
blob: 7c94c37cab98d37a4a070fbe18b8c6158a32ff28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
OpenPOWER on IntegriCloud