:	Unix/Tnix Version
:	Keyshell Version Number 4	*/

: This shell command script asks a user if he wishes to use an integration
: unit and if so, several other questions regarding its configuration.

: External variables
:	$compiler - Name of compiler
: 	$micro - the microprocessor being used
: 	$kshconfig - the file that holds the configuration description
:	$kppdefs - the file that holds "#defines" for the kpp build
:	$setTEK - the file that holds the initialization commands
:	$shelltype - Bourne or cshell

: Variables set by this subroutine
	iunit=;			: flag indicating inclusion of Int Unit
	iutype=;		: type of iunit, 8550 or 8540
	iuport=;		: port on 8560
	icomport=;		: the port name for the host Integration Unit
	iubaud=;		: baud rate for the Integration Unit
	hlldebug=;		: High Level Language debug is configured
	pprom=;			: prom programmer is configured
	tta=;			: Trigger Trace Analyzer is configured
	ddl=;			: Digital Design Lab is configured

invalid=0
while test $invalid
do
echo
echo -n "Will you be using a Tektronix 8540(50) Integration Unit ('y' or 'n')? "
read INPUT
case $INPUT in
Y | y)	
	invalid=
	iunit=1
: The bulk of the rest of the rest of this procedure is contained in this
: 'y' switch.  This section is not indented relative to the switch.

if test "$TNIX" = "yes" ; then
	
	: Determine if it is an 8550 or 8540

	cat <<!!

Please specify the type of integration unit you are using:

	1)	8540
	2)	8550

Enter 1 or 2:
!!
	invalid=0
	while test $invalid
	do
		read INPUT
		case $INPUT in
			1)	iutype=8540
				invalid=;;
			2)	iutype=8550
				invalid=;;
			*)	echo
				echo -n "Invalid input.  Please enter '1' or '2': "
				;;
		esac
	done

	: Determine the 8560 I/O Port being used.
	
	invalid=0
	while test $invalid
	do
	cat <<!!

Please specify which HSI I/O Port (on the 8560's rear panel) the 8540 or 8550
is attached to.

!!
	echo -n "Enter a number in the range (0-7): "
	read iuport
	case $iuport in
	0 | 1 | 2 | 3 | 4 | 5 | 6 | 7)	invalid=;;
 	*)	echo "Invalid input.  Please enter a number in the range (0-7).";;
	esac
	done
	
: Determine the baud rate of the I/O Port.

	invalid=0
	while test $invalid
	do
	cat <<!!

If the electrical interface on 8560 I/O Port $iuport is RS-232-C then you must
specify the baud rate.  (With an 8550 the only interface that will work is
RS-232-C.)

Please select the correct baud rate.

1) RS-422/HSI (default)     5) 1200 baud
2) 9600 baud                6) 600 baud
3) 4800 baud                7) 300 baud
4) 2400 baud

!!
	echo -n "Please enter the number of your selection (1-7): "
	read INPUT
	case $INPUT in
	1)	iubaud=;invalid=;;
	2)	iubaud=9600;invalid=;;
	3)	iubaud=4800;invalid=;;
	4)	iubaud=2400;invalid=;;
	5)	iubaud=1200;invalid=;;
	6)	iubaud=600;invalid=;;
	7)	iubaud=300;invalid=;;
	*)	echo "Invalid input.  Please enter a number in the range (1-7).";;
	esac
	done

else
: Configure for UNIX
:
: Determine one-line or two-line mode of host/8540\(50\) communication
: If one-line, set ICOMPORT to terminal name.
: If two-line, prompt for and read device name.
:

cat <<!!

Please specify your method of terminal connection:

	1)	terminal connected to 8540(50) Integration Unit;
	2)	terminal connected to host computer.

Enter the terminal connection method: 
!!
invalid=0
while test $invalid
do
	read INPUT
	case $INPUT in
		1)	twoline=
			invalid=;;
		2)	twoline=0
			invalid=;;
		*)	echo
			echo "Invalid input: Please enter '1' or '2'"
			echo
			echo -n "Enter the terminal connection method: "
			;;
	esac
done


:
: Determine the /dev/tty line being used if two-line mode.
:

if test "$twoline"
then
	if test "$ICOMPORT"
	then
		looptest=0
		echo "The 8540(50)'s line is currently set to $ICOMPORT."
	else 
		looptest=
		invalid=0
	fi
	while test $looptest 
	do
		echo
		echo -n "Leave the line set to $ICOMPORT? ('y' or 'n'): "
		read INPUT
		case $INPUT in
		'y' | 'Y')
			looptest=
			invalid=
			icomport=$ICOMPORT
			;;
		'n' | 'N')
			looptest=
			invalid=0
			;;
		*)
			echo "Invalid input: please enter 'y' for yes or 'n' for no."
			;;
		esac
	done

	while test $invalid
	do
	cat <<!!

Please specify the full pathname (start with a '/') of the device line 
to which the 8540(50) Integration Unit is attached. (e.g. /dev/ttyx)

!!
	looptest=0
	while test $looptest
	do
	echo "Enter the pathname :"
	read icomport
		echo
		echo -n "${icomport}     Please confirm ('y' or 'n'): "
		yntest=0
		while test $yntest
		do
			read INPUT
			case $INPUT in
				'y' | 'Y')	invalid=
						looptest=
						yntest=;;
				'n' | 'N')	yntest=;;
				*)	echo -n "invalid input: please enter 'y' for yes or 'n' for no: "
					echo
					echo -n "Enter the pathname: "
				;;
			esac
		done
	done
	done
else
	icomport="\`tty\`"
fi

:
: Determine the baud rate of the I/O Port.
:

if test "$twoline"
then 
	if test "$ICOMSPEED"
	then
		looptest=0
		echo "The 8540(50)'s baud rate is currently set at $ICOMSPEED."
	else 
		looptest=
		invalid=0
	fi
	while test $looptest 
	do
		echo
		echo -n "Leave the baud rate set at $ICOMSPEED? ('y' or 'n'): "
		read INPUT
		case $INPUT in
		'y' | 'Y')
			looptest=
			invalid=
			iubaud=$ICOMSPEED
			;;
		'n' | 'N')
			looptest=
			invalid=0
			;;
		*)
			echo "Invalid input: please enter 'y' for yes or 'n' for no."
			;;
		esac
	done
else 
	invalid=
fi

while test $invalid
do
	cat <<!!


Please select the correct baud rate for 8540(50)/host communication.

1) 9600 baud		    4) 1200 baud
2) 4800 baud                5) 600 baud
3) 2400 baud                6) 300 baud

Please enter the number of your selection (1-6): 
!!
	read INPUT
	case $INPUT in
	1)	iubaud=9600;invalid=;;
	2)	iubaud=4800;invalid=;;
	3)	iubaud=2400;invalid=;;
	4)	iubaud=1200;invalid=;;
	5)	iubaud=600;invalid=;;
	6)	iubaud=300;invalid=;;
	*)
		echo
		echo -n "Invalid input: please enter a number in range [1-6]: "
		;;
	esac
done
fi;	: this goes with the if TNIX else UNIX switch



:
: Determine combination of Integration Tools being used.
:

:
: Determine if the Prom Programmer is being used.
:
	invalid=0
	while test $invalid
	do
	echo
	echo -n "Will you be using the Tektronix PROM Programmer module('y' or 'n')? "
	read INPUT
	case $INPUT in
	Y | y)	pprom=1;invalid=;;
	N | n)	pprom=;invalid=;;
	*)	echo "Invalid input.  Please enter (y) for yes or (n) for no.";;
	esac
	done
:
: Determine if the TTA is being used.
:
	invalid=0
	while test $invalid
	do
	echo
	echo -n "Will you be using the Trigger Trace Analyzer ('y' or 'n')? "
	read INPUT
	case $INPUT in
	Y | y)	tta=1;invalid=;;
	N | n)	tta=;invalid=;;
	*)	echo "Invalid input.  Please enter (y) for yes or (n) for no.";;
	esac
	done

:
: Determine if DDL is being used.
:
	if test -f /bin/ddisp -o -f /usr/bin/ddisp \
		-o -f $TEKPATH/tek/bin/ddisp; then
	invalid=0
	while test $invalid
	do
	echo
	echo -n "Will you be using the Digital Design Lab package (y or n)? "
	read INPUT
	case $INPUT in
	Y | y)	ddl=1;invalid=;;
	N | n)	ddl=;invalid=;;
	*)	echo "Invalid input.  Please enter (y) for yes or (n) for no.";;
	esac
	done
	else ddl=; fi

: All of the questioning is done, put the results in the proper files
	echo "#define _iunit 1" >>$kppdefs
	if test $tta; then echo "#define _tta 1" >>$kppdefs; fi
	if test $ddl; then echo "#define _ddl 1" >>$kppdefs; fi
	if test $pprom; then echo "#define _pprom 1" >>$kppdefs; fi

	echo " o  An Integration Unit is configured." >>$kshconfig
	echo " o  The following Integration Tools are present:" >>$kshconfig
	if test $micro; then echo "        $micro emulator" >>$kshconfig; fi
	if test $tta; then echo "        Trigger Trace Analyzer" >>$kshconfig; fi
	if test $ddl; then echo "        Digital Design Lab" >>$kshconfig; fi
	if test $pprom; then echo "        PROM Programmer" >>$kshconfig; fi

	case $shelltype in
	_sh)
	if test "$TNIX" = "yes" ; then
		echo "IU=$iuport; export IU" >>$setTEK

	        if test "$iutype" = "8550" ; then
		   echo "stty IU $iubaud >/dev/tty$iuport" >>$setTEK
	        fi

	else
		echo "ICOMPORT=$icomport; export ICOMPORT" >>$setTEK
		echo "PATH=:\${TEKPATH}/tek/icom40:\${PATH}; export PATH" \
			>>$setTEK
		if test $iubaud
		then
			echo "ICOMSPEED=$iubaud; export ICOMSPEED" >>$setTEK
		fi
	fi
	;;
	_csh)
		echo "setenv ICOMPORT $icomport" >>$setTEK
		echo "setenv PATH :\${TEKPATH}/tek/icom40:\${PATH}" >>$setTEK
		if test $iubaud
		then
			echo "setenv ICOMSPEED $iubaud" >>$setTEK
		fi
	;;
	esac

: End of main 'y' switch
;;
N | n)	
	echo " o  The debug-related functions are not included." >>$kshconfig
	invalid=
;;
*)	echo "Invalid input.  Please enter (y) for yes or (n) for no.";;
esac
done

