lib/scripts/run-polyml
author wenzelm
Wed Dec 31 15:19:51 1997 +0100 (1997-12-31)
changeset 4505 4a2c872b6513
parent 4333 1d326b826851
child 5063 d45ec8d00ab0
permissions -rwxr-xr-x
use feeder to pipe into ML;
cleaned up;
wenzelm@3007
     1
#!/bin/bash
wenzelm@2301
     2
#
wenzelm@2314
     3
# $Id$
wenzelm@2314
     4
#
wenzelm@2301
     5
# Poly/ML startup script.
wenzelm@2301
     6
#
wenzelm@4333
     7
# Global vars: INFILE OUTFILE MLTEXT TERMINATE NOWRITE ISABELLE_TMP,
wenzelm@2301
     8
# and from settings
wenzelm@2301
     9
wenzelm@2301
    10
wenzelm@2301
    11
## diagnostics
wenzelm@2301
    12
wenzelm@2349
    13
function fail_out()
wenzelm@2301
    14
{
wenzelm@2349
    15
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
wenzelm@2301
    16
  exit 2
wenzelm@2301
    17
}
wenzelm@2301
    18
wenzelm@2301
    19
wenzelm@2400
    20
## Poly/ML programs
wenzelm@2301
    21
wenzelm@2301
    22
POLY=$ML_HOME/poly
wenzelm@2301
    23
DISCGARB=$ML_HOME/discgarb
wenzelm@2301
    24
wenzelm@2301
    25
case "$ML_SYSTEM" in
wenzelm@2349
    26
  polyml-3.*)
wenzelm@2314
    27
    DISCGARB="$DISCGARB -c"
wenzelm@2301
    28
    ;;
wenzelm@2301
    29
esac
wenzelm@2301
    30
wenzelm@2301
    31
wenzelm@2301
    32
## prepare databases
wenzelm@2301
    33
wenzelm@3055
    34
COPYDB=true
wenzelm@2349
    35
wenzelm@2301
    36
if [ -z "$INFILE" ]; then
wenzelm@2400
    37
  INFILE="$ML_HOME/ML_dbase"
wenzelm@3055
    38
  MLTEXT="val use = PolyML.use; val exit = PolyML.exit; $MLTEXT"
wenzelm@3055
    39
  COPYDB=""
wenzelm@2301
    40
fi
wenzelm@2301
    41
wenzelm@2301
    42
if [ -z "$OUTFILE" ]; then
wenzelm@2301
    43
  DB="$INFILE"
wenzelm@2349
    44
  ML_OPTIONS="-r $ML_OPTIONS"  
wenzelm@2349
    45
elif [ "$INFILE" -ef "$OUTFILE" ]; then
wenzelm@2301
    46
  DB="$INFILE"
wenzelm@2301
    47
elif [ -n "$COPYDB" ]; then
wenzelm@2936
    48
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
wenzelm@2548
    49
  cp "$INFILE" "$OUTFILE" || fail_out
wenzelm@2349
    50
  chmod +w "$OUTFILE" || fail_out
wenzelm@2301
    51
  DB="$OUTFILE"
wenzelm@2301
    52
else
wenzelm@2936
    53
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
wenzelm@2349
    54
  echo "PolyML.make_database \"$OUTFILE\"; PolyML.quit();" | $POLY -r "$INFILE"
wenzelm@2301
    55
  [ -f "$OUTFILE" ] || fail_out
wenzelm@2301
    56
  DB="$OUTFILE"
wenzelm@2301
    57
fi
wenzelm@2301
    58
wenzelm@2301
    59
wenzelm@2301
    60
## run it!
wenzelm@2301
    61
wenzelm@4505
    62
if [ -z "$TERMINATE" ]; then
wenzelm@4505
    63
  FEEDER_OPTS="-s"
wenzelm@4505
    64
else
wenzelm@4505
    65
  FEEDER_OPTS="-q"
wenzelm@4505
    66
fi
wenzelm@4505
    67
wenzelm@2400
    68
DB_INFO=$(ls -l "$DB")
wenzelm@2349
    69
wenzelm@4505
    70
$ISABELLE_HOME/lib/scripts/feeder -p -h "$MLTEXT" $FEEDER_OPTS | \
wenzelm@4505
    71
  { read FPID; $POLY $ML_OPTIONS "$DB"; RC=$?; kill -HUP $FPID; exit $RC; }
wenzelm@4505
    72
RC=$?
wenzelm@2301
    73
wenzelm@2400
    74
NEW_DB_INFO=$(ls -l "$DB")
wenzelm@2605
    75
[ -n "$OUTFILE" -a "$DB_INFO" != "$NEW_DB_INFO" ] && $DISCGARB "$OUTFILE"
wenzelm@4505
    76
[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
wenzelm@2301
    77
wenzelm@2301
    78
exit $RC