?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

