#!/bin/sh

#
# Written by Panagiotis Velissariou
# takis@superior.eng.ohio-state.edu (Civil Engineering at Ohio State)
# takis@takis2.ee.net (Home)
# pvelissa@postbox.acs.ohio-state.edu (Ohio State University)
#
OriginalDir=original
NeXTDir=NeXT
AnalogDir=Analog.2.0
ImagesDir=images
CurrentDir=`pwd`
TempDir=""

for i in `echo $CurrentDir | sed 's/\// /g'`
	do
          if test $i = $AnalogDir; then
            break
          fi
          TempDir=$TempDir/$i
	done

TempDir=$TempDir/$AnalogDir

if test $TempDir != $CurrentDir
	then
	  echo ""
	  echo "--------------------------------------------------------------"
	  echo "You should run this script within the $AnalogDir directory."
	  echo "Please move the script within the $AnalogDir directory and"
	  echo "rerun it."
	  echo "--------------------------------------------------------------"
	  echo ""
          exit 1
fi
	            
Files=" *.c *.h *.html *.mms *.opt *.tab Licence Update Makefile"
ImgFiles="*.gif"
OrigFiles="*.cfg"	        
NeXTFiles="*.conf *.cfg README.NeXT"
DeleteFiles="*.o $Files $NeXTFiles $OrigFiles $ImagesDir/*.gif"

case "$1" in
	original) echo "Checking for the $OriginalDir directory ..."
                  if test -d $CurrentDir/$OriginalDir
                   then
                     echo "Found it ..."
                     echo "Removing the unnecessary files ..."
                     for i in $DeleteFiles
                        do
                          echo "Deleting : $CurrentDir/$i"
                          rm -f $CurrentDir/$i
                        done
                     echo "Copying the original distribution files ..."
                     for i in $Files $OrigFiles
                        do
                          echo "From : $CurrentDir/$OriginalDir/$i"
                          echo "To   : $CurrentDir"
                          cp $OriginalDir/$i $CurrentDir
                        done
                     for i in $ImgFiles
                        do
                          echo "From : $CurrentDir/$OriginalDir/$ImagesDir/$i"
                          echo "To   : $CurrentDir/$ImagesDir"
                          cp $OriginalDir/$ImagesDir/$i $CurrentDir/$ImagesDir
                        done
                     echo ""
                     echo "All the files for the original distribution copied in place."
                     echo "Type make to compile analog using the original distribution."
                     echo ""
                   else
                     echo "Couldn't find the directory : $CurrentDir/$OriginalDir"
                     echo "Exiting ..."
                     exit 1
                  fi;;

	next    ) echo "Checking for the $NeXTDir directory ..."
                  if test -d $CurrentDir/$NeXTDir
                   then
                     echo "Found it ..."
                     echo "Removing the unnecessary files ..."
                     for i in $DeleteFiles
                        do
                          echo "Deleting : $CurrentDir/$i"
                          rm -f $CurrentDir/$i
                        done
                     echo "Copying the NeXT distribution files ..."
                     for i in $Files $NeXTFiles
                        do
                          echo "From : $CurrentDir/$NeXTDir/$i"
                          echo "To   : $CurrentDir"
                          cp $NeXTDir/$i $CurrentDir
                        done
                     for i in $ImgFiles
                        do
                          echo "From : $CurrentDir/$NeXTDir/$ImagesDir/$i"
                          echo "To   : $CurrentDir/$ImagesDir"
                          cp $NeXTDir/$ImagesDir/$i $CurrentDir/$ImagesDir
                        done
                     echo ""
                     echo "All the files for the NeXT distribution copied in place."
                     echo "Type make to compile analog for the NeXT distribution."
                     echo ""
                   else
                     echo "Couldn't find the directory : $CurrentDir/$NeXTDir"
                     echo "Exiting ..."
                     exit 1
                  fi;;

	*       ) echo "Usage: $0 \"distribution\""
                  echo "       where distribution is one of : next, original"
                  exit 1;;
esac

exit