#! /bin/csh
#
# Copyright (C) 1991 Texas Instruments Incorporated.
#
# Permission is granted to any individual or institution to use, copy, modify,
# and distribute this software, provided that this complete copyright and
# permission notice is maintained, intact, in all copies and supporting
# documentation.
#
# Texas Instruments Incorporated provides this software "as is" without
# express or implied warranty.
#
# ftp cool files to an IBM PS/2
# Usage: cd ice; util/os2copy <host> <login> <dir> <dir> ...
# The directories to copy default to:
#   ice_defs cpp CCC test util cool pisces
#
# Example: copy all of cool
#   cd ice; util/os2copy blue cool
#
# Example: copy just the String and String/tests directories
#   cd ice; util/os2copy blue cool/String
#
# NOTE:
#   We only copy *.C *.H *.c and Imakefile.  If other files need
#   to be copied, place a "ftp-script" file in the applicable
#   directory and it will be included in the ftp commands.
#   
#

if ($1 == "" || $2 == "") then
  echo "Usage: util/os2copy <host> <login> [<dirs>]"
  exit
endif

set HOST = $1
shift
set LOGIN = $1
shift

if ($1 == "") then
  set DIRS = "ice_defs cpp CCC test util cool pisces"
else
  set DIRS = $*
endif

set ICE = `pwd`

# Create a temporary file containing all the directory names
if (-e /tmp/cooldirs && "$1" == "") then
 echo "using /tmp/cooldirs"
else 
 rm -f /tmp/cooldirs
 touch /tmp/cooldirs
 echo "ice" >> /tmp/cooldirs
 foreach DIR ($DIRS)
   echo "Finding $DIR directory"
   echo "ice/$DIR" >> /tmp/cooldirs
   (cd $ICE/..; find ice/$DIR/* -type d -print | egrep -v 'RCS' >> /tmp/cooldirs)
 end
endif

# Create a temporary file containg ftp commands which copy all directories
echo "Creating ftp command file"
echo "open $HOST" > /tmp/ftp.script
echo "$LOGIN" >> /tmp/ftp.script
foreach DIR (`cat /tmp/cooldirs`)
  set OS2DIR=`echo "$DIR" | sed -e s'@/@\\\\@'g -e 's/^/\\\\/'`
  echo cd "$OS2DIR" >> /tmp/ftp.script
  echo lcd "$ICE/../$DIR" >> /tmp/ftp.script
  echo nmap \$1.\$2 \$1.cxx >> /tmp/ftp.script
  echo mput "*.C" >> /tmp/ftp.script
  echo nmap >> /tmp/ftp.script
  echo mput "*.h" >> /tmp/ftp.script
  echo mput "*.c" >> /tmp/ftp.script
  echo mput "Imakefile" >> /tmp/ftp.script
  if (-e ../$DIR/ftp-script) cat ../$DIR/ftp-script >> /tmp/ftp.script
end
echo "close" >> /tmp/ftp.script
echo "bye" >> /tmp/ftp.script

echo 'ftp -v -i < /tmp/ftp.script'
/bin/time ftp -v -i < /tmp/ftp.script
