lib/scripts/run-smlnj-0.93
author wenzelm
Fri, 02 Jan 1998 18:40:30 +0100
changeset 4513 6de428eac512
parent 4333 1d326b826851
child 5063 d45ec8d00ab0
permissions -rwxr-xr-x
feeder;

#!/bin/bash
#
# $Id$
#
# SML/NJ startup script (for 0.93).
#
# 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
  INFILE="$ML_HOME/sml"
  EXIT="val exit: int -> unit = 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


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


## fix heap file

[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"

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

exit $RC