lib/scripts/run-polyml
author wenzelm
Wed, 08 Mar 2000 17:40:24 +0100
changeset 8360 885a6414b9c8
parent 5063 d45ec8d00ab0
child 8821 b5c3aec69462
permissions -rwxr-xr-x
observe COMPRESS option;

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


## diagnostics

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

function check_mlhome_file()
{
  if [ ! -f "$1" ]; then
    echo "Unable to locate $1" >&2
    echo "Please check your ML_HOME setting!" >&2
    exit 2
  fi
}


## Poly/ML programs

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

check_mlhome_file "$POLY"
check_mlhome_file "$DISCGARB"

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


## prepare databases

COPYDB=true

if [ -z "$INFILE" ]; then
  INFILE="$ML_HOME/ML_dbase"
  check_mlhome_file "$INFILE"
  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!

if [ -z "$TERMINATE" ]; then
  FEEDER_OPTS="-s"
else
  FEEDER_OPTS="-q"
fi

DB_INFO=$(ls -l "$DB")

$ISABELLE_HOME/lib/scripts/feeder -p -h "$MLTEXT" $FEEDER_OPTS | \
  { read FPID; $POLY $ML_OPTIONS "$DB"; RC=$?; kill -HUP $FPID; exit $RC; }
RC=$?

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

exit $RC