#!/usr/bin/env bash # # $Id: run-smlnj,v 1.28 2004/06/21 08:25:58 kleing Exp $ # Author: Markus Wenzel, TU Muenchen # # SML/NJ startup script (for 110 or later). ## diagnostics fail_out() { echo "Unable to create output heap file: \"$OUTFILE\"" >&2 exit 2 } check_mlhome_file() { if [ ! -f "$1" ]; then echo "Unable to locate $1" >&2 echo "Please check your ML_HOME setting!" >&2 exit 2 fi } check_heap_file() { if [ ! -f "$1" ]; then echo "Expected to find ML heap file $1" >&2 return 1 else return 0 fi } ## compiler binaries SML="$ML_HOME/sml" check_mlhome_file "$SML" ## prepare databases if [ -z "$INFILE" ]; then EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;" DB="" else EXIT="" DB="@SMLload=$INFILE" fi if [ -z "$OUTFILE" ]; then COMMIT='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\n"); false);' else COMMIT="fun commit () = not (SMLofNJ.exportML\"$OUTFILE\");" [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; } fi ## run it! MLTEXT="$EXIT $COMMIT $MLTEXT" MLEXIT="commit();" if [ -z "$TERMINATE" ]; then FEEDER_OPTS="" else FEEDER_OPTS="-q" fi SAVE_OUTFILE="$OUTFILE" SAVE_MLTEXT="$MLTEXT" SAVE_NOWRITE="$NOWRITE" unset INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE OUTFILE="$SAVE_OUTFILE" MLTEXT="$SAVE_MLTEXT" NOWRITE="$SAVE_NOWRITE" "$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \ { read FPID; "$SML" $ML_OPTIONS "$DB"; RC="$?"; kill -HUP "$FPID"; exit "$RC"; } RC="$?" ## fix heap file name and permissions if [ -n "$OUTFILE" ]; then [ -z "$HEAP_SUFFIX" ] && HEAP_SUFFIX="$ML_PLATFORM" HEAP="$OUTFILE.$HEAP_SUFFIX" check_heap_file "$HEAP" && mv "$HEAP" "$OUTFILE" && \ [ -n "$NOWRITE" ] && chmod -w "$OUTFILE" fi exit "$RC"