This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RE: [perl #26136] localtime(3) calls tzset(3), but localtime_r(3) may not.
[metaconfig.git] / U / modified / Getfile.U
CommitLineData
959f3c4c
JH
1?RCS: $Id: Getfile.U,v 3.0.1.7 1997/02/28 15:01:06 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: Getfile.U,v $
12?RCS: Revision 3.0.1.7 1997/02/28 15:01:06 ram
13?RCS: patch61: getfile script now begins with "startsh"
14?RCS:
15?RCS: Revision 3.0.1.6 1995/02/15 14:11:00 ram
16?RCS: patch51: was not working if ~'s allowed with d_portable on (WED)
17?RCS:
18?RCS: Revision 3.0.1.5 1995/01/11 15:11:25 ram
19?RCS: patch45: added support for escaping answers to skip various checks
20?RCS: patch45: modified message issued after file expansion
21?RCS:
22?RCS: Revision 3.0.1.4 1994/10/29 15:53:19 ram
23?RCS: patch36: added ?F: line for metalint file checking
24?RCS:
25?RCS: Revision 3.0.1.3 1994/05/06 14:23:36 ram
26?RCS: patch23: getfile could be confused by file name in "locate" requests
27?RCS: patch23: new 'p' directive to assume file is in people's path (WED)
28?RCS:
29?RCS: Revision 3.0.1.2 1994/01/24 14:01:31 ram
30?RCS: patch16: added metalint hint on changed 'ans' variable
31?RCS:
32?RCS: Revision 3.0.1.1 1993/09/13 15:46:27 ram
33?RCS: patch10: minor format problems and misspellings fixed
34?RCS: patch10: now performs from package dir and not from UU subdir
35?RCS:
36?RCS: Revision 3.0 1993/08/18 12:04:56 ram
37?RCS: Baseline for dist 3.0 netwide release.
38?RCS:
39?X:
40?X: This unit produces a bit of shell code that must be dotted in in order
41?X: to get a file name and make some sanity checks. Optionally, a ~name
42?X: expansion is performed.
43?X:
44?X: To use this unit, $rp and $dflt must hold the question and the
45?X: default answer, which will be passed as-is to the myread script.
46?X: The $fn variable must hold the file type (f or d, for file/directory).
47?X: If $gfpth is set to a list of space-separated list of directories,
48?X: those are prefixes for the filename. Unless $gfpthkeep is set to 'y',
49?X: gfpth is cleared on return from Getfile.
50?X:
51?X: If is is followed by a ~, then ~name substitution will occur. Upon return,
52?X: $ans is set with the filename value. If a / is specified, then only a full
53?X: path name is accepted (but ~ substitution occurs before, if needed). The
54?X: expanded path name is returned in that case.
55?X:
56?X: If a + is specified, the existence checks are skipped. This usually means
57?X: the file/directory is under the full control of the program.
58?X:
59?X: If the 'n' (none) type is used, then the user may answer none.
60?X: The 'e' (expand) switch may be used to bypass d_portable, expanding ~name.
61?X:
62?X: If the 'l' (locate) type is used, then it must end with a ':' and then a
63?X: file name. If the answer is a directory, the file name will be appended
64?X: before testing for file existence. This is useful in locate-style
65?X: questions like "where is the active file?". In that case, one should
66?X: use:
67?X:
68?X: dflt='~news/lib'
69?X: fn='l~:active'
70?X: rp='Where is the active file?'
71?X: . ./getfile
72?X: active="$ans"
73?X:
74?X: If the 'p' (path) letter is specified along with 'l', then an answer
75?X: without a leading / will be expected to be found in everyone's path.
76?X:
77?X: It is also possible to include a comma-separated list of items within
78?X: parentheses to specify which items should be accepted as-is with no
79?X: further checks. This is useful when for instance a full path is expected
80?X: but the user may escape out via "magical" answers.
81?X:
82?X: If the answer to the question is 'none', then the existence checks are
83?X: skipped and the empty string is returned.
84?X:
a3e4b67c 85?MAKE:Getfile: d_portable contains startsh Myread Filexp tr trnl
959f3c4c
JH
86?MAKE: -pick add $@ %<
87?V:ansexp:fn gfpth gfpthkeep
88?F:./getfile
89?T:tilde type what orig_rp orig_dflt fullpath already redo skip none_ok \
17b6495f 90 value exp_file nopath_ok loc_file fp pf dir direxp
959f3c4c
JH
91?LINT:change ans
92?LINT:change gfpth
93: now set up to get a file name
94cat <<EOS >getfile
95$startsh
96EOS
97cat <<'EOSC' >>getfile
98tilde=''
99fullpath=''
100already=''
101skip=''
102none_ok=''
103exp_file=''
104nopath_ok=''
105orig_rp="$rp"
106orig_dflt="$dflt"
107case "$gfpth" in
108'') gfpth='.' ;;
109esac
110
111?X: Begin by stripping out any (...) grouping.
112case "$fn" in
113*\(*)
4f294a60
JH
114 : getfile will accept an answer from the comma-separated list
115 : enclosed in parentheses even if it does not meet other criteria.
116 expr "$fn" : '.*(\(.*\)).*' | $tr ',' $trnl >getfile.ok
959f3c4c
JH
117 fn=`echo $fn | sed 's/(.*)//'`
118 ;;
119esac
120
121?X: Catch up 'locate' requests early, so that we may strip the file name
122?X: before looking at the one-letter commands, in case the file name contains
123?X: one of them. Reported by Wayne Davison <davison@borland.com>.
124case "$fn" in
125*:*)
126 loc_file=`expr $fn : '.*:\(.*\)'`
127 fn=`expr $fn : '\(.*\):.*'`
128 ;;
129esac
130
131case "$fn" in
132*~*) tilde=true;;
133esac
134case "$fn" in
135*/*) fullpath=true;;
136esac
137case "$fn" in
138*+*) skip=true;;
139esac
140case "$fn" in
141*n*) none_ok=true;;
142esac
143case "$fn" in
144*e*) exp_file=true;;
145esac
146case "$fn" in
147*p*) nopath_ok=true;;
148esac
149
150case "$fn" in
151*f*) type='File';;
152*d*) type='Directory';;
153*l*) type='Locate';;
154esac
155
156what="$type"
157case "$what" in
158Locate) what='File';;
159esac
160
161case "$exp_file" in
162'')
163 case "$d_portable" in
164 "$define") ;;
165 *) exp_file=true;;
166 esac
167 ;;
168esac
169
170cd ..
171while test "$type"; do
172 redo=''
173 rp="$orig_rp"
174 dflt="$orig_dflt"
175 case "$tilde" in
176 true) rp="$rp (~name ok)";;
177 esac
178 . UU/myread
179?X: check for allowed escape sequence which may be accepted verbatim.
180 if test -f UU/getfile.ok && \
181 $contains "^$ans\$" UU/getfile.ok >/dev/null 2>&1
182 then
183 value="$ans"
184 ansexp="$ans"
185 break
186 fi
187 case "$ans" in
188 none)
189 value=''
190 ansexp=''
191 case "$none_ok" in
192 true) type='';;
193 esac
194 ;;
195 *)
196 case "$tilde" in
197 '') value="$ans"
198 ansexp="$ans";;
199 *)
200 value=`UU/filexp $ans`
201 case $? in
202 0)
203 if test "$ans" != "$value"; then
204 echo "(That expands to $value on this system.)"
205 fi
206 ;;
207 *) value="$ans";;
208 esac
209 ansexp="$value"
210 case "$exp_file" in
211 '') value="$ans";;
212 esac
213 ;;
214 esac
215 case "$fullpath" in
216 true)
217?X: Perform all the checks on ansexp and not value since when d_portable
218?X: is defined, the original un-expanded answer which is stored in value
219?X: would lead to "non-existent" error messages whilst ansexp has been
220?X: properly expanded. -- Fixed by Jan.Djarv@sa.erisoft.se (Jan Djarv)
221?X: Always expand ~user if '/' was requested
222 case "$ansexp" in
223 /*) value="$ansexp" ;;
ae35c09d 224 [a-zA-Z]:/*) value="$ansexp" ;;
959f3c4c
JH
225 *)
226 redo=true
227 case "$already" in
228 true)
229 echo "I shall only accept a full path name, as in /bin/ls." >&4
230 echo "Use a ! shell escape if you wish to check pathnames." >&4
231 ;;
232 *)
233 echo "Please give a full path name, starting with slash." >&4
234 case "$tilde" in
235 true)
236 echo "Note that using ~name is ok provided it expands well." >&4
237 already=true
238 ;;
239 esac
240 esac
241 ;;
242 esac
243 ;;
244 esac
245 case "$redo" in
246 '')
247 case "$type" in
248 File)
249 for fp in $gfpth; do
250 if test "X$fp" = X.; then
251 pf="$ansexp"
252 else
253 pf="$fp/$ansexp"
254 fi
255 if test -f "$pf"; then
256 type=''
257 elif test -r "$pf" || (test -h "$pf") >/dev/null 2>&1
258 then
259 echo "($value is not a plain file, but that's ok.)"
260 type=''
261 fi
262 if test X"$type" = X; then
263 value="$pf"
264 break
265 fi
266 done
267 ;;
268 Directory)
269 for fp in $gfpth; do
270 if test "X$fp" = X.; then
7303ecc3
JH
271 dir="$ans"
272 direxp="$ansexp"
959f3c4c 273 else
dcb06850 274 dir="$fp/$ansexp"
7303ecc3 275 direxp="$fp/$ansexp"
959f3c4c 276 fi
7303ecc3 277 if test -d "$direxp"; then
959f3c4c 278 type=''
7303ecc3 279 value="$dir"
959f3c4c
JH
280 break
281 fi
282 done
283 ;;
284 Locate)
285 if test -d "$ansexp"; then
286 echo "(Looking for $loc_file in directory $value.)"
287 value="$value/$loc_file"
288 ansexp="$ansexp/$loc_file"
289 fi
290 if test -f "$ansexp"; then
291 type=''
292 fi
293 case "$nopath_ok" in
294 true) case "$value" in
295 */*) ;;
296 *) echo "Assuming $value will be in people's path."
297 type=''
298 ;;
299 esac
300 ;;
301 esac
302 ;;
303 esac
304
305 case "$skip" in
306 true) type='';
307 esac
308
309 case "$type" in
310 '') ;;
311 *)
312 if test "$fastread" = yes; then
313 dflt=y
314 else
315 dflt=n
316 fi
317 rp="$what $value doesn't exist. Use that name anyway?"
318 . UU/myread
319 dflt=''
320 case "$ans" in
321 y*) type='';;
322 *) echo " ";;
323 esac
324 ;;
325 esac
326 ;;
327 esac
328 ;;
329 esac
330done
331cd UU
332ans="$value"
333rp="$orig_rp"
334dflt="$orig_dflt"
335rm -f getfile.ok
336test "X$gfpthkeep" != Xy && gfpth=""
337EOSC
338