summaryrefslogtreecommitdiff
path: root/mcon/U/Filexp.U
blob: 31e57a55a0fb375f7ee1d4c4f8cb28346c47a72e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
?RCS: $Id$
?RCS:
?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
?RCS:
?RCS: You may redistribute only under the terms of the Artistic License,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic License; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
?RCS: $Log: Filexp.U,v $
?RCS: Revision 3.0.1.2  1994/10/29  15:52:53  ram
?RCS: patch36: added ?F: line for metalint file checking
?RCS: patch36: added HOME to the ?T: line since metalint now checks ${HOME}
?RCS:
?RCS: Revision 3.0.1.1  1994/05/06  14:03:00  ram
?RCS: patch23: made sure error status from csh is propagated (WED)
?RCS:
?RCS: Revision 3.0  1993/08/18  12:04:53  ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
?X:
?X: This unit produces a shell script which will expand filenames beginning
?X: with tildes.  The script is deleted at the end of Configure.
?X:
?MAKE:Filexp: startsh sed test expr eunicefix
?MAKE:	-pick add $@ %<
?F:./filexp
?T:HOME LOGDIR dir me name failed
: set up shell script to do ~ expansion
cat >filexp <<EOSS
$startsh
: expand filename
?X:
?X: The case entries below escape the ~ as some shells have shown expansion
?X: of the ~ during here-doc processing.
?X:
case "\$1" in
 \~/*|\~)
	echo \$1 | $sed "s|~|\${HOME-\$LOGDIR}|"
	;;
 \~*)
	if $test -f /bin/csh; then
		/bin/csh -f -c "glob \$1"
		failed=\$?
		echo ""
		exit \$failed
	else
		name=\`$expr x\$1 : '..\([^/]*\)'\`
		dir=\`$sed -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}' </etc/passwd\`
		if $test ! -d "\$dir"; then
			me=\`basename \$0\`
			echo "\$me: can't locate home directory for: \$name" >&2
			exit 1
		fi
		case "\$1" in
		*/*)
			echo \$dir/\`$expr x\$1 : '..[^/]*/\(.*\)'\`
			;;
		*)
			echo \$dir
			;;
		esac
	fi
	;;
*)
	echo \$1
	;;
esac
EOSS
chmod +x filexp
$eunicefix filexp