lib/scripts/run-polyml
author wenzelm
Fri Sep 15 16:31:36 2000 +0200 (2000-09-15)
changeset 9977 32955afeb835
parent 9789 7e5e6c47c0b5
child 9990 09c65992894c
permissions -rwxr-xr-x
unexport exports;
wenzelm@3007
     1
#!/bin/bash
wenzelm@2301
     2
#
wenzelm@2314
     3
# $Id$
wenzelm@9789
     4
# Author: Markus Wenzel, TU Muenchen
wenzelm@9789
     5
# License: GPL (GNU GENERAL PUBLIC LICENSE)
wenzelm@2314
     6
#
wenzelm@2301
     7
# Poly/ML startup script.
wenzelm@9977
     8
wenzelm@9977
     9
export -n INFILE OUTFILE COMPRESS MLTEXT TERMINATE NOWRITE ISABELLE_TMP
wenzelm@2301
    10
wenzelm@2301
    11
wenzelm@2301
    12
## diagnostics
wenzelm@2301
    13
wenzelm@2349
    14
function fail_out()
wenzelm@2301
    15
{
wenzelm@2349
    16
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
wenzelm@2301
    17
  exit 2
wenzelm@2301
    18
}
wenzelm@2301
    19
wenzelm@5063
    20
function check_mlhome_file()
wenzelm@5063
    21
{
wenzelm@5063
    22
  if [ ! -f "$1" ]; then
wenzelm@5063
    23
    echo "Unable to locate $1" >&2
wenzelm@5063
    24
    echo "Please check your ML_HOME setting!" >&2
wenzelm@5063
    25
    exit 2
wenzelm@5063
    26
  fi
wenzelm@5063
    27
}
wenzelm@5063
    28
wenzelm@2301
    29
wenzelm@2400
    30
## Poly/ML programs
wenzelm@2301
    31
wenzelm@9789
    32
POLY="$ML_HOME/poly"
wenzelm@9789
    33
DISCGARB="$ML_HOME/discgarb"
wenzelm@2301
    34
wenzelm@5063
    35
check_mlhome_file "$POLY"
wenzelm@5063
    36
check_mlhome_file "$DISCGARB"
wenzelm@5063
    37
wenzelm@2301
    38
wenzelm@9765
    39
case "$ML_SYSTEM" in
wenzelm@9765
    40
  polyml-4.*)
wenzelm@9765
    41
    EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
wenzelm@9765
    42
    ;;
wenzelm@9765
    43
  *)
wenzelm@9765
    44
    EXIT="val exit = PolyML.exit;"
wenzelm@9765
    45
    ;;
wenzelm@9765
    46
esac
wenzelm@9765
    47
wenzelm@9765
    48
wenzelm@2301
    49
## prepare databases
wenzelm@2301
    50
wenzelm@3055
    51
COPYDB=true
wenzelm@2349
    52
wenzelm@2301
    53
if [ -z "$INFILE" ]; then
wenzelm@2400
    54
  INFILE="$ML_HOME/ML_dbase"
wenzelm@5063
    55
  check_mlhome_file "$INFILE"
wenzelm@3055
    56
  COPYDB=""
wenzelm@9765
    57
  MLTEXT="val use = PolyML.use; $EXIT $MLTEXT"
wenzelm@2301
    58
fi
wenzelm@2301
    59
wenzelm@2301
    60
if [ -z "$OUTFILE" ]; then
wenzelm@2301
    61
  DB="$INFILE"
wenzelm@2349
    62
  ML_OPTIONS="-r $ML_OPTIONS"  
wenzelm@2349
    63
elif [ "$INFILE" -ef "$OUTFILE" ]; then
wenzelm@2301
    64
  DB="$INFILE"
wenzelm@2301
    65
elif [ -n "$COPYDB" ]; then
wenzelm@2936
    66
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
wenzelm@2548
    67
  cp "$INFILE" "$OUTFILE" || fail_out
wenzelm@2349
    68
  chmod +w "$OUTFILE" || fail_out
wenzelm@2301
    69
  DB="$OUTFILE"
wenzelm@2301
    70
else
wenzelm@2936
    71
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
wenzelm@9789
    72
  echo "PolyML.make_database \"$OUTFILE\"; PolyML.quit();" | "$POLY" -r "$INFILE"
wenzelm@2301
    73
  [ -f "$OUTFILE" ] || fail_out
wenzelm@2301
    74
  DB="$OUTFILE"
wenzelm@2301
    75
fi
wenzelm@2301
    76
wenzelm@2301
    77
wenzelm@2301
    78
## run it!
wenzelm@2301
    79
wenzelm@4505
    80
if [ -z "$TERMINATE" ]; then
wenzelm@4505
    81
  FEEDER_OPTS="-s"
wenzelm@4505
    82
else
wenzelm@4505
    83
  FEEDER_OPTS="-q"
wenzelm@4505
    84
fi
wenzelm@4505
    85
wenzelm@2400
    86
DB_INFO=$(ls -l "$DB")
wenzelm@2349
    87
wenzelm@9789
    88
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" $FEEDER_OPTS | \
wenzelm@9789
    89
  { read FPID; "$POLY" $ML_OPTIONS "$DB"; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
wenzelm@9789
    90
RC="$?"
wenzelm@2301
    91
wenzelm@2400
    92
NEW_DB_INFO=$(ls -l "$DB")
wenzelm@9789
    93
[ -n "$OUTFILE" -a -n "$COMPRESS" -a "$DB_INFO" != "$NEW_DB_INFO" ] && "$DISCGARB" -c "$OUTFILE"
wenzelm@4505
    94
[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
wenzelm@2301
    95
wenzelm@9789
    96
exit "$RC"