lib/scripts/run-polyml
author wenzelm
Wed Dec 04 13:18:26 1996 +0100 (1996-12-04)
changeset 2314 67bf78c7c725
parent 2301 c72f4f7236b6
child 2349 e9475a7be4ad
permissions -rwxr-xr-x
replaced cat by ucat;
fixed RC handling;
wenzelm@2301
     1
#!/bin/bash
wenzelm@2301
     2
#
wenzelm@2314
     3
# $Id$
wenzelm@2314
     4
#
wenzelm@2301
     5
# Poly/ML startup script.
wenzelm@2301
     6
#
wenzelm@2301
     7
# Global vars: INFILE OUTFILE COPYDB MLTEXT OPTIONS TERMINATE,
wenzelm@2301
     8
# and from settings
wenzelm@2301
     9
wenzelm@2301
    10
wenzelm@2301
    11
## diagnostics
wenzelm@2301
    12
wenzelm@2301
    13
function fail()
wenzelm@2301
    14
{
wenzelm@2301
    15
  echo "$1"
wenzelm@2301
    16
  exit 2
wenzelm@2301
    17
}
wenzelm@2301
    18
wenzelm@2301
    19
wenzelm@2301
    20
wenzelm@2301
    21
## locations and settings
wenzelm@2301
    22
wenzelm@2301
    23
ML_QUIT=";PolyML.quit();"
wenzelm@2301
    24
ML_DBASE=$ML_HOME/ML_dbase
wenzelm@2301
    25
POLY=$ML_HOME/poly
wenzelm@2301
    26
DISCGARB=$ML_HOME/discgarb
wenzelm@2301
    27
wenzelm@2301
    28
case "$ML_SYSTEM" in
wenzelm@2301
    29
  polyml-3.1)
wenzelm@2314
    30
    DISCGARB="$DISCGARB -c"
wenzelm@2301
    31
    export LM_LICENSE_FILE=$ML_HOME/license.dat
wenzelm@2301
    32
    ;;
wenzelm@2301
    33
esac
wenzelm@2301
    34
wenzelm@2301
    35
wenzelm@2301
    36
wenzelm@2301
    37
## prepare databases
wenzelm@2301
    38
wenzelm@2301
    39
if [ -z "$INFILE" ]; then
wenzelm@2301
    40
  INFILE="$ML_DBASE"
wenzelm@2301
    41
  MLTEXT="val use = PolyML.use; val exit = PolyML.exit; $MLTEXT"
wenzelm@2301
    42
fi
wenzelm@2301
    43
wenzelm@2301
    44
function fail_out()
wenzelm@2301
    45
{
wenzelm@2301
    46
  fail "Unable to create output heap file: \"$OUTFILE\""
wenzelm@2301
    47
}
wenzelm@2301
    48
wenzelm@2301
    49
if [ -z "$OUTFILE" ]; then
wenzelm@2301
    50
  DB="$INFILE"
wenzelm@2301
    51
  OPTS="-r"  
wenzelm@2301
    52
elif [ "$INFILE" = "$OUTFILE" ]; then           # FIXME -ef !?
wenzelm@2301
    53
  DB="$INFILE"
wenzelm@2301
    54
  OPTS=""
wenzelm@2301
    55
elif [ -n "$COPYDB" ]; then
wenzelm@2301
    56
  cp "$INFILE" "$OUTFILE" || fail_out
wenzelm@2301
    57
  chmod +w "$OUTFILE"
wenzelm@2301
    58
  DB="$OUTFILE"
wenzelm@2301
    59
  OPTS=""
wenzelm@2301
    60
else
wenzelm@2301
    61
  [ -f "$OUTFILE" ] && { rm "$OUTFILE" || fail_out }
wenzelm@2301
    62
  echo "PolyML.make_database \"$OUTFILE\"; $ML_QUIT" | $POLY -r "$INFILE"
wenzelm@2301
    63
  [ -f "$OUTFILE" ] || fail_out
wenzelm@2301
    64
  DB="$OUTFILE"
wenzelm@2301
    65
  OPTS=""
wenzelm@2301
    66
fi
wenzelm@2301
    67
wenzelm@2301
    68
wenzelm@2301
    69
wenzelm@2301
    70
## run it!
wenzelm@2301
    71
wenzelm@2301
    72
START_POLY="$POLY $OPTS $ML_OPTIONS $OPTIONS $DB"
wenzelm@2301
    73
wenzelm@2301
    74
if [ -n "$TERMINATE" ]; then
wenzelm@2301
    75
  echo "$MLTEXT" "$ML_QUIT" | $START_POLY
wenzelm@2301
    76
  RC=$?
wenzelm@2301
    77
elif [ -z "$MLTEXT" ]; then
wenzelm@2301
    78
  $START_POLY
wenzelm@2301
    79
  RC=$?
wenzelm@2301
    80
else
wenzelm@2301
    81
  TMP_FILE=/tmp/mltext-$$
wenzelm@2301
    82
  echo "$MLTEXT" >$TMP_FILE
wenzelm@2314
    83
  $ISABELLE_HOME/lib/scripts/ucat $TMP_FILE - | $START_POLY
wenzelm@2301
    84
  RC=$?
wenzelm@2301
    85
  rm $TMP_FILE
wenzelm@2301
    86
fi
wenzelm@2301
    87
wenzelm@2314
    88
[ $RC -eq 0 -a -n "$OUTFILE" ] && $DISCGARB "$OUTFILE"
wenzelm@2301
    89
wenzelm@2301
    90
exit $RC