This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
/\=/ does not require \ even in older awk
[metaconfig.git] / U / modified / Myread.U
CommitLineData
c351c081
MB
1?RCS: $Id$
2?RCS:
3?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
4?RCS:
5?RCS: You may redistribute only under the terms of the Artistic License,
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 License; a copy of which may be found at the root
9?RCS: of the source tree for dist 4.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 counter
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
56case "$COLUMNS" in
57'') COLUMNS='80';;
58esac
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:
70myecho="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;;
83esac"
84
85: now set up to do reads with possible shell escape and default assignment
86cat <<EOSC >myread
87$startsh
88?X:
89?X: Save value of default -- do not alter original in case of eval
90?X:
91xxxm=\$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:
98ans='!'
5ca7fae2 99counter=42
c351c081
MB
100case "\$fastread" in
101yes) case "\$dflt" in
102 '') ;;
103 *) ans='';
104 case "\$silent-\$rp" in
105 true-) ;;
106 *) echo " " >&4;;
107 esac;;
108 esac;;
109*) case "\$silent" in
110 true) case "\$rp" in
111 '') ans='';;
112 esac;;
113 esac;;
114esac
115while expr "X\$ans" : "X!" >/dev/null; do
116 read answ
117?X:
118?X: Run 'eval' on the answer, in order to do variable substitution, in case
119?X: the user types $HOME or $WHATEVER. Variables must be evaluated now.
120?X: Typing '\$HOME' won't currently prevent from substitution -- use '\\$HOME'
121?X: The $1 .. $9 and $*, as well as $@, are available to refer to the
122?X: default value.
123?X:
124 set x \$xxxm
125 shift
126 aok=''; eval "ans=\\"\$answ\\"" && aok=y
127 case "\$answ" in
128?X:
129?X: Use "!" and not a plain ! because of a bug in BSD 4.4 shell
130?X: (reported by Wayne Davison)
131?X: We must handle the shell escapes before dealing with possible variable
132?X: substitution, since the shell we're launching in that case will be able
133?X: to do it as well as we can -- RAM, 15/03/96
134?X
135 "!")
136 sh 1>&4
137 echo " "
138 $myecho
139 ;;
140 !*)
141 set x \`expr "X\$ans" : "X!\(.*\)\$"\`
142 shift
143 sh 1>&4 -c "\$*"
144 echo " "
145 $myecho
146 ;;
147 "\$ans")
148 case "\$ans" in
149?X:
150?X: Answers starting with & are hooks allowing to dynamically turn on/off
151?X: some Configure options. That's for the future. -- RAM, 09/01/95
152?X: Today, we only recognize '& -d' to mean 'go on as if Configure -d, which
153?X: is a hardwired behaviour compatible with our general scheme.
154?X:
155 \\&*)
156 set x \`expr "X\$ans" : "X&\(.*\)\$"\`
157 shift
158 case "\$1" in
159 -d)
160 fastread=yes
161 echo "(OK, I'll run with -d after this question.)" >&4
162 ;;
163 -*)
164 echo "*** Sorry, \$1 not supported yet." >&4
165 ;;
166 esac
167 $myecho
168 ans=!
169 ;;
170 esac;;
171 *)
172 case "\$aok" in
173 y)
174 echo "*** Substitution done -- please confirm."
175 xxxm="\$ans"
176 ans=\`echo $n "\$ans$c" | tr '$trnl' ' '\`
177 xxxm="\$ans"
178 ans=!
179 ;;
180 *)
181 echo "*** Error -- try again."
182 ans=!
183 ;;
184 esac
185 $myecho
186 ;;
187 esac
188?X: Stick in myread if no default answer and nothing was answered
189 case "\$ans\$xxxm\$nostick" in
190 '')
191 ans=!
192 $myecho
193 ;;
194 esac
195 counter=\`echo \$counter | awk '{ print --\$0 }'\`
196 if [ \$counter = 0 ]; then
197 echo >&4
198 echo >&4 Too many attempts asking the same question. Giving up.
199 exit 1
200 fi
201done
202case "\$ans" in
203'') ans="\$xxxm";;
204esac
205EOSC
206