lib/scripts/run-polyml
author wenzelm
Thu Aug 31 17:25:52 2000 +0200 (2000-08-31)
changeset 9765 46def28153d6
parent 8821 b5c3aec69462
child 9789 7e5e6c47c0b5
permissions -rwxr-xr-x
improved exit function for polyml-4.0;
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@8360
     7
# Global vars: INFILE OUTFILE COMPRESS 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@5063
    19
function check_mlhome_file()
wenzelm@5063
    20
{
wenzelm@5063
    21
  if [ ! -f "$1" ]; then
wenzelm@5063
    22
    echo "Unable to locate $1" >&2
wenzelm@5063
    23
    echo "Please check your ML_HOME setting!" >&2
wenzelm@5063
    24
    exit 2
wenzelm@5063
    25
  fi
wenzelm@5063
    26
}
wenzelm@5063
    27
wenzelm@2301
    28
wenzelm@2400
    29
## Poly/ML programs
wenzelm@2301
    30
wenzelm@2301
    31
POLY=$ML_HOME/poly
wenzelm@2301
    32
DISCGARB=$ML_HOME/discgarb
wenzelm@2301
    33
wenzelm@5063
    34
check_mlhome_file "$POLY"
wenzelm@5063
    35
check_mlhome_file "$DISCGARB"
wenzelm@5063
    36
wenzelm@2301
    37
wenzelm@9765
    38
case "$ML_SYSTEM" in
wenzelm@9765
    39
  polyml-4.*)
wenzelm@9765
    40
    EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
wenzelm@9765
    41
    ;;
wenzelm@9765
    42
  *)
wenzelm@9765
    43
    EXIT="val exit = PolyML.exit;"
wenzelm@9765
    44
    ;;
wenzelm@9765
    45
esac
wenzelm@9765
    46
wenzelm@9765
    47
wenzelm@2301
    48
## prepare databases
wenzelm@2301
    49
wenzelm@3055
    50
COPYDB=true
wenzelm@2349
    51
wenzelm@2301
    52
if [ -z "$INFILE" ]; then
wenzelm@2400
    53
  INFILE="$ML_HOME/ML_dbase"
wenzelm@5063
    54
  check_mlhome_file "$INFILE"
wenzelm@3055
    55
  COPYDB=""
wenzelm@9765
    56
  MLTEXT="val use = PolyML.use; $EXIT $MLTEXT"
wenzelm@2301
    57
fi
wenzelm@2301
    58
wenzelm@2301
    59
if [ -z "$OUTFILE" ]; then
wenzelm@2301
    60
  DB="$INFILE"
wenzelm@2349
    61
  ML_OPTIONS="-r $ML_OPTIONS"  
wenzelm@2349
    62
elif [ "$INFILE" -ef "$OUTFILE" ]; then
wenzelm@2301
    63
  DB="$INFILE"
wenzelm@2301
    64
elif [ -n "$COPYDB" ]; then
wenzelm@2936
    65
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
wenzelm@2548
    66
  cp "$INFILE" "$OUTFILE" || fail_out
wenzelm@2349
    67
  chmod +w "$OUTFILE" || fail_out
wenzelm@2301
    68
  DB="$OUTFILE"
wenzelm@2301
    69
else
wenzelm@2936
    70
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
wenzelm@2349
    71
  echo "PolyML.make_database \"$OUTFILE\"; PolyML.quit();" | $POLY -r "$INFILE"
wenzelm@2301
    72
  [ -f "$OUTFILE" ] || fail_out
wenzelm@2301
    73
  DB="$OUTFILE"
wenzelm@2301
    74
fi
wenzelm@2301
    75
wenzelm@2301
    76
wenzelm@2301
    77
## run it!
wenzelm@2301
    78
wenzelm@4505
    79
if [ -z "$TERMINATE" ]; then
wenzelm@4505
    80
  FEEDER_OPTS="-s"
wenzelm@4505
    81
else
wenzelm@4505
    82
  FEEDER_OPTS="-q"
wenzelm@4505
    83
fi
wenzelm@4505
    84
wenzelm@2400
    85
DB_INFO=$(ls -l "$DB")
wenzelm@2349
    86
wenzelm@4505
    87
$ISABELLE_HOME/lib/scripts/feeder -p -h "$MLTEXT" $FEEDER_OPTS | \
wenzelm@4505
    88
  { read FPID; $POLY $ML_OPTIONS "$DB"; RC=$?; kill -HUP $FPID; exit $RC; }
wenzelm@4505
    89
RC=$?
wenzelm@2301
    90
wenzelm@2400
    91
NEW_DB_INFO=$(ls -l "$DB")
wenzelm@8821
    92
[ -n "$OUTFILE" -a -n "$COMPRESS" -a "$DB_INFO" != "$NEW_DB_INFO" ] && $DISCGARB -c "$OUTFILE"
wenzelm@4505
    93
[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
wenzelm@2301
    94
wenzelm@2301
    95
exit $RC