getans revision 24139
1#!/bin/csh -f
2set ny = (no yes)
3if ($2 == "yesno") then
4    @ i = $3 + 1
5    set pmpt = "$1 [$ny[$i]]: "
6else
7    if ("$3" == "") then
8        set pmpt = "${1}"
9    else
10        set pmpt = "$1 [$3]: "
11    endif
12endif
13rpt:
14echo -n "$pmpt"
15set input = $<
16switch ($2)
17    case number:
18	set tmp = `echo $input | tr -d 0123456789.`
19	if ("x$tmp" != x) then
20	    echo "Invalid number.  Please try again."
21	    goto rpt
22	endif
23	breaksw
24
25    case integer:
26	set tmp = `echo $input | tr -d 0123456789`
27	if ("x$tmp" != x) then
28	    echo "Invalid integer.  Please try again."
29	    goto rpt
30	endif
31	breaksw
32
33    case neginteger:
34	if ("x$input" != x-1) then
35	    set tmp = `echo $input | tr -d 0123456789`
36	    if ("x$tmp" != x) then
37	        echo "Invalid integer.  Please try again."
38	        goto rpt
39	    endif
40	endif
41	breaksw
42
43    case file:
44	if ("x$input" == "x") then
45	    set input = $3
46	endif
47	if (! -e "$input") then
48	    echo The file $input "does not exist.  Please try again."
49	    goto rpt
50	endif
51	breaksw
52
53    case path:
54	if ("x$input" == "x") then
55	    set input = "$3"
56	endif
57	if (! -e "$input") then
58	    foreach elt ($path)
59		if (-e "$elt/$input") breaksw
60	    end
61	    echo The command $input "was not found.  Please try again."
62	    goto rpt
63	endif
64	breaksw
65
66    case yesno:
67	if ("x$input" == xy || "x$input" == xyes) then
68	   set input = 1
69	else if ("x$input" == xn || "x$input" == xno) then
70	   set input = 0
71	else if ("x$input" != x) then
72	   echo 'Please answer "yes" or "no".'
73	   goto rpt
74	endif
75	breaksw
76
77    default:
78	breaksw
79
80endsw
81
82if ("x$input" == x) then
83    set input = "$3"
84endif
85
86echo $input > $4
87