#! /bin/csh -f -e
# Last edited on 2009-09-10 15:03:32 by stolfi

set usage = "$0 SOURCEDIR "

if ( ( $#argv < 1 ) && ( $#argv > 1 ) )  then
  echo "usage: ${usage}"; exit 1
endif

set files = ( \
  .Xdefaults .Xresources .xinitrc \
  .cshrc .login .logout .emacs .emacs.el .emacs_csh .vm \
  elisp \
  bin lib man info html tex/inputs include \
  PUB/colormaps PUB/povray \
)

cd ~
set us = ${USER}
set dd = "`/bin/date '+%Y-%m-%d-%H%M%S'`"
set tmp = "/tmp/${dd}-copied-files.dir"

/bin/rm -f ${tmp}
foreach f ( $files )
  if ( -e $f ) then
    /bin/mv -v $f ${f}.${us}-${dd} >>& ${tmp}
  endif
  if ( -e ${sdir}/$f ) then
    set pdir = "./${f}"; set pdir = "${pdir:h}"
    if ( ! ( -d ${pdir} ) ) /bin/mkdir -p ${pdir}
    /bin/cp -av ${sdir}/$f ${pdir} >>& ${tmp}
  else
    echo "${sdir}/$f not found"
  endif
end
echo "done (see ${tmp})."

