#!/bin/sh
#*******************************************************************************
# E.S.O. - VLT project
#
# "@(#) $Id: docDos2Unix,v 1.31 2002/06/08 17:20:42 vltsccm Exp $" 
#
# docDos2Unix
#
# who       when      what
# --------  --------  ----------------------------------------------
# pforstma  02/08/94  created
#

#************************************************************************
#   NAME
#   docDos2Unix - copy files from Dos to Unix (counterpart of docUnix2Dos)
# 
#   SYNOPSIS
#   docDos2Unix  [ <target_dir> ]
# 
#   DESCRIPTION
#   
#   In the following, a "DOS" directory is a UNIX directory containing
#   files which have been modified on a PC and copied to UNIX with 'mkdir'
#   and 'cp' commands. These files must have been transfered from UNIX
#   to DOS using docUnix2dos.
#
#   This command must be executed from the "DOS" directory.
#   The default target directory is the one from which the docUnix2Dos
#   command has been executed.
# 
#   docDos2Unix copy files from the current "DOS" directory to <target_dir> 
#   and rename them with their UNIX name. Note that <target_dir> must not 
#   have a final '/'.
#
#   To copy a DOS directory back to the original UNIX directory from an 
#   ENVIZEX terminal, do the following  steps:
#
#   1. Create the "DOS" directory on UNIX
#      mkdir $HOME/<dos_dir>
#   2. Copy the floppy disk directory <dir> to the "DOS" directory:
#      cp $HOME/floppy/<dir>/* $HOME/<dos_dir>
#   3. Copy the contents of the files and rename them:
#      docDos2Unix
#   
#
#   FILES
#   * in current floppy directory  read
#   
#
#   ENVIRONMENT
#
#   RETURN VALUES
#
#   CAUTIONS
#
#   A file which has been created on the floppy (i.e. which did'nt exist on
#   UNIX) is copied back as it is, using 'cp' naming conventions.
#
#   This command executed without any argument will overwrite the original 
#   files.
#
#   EXAMPLES
#
#   SEE ALSO
#
#   docUnix2Dos
#
#   BUGS     
#
#------------------------------------------------------------------------
#

if [ $# -eq  1 ]
then
    target=$1
else
    target=.
fi

cwd=`pwd`
dir=`basename $cwd`

if [ ! -f dos2unix ]
then 
    echo dos2unix does not exist
    exit -1
fi

#
# the unix2dos shell script has been generated by the docUnix2Dos command.
#
if [ $target = "." ]
then target=""
fi
sh dos2unix $target

# here we need to copy files which didn't exist on UNIX and which have
# been created on DOS.

echo ${target:="."} >/dev/null

for i in *
do
    if [ ! $i -eq "dos2unix" ]
    then 
        grep $i dos2unix >/dev/null
        if [ $? -eq 1 ]
        then echo file $i created
             cp $i $target/$i
        fi
   fi
done
