1#!/bin/csh -f 2set ny = (no yes) 3if ($2 == "yesno") then 4 @ i = $3 + 1 5 set pmpt = "$1 [$ny[$i]]: "
| 1#!/bin/sh 2# getans prompt type default results_filename 3# type is one of 4# number 5# integer 6# neginteger 7# file default=default filename 8# path 9# yesno default=0,1 corres yes or no 10# string (default) 11 12RAWPMPT=$1 13TYP=$2 14DFLT=$3 15OFNM=$4 16 17ny0="no"; ny1="yes" 18if [ ${TYP} = "yesno" ]; then 19 eval ny=\$ny${DFLT} 20 pmpt="${RAWPMPT} [$ny]: "
|
6else
| 21else
|
7 if ("$3" == "") then 8 set pmpt = "${1}"
| 22 if [ -z "${DFLT}" ]; then 23 pmpt="${RAWPMPT}"
|
9 else
| 24 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
| 25 pmpt="${RAWPMPT} [${DFLT}]: " 26 fi 27fi 28if [ x"`echo -n`" = x-n ] 29then 30 c=\\c 31else 32 n=-n 33fi 34 35while : 36do 37 echo $n "$pmpt"$c 38 read input 39 case "$TYP" in 40 number) 41 tmp=`echo $input | tr -d 0123456789.` 42 if [ -n "$tmp" ]; then
|
20 echo "Invalid number. Please try again."
| 43 echo "Invalid number. Please try again."
|
21 goto rpt 22 endif 23 breaksw
| 44 continue 45 fi 46 ;;
|
24
| 47
|
25 case integer: 26 set tmp = `echo $input | tr -d 0123456789` 27 if ("x$tmp" != x) then
| 48 integer) 49 tmp=`echo $input | tr -d 0123456789` 50 if [ -n "$tmp" ]; then
|
28 echo "Invalid integer. Please try again."
| 51 echo "Invalid integer. Please try again."
|
29 goto rpt 30 endif 31 breaksw
| 52 continue 53 fi 54 ;;
|
32
| 55
|
33 case neginteger: 34 if ("x$input" != x-1) then 35 set tmp = `echo $input | tr -d 0123456789` 36 if ("x$tmp" != x) then
| 56 neginteger) 57 if [ "x$input" != "x-1" ]; then 58 tmp=`echo $input | tr -d 0123456789` 59 if [ -n "$tmp" ]; then
|
37 echo "Invalid integer. Please try again."
| 60 echo "Invalid integer. Please try again."
|
38 goto rpt 39 endif 40 endif 41 breaksw
| 61 continue 62 fi 63 fi 64 ;;
|
42
| 65
|
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
| 66 file) 67 if [ -z "$input" ]; then 68 input=${DFLT} 69 fi 70 if [ ! -f "$input" -a ! -d "$input" ]; then 71 echo "The file $input does not exist. Please try again." 72 continue 73 fi 74 ;;
|
52
| 75
|
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
| 76 path) 77 if [ -z "$input" ]; then 78 input="${DFLT}" 79 fi 80 if [ ! -f "$input" ]; then 81 path=`echo $PATH | sed -e s'/::/ . /g' -e 's/:/ /g'` 82 x= 83 for elt in $path; do 84 if [ -f "$elt/$input" ]; then x=1; break; fi 85 done 86 if [ -z "$x" ] ;then 87 echo "The command $input was not found. Please try again." 88 continue 89 fi 90 fi 91 ;;
|
65
| 92
|
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
| 93 yesno) 94 if [ -z "$input" ]; then 95 input="${DFLT}" 96 else 97 case $input in 98 y | yes) 99 input=1 ;; 100 n | no) 101 input=0 ;; 102 *) 103 echo 'Please answer "yes" or "no".' 104 continue ;; 105 esac 106 fi 107 ;;
|
76
| 108
|
77 default: 78 breaksw
| 109 *) ;; 110 esac 111 break 112done
|
79
| 113
|
80endsw
| 114if [ -z "$input" ]; then 115 input="${DFLT}" 116fi
|
81
| 117
|
82if ("x$input" == x) then 83 set input = "$3" 84endif 85 86echo $input > $4
| 118echo $input > ${OFNM}
|
| |