lib/scripts/run-polyml
author wenzelm
Mon Dec 09 16:42:24 1996 +0100 (1996-12-09)
changeset 2349 e9475a7be4ad
parent 2314 67bf78c7c725
child 2389 d472c732bc21
permissions -rwxr-xr-x
various fixes;
wenzelm@2349
     1
#!/bin/bash -norc
wenzelm@2301
     2
#
wenzelm@2314
     3
# $Id$
wenzelm@2314
     4
#
wenzelm@2301
     5
# Poly/ML startup script.
wenzelm@2301
     6
#
wenzelm@2349
     7
# Global vars: INFILE OUTFILE COPYDB 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@2301
    20
## locations and settings
wenzelm@2301
    21
wenzelm@2301
    22
ML_DBASE=$ML_HOME/ML_dbase
wenzelm@2301
    23
POLY=$ML_HOME/poly
wenzelm@2301
    24
DISCGARB=$ML_HOME/discgarb
wenzelm@2301
    25
wenzelm@2301
    26
case "$ML_SYSTEM" in
wenzelm@2349
    27
  polyml-3.*)
wenzelm@2314
    28
    DISCGARB="$DISCGARB -c"
wenzelm@2301
    29
    ;;
wenzelm@2301
    30
esac
wenzelm@2301
    31
wenzelm@2301
    32
wenzelm@2301
    33
## prepare databases
wenzelm@2301
    34
wenzelm@2349
    35
MLINIT=""
wenzelm@2349
    36
wenzelm@2301
    37
if [ -z "$INFILE" ]; then
wenzelm@2301
    38
  INFILE="$ML_DBASE"
wenzelm@2349
    39
  MLINIT="val use = PolyML.use; val exit = PolyML.exit; fun init_database () = ();"
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@2301
    48
  cp "$INFILE" "$OUTFILE" || fail_out
wenzelm@2349
    49
  chmod +w "$OUTFILE" || fail_out
wenzelm@2301
    50
  DB="$OUTFILE"
wenzelm@2301
    51
else
wenzelm@2301
    52
  [ -f "$OUTFILE" ] && { rm "$OUTFILE" || fail_out }
wenzelm@2349
    53
  echo "PolyML.make_database \"$OUTFILE\"; PolyML.quit();" | $POLY -r "$INFILE"
wenzelm@2301
    54
  [ -f "$OUTFILE" ] || fail_out
wenzelm@2301
    55
  DB="$OUTFILE"
wenzelm@2349
    56
  MLINIT="$MLINIT init_database ();"
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@2349
    63
wenzelm@2349
    64
[ -n "$MLINIT" ] && MLTEXT="$MLINIT $MLTEXT"
wenzelm@2301
    65
wenzelm@2301
    66
if [ -n "$TERMINATE" ]; then
wenzelm@2349
    67
  echo "$MLTEXT" | $START_POLY
wenzelm@2301
    68
  RC=$?
wenzelm@2301
    69
elif [ -z "$MLTEXT" ]; then
wenzelm@2301
    70
  $START_POLY
wenzelm@2301
    71
  RC=$?
wenzelm@2301
    72
else
wenzelm@2349
    73
  { echo "$MLTEXT"; $ISABELLE_HOME/lib/scripts/ucat } | $START_POLY
wenzelm@2301
    74
  RC=$?
wenzelm@2301
    75
fi
wenzelm@2301
    76
wenzelm@2314
    77
[ $RC -eq 0 -a -n "$OUTFILE" ] && $DISCGARB "$OUTFILE"
wenzelm@2301
    78
wenzelm@2301
    79
exit $RC