lib/scripts/run-smlnj-0.93
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 0.93).
#
# Global vars: INFILE OUTFILE MLTEXT TERMINATE,
# and from settings


## diagnostics

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


## prepare databases

if [ -z "$INFILE" ]; then
  INFILE="$ML_HOME/sml"
  EXIT="val exit = System.Unsafe.CInterface.exit;"
else
  EXIT=""
fi

MOVE=""

if [ -z "$OUTFILE" ]; then
  COMMIT='fun commit () = (output (std_err, "Error - Database is not opened for writing.\\n"); false);'
else
  if [ "$INFILE" -ef "$OUTFILE" ]; then
    OUTDIR=$(dirname "$OUTFILE")/tmp
    OUTFILE=$OUTDIR/$(basename "$OUTFILE")
    mkdir -p "$OUTDIR" || fail_out
    MOVE=true
  fi
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
  COMMIT="fun commit () = not (exportML\"$OUTFILE\");"
fi

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


## run it!

START_SML="$INFILE $ML_OPTIONS"

if [ -n "$TERMINATE" ]; then
  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

if [ -n "$MOVE" -a -f "$OUTFILE" ]; then
  rm -f "$INFILE" || fail_out
  mv "$OUTFILE" "$INFILE" || fail_out
fi

exit $RC