
:	TNIX/Unix Version
:	Keyshell Version Number 2	*/


:
: setksh version 1.0 12 oct 83
:
: This shell procedure provides the user the ability to set up or
: change the configuration for ColorKey+ user interface and several
: Tektronix products including 8540 Integration unit, assemblers, compilers,
: Language Development systems and editors.
:


: Print an introduction to the user and gives some warnings.

: Check if UNIX or TNIX and set TNIX variable
TNIX=
( version | fgrep -s Tnix ) 2>/dev/null && TNIX=yes
export TNIX

if test -f $HOME/.setTEK -a -f $HOME/.setKSH ; then
:
else
	cat << !!

			   SETKSH

This procedure is to assist you in setting up or changing your 
ColorKey+ User Interface.  ColorKey+ may be configured to support a 
number of different Tektronix products including integration units, 
assemblers, compilers and LANDS systems.

			*** WARNING ***
    This process reserves the following file names in the user's
    login directory: ".ksh", ".saveksh", ".setKSH" and ".setTEK",
    ".oldprofile", ".oldlogin", ".oldcshrc".  If you have files or 
    directories with these names that you wish to save, please move 
    them now before you proceed.
			*** WARNING ***

Press <control>c to terminate this procedure.
Press [RETURN] to continue
!!
	read junk
fi
cd $HOME		
: Get variable TEKPATH if necessary.

if test -n "$TEKPATH" -a -d "$TEKPATH/tek"
then
	:
else
	cat <<!!

Before you may proceed, the variable TEKPATH must be set to the 
pathname where the Tektronix directory (/tek) was installed.
For example :
	If Tektronix products are in 	/usr/tek/
	then set TEKPATH to	 	/usr

Enter the full pathname (start with a '/')
of the directory to be assigned to TEKPATH: 
!!
	invalid=0
	while test $invalid
	do
		read tekpath
		if test -n "$tekpath" -a -d "$tekpath/tek"
		then
			invalid=
			TEKPATH=$tekpath; export TEKPATH
		else
			echo "'$tekpath/tek': not found"
			echo
			echo "Enter the full pathname (start with a '/')"
			echo -n "of the directory to be assigned to TEKPATH: "
		fi
	
	done

fi


: set the directory for this procedures sub-routines.
idir=$TEKPATH/tek/ksh/lib; export idir


:
: Set up the eternal loop of the program.  The algorithm is:
:
:	1.	Print the menu
:	2.	Read the ACTION
:	3.	Perform the ACTION
:	4.	GOTO 1
:
: The user breaks the loop by choosing the quit option.
:


modmesg=			
: if modified,  print a message to login at termination

true=1
while test true
do
modified=			

cat <<!!




		     SETKSH MAIN MENU


	1)  SHOW current ColorKey+ configuration

	2)  Build a CUSTOM ColorKey+ configuration

	3)  COPY another user's custom configuration

	4)  Set up the DEFAULT ColorKey+ configuration

	5)  SAVE the current ColorKey+ configuration

	6)  RESTORE a previously saved configuration

	7)  REMOVE a ColorKey+ configuration

	8)  HELP

	9)  QUIT

Please enter your choice: 
!!
looptest=0
while test $looptest
do
	read ACTION
	case $ACTION in
	1)	ACTION=SHOW
		looptest=;;
	2)	ACTION=CUSTOM
		looptest=;;
	3)	ACTION=COPY
		looptest=;;
	4)	ACTION=DEFLT
		looptest=;;
	5)	ACTION=SAVE
		looptest=;;
	6)	ACTION=RESTORE
		looptest=;;
	7)	ACTION=REMOVE
		looptest=;;
	8)	ACTION=HELP
		cat <<!!



1)  SHOW current ColorKey+ configurations - Prints information about the 
	current ColorKey+ configuration and prints the names of any saved 
	configurations.
2)  Build a CUSTOM ColorKey+ configuration - This procedure will ask you 
	several questions about specific Tektronix products and options 
	and then build the specified ColorKey+ configuration.
3)  COPY another user's custom configuration - This avoids the lengthy 
	procedure of building a custom configuration.
4)  Set up the DEFAULT ColorKey+ configuration - The default ColorKey+
	configuration supports general commands but no specific Tektronix 
	products or microprocessors.
5)  SAVE the current ColorKey+ configuration - Saves the current configuration
	to a name specified by the user.
6)  RESTORE a saved configuration - Makes a previously saved configuration 
	the current configuration.
7)  REMOVE ColorKey+ configurations.
8)  HELP - Print this screen.
9)  QUIT - Terminate this program.

Please enter your choice:
!!
		;;
	9)	ACTION=QUIT
		looptest=;;
	*)	echo "Invalid input: Please enter a number in range [1-9]."
		echo
		echo -n "Please enter your choice: "
		;;
	esac
done

:
: Perform the chosen action.
:

case $ACTION in 

SHOW)
	$idir/show
;;


COPY | CUSTOM | DEFLT | RESTORE)	
	if test -f $HOME/.setKSH
	then
		cat <<!!

A ColorKey+ configuration currently exists.  Do you wish to:

	1)	Save current configuration and continue

	2)	Destroy current configuration and continue

	3)	Return to main menu

Enter your choice: 
!!

		looptest=0
		while test $looptest 
		do
			read INPUT
			case $INPUT in
			1)
				$idir/save
				if test $? = 0
				then
					modified=0
					modmesg=0
					continue=0
				else
					continue=
				fi
				looptest=
				;;
			2)
				continue=0
				looptest=
				;;
			3)
				continue=
				looptest=
				;;
			*)	echo "Invalid input: Please enter a number in the range [1-3]"
				echo
				echo -n "Enter your choice: "
				;;
			esac
		done

	else 			
		continue=0
	fi

	if test $continue
	then
		case $ACTION in
		
			CUSTOM | DEFLT)
				export ACTION
				if test $ACTION = CUSTOM
				then
					cat <<!!

The following build procedure will create a new ColorKey+ User Interface.
You will be asked if you wish to use the following Tektronix products.

       -  Integration Unit, if so you must specify:
		pathname to device
		baud rate
       -  Assemblers or compilers, if so, specify for which microprocessor
       -  LANDS packages
	
!!
				fi
				$idir/build		
				if test $? = 0
				then
					modified=0
					modmesg=0
					echo "...Build procedure done..."
				fi
			;;	
			COPY)
				$idir/copy
				if test $? = 0
				then
					modified=0
					modmesg=0
			 		echo "...Copy completed..."
				fi
			;;	
			RESTORE)
				$idir/restore
				if test $? = 0
				then
					modified=0
					modmesg=0
				fi
			;;	
		esac
	fi			
;;				


SAVE)
	if test -f $HOME/.setKSH
	then
		$idir/save
		if test $? = 0; then modified=0; modmesg=0; fi
	else 
		echo "Can't save: ColorKey+ not configured."
	fi
;;

REMOVE)
	if test -f $HOME/.setKSH -o -d $HOME/.saveksh
	then
		$idir/remove
		if test $? = 0; then modified=0; modmesg=0; fi
	else 
		echo "Can't remove: No ColorKey+ configurations."
	fi
;;

QUIT)
	if test $modmesg
	then
		echo "Please type 'login' which will execute the login" 
		echo "procedure and set up your new ColorKey+ configuration."
	fi
	exit
	;;

*)	:;;


esac



done

