#! /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 Imakefiles to an IBM PS/2
# Usage: cd ice; util/os2copy_imakefiles <host> <login> <dir> <dir> ...
# The directories to copy default to: cool
#   ice_defs cpp CCC test util cool pisces
#
# Example: copy cool Imakefiles
#   cd ice; util/os2copy_imakefiles blue ssb cool
#
# Example: copy just the String and String/tests Imakefiles
#   cd ice; util/os2copy_imakefiles blue ssb cool/String
#

if ($1 == "" || $2 == "") then
  echo "Usage: util/os2copy_imakefiles <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 containg 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 >> /tmp/cooldirs)
 end
endif

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 mput Imakefile >> /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
