1 ?RCS: $Id: Myread.U 1 2006-08-24 12:32:52Z rmanfredi $
3 ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
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 4.0.
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
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
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
22 ?RCS: Revision 3.0.1.3 1994/10/29 15:56:20 ram
23 ?RCS: patch36: added ?F: line for metalint file checking
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
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
31 ?RCS: Revision 3.0 1993/08/18 12:05:08 ram
32 ?RCS: Baseline for dist 3.0 netwide release.
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.
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.
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!
48 ?MAKE:Myread: Options startsh n c trnl
49 ?MAKE: -pick add $@ %<
50 ?V:ans:dflt rp nostick
52 ?T:COLUMNS xxxm rp dflt answ aok myecho
54 ?X: Some shells (Ultrix) do not understand ${COLUMNS:-80}, sigh!
55 : compute the number of columns on the terminal for proper question formatting
60 : set up the echo used in my read
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.
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.
70 myecho="case \"\$xxxm\" in
71 '') echo $n \"\$rp $c\" >&4;;
73 '') echo $n \"[\$xxxm] $c\";;
75 if test \`echo \"\$rp [\$xxxm] \" | wc -c\` -ge $COLUMNS; then
77 echo $n \"[\$xxxm] $c\" >&4
79 echo $n \"\$rp [\$xxxm] $c\" >&4
85 : now set up to do reads with possible shell escape and default assignment
89 ?X: Save value of default -- do not alter original in case of eval
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.
100 yes) case "\$dflt" in
103 case "\$silent-\$rp" in
108 *) case "\$silent" in
114 while expr "X\$ans" : "X!" >/dev/null; do
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
125 aok=''; eval "ans=\\"\$answ\\"" && aok=y
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
140 set x \`expr "X\$ans" : "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.
155 set x \`expr "X\$ans" : "X&\(.*\)\$"\`
160 echo "(OK, I'll run with -d after this question.)" >&4
163 echo "*** Sorry, \$1 not supported yet." >&4
173 echo "*** Substitution done -- please confirm."
175 ans=\`echo $n "\$ans$c" | tr '$trnl' ' '\`
180 echo "*** Error -- try again."
187 ?X: Stick in myread if no default answer and nothing was answered
188 case "\$ans\$xxxm\$nostick" in