lib/scripts/run-polyml
author wenzelm
Tue, 21 Nov 2006 18:07:33 +0100
changeset 21437 a3c55b85cf0e
parent 21356 556addc67737
child 25123 8831ca91f43f
permissions -rwxr-xr-x
moved theorem kinds from PureThy to Thm;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10555
2323ec838401 /usr/bin/env bash;
wenzelm
parents: 10206
diff changeset
     1
#!/usr/bin/env 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
2314
67bf78c7c725 replaced cat by ucat;
wenzelm
parents: 2301
diff changeset
     5
#
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
     6
# Poly/ML startup script.
9977
32955afeb835 unexport exports;
wenzelm
parents: 9789
diff changeset
     7
10105
f9be78009930 added COPYDB argument;
wenzelm
parents: 9997
diff changeset
     8
export -n INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
     9
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    10
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    11
## diagnostics
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    12
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    13
function fail_out()
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    14
{
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    15
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    16
  exit 2
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    17
}
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    18
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    19
function check_file()
5063
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    20
{
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    21
  if [ ! -f "$1" ]; then
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    22
    echo "Unable to locate $1" >&2
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    23
    echo "Please check your ML system settings!" >&2
5063
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    24
    exit 2
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    25
  fi
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    26
}
d45ec8d00ab0 check_mlhome_file;
wenzelm
parents: 4505
diff changeset
    27
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    28
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    29
## Poly/ML executable and database
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    30
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    31
ML_DBASE_PREFIX=""
16374
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    32
21356
556addc67737 removed old cygwin wrappers;
wenzelm
parents: 18166
diff changeset
    33
POLY="$ML_HOME/poly"
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    34
check_file "$POLY"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    35
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    36
if [ -z "$ML_DBASE" ]; then
21356
556addc67737 removed old cygwin wrappers;
wenzelm
parents: 18166
diff changeset
    37
  if [ ! -e "$ML_HOME/ML_dbase" -a "$(basename "$ML_HOME")" = bin ]; then
17051
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    38
    ML_DBASE_HOME="$(cd "$ML_HOME"; cd "$(pwd -P)"; cd ../lib/poly; pwd)"
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    39
  else
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    40
    ML_DBASE_HOME="$ML_HOME"
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    41
  fi
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    42
  if [ -z "$COPYDB" ]; then
17051
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    43
    ML_DBASE_PREFIX="$ML_DBASE_HOME/"
21356
556addc67737 removed old cygwin wrappers;
wenzelm
parents: 18166
diff changeset
    44
    ML_DBASE="ML_dbase"
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    45
  else
21356
556addc67737 removed old cygwin wrappers;
wenzelm
parents: 18166
diff changeset
    46
    ML_DBASE="$ML_DBASE_HOME/ML_dbase"
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    47
  fi
21356
556addc67737 removed old cygwin wrappers;
wenzelm
parents: 18166
diff changeset
    48
  export POLYPATH="$ML_DBASE_HOME"
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    49
else
21356
556addc67737 removed old cygwin wrappers;
wenzelm
parents: 18166
diff changeset
    50
  export POLYPATH="$(dirname "$ML_DBASE")"
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    51
fi
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    52
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    53
DISCGARB_OPTIONS="-d -c"
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    54
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    55
EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
9765
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    56
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    57
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    58
## prepare databases
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    59
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    60
if [ -z "$INFILE" ]; then
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    61
  check_file "$ML_DBASE_PREFIX$ML_DBASE"
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    62
  INFILE="$ML_DBASE"
9765
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    63
  MLTEXT="val use = PolyML.use; $EXIT $MLTEXT"
16285
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    64
  case "$ML_SYSTEM" in
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    65
    polyml-4.1.[12])
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    66
      DISCGARB_OPTIONS="$DISCGARB_OPTIONS -S 180"
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    67
      ;;
18166
b7c3136f604d support for polyml-4.2.0;
wenzelm
parents: 17051
diff changeset
    68
    polyml-4.1.[34] | polyml-4.2.*)
16285
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    69
      DISCGARB_OPTIONS="$DISCGARB_OPTIONS -S max"
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    70
      ;;
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    71
  esac
10105
f9be78009930 added COPYDB argument;
wenzelm
parents: 9997
diff changeset
    72
else
f9be78009930 added COPYDB argument;
wenzelm
parents: 9997
diff changeset
    73
  COPYDB=true
2301
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
if [ -z "$OUTFILE" ]; then
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    77
  DB="$INFILE"
15850
30e878979457 no longer need feeder to run normal interactive sessions;
wenzelm
parents: 14981
diff changeset
    78
  ML_OPTIONS="-r $ML_OPTIONS"
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    79
elif [ "$INFILE" -ef "$OUTFILE" ]; then
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    80
  DB="$INFILE"
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    81
elif [ -n "$COPYDB" ]; then
2936
bd33e7aae062 fixed { ... } shell syntax to accomodate bash 2.x;
wenzelm
parents: 2605
diff changeset
    82
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
2548
b5d19d99a58d 'rm -f' instead of 'cp -f';
wenzelm
parents: 2400
diff changeset
    83
  cp "$INFILE" "$OUTFILE" || fail_out
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    84
  chmod +w "$OUTFILE" || fail_out
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    85
  DB="$OUTFILE"
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    86
else
2936
bd33e7aae062 fixed { ... } shell syntax to accomodate bash 2.x;
wenzelm
parents: 2605
diff changeset
    87
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
21356
556addc67737 removed old cygwin wrappers;
wenzelm
parents: 18166
diff changeset
    88
  echo "PolyML.make_database \"$OUTFILE\"; PolyML.quit();" | "$POLY" -r "$INFILE"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    89
  [ -f "$OUTFILE" ] || fail_out
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    90
  DB="$OUTFILE"
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    91
fi
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    92
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    93
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    94
## run it!
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    95
16969
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
    96
case "$ML_SYSTEM" in
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
    97
  polyml-4.1.[12])
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
    98
    ;;
18166
b7c3136f604d support for polyml-4.2.0;
wenzelm
parents: 17051
diff changeset
    99
  polyml-4.1.[34] | polyml-4.2.*)
16969
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
   100
    MLTEXT="PolyML.Compiler.printInAlphabeticalOrder := false; $MLTEXT"
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
   101
    ;;
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
   102
esac
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
   103
16254
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   104
if [ -z "$TERMINATE" ]; then
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   105
  FEEDER_OPTS=""
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   106
else
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   107
  FEEDER_OPTS="-q"
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   108
fi
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   109
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
   110
DB_INFO="$(ls -l "$DB" 2>/dev/null)"
15850
30e878979457 no longer need feeder to run normal interactive sessions;
wenzelm
parents: 14981
diff changeset
   111
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
   112
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" $FEEDER_OPTS | {
21356
556addc67737 removed old cygwin wrappers;
wenzelm
parents: 18166
diff changeset
   113
  read FPID; "$POLY" $ML_OPTIONS "$DB";
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
   114
  RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
9789
wenzelm
parents: 9765
diff changeset
   115
RC="$?"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
   116
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
   117
NEW_DB_INFO="$(ls -l "$DB" 2>/dev/null)"
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
   118
[ -n "$OUTFILE" -a -n "$COMPRESS" -a "$DB_INFO" != "$NEW_DB_INFO" ] && \
16393
4bc08baa3fbb use POLY instead of DISCGARB;
wenzelm
parents: 16392
diff changeset
   119
  "$POLY" $DISCGARB_OPTIONS "$OUTFILE"
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4333
diff changeset
   120
[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
   121
9789
wenzelm
parents: 9765
diff changeset
   122
exit "$RC"