#!/bin/sh
# Copyright (C) 1999 INRIA/INSA de Rennes.
#
# Author : Erwan Jahier <jahier@irisa.fr>
#
# 1st argument is the socket address (unix) or the port name (inet),
# 2nd argument is the socket domain (unix or inet),
# 3rd argument is name of the machine to run the mercury program on,
# 4th argument is the name of the program being called,
# the following arguments are the arguments of the program being called.


SOCKETDOMAIN=$2
REMOTEMACHINE=$3
LOCALMACHINE=`uname -n`

case $SOCKETDOMAIN in
unix)		MERCURY_DEBUGGER_UNIX_SOCKET=$1
		MERCURY_OPTIONS="$MERCURY_OPTIONS -De" 
		export MERCURY_DEBUGGER_UNIX_SOCKET
		export MERCURY_OPTIONS
		shift 3
		$@ 
	        ;;

inet) HOSTADDR=`ypcat hosts|grep $LOCALMACHINE|awk '{printf "%s\n", $1}'|sort -u`
		# XXX How can I retrieve the host address without this horrible 
		# hack? 
		# That don't even work on machines that have not got ypcat...
		# Note it is not a big deal since it is only needed if people 
		# want to use internet sockets and there is no reason why people 
		# would want those. (except if they don't have eclipse 4.1).
		MERCURY_DEBUGGER_INET_SOCKET="$HOSTADDR $1"
		MERCURY_OPTIONS="$MERCURY_OPTIONS -De" 
		export MERCURY_DEBUGGER_INET_SOCKET
		export MERCURY_OPTIONS
		shift 3
		case $REMOTEMACHINE in
		    local)  $@ ;;
		    # XXX Remote debugging does not work yet.
	            *) rsh $REMOTEMACHINE $@;;
		esac 
	        ;;

*)		echo "error in exec_mercury_program"
		echo "SOCKETDOMAIN should be set to unix or inet"
	        ;;
esac





