lib/scripts/run-polyml
author wenzelm
Thu, 28 Sep 2000 14:41:48 +0200
changeset 10105 f9be78009930
parent 9997 38598a19e701
child 10206 d48a2e324abf
permissions -rwxr-xr-x
added COPYDB argument;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3007
e5efa177ee0c removed -norc;
wenzelm
parents: 2936
diff changeset
     1
#!/bin/bash
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
     2
#
2314
67bf78c7c725 replaced cat by ucat;
wenzelm
parents: 2301
diff changeset
     3
# $Id$
9789
wenzelm
parents: 9765
diff changeset
     4
# Author: Markus Wenzel, TU Muenchen
wenzelm
parents: 9765
diff changeset
     5
# License: GPL (GNU GENERAL PUBLIC LICENSE)
2314
67bf78c7c725 replaced cat by ucat;
wenzelm
parents: 2301
diff changeset
     6
#
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
     7
# Poly/ML startup script.
9977
32955afeb835 unexport exports;
wenzelm
parents: 9789
diff changeset
     8
10105
f9be78009930 added COPYDB argument;
wenzelm
parents: 9997
diff changeset
     9
export -n INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    10
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    11
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    12
## diagnostics
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    13
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    14
function fail_out()
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    15
{
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    16
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    17
  exit 2
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    18
}
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    19
5063
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    20
function check_mlhome_file()
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    21
{
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    22
  if [ ! -f "$1" ]; then
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    23
    echo "Unable to locate $1" >&2
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    24
    echo "Please check your ML_HOME setting!" >&2
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    25
    exit 2
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    26
  fi
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    27
}
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    28
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    29
2400
4b08766bc9d1 added symbolinput filter;
wenzelm
parents: 2389
diff changeset
    30
## Poly/ML programs
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    31
9789
wenzelm
parents: 9765
diff changeset
    32
POLY="$ML_HOME/poly"
wenzelm
parents: 9765
diff changeset
    33
DISCGARB="$ML_HOME/discgarb"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    34
5063
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    35
check_mlhome_file "$POLY"
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    36
check_mlhome_file "$DISCGARB"
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    37
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    38
9765
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    39
case "$ML_SYSTEM" in
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    40
  polyml-4.*)
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    41
    EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    42
    ;;
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    43
  *)
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    44
    EXIT="val exit = PolyML.exit;"
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    45
    ;;
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    46
esac
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    47
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    48
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    49
## prepare databases
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    50
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    51
if [ -z "$INFILE" ]; then
2400
4b08766bc9d1 added symbolinput filter;
wenzelm
parents: 2389
diff changeset
    52
  INFILE="$ML_HOME/ML_dbase"
5063
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    53
  check_mlhome_file "$INFILE"
9765
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    54
  MLTEXT="val use = PolyML.use; $EXIT $MLTEXT"
10105
f9be78009930 added COPYDB argument;
wenzelm
parents: 9997
diff changeset
    55
else
f9be78009930 added COPYDB argument;
wenzelm
parents: 9997
diff changeset
    56
  COPYDB=true
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    57
fi
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    58
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    59
if [ -z "$OUTFILE" ]; then
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    60
  DB="$INFILE"
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    61
  ML_OPTIONS="-r $ML_OPTIONS"  
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    62
elif [ "$INFILE" -ef "$OUTFILE" ]; then
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    63
  DB="$INFILE"
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    64
elif [ -n "$COPYDB" ]; then
2936
bd33e7aae062 fixed { ... } shell syntax to accomodate bash 2.x;
wenzelm
parents: 2605
diff changeset
    65
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
2548
b5d19d99a58d 'rm -f' instead of 'cp -f';
wenzelm
parents: 2400
diff changeset
    66
  cp "$INFILE" "$OUTFILE" || fail_out
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    67
  chmod +w "$OUTFILE" || fail_out
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    68
  DB="$OUTFILE"
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    69
else
2936
bd33e7aae062 fixed { ... } shell syntax to accomodate bash 2.x;
wenzelm
parents: 2605
diff changeset
    70
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
9789
wenzelm
parents: 9765
diff changeset
    71
  echo "PolyML.make_database \"$OUTFILE\"; PolyML.quit();" | "$POLY" -r "$INFILE"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    72
  [ -f "$OUTFILE" ] || fail_out
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    73
  DB="$OUTFILE"
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    74
fi
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    75
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    76
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    77
## run it!
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    78
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4333
diff changeset
    79
if [ -z "$TERMINATE" ]; then
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4333
diff changeset
    80
  FEEDER_OPTS="-s"
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4333
diff changeset
    81
else
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4333
diff changeset
    82
  FEEDER_OPTS="-q"
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4333
diff changeset
    83
fi
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4333
diff changeset
    84
2400
4b08766bc9d1 added symbolinput filter;
wenzelm
parents: 2389
diff changeset
    85
DB_INFO=$(ls -l "$DB")
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    86
9789
wenzelm
parents: 9765
diff changeset
    87
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" $FEEDER_OPTS | \
wenzelm
parents: 9765
diff changeset
    88
  { read FPID; "$POLY" $ML_OPTIONS "$DB"; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
wenzelm
parents: 9765
diff changeset
    89
RC="$?"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    90
2400
4b08766bc9d1 added symbolinput filter;
wenzelm
parents: 2389
diff changeset
    91
NEW_DB_INFO=$(ls -l "$DB")
9789
wenzelm
parents: 9765
diff changeset
    92
[ -n "$OUTFILE" -a -n "$COMPRESS" -a "$DB_INFO" != "$NEW_DB_INFO" ] && "$DISCGARB" -c "$OUTFILE"
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4333
diff changeset
    93
[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    94
9789
wenzelm
parents: 9765
diff changeset
    95
exit "$RC"