lib/scripts/run-smlnj
author wenzelm
Mon, 16 Dec 1996 10:29:30 +0100
changeset 2411 256dbda3df4f
parent 2396 721a9e01457b
child 2429 747177b67670
permissions -rwxr-xr-x
SML/NJ startup script (for 0.93).

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


## diagnostics

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


## prepare databases

EXIT=""
if [ -z "$INFILE" ]; then
  case "$ML_SYSTEM" in
    smlnj-1.0[678])
      EXIT="val exit = System.Unix.exit;"
      ;;
    smlnj-1.09*)
      EXIT="fun exit 0 = OS.Process.exit OS.Process.success | exit _ = OS.Process.exit OS.Process.failure;"
    ;;
  esac
fi

DB="$INFILE"
[ -n "$DB" ] && DB="@SMLload=$INFILE"

COMMIT="fun commit () = not (exportML\"$OUTFILE\");"

if [ -z "$OUTFILE" ]; then
  COMMIT='fun commit () = (output (std_err, "Error - Database is not opened for writing.\n"); false);'
elif [ -n "$INFILE" -a ! "$INFILE" -ef "$OUTFILE" ]; then
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out }
  cp "$INFILE" "$OUTFILE" || fail_out
fi

[ -n "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out }

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


## run it!

START_SML="$ML_HOME/bin/sml $ML_OPTIONS $DB"

if [ -n "$TERMINATE" ]; then
  { echo "$MLTEXT"; echo "$MLEXIT" } | $START_SML
  RC=$?
else
  { echo "$MLTEXT"; $ISABELLE_HOME/lib/scripts/ucat; echo "$MLEXIT" } | $START_SML
  RC=$?
fi

exit $RC