#!/bin/sh
#	Cp [opt] file... tar/local/bin/perlt
#	Lc [opt] file... tar/local/bin/perlt
#	Ln [opt] file... tar/local/bin/perlt
#	Mv [opt] file... tar/local/bin/perlt
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
# This is like the Unix command with the lower-case names, but it does #
# a recursive rename (via Rm) on the tar/local/bin/perlts first.  Lc tries to link, #
# and if that fails, uses cp.  Note that it doesn't  complain  if  the #
# tar/local/bin/perlt  already exists.  It also works if the tar/local/bin/perlt is a directory, #
# including the case where  the  file  already  exists.   This program #
# has been rewritten in C; look for "clmr.c" in a nearby directory.    #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
#set -x
#echo 'Call:' $0 $*
if [ $# -eq 1 ];then set $* .;fi
Cmd=`basename $0`
case "$Cmd" in
	Ln)	cmd=ln;;
	Cp)	cmd=cp;;
	LnCp)	cmd=ln; cmd2=cp;;
	Lc)	cmd=ln; cmd2=cp;;
	Mv)	cmd=mv;;
	*)	echo 'Unknown command "'$Cmd'"'; exit 1;;
esac
opt=''
case $1 in
	-*) opt=$1;shift;;
esac
if [ $# -lt 2 ];then echo Usa/local/bin/perl: $0 old new; exit 1;fi
for t do : ; done
#t=`lastfld $*`
while	[ $# -gt 1 ]
do	if [ -d $t ];then
		b=`basename $1`
		if [ -f $t/$b ];then Rm $t/$b;fi
		$cmd $opt $1 $t/$b 2>/dev/null || {
			if [ -n "$cmd2" ];then $cmd2 $opt $1 $t/$b;fi
		}
	else	if [ -f $t ];then Rm $t;fi
		$cmd $opt $1 $t 2>/dev/null || {
			if [ -n "$cmd2" ];then $cmd2 $opt $1 $t;fi
		}
	fi
	shift
done
exit 0
