lib/scripts/run-polyml-5.5.1
author wenzelm
Fri Jan 01 16:40:47 2016 +0100 (2016-01-01)
changeset 62028 2ecee4679f99
parent 59344 e0ce214303c1
permissions -rwxr-xr-x
updated for release;
     1 #!/usr/bin/env bash
     2 # :mode=shellscript:
     3 #
     4 # Author: Makarius
     5 #
     6 # Startup script for Poly/ML 5.5.1.
     7 
     8 export -n INFILE OUTFILE MLTEXT TERMINATE NOWRITE
     9 
    10 
    11 ## diagnostics
    12 
    13 function fail()
    14 {
    15   echo "$1" >&2
    16   exit 2
    17 }
    18 
    19 function fail_out()
    20 {
    21   fail "Unable to create output heap file: \"$OUTFILE\""
    22 }
    23 
    24 function check_file()
    25 {
    26   [ ! -f "$1" ] && fail "Unable to locate \"$1\""
    27 }
    28 
    29 
    30 ## compiler executables and libraries
    31 
    32 [ -z "$ML_HOME" ] && fail "Missing ML installation (ML_HOME)"
    33 
    34 POLY="$ML_HOME/poly"
    35 check_file "$POLY"
    36 
    37 librarypath "$ML_HOME"
    38 
    39 
    40 
    41 ## prepare databases
    42 
    43 if [ -z "$INFILE" ]; then
    44   INIT=""
    45   EXIT="fun exit rc = Posix.Process.exit (Word8.fromInt rc);"
    46 else
    47   check_file "$INFILE"
    48   INIT="(Signal.signal (2, Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ())); PolyML.SaveState.loadState \"$INFILE\" handle exn => (TextIO.output (TextIO.stdErr, General.exnMessage exn ^ \": $INFILE\\n\"); Posix.Process.exit 0w1));"
    49   EXIT=""
    50 fi
    51 
    52 if [ -z "$OUTFILE" ]; then
    53   MLEXIT=""
    54 else
    55   if [ -z "$INFILE" ]; then
    56     MLEXIT="(PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.SaveState.saveState \"$OUTFILE\"; true) handle exn => (TextIO.output (TextIO.stdErr, General.exnMessage exn ^ \": $OUTFILE\\n\"); Posix.Process.exit 0w1);"
    57   else
    58     MLEXIT="Session.save \"$OUTFILE\";"
    59   fi
    60   [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
    61 fi
    62 
    63 
    64 ## run it!
    65 
    66 MLTEXT="$INIT $EXIT $MLTEXT"
    67 
    68 if [ -n "$TERMINATE" -a -z "$MLEXIT" ]; then
    69   "$POLY" -q -i $ML_OPTIONS --eval "$(perl "$ISABELLE_HOME/lib/scripts/recode.pl" "$MLTEXT")" \
    70     --error-exit </dev/null
    71   RC="$?"
    72 else
    73   if [ -z "$TERMINATE" ]; then
    74     FEEDER_OPTS=""
    75   else
    76     FEEDER_OPTS="-q"
    77     ML_OPTIONS="$ML_OPTIONS --error-exit"
    78   fi
    79   "$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
    80     { read FPID; "$POLY" -q -i $ML_OPTIONS; RC="$?"; kill -TERM "$FPID"; exit "$RC"; }
    81   RC="$?"
    82 fi
    83 
    84 [ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
    85 
    86 exit "$RC"
    87 
    88 #:wrap=soft:maxLineLen=100: