lib/scripts/run-smlnj
author wenzelm
Tue Apr 22 11:37:12 1997 +0200 (1997-04-22)
changeset 3007 e5efa177ee0c
parent 2936 bd33e7aae062
child 3010 4be22c300966
permissions -rwxr-xr-x
removed -norc;
     1 #!/bin/bash
     2 #
     3 # $Id$
     4 #
     5 # SML/NJ startup script (for 1.06 or later).
     6 #
     7 # Global vars: INFILE OUTFILE COPYDB MLTEXT TERMINATE,
     8 # and from settings
     9 
    10 
    11 ## diagnostics
    12 
    13 function fail_out()
    14 {
    15   echo "Unable to create output heap file: \"$OUTFILE\"" >&2
    16   exit 2
    17 }
    18 
    19 
    20 ## prepare databases
    21 
    22 EXIT=""
    23 if [ -z "$INFILE" ]; then
    24   case "$ML_SYSTEM" in
    25     smlnj-1.0[678])
    26       EXIT="val exit = System.Unix.exit;"
    27       ;;
    28     smlnj-1.09*)
    29       EXIT="fun exit 0 = OS.Process.exit OS.Process.success | exit _ = OS.Process.exit OS.Process.failure;"
    30     ;;
    31   esac
    32 fi
    33 
    34 DB="$INFILE"
    35 [ -n "$DB" ] && DB="@SMLload=$INFILE"
    36 
    37 COMMIT="fun commit () = not (exportML\"$OUTFILE\");"
    38 
    39 if [ -z "$OUTFILE" ]; then
    40   COMMIT='fun commit () = (output (std_err, "Error - Database is not opened for writing.\n"); false);'
    41 elif [ -n "$INFILE" -a ! "$INFILE" -ef "$OUTFILE" ]; then
    42   [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
    43   cp "$INFILE" "$OUTFILE" || fail_out
    44 fi
    45 
    46 [ -n "$OUTFILE" -a -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
    47 
    48 MLTEXT="$EXIT $COMMIT $MLTEXT"
    49 MLEXIT="commit();"
    50 
    51 
    52 ## run it!
    53 
    54 START_SML="$ML_HOME/sml $ML_OPTIONS $DB"
    55 
    56 if [ -n "$TERMINATE" ]; then
    57   { echo "$MLTEXT" "$MLEXIT" } | $START_SML
    58   RC=$?
    59 elif [ -z "$MLTEXT" ]; then
    60   sh -c "{ $ISABELLE_HOME/lib/scripts/ucat; echo '$MLEXIT'; } | $START_SML"
    61   RC=$?
    62 else
    63   sh -c "{ echo '$MLTEXT'; $ISABELLE_HOME/lib/scripts/ucat; echo '$MLEXIT'; } | $START_SML"
    64   RC=$?
    65 fi
    66 
    67 exit $RC