bin/isabelle-process
author wenzelm
Fri Mar 08 16:24:06 2002 +0100 (2002-03-08)
changeset 13049 ce180e5b7fa0
parent 11550 915c5de6480f
child 14712 81362115cedd
permissions -rwxr-xr-x
tuned;
wenzelm@11550
     1
#!/usr/bin/env bash
wenzelm@11550
     2
#
wenzelm@11550
     3
# $Id$
wenzelm@11550
     4
# Author: Markus Wenzel, TU Muenchen
wenzelm@11550
     5
# License: GPL (GNU GENERAL PUBLIC LICENSE)
wenzelm@11550
     6
#
wenzelm@11550
     7
# Isabelle process startup script.
wenzelm@11550
     8
wenzelm@11550
     9
wenzelm@11550
    10
## settings
wenzelm@11550
    11
wenzelm@11550
    12
PRG="$(basename "$0")"
wenzelm@11550
    13
wenzelm@11550
    14
ISABELLE_HOME="$(dirname "$0")/.."
wenzelm@11550
    15
. "$ISABELLE_HOME/lib/scripts/getsettings" || \
wenzelm@11550
    16
  { echo "$PRG probably not called from its original place!"; exit 2; }
wenzelm@11550
    17
wenzelm@11550
    18
wenzelm@11550
    19
## diagnostics
wenzelm@11550
    20
wenzelm@11550
    21
function usage()
wenzelm@11550
    22
{
wenzelm@11550
    23
  echo
wenzelm@11550
    24
  echo "Usage: $PRG [OPTIONS] [INPUT] [OUTPUT]"
wenzelm@11550
    25
  echo
wenzelm@11550
    26
  echo "  Options are:"
wenzelm@11550
    27
  echo "    -C           tell ML system to copy output image"
wenzelm@11550
    28
  echo "    -I           startup Isar interaction mode"
wenzelm@11550
    29
  echo "    -P           startup Proof General interaction mode"
wenzelm@11550
    30
  echo "    -c           tell ML system to compress output image"
wenzelm@11550
    31
  echo "    -e MLTEXT    pass MLTEXT to the ML session"
wenzelm@11550
    32
  echo "    -f           pass 'Session.finish();' to the ML session"
wenzelm@11550
    33
  echo "    -m MODE      add print mode for output"
wenzelm@11550
    34
  echo "    -q           non-interactive session"
wenzelm@11550
    35
  echo "    -r           open heap file read-only"
wenzelm@11550
    36
  echo "    -u           pass 'use\"ROOT.ML\";' to the ML session"
wenzelm@11550
    37
  echo "    -w           reset write permissions on OUTPUT"
wenzelm@11550
    38
  echo
wenzelm@11550
    39
  echo "  INPUT (default \"$ISABELLE_LOGIC\") and OUTPUT specify in/out heaps."
wenzelm@11550
    40
  echo "  These are either names to be searched in the Isabelle path, or"
wenzelm@11550
    41
  echo "  actual file names (containing at least one /)."
wenzelm@11550
    42
  echo "  If INPUT is \"RAW_ML_SYSTEM\", just start the bare bones ML system."
wenzelm@11550
    43
  echo
wenzelm@11550
    44
  exit 1
wenzelm@11550
    45
}
wenzelm@11550
    46
wenzelm@11550
    47
function fail()
wenzelm@11550
    48
{
wenzelm@11550
    49
  echo "$1" >&2
wenzelm@11550
    50
  exit 2
wenzelm@11550
    51
}
wenzelm@11550
    52
wenzelm@11550
    53
wenzelm@11550
    54
## process command line
wenzelm@11550
    55
wenzelm@11550
    56
# options
wenzelm@11550
    57
wenzelm@11550
    58
COPYDB=""
wenzelm@11550
    59
ISAR=false
wenzelm@11550
    60
PROOFGENERAL=""
wenzelm@11550
    61
COMPRESS=""
wenzelm@11550
    62
MLTEXT=""
wenzelm@11550
    63
MODES=""
wenzelm@11550
    64
TERMINATE=""
wenzelm@11550
    65
READONLY=""
wenzelm@11550
    66
NOWRITE=""
wenzelm@11550
    67
wenzelm@11550
    68
while getopts "CIPce:fm:qruw" OPT
wenzelm@11550
    69
do
wenzelm@11550
    70
  case "$OPT" in
wenzelm@11550
    71
    C)
wenzelm@11550
    72
      COPYDB=true
wenzelm@11550
    73
      ;;
wenzelm@11550
    74
    I)
wenzelm@11550
    75
      ISAR=true
wenzelm@11550
    76
      ;;
wenzelm@11550
    77
    P)
wenzelm@11550
    78
      PROOFGENERAL=true
wenzelm@11550
    79
      ;;
wenzelm@11550
    80
    c)
wenzelm@11550
    81
      COMPRESS=true
wenzelm@11550
    82
      ;;
wenzelm@11550
    83
    e)
wenzelm@11550
    84
      MLTEXT="$MLTEXT $OPTARG"
wenzelm@11550
    85
      ;;
wenzelm@11550
    86
    f)
wenzelm@11550
    87
      MLTEXT="$MLTEXT Session.finish();"
wenzelm@11550
    88
      ;;
wenzelm@11550
    89
    m)
wenzelm@11550
    90
      if [ -z "$MODES" ]; then
wenzelm@11550
    91
        MODES="\"$OPTARG\""
wenzelm@11550
    92
      else
wenzelm@11550
    93
        MODES="\"$OPTARG\", $MODES"
wenzelm@11550
    94
      fi
wenzelm@11550
    95
      ;;
wenzelm@11550
    96
    q)
wenzelm@11550
    97
      TERMINATE=true
wenzelm@11550
    98
      ;;
wenzelm@11550
    99
    r)
wenzelm@11550
   100
      READONLY=true
wenzelm@11550
   101
      ;;
wenzelm@11550
   102
    u)
wenzelm@11550
   103
      MLTEXT="$MLTEXT use\"ROOT.ML\";"
wenzelm@11550
   104
      ;;
wenzelm@11550
   105
    w)
wenzelm@11550
   106
      NOWRITE=true
wenzelm@11550
   107
      ;;
wenzelm@11550
   108
    \?)
wenzelm@11550
   109
      usage
wenzelm@11550
   110
      ;;
wenzelm@11550
   111
  esac
wenzelm@11550
   112
done
wenzelm@11550
   113
wenzelm@11550
   114
shift $(($OPTIND - 1))
wenzelm@11550
   115
wenzelm@11550
   116
wenzelm@11550
   117
# args
wenzelm@11550
   118
wenzelm@11550
   119
INPUT=""
wenzelm@11550
   120
OUTPUT=""
wenzelm@11550
   121
wenzelm@11550
   122
if [ "$#" -ge 1 ]; then
wenzelm@11550
   123
  INPUT="$1"
wenzelm@11550
   124
  shift
wenzelm@11550
   125
fi
wenzelm@11550
   126
wenzelm@11550
   127
if [ "$#" -ge 1 ]; then
wenzelm@11550
   128
  OUTPUT="$1"
wenzelm@11550
   129
  shift
wenzelm@11550
   130
fi
wenzelm@11550
   131
wenzelm@11550
   132
[ "$#" -ne 0 ] && { echo "Bad args: $*"; usage; }
wenzelm@11550
   133
wenzelm@11550
   134
wenzelm@11550
   135
## check ML system
wenzelm@11550
   136
wenzelm@11550
   137
[ -z "$ML_SYSTEM" ] && fail "Missing ML system settings! Unable to run Isabelle."
wenzelm@11550
   138
wenzelm@11550
   139
wenzelm@11550
   140
## input heap file
wenzelm@11550
   141
wenzelm@11550
   142
[ -z "$INPUT" ] && INPUT="$ISABELLE_LOGIC"
wenzelm@11550
   143
wenzelm@11550
   144
case "$INPUT" in
wenzelm@11550
   145
  RAW_ML_SYSTEM)
wenzelm@11550
   146
    INFILE=""
wenzelm@11550
   147
    ;;
wenzelm@11550
   148
  */*)
wenzelm@11550
   149
    INFILE="$INPUT"
wenzelm@11550
   150
    [ ! -f "$INFILE" ] && fail "Bad heap file: \"$INFILE\""
wenzelm@11550
   151
    ;;
wenzelm@11550
   152
  *)
wenzelm@11550
   153
    INFILE=""
wenzelm@11550
   154
    ISA_PATH=""
wenzelm@11550
   155
wenzelm@11550
   156
    ORIG_IFS="$IFS"
wenzelm@11550
   157
    IFS=":"
wenzelm@11550
   158
    for DIR in $ISABELLE_PATH
wenzelm@11550
   159
    do
wenzelm@11550
   160
      DIR="$DIR/$ML_IDENTIFIER"
wenzelm@11550
   161
      ISA_PATH="$ISA_PATH  $DIR\n"
wenzelm@11550
   162
      [ -z "$INFILE" -a -f "$DIR/$INPUT" ] && INFILE="$DIR/$INPUT"
wenzelm@11550
   163
    done
wenzelm@11550
   164
    IFS="$ORIG_IFS"
wenzelm@11550
   165
wenzelm@11550
   166
    if [ -z "$INFILE" ]; then
wenzelm@11550
   167
      echo "Unknown logic \"$INPUT\" -- no heap file found in:" >&2
wenzelm@11550
   168
      echo -ne "$ISA_PATH" >&2
wenzelm@11550
   169
      exit 2
wenzelm@11550
   170
    fi
wenzelm@11550
   171
    ;;
wenzelm@11550
   172
esac
wenzelm@11550
   173
wenzelm@11550
   174
wenzelm@11550
   175
## output heap file
wenzelm@11550
   176
wenzelm@11550
   177
case "$OUTPUT" in
wenzelm@11550
   178
  "")
wenzelm@11550
   179
    [ -z "$READONLY" -a -w "$INFILE" ] && OUTFILE="$INFILE"
wenzelm@11550
   180
    ;;
wenzelm@11550
   181
  */*)
wenzelm@11550
   182
    OUTFILE="$OUTPUT"
wenzelm@11550
   183
    ;;
wenzelm@11550
   184
  *)
wenzelm@11550
   185
    mkdir -p "$ISABELLE_OUTPUT"
wenzelm@11550
   186
    OUTFILE="$ISABELLE_OUTPUT/$OUTPUT"
wenzelm@11550
   187
    ;;
wenzelm@11550
   188
esac
wenzelm@11550
   189
wenzelm@11550
   190
wenzelm@11550
   191
## prepare tmp directory
wenzelm@11550
   192
wenzelm@11550
   193
[ -z "$ISABELLE_TMP_PREFIX" ] && ISABELLE_TMP_PREFIX=/tmp/isabelle
wenzelm@11550
   194
wenzelm@11550
   195
ISABELLE_TMP="$ISABELLE_TMP_PREFIX$$"
wenzelm@11550
   196
mkdir -p "$ISABELLE_TMP"
wenzelm@11550
   197
wenzelm@11550
   198
wenzelm@11550
   199
## run it!
wenzelm@11550
   200
wenzelm@11550
   201
ML_SYSTEM_BASE=$(echo "$ML_SYSTEM" | cut -f1 -d-)
wenzelm@11550
   202
wenzelm@11550
   203
[ -n "$MODES" ] && MLTEXT="print_mode := [$MODES]; $MLTEXT"
wenzelm@11550
   204
wenzelm@11550
   205
if [ -n "$PROOFGENERAL" ]; then
wenzelm@11550
   206
  MLTEXT="$MLTEXT; ProofGeneral.init $ISAR;"
wenzelm@11550
   207
elif [ "$ISAR" = true ]; then
wenzelm@11550
   208
  MLTEXT="$MLTEXT; Isar.main();"
wenzelm@11550
   209
fi
wenzelm@11550
   210
wenzelm@11550
   211
export INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE ISABELLE_TMP
wenzelm@11550
   212
wenzelm@11550
   213
if [ -f "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM" ]; then
wenzelm@11550
   214
  "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM"
wenzelm@11550
   215
else
wenzelm@11550
   216
  "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM_BASE"
wenzelm@11550
   217
fi
wenzelm@11550
   218
RC="$?"
wenzelm@11550
   219
wenzelm@11550
   220
rmdir "$ISABELLE_TMP"
wenzelm@11550
   221
wenzelm@11550
   222
exit "$RC"