lib/scripts/run-polyml
author wenzelm
Wed, 26 Jul 2006 00:44:44 +0200
changeset 20207 4c57e850e8d5
parent 18166 b7c3136f604d
child 21356 556addc67737
permissions -rwxr-xr-x
added Pure/subgoal.ML;
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
ML_DBASE_SUFFIX=""
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    33
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    34
case "$ML_PLATFORM" in
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    35
  *-cygwin)
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    36
    ML_DBASE_SUFFIX=".pmd"
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    37
    POLY="$ML_HOME/PolyML.exe"
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    38
    function fixpath () { cygpath -m "$@"; }
16374
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    39
    ;;
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    40
  *)
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    41
    POLY="$ML_HOME/poly"
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    42
    function fixpath () { echo -n "$@"; }
16374
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    43
    ;;
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    44
esac
f4b7cf8975af some cygwin support;
wenzelm
parents: 16285
diff changeset
    45
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    46
check_file "$POLY"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    47
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    48
if [ -z "$ML_DBASE" ]; then
17051
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    49
  if [ ! -e "$ML_HOME/ML_dbase${ML_DBASE_SUFFIX}" -a "$(basename "$ML_HOME")" = bin ]; then
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    50
    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
    51
  else
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    52
    ML_DBASE_HOME="$ML_HOME"
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    53
  fi
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    54
  if [ -z "$COPYDB" ]; then
17051
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    55
    ML_DBASE_PREFIX="$ML_DBASE_HOME/"
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    56
    ML_DBASE="ML_dbase${ML_DBASE_SUFFIX}"
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    57
  else
17051
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    58
    ML_DBASE="$ML_DBASE_HOME/ML_dbase${ML_DBASE_SUFFIX}"
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    59
  fi
17051
d17cfb0b9ba2 proper ML_DBASE for .../bin/poly;
wenzelm
parents: 16969
diff changeset
    60
  export POLYPATH="$(fixpath "$ML_DBASE_HOME")"
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    61
else
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    62
  export POLYPATH="$(fixpath "$(dirname "$ML_DBASE")")"
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    63
fi
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    64
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    65
DISCGARB_OPTIONS="-d -c"
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    66
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
    67
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
    68
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    69
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    70
## prepare databases
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    71
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    72
if [ -z "$INFILE" ]; then
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    73
  check_file "$ML_DBASE_PREFIX$ML_DBASE"
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
    74
  INFILE="$ML_DBASE"
9765
46def28153d6 improved exit function for polyml-4.0;
wenzelm
parents: 8821
diff changeset
    75
  MLTEXT="val use = PolyML.use; $EXIT $MLTEXT"
16285
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    76
  case "$ML_SYSTEM" in
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    77
    polyml-4.1.[12])
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    78
      DISCGARB_OPTIONS="$DISCGARB_OPTIONS -S 180"
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    79
      ;;
18166
b7c3136f604d support for polyml-4.2.0;
wenzelm
parents: 17051
diff changeset
    80
    polyml-4.1.[34] | polyml-4.2.*)
16285
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    81
      DISCGARB_OPTIONS="$DISCGARB_OPTIONS -S max"
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    82
      ;;
75954ae8b247 DISCGARB_OPTIONS back in od position;
wenzelm
parents: 16254
diff changeset
    83
  esac
10105
f9be78009930 added COPYDB argument;
wenzelm
parents: 9997
diff changeset
    84
else
f9be78009930 added COPYDB argument;
wenzelm
parents: 9997
diff changeset
    85
  COPYDB=true
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    86
fi
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    87
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    88
if [ -z "$OUTFILE" ]; then
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    89
  DB="$INFILE"
15850
30e878979457 no longer need feeder to run normal interactive sessions;
wenzelm
parents: 14981
diff changeset
    90
  ML_OPTIONS="-r $ML_OPTIONS"
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    91
elif [ "$INFILE" -ef "$OUTFILE" ]; then
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    92
  DB="$INFILE"
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    93
elif [ -n "$COPYDB" ]; then
2936
bd33e7aae062 fixed { ... } shell syntax to accomodate bash 2.x;
wenzelm
parents: 2605
diff changeset
    94
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
2548
b5d19d99a58d 'rm -f' instead of 'cp -f';
wenzelm
parents: 2400
diff changeset
    95
  cp "$INFILE" "$OUTFILE" || fail_out
2349
e9475a7be4ad various fixes;
wenzelm
parents: 2314
diff changeset
    96
  chmod +w "$OUTFILE" || fail_out
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    97
  DB="$OUTFILE"
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
    98
else
2936
bd33e7aae062 fixed { ... } shell syntax to accomodate bash 2.x;
wenzelm
parents: 2605
diff changeset
    99
  [ -f "$OUTFILE" ] && { rm -f "$OUTFILE" || fail_out; }
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
   100
  echo "PolyML.make_database \"$(fixpath "$OUTFILE")\"; PolyML.quit();" | "$POLY" -r "$(fixpath "$INFILE")"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
   101
  [ -f "$OUTFILE" ] || fail_out
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
   102
  DB="$OUTFILE"
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
   103
fi
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
   104
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
   105
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
   106
## run it!
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
   107
16969
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
   108
case "$ML_SYSTEM" in
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
   109
  polyml-4.1.[12])
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
   110
    ;;
18166
b7c3136f604d support for polyml-4.2.0;
wenzelm
parents: 17051
diff changeset
   111
  polyml-4.1.[34] | polyml-4.2.*)
16969
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
   112
    MLTEXT="PolyML.Compiler.printInAlphabeticalOrder := false; $MLTEXT"
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
   113
    ;;
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
   114
esac
e26915e01d15 PolyML.Compiler.printInAlphabeticalOrder := false;
wenzelm
parents: 16393
diff changeset
   115
16254
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   116
if [ -z "$TERMINATE" ]; then
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   117
  FEEDER_OPTS=""
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   118
else
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   119
  FEEDER_OPTS="-q"
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   120
fi
1b2683e18fd2 DISCGARB_OPTIONS: proper treatment of specific polyml versions;
wenzelm
parents: 15850
diff changeset
   121
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
   122
DB_INFO="$(ls -l "$DB" 2>/dev/null)"
15850
30e878979457 no longer need feeder to run normal interactive sessions;
wenzelm
parents: 14981
diff changeset
   123
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
   124
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" $FEEDER_OPTS | {
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
   125
  read FPID; "$POLY" $ML_OPTIONS "$(fixpath "$DB")";
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
   126
  RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
9789
wenzelm
parents: 9765
diff changeset
   127
RC="$?"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
   128
16392
7212040b71f2 discontinued polyml-3.x;
wenzelm
parents: 16374
diff changeset
   129
NEW_DB_INFO="$(ls -l "$DB" 2>/dev/null)"
10206
d48a2e324abf accomodate Poly/ML 4.0;
wenzelm
parents: 10105
diff changeset
   130
[ -n "$OUTFILE" -a -n "$COMPRESS" -a "$DB_INFO" != "$NEW_DB_INFO" ] && \
16393
4bc08baa3fbb use POLY instead of DISCGARB;
wenzelm
parents: 16392
diff changeset
   131
  "$POLY" $DISCGARB_OPTIONS "$OUTFILE"
4505
4a2c872b6513 use feeder to pipe into ML;
wenzelm
parents: 4333
diff changeset
   132
[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
2301
c72f4f7236b6 run-polyml: Poly/ML startup script.
wenzelm
parents:
diff changeset
   133
9789
wenzelm
parents: 9765
diff changeset
   134
exit "$RC"