lib/scripts/run-smlnj
author paulson
Mon, 16 Nov 1998 10:36:30 +0100
changeset 5865 2303f5a3036d
parent 5708 fb09ab6a447f
child 6078 e01e2328d0f0
permissions -rwxr-xr-x
moved some facts about Pi from ex/PiSets to Fun.ML

#!/bin/bash
#
# $Id$
#
# SML/NJ startup script (for 110 or later).
#
# Global vars: INFILE OUTFILE MLTEXT TERMINATE NOWRITE ISABELLE_TMP,
# and from settings


## diagnostics

function fail_out()
{
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
  exit 2
}

function check_mlhome_file()
{
  if [ ! -f "$1" ]; then
    echo "Unable to locate $1" >&2
    echo "Please check your ML_HOME setting!" >&2
    exit 2
  fi
}


## compiler binaries

SML="$ML_HOME/sml"
ARCH_N_OPSYS="$ML_HOME/.arch-n-opsys"

check_mlhome_file "$SML"
check_mlhome_file "$ARCH_N_OPSYS"



## prepare databases

if [ -z "$INFILE" ]; then
  EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
  DB=""
else
  EXIT=""
  DB="@SMLload=$INFILE"
fi

if [ -z "$OUTFILE" ]; then
  COMMIT='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\n"); false);'
else
  COMMIT="fun commit () = not (SMLofNJ.exportML\"$OUTFILE\");"
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
fi


## run it!

MLTEXT="$EXIT $COMMIT $MLTEXT"
MLEXIT="commit();"

if [ -z "$TERMINATE" ]; then
  FEEDER_OPTS=""
else
  FEEDER_OPTS="-q"
fi

$ISABELLE_HOME/lib/scripts/feeder -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
  { read FPID; $SML $ML_OPTIONS $DB; RC=$?; kill -HUP $FPID; exit $RC; }
RC=$?


## fix heap file name and permissions

if [ -n "$OUTFILE" ]; then
  eval $($ARCH_N_OPSYS)
  SUFFIX=".$ARCH-$OPSYS"
  if [ -f "$OUTFILE$SUFFIX" ]; then
    mv "$OUTFILE$SUFFIX" "$OUTFILE"
    [ -n "$NOWRITE" ] && chmod -w "$OUTFILE"
  fi
fi

exit $RC