#!/bin/csh -fe
set nonomatch
echo "----------------------------------------------------------------------"
echo " \
This Script will upadte console files in the following ways: \
	rename console/vopcon files to have the [new] correct \
	  extension. \
	edit the .con/.vop files to replace certain fontnames with \
	  their new fontnames. \
 \
The new extensions are now: \
	'.con' instead of '.console' or '.Console' \
	'.vop' instead of '.vopcon' or '.Vopcon' \
 \
Then known changed font names are: \
	con10 instead of console10 \
	con12 instead of console12 \
	andy120 instead of andrew120 \
	msgs10 instead of messages10 \
	msgs14 isntead of messages14 "
echo ""
echo "----------------------------------------------------------------------"
echo -n "Rename console/vopcon files to use new extension? (y/n) [y] "
set foo=$<
if ($foo != "n" && $foo != "N") then
	set CONS = `/bin/ls *.console *.Console` 
	set VOPS = `/bin/ls *.vopcon *.Vopcon`
	if ($#CONS == 0 && $#VOPS == 0) then
		echo "No files to be renamed"
	else
		echo "Begining rename"
		if ($#CONS != 0) then
			foreach i (${CONS})
				echo "## $i"
				set conname = $i:r
				mv $i ${conname}.con
			end
		endif
		if ($#VOPS != 0) then
			foreach i (${VOPS})
				echo "## $i"
				set conname = $i:r
				mv $i ${conname}.vop
			end
		endif
		echo "Done."
	endif
endif

echo "----------------------------------------------------------------------"
echo  -n "Replace outdated fontnames with new fontnames? (y/n) [y] "
set foo=$<
if ($foo != "n" && $foo != "N") then
	set CONS = `/bin/ls *.con`
	set VOPS = `/bin/ls *.vop`
	if ($#CONS == 0 && $#VOPS == 0) then
		echo "No files to edit"
	else
		echo "Replacing fontnames"
		foreach i (${CONS} ${VOPS})
			echo "### $i"
			chmod +w $i
			cat $i | sed \
				-e 's;console10;con10;g' \
				-e 's;console12;con12;g' \
				-e 's;Console10;con10;g' \
				-e 's;Console12;con12;g' \
				-e 's;CONSOLE10;con10;g' \
				-e 's;CONSOLE12;con12;g' \
				-e 's;andrew120;andy120;g' \
				-e 's;Andrew120;andy120;g' \
				-e 's;ANDREW120;andy120;g' \
				-e 's;messages10;msgs10;g' \
				-e 's;messages14;msgs15;g' \
				-e 's;Messages10;msgs10;g' \
				-e 's;Messages14;msgs15;g' \
				-e 's;MESSAGES10;msgs10;g' \
				-e 's;MESSAGES14;msgs15;g' \
				 > .foo
			mv .foo $i
			chmod -w $i
		end
		echo "Done."
	endif
	echo "----------------------------------------------------------------------"
	echo "WARNING - all .con and .vop files have now been made read-only"
	echo -n "Do you want them re-set back to read-write? (y/n) [n] "
	set foo=$<
	if ($foo == "y" || $foo == "Y") then
		echo "OK - chmod'ing them to be r/w"
		chmod +w *.con *.vop
		echo "Done."
	endif
endif

echo "All Done with Script \
	if there are any problems - please send mail to \
	Adam Stoller: \
	ghoti+@andrew.cmu.edu"

