: $Workfile:   sununikix.sh  $ $Revision:   1.0  $
#**********************************************************************#
#*                                                                    *#
#* Copyright (c) 2001 by Sun Microsystems, Inc.                       *#
#* All rights reserved.                                               *#
#*                                                                    *#
#**********************************************************************#


# usage: sununikix [-4 | -5] shlscrpt-name [screen-position] 
# used to open a window on the sun


# check	to see if we are running under OpenWindows.  if	we are
# then set up the function keys	for the	terminal windows.
#
# the desired function keys are	as follows:
#	Sun Keyboard		IBM Equivalent
#	   F1-F12		   PF1-PF12
#	ESC F1-ESC F12		   PF13-PF24
#	   Pause		   PF1		Required if F1 is help
#	  Esc Pause		   PF13		Required if F13	is help
#	 Key Pad Enter		   Enter
#	   Key Pad +		   Clear
#	   Key Pad -		   Reset
#	   Key Pad =		   PA1
#	   Key Pad /		   PA2
#	   Key Pad *		   PA3
#	   Pr Sc		   Print
#	   Ins			   Insert Char
#	   Del			   Delete Char
#
# check	OPENWINHOME to see if OpenWindows is active.  If it is,
# check	for .ttyswrc.  This file resets	the keyboard mapping.
# If it	is not present,	copy it	from $UNIKIX/lib/ttyswrc.

# params:  4    Model 4 window (43x80)
#          5    Model 5 window (27x132)
#          SHLSCRPT to execute on xterm
#          SCRNPOS of xterm

PARAM1=$1
PARAM2=$2
PARAM3=$3
COLUMNS=80
LINES=25
set -- `getopt 45 $*`
#while options to process
while test  "$1" != "--"
do
    case $1 in
	-4)
	    COLUMNS=80
	    LINES=43
	    ;;
        -5)
	    COLUMNS=132
	    LINES=27
	    ;;
    esac
    shift
done

if test $LINES -ne 25
then
    SHLSCRPT=$PARAM2
    SCRNPOS=$PARAM3
else
    SHLSCRPT=$PARAM1
    SCRNPOS=$PARAM2
fi

if [ -n "$OPENWINHOME" ];	then
    # define KP_Enter as R13, KP_Add as	F35, KP_Subtract as F29
    # KP_Equal as F24, KP_Divide as F25, Insert	as F23 and Delete as F31
    xmodmap -e "keycode	97 = R13" \
	    -e "keycode	78 = F35" \
	    -e "keycode	132 = F29" \
	    -e "keycode	52 = F24" \
	    -e "keycode	53 = F25" \
	    -e "keycode	54 = F26" \
	    -e "keycode	101 = F23" \
	    -e "keycode	57 = F31"
    if [	! -f $HOME/.ttyswrc ]; then
	if [ -d $HOME -a	-w $HOME ]; then
	    /bin/cp $UNIKIX/lib/ttyswrc	$HOME/.ttyswrc
	    if [	! -f $HOME/.ttyswrc ]; then
		echo " Creation	of .ttyswrc for	OpenWindows failed"
	    fi
	else
	    echo " Can't create	.ttyswrc for OpenWindows. $HOME	is not writable"
	fi
    fi
fi

shelltool -Wf 0	0 255 -Wb 250 250 255 -Wg -Ww $COLUMNS -Wh $LINES -Wp $SCRNPOS \
	-WL "$SHLSCRPT" $SHLSCRPT &
sleep 1
exit $?
