Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: Myread.U,v 3.0.1.6 1997/02/28 15:05:39 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1993, Raphael Manfredi | |
4 | ?RCS: | |
5 | ?RCS: You may redistribute only under the terms of the Artistic Licence, | |
6 | ?RCS: as specified in the README file that comes with the distribution. | |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
8 | ?RCS: that same Artistic Licence; a copy of which may be found at the root | |
9 | ?RCS: of the source tree for dist 3.0. | |
10 | ?RCS: | |
11 | ?RCS: $Log: Myread.U,v $ | |
12 | ?RCS: Revision 3.0.1.6 1997/02/28 15:05:39 ram | |
13 | ?RCS: patch61: myread script now starts with a "startsh" | |
14 | ?RCS: patch61: miscellaneous fixes | |
15 | ?RCS: | |
16 | ?RCS: Revision 3.0.1.5 1995/01/11 15:14:22 ram | |
17 | ?RCS: patch45: added & escape allowing user to turn on -d from the prompt | |
18 | ?RCS: | |
19 | ?RCS: Revision 3.0.1.4 1994/10/31 09:48:04 ram | |
20 | ?RCS: patch44: added Options to the MAKE line since it's no longer in Init.U | |
21 | ?RCS: | |
22 | ?RCS: Revision 3.0.1.3 1994/10/29 15:56:20 ram | |
23 | ?RCS: patch36: added ?F: line for metalint file checking | |
24 | ?RCS: | |
25 | ?RCS: Revision 3.0.1.2 1993/08/30 08:57:59 ram | |
26 | ?RCS: patch8: added new visible 'nostick' symbol, mainly for Finish.U | |
27 | ?RCS: | |
28 | ?RCS: Revision 3.0.1.1 1993/08/27 14:39:20 ram | |
29 | ?RCS: patch7: now sticks to the question when no default and empty answer | |
30 | ?RCS: | |
31 | ?RCS: Revision 3.0 1993/08/18 12:05:08 ram | |
32 | ?RCS: Baseline for dist 3.0 netwide release. | |
33 | ?RCS: | |
34 | ?X: | |
35 | ?X: This unit produces a bit of shell code that must be dotted in in order | |
36 | ?X: to do a read. It allows for shell escapes, default assignment and | |
37 | ?X: parameter evaluation. | |
38 | ?X: | |
39 | ?X: To use this unit, $rp and $dflt must hold the question and the | |
40 | ?X: default answer. The question will be printed by the script itself. | |
41 | ?X: Neither $rp nor $dflt is altered by the script. | |
42 | ?X: | |
43 | ?X: The myread script will stick to the question if no default is proposed | |
44 | ?X: and the user answer is empty, which prevents mistakes. However, at the | |
45 | ?X: end of Configure, there is an exception to this rule (Finish.U) where we | |
46 | ?X: set nostick to a non-empty value to allow the Return key to play its role! | |
47 | ?X: | |
48 | ?MAKE:Myread: Options startsh n c trnl | |
49 | ?MAKE: -pick add $@ %< | |
50 | ?V:ans:dflt rp nostick | |
51 | ?F:./myread | |
52 | ?T:COLUMNS xxxm rp dflt answ aok myecho | |
53 | ?LINT:change fastread | |
54 | ?X: Some shells (Ultrix) do not understand ${COLUMNS:-80}, sigh! | |
55 | : compute the number of columns on the terminal for proper question formatting | |
56 | case "$COLUMNS" in | |
57 | '') COLUMNS='80';; | |
58 | esac | |
59 | ||
60 | : set up the echo used in my read | |
61 | ?X: | |
62 | ?X: This variable is intended to be eval'ed. It will echo the two | |
63 | ?X: variables $rp and $dflt (provided this latter has a non null value). | |
64 | ?X: It is mainly used by the myread script to echo the questions. | |
65 | ?X: | |
66 | ?X: The $n and $c below are substituted before Loc does its silly echo check | |
67 | ?X: so don't put a $ on the echo below so we get builtin, even if $echo is | |
68 | ?X: pointing to /bin/echo. | |
69 | ?X: | |
70 | myecho="case \"\$xxxm\" in | |
71 | '') echo $n \"\$rp $c\" >&4;; | |
72 | *) case \"\$rp\" in | |
73 | '') echo $n \"[\$xxxm] $c\";; | |
74 | *) | |
75 | if test \`echo \"\$rp [\$xxxm] \" | wc -c\` -ge $COLUMNS; then | |
76 | echo \"\$rp\" >&4 | |
77 | echo $n \"[\$xxxm] $c\" >&4 | |
78 | else | |
79 | echo $n \"\$rp [\$xxxm] $c\" >&4 | |
80 | fi | |
81 | ;; | |
82 | esac;; | |
83 | esac" | |
84 | ||
85 | : now set up to do reads with possible shell escape and default assignment | |
86 | cat <<EOSC >myread | |
87 | $startsh | |
88 | ?X: | |
89 | ?X: Save value of default -- do not alter original in case of eval | |
90 | ?X: | |
91 | xxxm=\$dflt | |
92 | $myecho | |
93 | ?X: | |
94 | ?X: If there is no default, then stop, regardless of the value in fastread. | |
95 | ?X: In silent mode, no new-line is to be echoed if the question is empty, | |
96 | ?X: since this is used to wait for the "return" key. | |
97 | ?X: | |
98 | ans='!' | |
99 | case "\$fastread" in | |
100 | yes) case "\$dflt" in | |
101 | '') ;; | |
102 | *) ans=''; | |
103 | case "\$silent-\$rp" in | |
104 | true-) ;; | |
105 | *) echo " " >&4;; | |
106 | esac;; | |
107 | esac;; | |
108 | *) case "\$silent" in | |
109 | true) case "\$rp" in | |
110 | '') ans='';; | |
111 | esac;; | |
112 | esac;; | |
113 | esac | |
114 | while expr "X\$ans" : "X!" >/dev/null; do | |
115 | read answ | |
116 | ?X: | |
117 | ?X: Run 'eval' on the answer, in order to do variable substitution, in case | |
118 | ?X: the user types $HOME or $WHATEVER. Variables must be evaluated now. | |
119 | ?X: Typing '\$HOME' won't currently prevent from substitution -- use '\\$HOME' | |
120 | ?X: The $1 .. $9 and $*, as well as $@, are available to refer to the | |
121 | ?X: default value. | |
122 | ?X: | |
123 | set x \$xxxm | |
124 | shift | |
125 | aok=''; eval "ans=\\"\$answ\\"" && aok=y | |
126 | case "\$answ" in | |
127 | ?X: | |
128 | ?X: Use "!" and not a plain ! because of a bug in BSD 4.4 shell | |
129 | ?X: (reported by Wayne Davison) | |
130 | ?X: We must handle the shell escapes before dealing with possible variable | |
131 | ?X: substitution, since the shell we're launching in that case will be able | |
132 | ?X: to do it as well as we can -- RAM, 15/03/96 | |
133 | ?X | |
134 | "!") | |
135 | sh 1>&4 | |
136 | echo " " | |
137 | $myecho | |
138 | ;; | |
139 | !*) | |
140 | set x \`expr "X\$ans" : "X!\(.*\)\$"\` | |
141 | shift | |
142 | sh 1>&4 -c "\$*" | |
143 | echo " " | |
144 | $myecho | |
145 | ;; | |
146 | "\$ans") | |
147 | case "\$ans" in | |
148 | ?X: | |
149 | ?X: Answers starting with & are hooks allowing to dynamically turn on/off | |
150 | ?X: some Configure options. That's for the future. -- RAM, 09/01/95 | |
151 | ?X: Today, we only recognize '& -d' to mean 'go on as if Configure -d, which | |
152 | ?X: is a hardwired behaviour compatible with our general scheme. | |
153 | ?X: | |
154 | \\&*) | |
155 | set x \`expr "X\$ans" : "X&\(.*\)\$"\` | |
156 | shift | |
157 | case "\$1" in | |
158 | -d) | |
159 | fastread=yes | |
160 | echo "(OK, I'll run with -d after this question.)" >&4 | |
161 | ;; | |
162 | -*) | |
163 | echo "*** Sorry, \$1 not supported yet." >&4 | |
164 | ;; | |
165 | esac | |
166 | $myecho | |
167 | ans=! | |
168 | ;; | |
169 | esac;; | |
170 | *) | |
171 | case "\$aok" in | |
172 | y) | |
173 | echo "*** Substitution done -- please confirm." | |
174 | xxxm="\$ans" | |
175 | ans=\`echo $n "\$ans$c" | tr '$trnl' ' '\` | |
176 | xxxm="\$ans" | |
177 | ans=! | |
178 | ;; | |
179 | *) | |
180 | echo "*** Error -- try again." | |
181 | ans=! | |
182 | ;; | |
183 | esac | |
184 | $myecho | |
185 | ;; | |
186 | esac | |
187 | ?X: Stick in myread if no default answer and nothing was answered | |
188 | case "\$ans\$xxxm\$nostick" in | |
189 | '') | |
190 | ans=! | |
191 | $myecho | |
192 | ;; | |
193 | esac | |
194 | done | |
195 | case "\$ans" in | |
196 | '') ans="\$xxxm";; | |
197 | esac | |
198 | EOSC | |
199 |