#!/bin/csh -f

unalias cp
unalias rm

nextfile:
set LINKFILE = $1

if ( "$LINKFILE" == "" ) exit

set TEMPFILE = $LINKFILE.link

if (! -e $LINKFILE ) then 
echo "$LINKFILE does not exist"
goto endthisfile
endif

if ( -w $LINKFILE ) then 
echo "$LINKFILE is writable"
goto endthisfile
endif

cp $LINKFILE $TEMPFILE
if ( $status != 0 ) then 
goto endthisfile
endif

rm -f $LINKFILE
cp $TEMPFILE $LINKFILE
if ( $status == 0 ) then
      rm -f $TEMPFILE
      chmod ug+rw $LINKFILE
else
       echo "unlinking failed"
	goto endthisfile
endif

endthisfile:
shift

goto nextfile

