lib/scripts/run-polyml
author wenzelm
Fri Apr 25 15:10:52 1997 +0200 (1997-04-25)
changeset 3055 5da4afa207ad
parent 3007 e5efa177ee0c
child 3503 390093b95cb0
permissions -rwxr-xr-x
removed COPYDB flag;
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@3055
     7
# Global vars: INFILE OUTFILE MLTEXT TERMINATE,
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@2349
    62
START_POLY="$POLY $ML_OPTIONS $DB"
wenzelm@2400
    63
DB_INFO=$(ls -l "$DB")
wenzelm@2349
    64
wenzelm@2301
    65
if [ -n "$TERMINATE" ]; then
wenzelm@2349
    66
  echo "$MLTEXT" | $START_POLY
wenzelm@2301
    67
  RC=$?
wenzelm@2605
    68
elif [ -z "$MLTEXT" ]; then
wenzelm@2605
    69
  sh -c "$ISABELLE_HOME/lib/Tools/symbolinput | $START_POLY"
wenzelm@2605
    70
  RC=$?
wenzelm@2301
    71
else
wenzelm@2605
    72
  sh -c "{ echo '$MLTEXT'; $ISABELLE_HOME/lib/Tools/symbolinput; } | $START_POLY"
wenzelm@2301
    73
  RC=$?
wenzelm@2301
    74
fi
wenzelm@2301
    75
wenzelm@2400
    76
NEW_DB_INFO=$(ls -l "$DB")
wenzelm@2605
    77
[ -n "$OUTFILE" -a "$DB_INFO" != "$NEW_DB_INFO" ] && $DISCGARB "$OUTFILE"
wenzelm@2301
    78
wenzelm@2301
    79
exit $RC