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