lib/scripts/run-smlnj
author wenzelm
Fri, 01 Sep 2000 17:54:58 +0200
changeset 9789 7e5e6c47c0b5
parent 6078 e01e2328d0f0
child 9977 32955afeb835
permissions -rwxr-xr-x
GPLed; more robust handling of spaces in args / file names;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3007
e5efa177ee0c removed -norc;
wenzelm
parents: 2936
diff changeset
     1
#!/bin/bash
2302
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
     2
#
2313
d97eef398257 replaced cat by ucat;
wenzelm
parents: 2302
diff changeset
     3
# $Id$
9789
wenzelm
parents: 6078
diff changeset
     4
# Author: Markus Wenzel, TU Muenchen
wenzelm
parents: 6078
diff changeset
     5
# License: GPL (GNU GENERAL PUBLIC LICENSE)
2313
d97eef398257 replaced cat by ucat;
wenzelm
parents: 2302
diff changeset
     6
#
5708
fb09ab6a447f dropped support for SML/NJ 109.x;
wenzelm
parents: 5063
diff changeset
     7
# SML/NJ startup script (for 110 or later).
2302
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
     8
#
4333
1d326b826851 ISABELLE_TMP;
wenzelm
parents: 3630
diff changeset
     9
# Global vars: INFILE OUTFILE MLTEXT TERMINATE NOWRITE ISABELLE_TMP,
2302
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    10
# and from settings
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    11
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    12
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    13
## diagnostics
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    14
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2316
diff changeset
    15
function fail_out()
2302
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    16
{
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2316
diff changeset
    17
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
2302
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    18
  exit 2
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    19
}
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    20
5063
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    21
function check_mlhome_file()
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    22
{
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    23
  if [ ! -f "$1" ]; then
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    24
    echo "Unable to locate $1" >&2
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    25
    echo "Please check your ML_HOME setting!" >&2
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    26
    exit 2
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    27
  fi
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    28
}
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    29
6078
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    30
function check_heap_file()
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    31
{
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    32
  if [ ! -f "$1" ]; then
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    33
    echo "Expected to find ML heap file $1" >&2
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    34
    return 1
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    35
  else
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    36
    return 0
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    37
  fi
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    38
}
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    39
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    40
5063
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    41
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    42
## compiler binaries
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    43
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    44
SML="$ML_HOME/sml"
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    45
ARCH_N_OPSYS="$ML_HOME/.arch-n-opsys"
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    46
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    47
check_mlhome_file "$SML"
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    48
check_mlhome_file "$ARCH_N_OPSYS"
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    49
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    50
2302
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    51
3046
6b7935317538 adapted to SML/NJ 1.09.27;
wenzelm
parents: 3010
diff changeset
    52
## prepare databases
6b7935317538 adapted to SML/NJ 1.09.27;
wenzelm
parents: 3010
diff changeset
    53
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    54
if [ -z "$INFILE" ]; then
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    55
  EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    56
  DB=""
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    57
else
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    58
  EXIT=""
3046
6b7935317538 adapted to SML/NJ 1.09.27;
wenzelm
parents: 3010
diff changeset
    59
  DB="@SMLload=$INFILE"
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2316
diff changeset
    60
fi
e9475a7be4ad various fixes;
wenzelm
parents: 2316
diff changeset
    61
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    62
if [ -z "$OUTFILE" ]; then
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    63
  COMMIT='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\n"); false);'
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    64
else
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    65
  COMMIT="fun commit () = not (SMLofNJ.exportML\"$OUTFILE\");"
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    66
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    67
fi
2302
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    68
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    69
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    70
## run it!
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    71
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    72
MLTEXT="$EXIT $COMMIT $MLTEXT"
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    73
MLEXIT="commit();"
2302
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    74
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    75
if [ -z "$TERMINATE" ]; then
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    76
  FEEDER_OPTS=""
2302
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    77
else
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    78
  FEEDER_OPTS="-q"
2302
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    79
fi
47e078e60ab1 run-smlnj: SML/NJ startup script (for 1.06 or later).
wenzelm
parents:
diff changeset
    80
9789
wenzelm
parents: 6078
diff changeset
    81
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
wenzelm
parents: 6078
diff changeset
    82
  { read FPID; "$SML" $ML_OPTIONS "$DB"; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
wenzelm
parents: 6078
diff changeset
    83
RC="$?"
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    84
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    85
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    86
## fix heap file name and permissions
3046
6b7935317538 adapted to SML/NJ 1.09.27;
wenzelm
parents: 3010
diff changeset
    87
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    88
if [ -n "$OUTFILE" ]; then
9789
wenzelm
parents: 6078
diff changeset
    89
  eval $("$ARCH_N_OPSYS")
6078
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    90
  [ -z "$HEAP_SUFFIX" ] && HEAP_SUFFIX="$ARCH-$OPSYS"
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    91
  HEAP="$OUTFILE.$HEAP_SUFFIX"
e01e2328d0f0 more robust heap file detection;
wenzelm
parents: 5708
diff changeset
    92
  check_heap_file "$HEAP" && mv "$HEAP" "$OUTFILE" && \
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    93
    [ -n "$NOWRITE" ] && chmod -w "$OUTFILE"
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4415
diff changeset
    94
fi
3503
390093b95cb0 NOWRITE;
wenzelm
parents: 3055
diff changeset
    95
9789
wenzelm
parents: 6078
diff changeset
    96
exit "$RC"