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


: getlde 

: This is a shell command subroutine that determines whether a user will
: be using any Tektronix Language Diercted Editors \(LDE\), and which ones.
: The list of all valid compilers in the variable 'validlde' is passed in
: from the calling routine, kshoptions.  A valid LDE is one that 
: exists on the system.
: We count the number of LDE\'s that exist.  If there is one we query the
: user as to its inclusion.  If there is more than one, the
: list is printed and the user is asked to specify which ones to include.

: External variables
: 	$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
:	$validlde - The list of LDE\'s that exist.

: Where do we find configuration files
if test "$TNIX" = "yes" ; then
	LDELIB=/usr/lib/lde
else
	LDELIB='$TEKPATH/tek/\$LANDS/lde'
fi

: Expand the names in the validlde list
ldenames=
for i in $validlde
do
	case $i in
	pas)
		ldenames="$ldenames pascal"
		;;
	*)
		ldenames="$ldenames $i"
		;;
	esac
done

count=`echo $ldenames | wc -w | tr -d ' '`

if test $count -lt 1 ; then
	CONTINUE=no
elif test $count -eq 1 ; then
	CONTINUE=yes
elif test $count -gt 1 ; then
	CONTINUE=yes
	echo
	echo "The following Language Directed Editors are available:"
	echo
	for i in $ldenames ; do
		echo "	$i"
	done
fi
if test $CONTINUE = yes ; then
	CHOSEN=
	for I in $ldenames ; do
	VALID=no
	while test $VALID = no ;do
		echo
		echo -n "Do you wish to use the $I Language Directed Editor ('y' or 'n')?: "
		read INPUT
		case $INPUT in
		'y' | 'Y')
			VALID=yes
			CHOSEN="$CHOSEN $I"
			echo " o  The $I Language Directed Editor is included."  >>$kshconfig
			case $I in
			pascal)
				comtype=pas
				;;
			*)
				comtype=$I
				;;
			esac
			echo "#define _$comtype""lde 1" >>$kppdefs
			;;
		'n' | 'N')
			VALID=yes
			;;
	 	*)	echo "Invalid input: Please enter 'y' or 'n'";;
		esac
	done
	done

	
	count=`echo $CHOSEN | wc -w | tr -d ' '`

	if test $count -lt 1 ; then
		CONTINUE=no
	elif test $count -eq 1 ; then
			DEFAULT=$CHOSEN
	elif test $count -gt 1 ; then
		cat <<!!

The following Language Directed Editors have been chosen.

!!
		for I in $CHOSEN ; do
			echo "   $I"
		done
		cat <<!!

Enter the name of the LDE that is to be the default.
!!
		looptest=0
		while test $looptest ; do
			read DEFAULT
			looptest=
			echo $CHOSEN | grep -swi $DEFAULT
			if test $? -eq 0
			then
				:
			else
				echo "$i : invalid editor name"
				echo "Please enter the names exactly as they appear in the above list."
				looptest=0
			fi
		done
	fi

	if test $CONTINUE = yes ; then
	DEFAULT=`echo $DEFAULT`
	case $DEFAULT in
	pascal)
		comtype=pas
		;;
	*)
		comtype=$DEFAULT
		;;
	esac

	case $shelltype in
	_sh)
		echo "LANDS=$comtype; export LANDS" >>$setTEK
		echo "case \$TERM in" >> $setTEK
		echo "4105|4107|4109|vt100|vt100k|ct8500) TTYPE=\$TERM;;" >> $setTEK
		echo "*) TTYPE=any;;" >> $setTEK
		echo "esac" >> $setTEK
		echo "LDECFGLOC=$LDELIB/lde.\$TTYPE.cfg;export LDECFGLOC" >> $setTEK
		echo "eval LDECONFIG=\$LDECFGLOC;export LDECONFIG" >> $setTEK
		;;
	_csh)
		echo "setenv LANDS $comtype" >>$setTEK 
		echo "switch (\$TERM)" >> $setTEK
		echo "case 4105:" >> $setTEK
		echo "case 4107:" >> $setTEK
		echo "case 4109:" >> $setTEK
		echo "case vt100:" >> $setTEK
		echo "case vt100:" >> $setTEK
		echo "case ct8500:" >> $setTEK
		echo "set TTYPE=\$TERM" >> $setTEK
		echo "breaksw" >> $setTEK
		echo "default:" >> $setTEK
		echo "set TTYPE=any" >> $setTEK
		echo "breaksw" >> $setTEK
		echo "endsw" >> $setTEK
		echo "setenv LDECFGLOC $LDELIB/lde.\$TTYPE.cfg" >> $setTEK
		echo "eval setenv LDECONFIG \$LDECFGLOC" >> $setTEK
		;;
	esac
	fi
fi
