lib/scripts/run-smlnj
author wenzelm
Fri, 13 Mar 1998 18:15:14 +0100
changeset 4744 4469d498cd48
parent 4505 4a2c872b6513
child 5063 d45ec8d00ab0
permissions -rwxr-xr-x
moved addsplits [expand_if] from HOL_basic_ss to HOL_ss;

#!/bin/bash
#
# $Id$
#
# SML/NJ startup script (for 109.27-109.33, 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
}


## 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; $ML_HOME/sml $ML_OPTIONS $DB; RC=$?; kill -HUP $FPID; exit $RC; }
RC=$?


## fix heap file name and permissions

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

exit $RC