#!/usr/local/bin/perl -w
#
# simpram_runpram__host
#
# (C) 1997 by Jochen Rhrig & Michael Bosch
#
# The following environment variables that are needed by the host program
# are set in simpram
#
# SBP_HOSTMODULEPATH
# SBP_HOSTRC
# SBP_HOSTMODULEFILE
# SBP_LOADER
# SBP_PRAMOS_ISSUE
# SBP_PRAMOS_MOTD
# SBP_HOSTRC
#
# The following environment variables that are needed to call the host
# properly are set in simpram_runpram
#
# HOST, HOST_LOADERRC, HOST_LOADEROUT, HOST_LOGFILE, PROGRAM
#
#
# Assumes that the following environement variables that are used by
# the PRAM-access-lib are set either by the user (in case we're
# running on the real hardware) or by simpram_runpram (in case we're
# running on the simulator)
#
# PRAM_DEV_PREFIX, PRAM_CFG_FILE
#

sleep 6; # just to be sure that the simulator has mapped the "device"-files

$run="$ENV{'HOST'} --tcp-port 4000".
     " -r".
     " -P".
     " -c".
     " --sysv-messages".
     " --loaderrc $ENV{'HOST_LOADERRC'}".
     " --loaderout $ENV{'HOST_LOADEROUT'}";

#echo $run;
#sleep 5;

if($ENV{'NONINTERACTIVE'})
{
    open BLUBBER, "|$run";
    print BLUBBER "load $ENV{'PROGRAM'}\n";
    close BLUBBER;
}
else
{
    system "$ENV{'WRITE_STDIN_PROG'} -n load $ENV{'PROGRAM'}";
    if(defined($ENV{'HOST_LOGFILE'}))
    {
	exec   "$run | tee $ENV{'HOST_LOGFILE'}";
    }
    else
    {
	exec   "$run";
    }
}
