#!/bin/csh
if ( "x$1" == "x" ) then
  echo "Syntax: safecp file1 ... filen destdir"
  exit 1
endif

if ( ! -d safecpdir ) then
  mkdir safecpdir
endif

set dest=$argv[$#argv]

if ( ! -d $dest ) then
  echo $dest does not exist
  exit 1
endif

echo -n "" >! safecpdir/touninstall.txt
foreach src ( $* )
  if ( "x$src" != "x$dest" ) then
    if ( -e $dest/$src ) then
      cp -f $dest/$src safecpdir/
    endif
    cp -f $src $dest
    echo $dest/`echo $src | sed 's+.*/++g'` >> safecpdir/touninstall.txt
  endif
end