#!/bin/csh
#
#  change-perl - Changes Perl scripts to use another path to perl rather
#                than /usr/local/bin/perl
#
echo "This program will change all references to /usr/local/bin/perl"
echo "in the Essence programs to another path."
echo ""

if ($1 != "") then
	set newpath = $1
	goto skip
endif

loop:

echo -n "Enter the full path to your perl program: "
set newpath = $<

skip:
echo ""
if (! -e "$newpath") then
	echo "The command $newpath does not exist."
endif
echo -n "Do you want $newpath as the new path to perl? (y/n) [n] "
if ($< != "y") then
	goto loop
endif 

set re = `echo $newpath | sed -e 's/\//\\\//g'`
foreach file (`find . -type f ! -name "*,v" ! -name "*.bak" -print`)
	grep -s '^#./usr/local/bin/perl' $file
	if ($status == 0) then
		echo "Changing $file"
		cp $file ${file}.bak
		chmod +w $file
		sed -e "s/.usr.local.bin.perl/$re/g" < ${file}.bak > $file
		chmod 755 $file ${file}.bak
	endif
end
