:
#	@(#) reniii.sh 1.7 93/01/19 
clear
init_range="C8000 D0000 D8000 E0000 E8000"
echo "\n\n\tRendition III Grafinfo File Configuration\n"
echo "
The Rendition III video card is accessed by the X server via a 32KB
memory window mapped into physical PC address space.

This script expects you to know which 32KB address range is available
on your machine for this mapping.

Supported memory mapped window address are $init_range.
Please check that no other installed hardware conflicts with the address
you select.

This script will remove and then replace the file named reniii.xgi in
the directory /usr/lib/grafinfo/appian.  If you have made any
modifications to this file you should exit this script now and backup
those modifications.
"

echo -n "Do you want to configure your video cards memory mapping [y]: "
read sure
if [ "$sure" = "" ]
then
	sure="y"
fi
if [ "$sure" != "y" ]
then
	# If reniii.xgi still contains "select-this-mode" then
	# a card hasn't been configured yet.
	grep select-this-mode /usr/lib/grafinfo/appian/reniii.xgi > /dev/null 2>&1
	if [ $? = 1 ] # select-this-mode wasn't found so card _was_ configured
	then
		echo "Exiting script."
		exit 0
	fi
	echo "\nERROR: The Rendition III video card must be configured at least one time."
	echo "\nExiting script."
	exit 1
fi

rm -f /usr/lib/grafinfo/appian/reniii.xgi
sure=n
i=0
echo "\nConfiguring card:"
def_range="D8000"
range="$init_range"
found=0
while [ "$found" -eq 0 ]
do
	echo "\tSelect a base address for the 32KB memory window"
	echo -n "\tfrom the range $range [$def_range]: "
	read sel_range
	if [ "$sel_range" = "" ]
	then
		sel_range="$def_range"
	fi
	found=0
	for j in $range
	do
		if [ "$j" = "$sel_range" ]
		then
			found=1
		fi
	done
	if [ "$found" -eq 0 ]
	then
		echo "Invalid memory window address selected."
	fi
done
sed_output="/usr/lib/grafinfo/appian/reniii.xgi"
mem_base=$sel_range
mem_base_k1=`echo $sel_range | sed -e 's/....$//'`
mem_base_k2=`echo $sel_range | sed -e 's/...$//' -e 's/^.//'`
sed_input=/usr/lib/grafinfo/appian/reniii.tms3
sed	-e "s/@MEM_BASE@/$mem_base/g" \
	-e "s/@MEM_BASE_K1@/$mem_base_k1/g" \
	-e "s/@MEM_BASE_K2@/$mem_base_k2/g" \
	< $sed_input > $sed_output
chmod 444 $sed_output
chown bin $sed_output
chgrp bin $sed_output
echo "Script complete."
exit 0
