lib/scripts/run-smlnj
author paulson
Thu, 05 Jun 1997 13:22:25 +0200
changeset 3403 6cc663f6d62e
parent 3055 5da4afa207ad
child 3503 390093b95cb0
permissions -rwxr-xr-x
A slight simplification of optstring The new "simpset" keyword in the "recdef" declaration

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


## diagnostics

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


## version specific stuff

EXIT=""
COMMIT=""
SUFFIX=""

case "$ML_SYSTEM" in
  smlnj-1.0[678]*)
    EXIT="val exit = System.Unix.exit;"
    COMMIT="fun commit () = not (exportML\"$OUTFILE\");"
    COMMIT_RO='fun commit () = (output (std_err, "Error - Database is not opened for writing.\\n"); false);'
    ;;
  smlnj-1.09*)
    EXIT="fun exit 0 : unit = OS.Process.exit OS.Process.success | exit _ = OS.Process.exit OS.Process.failure;"
    COMMIT="fun commit () = not (SMLofNJ.exportML\"$OUTFILE\");"
    COMMIT_RO='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\\n"); false);'
    eval $($ML_HOME/.arch-n-opsys)
    SUFFIX=".$ARCH-$OPSYS"
    ;;
esac


## prepare databases

DB="$INFILE"

if [ -n "$DB" ]; then
  DB="@SMLload=$INFILE"
  EXIT=""
fi

[ -z "$OUTFILE" ] && COMMIT="$COMMIT_RO"
[ -n "$OUTFILE" -a -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }

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


## run it!

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

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

#fix heap file name
[ -n "$OUTFILE" -a -n "$SUFFIX" -a -f "$OUTFILE$SUFFIX" ] \
  && mv "$OUTFILE$SUFFIX" "$OUTFILE"

exit $RC