lib/scripts/run-poplogml
author wenzelm
Tue, 04 Oct 2005 21:33:09 +0200
changeset 17759 dce4b7eb69c0
child 17794 87fe1dd02d34
permissions -rwxr-xr-x
Poplog/PML startup script.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17759
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
     1
#!/usr/bin/env bash
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
     2
#
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
     3
# $Id$
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
     4
# Author: Makarius
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
     5
#
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
     6
# Poplog/PML startup script (version 15.6/2.1).
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
     7
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
     8
export -n INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
     9
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    10
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    11
## diagnostics
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    12
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    13
function fail_out()
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    14
{
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    15
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    16
  exit 2
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    17
}
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    18
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    19
function check_mlhome_file()
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    20
{
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    21
  if [ ! -f "$1" ]; then
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    22
    echo "Unable to locate $1" >&2
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    23
    echo "Please check your ML_HOME setting!" >&2
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    24
    exit 2
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    25
  fi
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    26
}
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    27
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    28
function check_heap_file()
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    29
{
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    30
  if [ ! -f "$1" ]; then
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    31
    echo "Expected to find ML heap file $1" >&2
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    32
    return 1
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    33
  else
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    34
    return 0
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    35
  fi
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    36
}
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    37
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    38
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    39
## prepare databases
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    40
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    41
if [ -z "$INFILE" ]; then
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    42
  EXIT="fun exit (i: int) = OS.execve \"/bin/sh\" [\"sh\", \"-c\", \"exit \" ^ makestring i] (OS.envlist());"
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    43
  DB=""
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    44
else
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    45
  EXIT=""
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    46
  DB="+$INFILE"
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    47
fi
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    48
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    49
if [ -z "$OUTFILE" ]; then
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    50
  COMMIT='fun commit () = (StdIO.output (StdIO.std_err, "Error - Database is not opened for writing.\n"); false);'
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    51
else
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    52
  if [ -z "$NOWRITE" ]; then
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    53
    COMMIT="fun commit () = if System.make {image =\"$OUTFILE\", lock = false, share = false, banner = false, init = false} then System.restart() else true;"
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    54
  else
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    55
    COMMIT="fun commit () = if System.make {image =\"$OUTFILE\", lock = true, share = true, banner = false, init = false} then System.restart() else true;"
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    56
  fi
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    57
  [ -f "${OUTFILE}.psv" ] && { chmod +w "${OUTFILE}.psv" || fail_out; }
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    58
fi
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    59
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    60
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    61
## run it!
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    62
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    63
POPLOG="$ML_HOME/poplog"
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    64
check_mlhome_file "$POPLOG"
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    65
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    66
MLTEXT="val use = Compile.use; $EXIT $COMMIT $MLTEXT"
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    67
MLEXIT="commit();"
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    68
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    69
if [ -z "$TERMINATE" ]; then
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    70
  FEEDER_OPTS=""
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    71
else
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    72
  FEEDER_OPTS="-q"
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    73
fi
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    74
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    75
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    76
  { read FPID; "$POPLOG" pml "$DB" $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    77
RC="$?"
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    78
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    79
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    80
## fix heap file name and permissions
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    81
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    82
if [ -n "$OUTFILE" ]; then
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    83
  check_heap_file "${OUTFILE}.psv" && \
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    84
    [ -n "$NOWRITE" ] && chmod -w "${OUTFILE}.psv"
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    85
fi
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    86
dce4b7eb69c0 Poplog/PML startup script.
wenzelm
parents:
diff changeset
    87
exit "$RC"