lib/scripts/run-smlnj-0.93
author wenzelm
Wed May 14 18:38:15 1997 +0200 (1997-05-14)
changeset 3185 7a6c933d51d0
parent 3055 5da4afa207ad
child 3503 390093b95cb0
permissions -rwxr-xr-x
tuned;
wenzelm@3007
     1
#!/bin/bash
wenzelm@2411
     2
#
wenzelm@2411
     3
# $Id$
wenzelm@2411
     4
#
wenzelm@2411
     5
# SML/NJ startup script (for 0.93).
wenzelm@2411
     6
#
wenzelm@3055
     7
# Global vars: INFILE OUTFILE MLTEXT TERMINATE,
wenzelm@2411
     8
# and from settings
wenzelm@2411
     9
wenzelm@2411
    10
wenzelm@2411
    11
## diagnostics
wenzelm@2411
    12
wenzelm@2411
    13
function fail_out()
wenzelm@2411
    14
{
wenzelm@2411
    15
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
wenzelm@2411
    16
  exit 2
wenzelm@2411
    17
}
wenzelm@2411
    18
wenzelm@2411
    19
wenzelm@2411
    20
## prepare databases
wenzelm@2411
    21
wenzelm@2440
    22
if [ -z "$INFILE" ]; then
wenzelm@2440
    23
  INFILE="$ML_HOME/sml"
wenzelm@2440
    24
  EXIT="val exit = System.Unsafe.CInterface.exit;"
wenzelm@2440
    25
else
wenzelm@2440
    26
  EXIT=""
wenzelm@2440
    27
fi
wenzelm@2411
    28
wenzelm@2411
    29
MOVE=""
wenzelm@2411
    30
wenzelm@2411
    31
if [ -z "$OUTFILE" ]; then
wenzelm@2622
    32
  COMMIT='fun commit () = (output (std_err, "Error - Database is not opened for writing.\\n"); false);'
wenzelm@2411
    33
else
wenzelm@2411
    34
  if [ "$INFILE" -ef "$OUTFILE" ]; then
wenzelm@2411
    35
    OUTDIR=$(dirname "$OUTFILE")/tmp
wenzelm@2411
    36
    OUTFILE=$OUTDIR/$(basename "$OUTFILE")
wenzelm@2411
    37
    mkdir -p "$OUTDIR" || fail_out
wenzelm@2411
    38
    MOVE=true
wenzelm@2411
    39
  fi
wenzelm@2936
    40
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
wenzelm@2411
    41
  COMMIT="fun commit () = not (exportML\"$OUTFILE\");"
wenzelm@2411
    42
fi
wenzelm@2411
    43
wenzelm@2411
    44
MLTEXT="$EXIT $COMMIT $MLTEXT"
wenzelm@2411
    45
MLEXIT="commit();"
wenzelm@2411
    46
wenzelm@2411
    47
wenzelm@2411
    48
## run it!
wenzelm@2411
    49
wenzelm@2411
    50
START_SML="$INFILE $ML_OPTIONS"
wenzelm@2411
    51
wenzelm@2411
    52
if [ -n "$TERMINATE" ]; then
wenzelm@3010
    53
  echo "$MLTEXT" "$MLEXIT" | $START_SML
wenzelm@2622
    54
  RC=$?
wenzelm@2622
    55
elif [ -z "$MLTEXT" ]; then
wenzelm@2622
    56
  sh -c "{ $ISABELLE_HOME/lib/scripts/ucat; echo '$MLEXIT'; } | $START_SML"
wenzelm@2411
    57
  RC=$?
wenzelm@2411
    58
else
wenzelm@2622
    59
  sh -c "{ echo '$MLTEXT'; $ISABELLE_HOME/lib/scripts/ucat; echo '$MLEXIT'; } | $START_SML"
wenzelm@2411
    60
  RC=$?
wenzelm@2411
    61
fi
wenzelm@2411
    62
wenzelm@2411
    63
if [ -n "$MOVE" -a -f "$OUTFILE" ]; then
wenzelm@2551
    64
  rm -f "$INFILE" || fail_out
wenzelm@2551
    65
  mv "$OUTFILE" "$INFILE" || fail_out
wenzelm@2411
    66
fi
wenzelm@2411
    67
wenzelm@2411
    68
exit $RC