lib/scripts/run-polyml-4.1.4
author wenzelm
Sat Dec 20 11:55:34 2008 +0100 (2008-12-20)
changeset 29145 b1c6f4563df7
parent 26215 94d32a7cd0fb
permissions -rwxr-xr-x
removed Ids;
     1 #!/usr/bin/env bash
     2 #
     3 # Author: Markus Wenzel, TU Muenchen
     4 #
     5 # Poly/ML 4.x startup script.
     6 
     7 export -n INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE
     8 
     9 
    10 ## diagnostics
    11 
    12 function fail_out()
    13 {
    14   echo "Unable to create output heap file: \"$OUTFILE\"" >&2
    15   exit 2
    16 }
    17 
    18 function check_file()
    19 {
    20   if [ ! -f "$1" ]; then
    21     echo "Unable to locate $1" >&2
    22     echo "Please check your ML system settings!" >&2
    23     exit 2
    24   fi
    25 }
    26 
    27 
    28 ## Poly/ML executable and database
    29 
    30 ML_DBASE_PREFIX=""
    31 
    32 POLY="$ML_HOME/poly"
    33 check_file "$POLY"
    34 
    35 if [ -z "$ML_DBASE" ]; then
    36   if [ ! -e "$ML_HOME/ML_dbase" -a "$(basename "$ML_HOME")" = bin ]; then
    37     ML_DBASE_HOME="$(cd "$ML_HOME"; cd "$(pwd -P)"; cd ../lib/poly; pwd)"
    38   else
    39     ML_DBASE_HOME="$ML_HOME"
    40   fi
    41   if [ -z "$COPYDB" ]; then
    42     ML_DBASE_PREFIX="$ML_DBASE_HOME/"
    43     ML_DBASE="ML_dbase"
    44   else
    45     ML_DBASE="$ML_DBASE_HOME/ML_dbase"
    46   fi
    47   export POLYPATH="$ML_DBASE_HOME"
    48 else
    49   export POLYPATH="$(dirname "$ML_DBASE")"
    50 fi
    51 
    52 DISCGARB_OPTIONS="-d -c"
    53 
    54 EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
    55 
    56 
    57 ## prepare databases
    58 
    59 if [ -z "$INFILE" ]; then
    60   check_file "$ML_DBASE_PREFIX$ML_DBASE"
    61   INFILE="$ML_DBASE"
    62   MLTEXT="val use = PolyML.use; $EXIT $MLTEXT"
    63   DISCGARB_OPTIONS="$DISCGARB_OPTIONS -S max"
    64 else
    65   COPYDB=true
    66 fi
    67 
    68 if [ -z "$OUTFILE" ]; then
    69   DB="$INFILE"
    70   ML_OPTIONS="-r $ML_OPTIONS"
    71 elif [ "$INFILE" -ef "$OUTFILE" ]; then
    72   DB="$INFILE"
    73 elif [ -n "$COPYDB" ]; then
    74   [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
    75   cp "$INFILE" "$OUTFILE" || fail_out
    76   chmod +w "$OUTFILE" || fail_out
    77   DB="$OUTFILE"
    78 else
    79   [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
    80   echo "PolyML.make_database \"$OUTFILE\"; PolyML.quit();" | "$POLY" -r "$INFILE"
    81   [ -f "$OUTFILE" ] || fail_out
    82   DB="$OUTFILE"
    83 fi
    84 
    85 
    86 ## run it!
    87 
    88 if [ -z "$TERMINATE" ]; then
    89   FEEDER_OPTS=""
    90 else
    91   FEEDER_OPTS="-q"
    92 fi
    93 
    94 DB_INFO="$(ls -l "$DB" 2>/dev/null)"
    95 
    96 "$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" $FEEDER_OPTS | {
    97   read FPID; "$POLY" $ML_OPTIONS "$DB";
    98   RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
    99 RC="$?"
   100 
   101 NEW_DB_INFO="$(ls -l "$DB" 2>/dev/null)"
   102 [ -n "$OUTFILE" -a -n "$COMPRESS" -a "$DB_INFO" != "$NEW_DB_INFO" ] && \
   103   "$POLY" $DISCGARB_OPTIONS "$OUTFILE"
   104 [ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
   105 
   106 exit "$RC"