:
#ident	"@(#)mousconfig	1.2	90/08/16"
#ident "@(#)mousconfig	1.2 89/09/29"
#	@(#) mousconfig 1.6 89/03/09 
#
#	Copyright (C) The Santa Cruz Operation, 1988-89.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, Microsoft Corporation
#	and AT&T, and should be treated as Confidential.
#
# MOUSCONFIG	- UNIX busmouse configuration.
#

PATH=/etc:/bin:/usr/bin
MOUSFILE=space.c
TMPFILE=/tmp/mc$$

# Define return values
: ${OK=0} ${FAIL=1} ${STOP=10} ${HALT=11}

cleanup="rm -rf $TMPFILE"

trap 'eval $cleanup; exit $FAIL' 1 2 3 15

# Prompt for yes or no answer - returns non-zero for no
getyn() {
	while	echo "\n$* (y/n) \c">&2
	do	read yn rest
		case $yn in
		[yY])	return 0 			;;
		[nN])	return 1			;;
		*)	echo "Please answer y or n" >&2	;;
		esac
	done
}

Getdfl() {
	read prm1 prm2 < $TMPFILE
	modified=
}
Reset() {
	prm1=5 prm2=0x00
	modified=1
}
Getcur() {
	echo `sed -n -e '
		/@PARM/	{
			s?.*[ET]??
			s?/.*??
			p
			}
	' $MOUSFILE` > $TMPFILE
}
Setcur() {
	ed - $MOUSFILE <<-EOF
		/@PARM1/s?T[^/]*?T	 	$prm1	?
		/@PARM2/s?E[^/]*?E 	$prm2	?
	w
	q
	EOF
}
Showcur() {
	echo "
	Busmouse Parameters	Values	Comments
	-------------------     ------	--------
	1. Interrupt Vector	$prm1	logical vector number
	2. Base Address		$prm2	i/o addresses start here
	
	Zero Values Imply Auto-Configuration"
}

# beginning
case $# in
0)
	;;
*)
	echo "USAGE: mousconfig"
	eval $cleanup
	exit $FAIL
	;;
esac

status=0
Getcur
Getdfl

while echo "\nBusmouse Configuration

	1. Display current busmouse parameters
	2. Modify current busmouse parameters
	3. Select previous busmouse parameters
	4. Select default busmouse parameters

Enter an option or 'q' to quit: \c"
do
	read ans
	case "$ans" in
	1)	Showcur
		;;
	2)
		Showcur
		while echo "\nEnter a parameter to modify or 'q' to return to the main menu: \c"
		do
			read y
			case "$y" in
			[1-2])	while echo "\nHexadecimal values must be entered with prefix '0x'.
For example Hexadecimal 300 should be entered as 0x300.
Enter the new value or <RETURN> to use the existing value: \c"
				do
					read z
					case "$z" in
					[0-9]*)
						eval prm$y=$z
						modified=1
						break
						;;
					"")	break
						;;
					*)	echo "Please enter a numeric value. \n"
						;;
					esac
				done
				;;
			[qQ])	break
				;;
			*)	echo "Please enter a choice, 1-2 or 'q'. \n"
				;;
			esac
		done
		;;
	3)	[ $modified ] && {
			Getdfl
			Showcur
			}
		;;
	4)	Reset
		Showcur
		;;
	[qQ])	[ $modified ] && Setcur 
		break
		;;
	*)	echo "\nPlease enter '1', '2', '3', '4' or 'q'.\n"
		;;
	esac
done
eval $cleanup
