lib/scripts/run-smlnj-0.93
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 0.93).
     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 if [ -z "$INFILE" ]; then
    23   INFILE="$ML_HOME/sml"
    24   EXIT="val exit = System.Unsafe.CInterface.exit;"
    25 else
    26   EXIT=""
    27 fi
    28 
    29 MOVE=""
    30 
    31 if [ -z "$OUTFILE" ]; then
    32   COMMIT='fun commit () = (output (std_err, "Error - Database is not opened for writing.\\n"); false);'
    33 else
    34   if [ "$INFILE" -ef "$OUTFILE" ]; then
    35     OUTDIR=$(dirname "$OUTFILE")/tmp
    36     OUTFILE=$OUTDIR/$(basename "$OUTFILE")
    37     mkdir -p "$OUTDIR" || fail_out
    38     MOVE=true
    39   fi
    40   [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
    41   COMMIT="fun commit () = not (exportML\"$OUTFILE\");"
    42 fi
    43 
    44 MLTEXT="$EXIT $COMMIT $MLTEXT"
    45 MLEXIT="commit();"
    46 
    47 
    48 ## run it!
    49 
    50 START_SML="$INFILE $ML_OPTIONS"
    51 
    52 if [ -n "$TERMINATE" ]; then
    53   { echo "$MLTEXT" "$MLEXIT" } | $START_SML
    54   RC=$?
    55 elif [ -z "$MLTEXT" ]; then
    56   sh -c "{ $ISABELLE_HOME/lib/scripts/ucat; echo '$MLEXIT'; } | $START_SML"
    57   RC=$?
    58 else
    59   sh -c "{ echo '$MLTEXT'; $ISABELLE_HOME/lib/scripts/ucat; echo '$MLEXIT'; } | $START_SML"
    60   RC=$?
    61 fi
    62 
    63 if [ -n "$MOVE" -a -f "$OUTFILE" ]; then
    64   rm -f "$INFILE" || fail_out
    65   mv "$OUTFILE" "$INFILE" || fail_out
    66 fi
    67 
    68 exit $RC