# spc2flop
# script to copy the spc toolbox to an MS-DOS floppy
# D.W. Brown, 4-20-93

# check for sun4 arch
if (`arch` != "sun4") then

	echo "spc2flop: Can only be executed from a Sun Workstation."
	echo "spc2flop: Aborted"

	exit 1
endif

# check which network in order to set proper drive letter
set net  = `ypcat hosts | grep sp254201 | awk '{print $2 }'`
if ($net == "ece") then

	set drive = a

else if ($net == "cc") then

	set drive = b

else

	set drive = a
	
endif

# check path to spctools
set SPCDIR='/tools4/matlab/toolbox/spctools'
if (!(-d $SPCDIR) ) then

	echo "spc2flop: Cannot find spctools directory."
	echo "spc2flop: Contact your Sys Admin to modify this script."
	echo "spc2flop: Aborted"
	exit 1
endif

unset verbose

# format disk if requested
echo -n "Format disk in drive $drive? (y[n]) "
set a = ($<)
if ($a == "y" || $a == "Y") then

	echo "MS-DOS formatting disk in drive $drive\:"
	fdformat
	mformat $drive\:

endif

# get directory filenames from disk
set d = `mdir $drive\:\\ | grep "<DIR>" | $SPCDIR/lower | awk '{ print $1 }' | grep  spctools`

# create dir if necessary
if ($d != spctools) then

	# create the directory
	mmd $drive\:\/spctools

endif

# set directory names
set d = (spccomms spcgui spcline spcprog spcspch spcsspi spcutil dos42mex)

# files to copy
set datafiles = (seatsit.voc t0x.mat uuu.mat datax.mat)
set mscripts = (spcolors.m spcbandw.m spcpath.m spcdata.m spc2flop.m \
	spcolor.m Contents.m Readme.m)
set text = (install.txt descript.txt bugs.txt support.txt)

# copy files
echo "Copying datafiles"
foreach fname ( $datafiles )
	
	mcopy -n $SPCDIR/$fname $drive\:/spctools

end
echo "Copying base m-files"
foreach fname ( $mscripts )
	
	mcopy -tn $SPCDIR/$fname $drive\:/spctools

end
echo "Copying text files"
foreach fname ( $text )
	
	mcopy -tn $SPCDIR/$fname $drive\:/spctools

end

# copy files from directories
foreach dname ( $d )

	# see if directory exists
	set dd = `mdir $drive\:\/spctools | grep "<DIR>" | grep -v '\.' | $SPCDIR/lower | awk '{ print $1 }' | grep $dname`

	if ($dd != $dname) then
		echo "Creating directory '$dname'"
		mmd $drive\:\/spctools\/$dname
	endif

	echo "Copying *.m files from spctools/$dname"
	mcopy -tn $SPCDIR/$dname/*.m $drive\:\/spctools\/$dname

	set cfiles = `ls $SPCDIR/$dname/*.mex`
	if ($#cfiles > 0) then
		echo "Copying *.mex files from spctools/$dname"
		mcopy -n $SPCDIR/$dname/*.mex $drive\:\/spctools\/$dname
	endif

	set cfiles = `ls $SPCDIR/$dname/*.c`
	if ($#cfiles > 0) then
		echo "Copying *.c files from spctools/$dname"
		mcopy -tn $SPCDIR/$dname/*.c $drive\:\/spctools\/$dname
	endif

end

unset d
unset dd
unset dname
unset cfiles
unset text

echo "Don't forget your disk\!"
eject
