1 ?RCS: $Id: Getfile.U,v 3.0.1.7 1997/02/28 15:01:06 ram Exp $
3 ?RCS: Copyright (c) 1991-1993, 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 3.0.
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"
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)
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
22 ?RCS: Revision 3.0.1.4 1994/10/29 15:53:19 ram
23 ?RCS: patch36: added ?F: line for metalint file checking
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)
29 ?RCS: Revision 3.0.1.2 1994/01/24 14:01:31 ram
30 ?RCS: patch16: added metalint hint on changed 'ans' variable
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
36 ?RCS: Revision 3.0 1993/08/18 12:04:56 ram
37 ?RCS: Baseline for dist 3.0 netwide release.
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.
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.
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.
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.
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.
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
70 ?X: rp='Where is the active file?'
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.
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.
82 ?X: If the answer to the question is 'none', then the existence checks are
83 ?X: skipped and the empty string is returned.
85 ?MAKE:Getfile: d_portable contains startsh Myread Filexp trnl
86 ?MAKE: -pick add $@ %<
87 ?V:ansexp:fn gfpth gfpthkeep
89 ?T:tilde type what orig_rp orig_dflt fullpath already redo skip none_ok \
90 value exp_file nopath_ok loc_file fp pf direxp
93 : now set up to get a file name
97 cat <<'EOSC' >>getfile
111 ?X: Begin by stripping out any (...) grouping.
114 expr $fn : '.*(\(.*\)).*' | tr ',' $trnl >getfile.ok
115 fn=`echo $fn | sed 's/(.*)//'`
119 ?X: Catch up 'locate' requests early, so that we may strip the file name
120 ?X: before looking at the one-letter commands, in case the file name contains
121 ?X: one of them. Reported by Wayne Davison <davison@borland.com>.
124 loc_file=`expr $fn : '.*:\(.*\)'`
125 fn=`expr $fn : '\(.*\):.*'`
145 *p*) nopath_ok=true;;
150 *d*) type='Directory';;
156 Locate) what='File';;
161 case "$d_portable" in
169 while test "$type"; do
174 true) rp="$rp (~name ok)";;
177 ?X: check for allowed escape sequence which may be accepted verbatim.
178 if test -f UU/getfile.ok && \
179 $contains "^$ans\$" UU/getfile.ok >/dev/null 2>&1
198 value=`UU/filexp $ans`
201 if test "$ans" != "$value"; then
202 echo "(That expands to $value on this system.)"
215 ?X: Perform all the checks on ansexp and not value since when d_portable
216 ?X: is defined, the original un-expanded answer which is stored in value
217 ?X: would lead to "non-existent" error messages whilst ansexp has been
218 ?X: properly expanded. -- Fixed by Jan.Djarv@sa.erisoft.se (Jan Djarv)
219 ?X: Always expand ~user if '/' was requested
221 /*) value="$ansexp" ;;
226 echo "I shall only accept a full path name, as in /bin/ls." >&4
227 echo "Use a ! shell escape if you wish to check pathnames." >&4
230 echo "Please give a full path name, starting with slash." >&4
233 echo "Note that using ~name is ok provided it expands well." >&4
247 if test "X$fp" = X.; then
252 if test -f "$pf"; then
254 elif test -r "$pf" || (test -h "$pf") >/dev/null 2>&1
256 echo "($value is not a plain file, but that's ok.)"
259 if test X"$type" = X; then
267 if test "X$fp" = X.; then
274 if test -d "$direxp"; then
282 if test -d "$ansexp"; then
283 echo "(Looking for $loc_file in directory $value.)"
284 value="$value/$loc_file"
285 ansexp="$ansexp/$loc_file"
287 if test -f "$ansexp"; then
291 true) case "$value" in
293 *) echo "Assuming $value will be in people's path."
309 if test "$fastread" = yes; then
314 rp="$what $value doesn't exist. Use that name anyway?"
333 test "X$gfpthkeep" != Xy && gfpth=""