lib/scripts/run-polyml
author wenzelm
Mon, 01 Dec 1997 18:22:02 +0100
changeset 4333 1d326b826851
parent 3503 390093b95cb0
child 4505 4a2c872b6513
permissions -rwxr-xr-x
ISABELLE_TMP;

#!/bin/bash
#
# $Id$
#
# Poly/ML startup script.
#
# Global vars: INFILE OUTFILE MLTEXT TERMINATE NOWRITE ISABELLE_TMP,
# and from settings


## diagnostics

function fail_out()
{
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
  exit 2
}


## Poly/ML programs

POLY=$ML_HOME/poly
DISCGARB=$ML_HOME/discgarb

case "$ML_SYSTEM" in
  polyml-3.*)
    DISCGARB="$DISCGARB -c"
    ;;
esac


## prepare databases

COPYDB=true

if [ -z "$INFILE" ]; then
  INFILE="$ML_HOME/ML_dbase"
  MLTEXT="val use = PolyML.use; val exit = PolyML.exit; $MLTEXT"
  COPYDB=""
fi

if [ -z "$OUTFILE" ]; then
  DB="$INFILE"
  ML_OPTIONS="-r $ML_OPTIONS"  
elif [ "$INFILE" -ef "$OUTFILE" ]; then
  DB="$INFILE"
elif [ -n "$COPYDB" ]; then
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
  cp "$INFILE" "$OUTFILE" || fail_out
  chmod +w "$OUTFILE" || fail_out
  DB="$OUTFILE"
else
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
  echo "PolyML.make_database \"$OUTFILE\"; PolyML.quit();" | $POLY -r "$INFILE"
  [ -f "$OUTFILE" ] || fail_out
  DB="$OUTFILE"
fi


## run it!

START_POLY="$POLY $ML_OPTIONS $DB"
DB_INFO=$(ls -l "$DB")

if [ -n "$TERMINATE" ]; then
  echo "$MLTEXT" | $START_POLY
  RC=$?
elif [ -z "$MLTEXT" ]; then
  sh -c "$ISABELLE_HOME/lib/Tools/symbolinput | $START_POLY"
  RC=$?
else
  sh -c "{ echo '$MLTEXT'; $ISABELLE_HOME/lib/Tools/symbolinput; } | $START_POLY"
  RC=$?
fi

NEW_DB_INFO=$(ls -l "$DB")
[ -n "$OUTFILE" -a "$DB_INFO" != "$NEW_DB_INFO" ] && $DISCGARB "$OUTFILE"
[ -n "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"

exit $RC