lib/scripts/run-smlnj-0.93
author paulson
Mon, 16 Nov 1998 10:36:30 +0100
changeset 5865 2303f5a3036d
parent 5063 d45ec8d00ab0
child 9789 7e5e6c47c0b5
permissions -rwxr-xr-x
moved some facts about Pi from ex/PiSets to Fun.ML

#!/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
}

function check_mlhome_file()
{
  if [ ! -f "$1" ]; then
    echo "Unable to locate $1" >&2
    echo "Please check your ML_HOME setting!" >&2
    exit 2
  fi
}


## prepare databases

if [ -z "$INFILE" ]; then
  INFILE="$ML_HOME/sml"
  check_mlhome_file "$INFILE"
  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