:
#	@(#) scanon 23.4 91/11/21 
#
#	Copyright (C) 1991 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#

TTYFILE="/etc/ttytype"

scanloop()
{
while [ $# -gt 0 ]
do
	# Look up the tty type for the required device in /etc/ttytype
	ttname=`echo $1 | sed 's:/dev/::p'`
	ttype=`awk '$2 == tname {print $1; exit}' tname=$ttname $TTYFILE`

	[ "$ttype" = "" -o "$ttype" = "unknown" ] && {
		echo "$0: cannot find $1 terminal type in $TTYFILE" >&2
		errcnt=`expr $errcnt + 1`
		shift; continue
	}

	# We need to check whether the term is already in scancode mode
	# because the Wyse60 locks up if we try to do it twice
	stty -a < "$1" | grep "\-isscancode" > /dev/null
	if [ $? -eq 0 ]
	then
		[ -c "$1" ] && tput -T"$ttype" smsc > "$1" && \
		stty isscancode xscancode < "$1" || {
			echo "$0: cannot set $1 scancode on" >&2
			errcnt=`expr $errcnt + 1`
			shift; continue
		}

		mapstr -f "$ttype" < "$1" || {
			echo "$0: cannot set $1 function key strings" >&2
			errcnt=`expr $errcnt + 1`
		}
	else
		echo "$0: $1 is already in scancode mode" >&2
	fi
	shift
done
}

scan_on()
{
	# We need to check if already in scancode mode, since if
	# we happen to be a Wyse60 doing it twice will lock the terminal
	stty -a | grep "\-isscancode" > /dev/null
	if [ $? -eq 0 ]
	then
		tput smsc && stty isscancode xscancode || {
			echo "$0: cannot set scancode on" >&2
			errcnt=1
			return
		}
		[ -z "$TERM" ] || mapstr -f "$TERM" || {
			echo "$0: cannot set function key strings" >&2
			errcnt=1
		}
	else
		echo "$0: already in scancode mode" >&2
	fi
}

errcnt=0
case $# in
0) scan_on	;;
*) scanloop "$@";;
esac
exit $errcnt
