#! /bin/sh -
# $Header:andrew 12.0$ 
# $ACIS:andrew 12.0$ 
# $Source: /ibm/acis/usr/src/usr.skel/RCS/andrew,v $ 

#
# 5799-WZQ (C) COPYRIGHT IBM CORPORATION 1988
# LICENSED MATERIALS - PROPERTY OF IBM
# REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
#
# Synopsis:	andrew [display] [screens] 
# Description:	Invoke Andrew Window Manager with X Server on specified display
#	and screens.
#	Display can be :0 to :7. Default display is :0.	
#	Recognized screens are:
#		-8514
#		-vga
#		-mpel
#		-ega
#		-apa16
#		-aed
#	Default screen is the default one of Xibm.


# Check PATH
ANDREWDIR=/usr/andrew; export ANDREWDIR
if ( echo ${PATH} | grep "${ANDREWDIR}/bin" > /dev/null )
then
	echo -n > /dev/null	# do nothing
else
	PATH=${ANDREWDIR}/bin:${PATH}; export PATH
fi
CLASSPATH=${ANDREWDIR}/dlib/be2; export CLASSPATH

BE2WM=x11; export BE2WM		# used by the Andrew Window Manager
AWM=cwm				# Andrew Window Manager
XSERV=Xibm			# X Server 
SCREEN=0			# Default screen
COUNT=0				# Number of screens

# Check the Andrew Window Manager
if test ! -f ${ANDREWDIR}/bin/${AWM}
then
	echo "$0: Cannot find the Andrew Window Manager" >&2
	exit 1
fi

# Set DISPLAY
export DISPLAY
case $1 in
:[0-7])
	DISPLAY=$1 
	shift
	;;
*)	;;
esac
if [ -z "${DISPLAY}" ]	
then
	DISPLAY=:0  		# Default display
fi
DIS=${DISPLAY}

# Set XSERV and count number of displays
XSERV="${XSERV} ${DISPLAY}"
for i in $*
do
	case "$i" in
	8514 | -8514)
		XSERV="${XSERV} -8514"
		COUNT=`expr ${COUNT} + 1`
		;;
	vga | -vga)
		XSERV="${XSERV} -vga"
		COUNT=`expr ${COUNT} + 1`
		;;
	mpel | -mpel)	
		XSERV="${XSERV} -mpel"
		COUNT=`expr ${COUNT} + 1`
		;;
	ega | -ega)	
		XSERV="${XSERV} -ega"
		COUNT=`expr ${COUNT} + 1`
		;;
	apa16 | -apa16)
		XSERV="${XSERV} -apa16"
		COUNT=`expr ${COUNT} + 1`
		;;
	aed | -aed)
		XSERV="${XSERV} -aed"
		COUNT=`expr ${COUNT} + 1`
		;;
	*)	exec echo "Usage: $0 [display] [8514 | vga | mpel | ega | apa16 | aed]" >&2
		;;
	esac
done

# Start X Server on all displays and 
# open the Andrew Window Manager on the main/default display.
DISPLAY=${DIS}.${SCREEN}
xinit ${AWM} ${DISPLAY} -- ${XSERV} &

# Open the Andrew Window Manager on remaining displays, if any.
if [ ${COUNT} -ge 2 ]
then
	sleep 20
	while [ ${COUNT} -ge 2 ]
	do 
		SCREEN=`expr ${SCREEN} + 1`
		DISPLAY=${DIS}.${SCREEN}
		$AWM ${DISPLAY} &
		COUNT=`expr ${COUNT} - 1`
	done
fi
