#!/bin/sh
#OSF/Motif: @(#)run_PINames	3.2 92/01/31
#*****************************************************************************
#*****************************************************************************
#
#  (c) Copyright 1989, 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC.
#  ALL RIGHTS RESERVED
#  
#  	THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED
#  AND COPIED ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND
#  WITH THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR
#  ANY OTHER COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE
#  AVAILABLE TO ANY OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF THE
#  SOFTWARE IS HEREBY TRANSFERRED.
#  
#  	THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT
#  NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY OPEN SOFTWARE
#  FOUNDATION, INC. OR ITS THIRD PARTY SUPPLIERS  
#  
#  	OPEN SOFTWARE FOUNDATION, INC. AND ITS THIRD PARTY SUPPLIERS,
#  ASSUME NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE ANY OF ITS
#  SOFTWARE .   OSF SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
#  KIND, AND OSF EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES, INCLUDING
#  BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
#  FITNESS FOR A PARTICULAR PURPOSE.
#  
#  Notice:  Notwithstanding any other lease or license that may pertain to,
#  or accompany the delivery of, this computer software, the rights of the
#  Government regarding its use, reproduction and disclosure are as set
#  forth in Section 52.227-19 of the FARS Computer Software-Restricted
#  Rights clause.
#  
#  (c) Copyright 1989, 1990, 1991, 1992 Open Software Foundation, Inc.  Unpublished - all
#  rights reserved under the Copyright laws of the United States.
#  
#  RESTRICTED RIGHTS NOTICE:  Use, duplication, or disclosure by the
#  Government is subject to the restrictions as set forth in subparagraph
#  (c)(1)(ii) of the Rights in Technical Data and Computer Software clause
#  at DFARS 52.227-7013.
#  
#  Open Software Foundation, Inc.
#  11 Cambridge Center
#  Cambridge, MA   02142
#  (617)621-8700
#  
#  RESTRICTED RIGHTS LEGEND:  This computer software is submitted with
#  "restricted rights."  Use, duplication or disclosure is subject to the
#  restrictions as set forth in NASA FAR SUP 18-52.227-79 (April 1985)
#  "Commercial Computer Software- Restricted Rights (April 1985)."  Open
#  Software Foundation, Inc., 11 Cambridge Center, Cambridge, MA  02142.  If
#  the contract contains the Clause at 18-52.227-74 "Rights in Data General"
#  then the "Alternate III" clause applies.
#  
#  (c) Copyright 1989, 1990, 1991, 1992 Open Software Foundation, Inc.
#  ALL RIGHTS RESERVED 
#  
#  
# Open Software Foundation is a trademark of The Open Software Foundation, Inc.
# OSF is a trademark of Open Software Foundation, Inc.
# OSF/Motif is a trademark of Open Software Foundation, Inc.
# Motif is a trademark of Open Software Foundation, Inc.
# X Window System is a trademark of the Massachusetts Institute of Technology
#
#*****************************************************************************
#*****************************************************************************
#
# script to run the MWM Programmatic Interface test
#

TEST_MWM=../../../clients/mwm/mwm

SYSTEM=`uname -a | awk -F' ' '{print $1}'`

echo "System is "${SYSTEM}

# print out warnings and question
	echo; echo
	echo "This is the execution script for the test - PINames"
	echo
	echo "To begin this test, the window manager \"mwm\" will be"
	echo "killed and restarted with additions to the resource database."
	echo "You will be asked to hit return when the new \"mwm\" is"
	echo "up and running.  Then, the actual test will be run, and upon"
	echo "completion, the original \"mwm\" will be restarted with it's"
	echo "original resource database intact."
	echo
	echo "It is assumed the original \"mwm\" running was ${TEST_MWM}," 
	echo "and, therefore, that is what will be restarted."
	echo

if [ ${SYSTEM} = "HP-UX" ]
then
# HP version
	echo "Do you want to continue? (n) \c"
else
# others, like DEC version
	echo -n "Do you want to continue? (n) "
fi

	read ANS
	ANS2=".${ANS}"
	if [ ${ANS2} != ".y" ]
	then
		echo "Cancelling test."
		exit
	fi

# merge in new resources into database
	xrdb -edit /tmp/oldxdef$$
	xrdb -merge < ./PI.Xdefaults

# get the wm process and kill it
#	look for " mwm" or ".../mwm"
#	this should give you only things that really are mwm
#	remove all leading whitespace and replace multiple
#	tabs/spaces with 1 space
if [ ${SYSTEM} = "HP-UX" ]
then
# HP version
	MWM_LINE=`ps -ef | egrep ' mwm|/mwm' | grep -v egrep`
	BETTER_MWM_LINE=`echo ${MWM_LINE} | sed -e 's/^[	 ]*//
		s/[	 ][	 ]*/ /g'`
	MWM_PID=`echo ${BETTER_MWM_LINE} | cut -d' ' -f2`
	MWM_CMD=`echo ${BETTER_MWM_LINE} | cut -d' ' -f8-`
	MWM_OPTS=`echo ${BETTER_MWM_LINE} | cut -d' ' -f9-`
else
# others, like DEC version
    MWM_LINE=`ps -axw | egrep ' mwm|/mwm' | grep -v egrep`
	BETTER_MWM_LINE=`echo ${MWM_LINE} | sed -e 's/^[   ]*//
		s/[  ][  ]*/ /g'`
	MWM_PID=`echo ${BETTER_MWM_LINE} | cut -d' ' -f1`
	MWM_CMD=`echo ${BETTER_MWM_LINE} | cut -d' ' -f5-`
	MWM_OPTS=`echo ${BETTER_MWM_LINE} | cut -d' ' -f6-`
fi

	kill -9 ${MWM_PID}

# start new wm and then start test
	${TEST_MWM} ${MWM_OPTS} >/dev/null 2>&1 &
	sleep 10

if [ ${SYSTEM} = "HP-UX" ]
then
# HP version
	echo "Hit return after the new \"mwm\" is up and running. (CR) \c"
else
# others, like DEC version
	echo -n "Hit return after the new \"mwm\" is up and running. (CR) "
fi

	read ANS

# now start the test program
	./PINames

# restore old resource database, kill new wm and restart old one
	echo "The original \"mwm\" is being restored..."

if [ -s /tmp/oldxdef$$ ]
then
	xrdb /tmp/oldxdef$$
else
	xrdb -remove	
fi

# remove all leading whitespace and replace multiple tabs/spaces with 1 space
if [ ${SYSTEM} = "HP-UX" ]
then
# HP version
	MWM_LINE=`ps -ef | egrep ' mwm|/mwm' | grep -v egrep`
	BETTER_MWM_LINE=`echo ${MWM_LINE} | sed -e 's/^[	 ]*//
		s/[	 ][	 ]*/ /g'`
	TEST_MWM_PID=`echo ${BETTER_MWM_LINE} | cut -d' ' -f2`
else
# others, like DEC version
    MWM_LINE=`ps -axw | egrep ' mwm|/mwm' | grep -v egrep`
	BETTER_MWM_LINE=`echo ${MWM_LINE} | sed -e 's/^[   ]*//
		s/[  ][  ]*/ /g'`
	TEST_MWM_PID=`echo ${BETTER_MWM_LINE} | cut -d' ' -f1`
fi

	kill -9 ${TEST_MWM_PID}
#	${MWM_CMD} >/dev/null 2>&1 &
	${TEST_MWM} ${MWM_OPTS} >/dev/null 2>&1 &

	rm -f /tmp/oldxdef$$*

# end of script
