bin/isabelle-process
author wenzelm
Sat Dec 15 17:53:32 2007 +0100 (2007-12-15)
changeset 25645 b2ed983a5e80
parent 25523 08b0feb07239
child 27201 e0323036bcf2
permissions -rwxr-xr-x
non-ML session: run with 'nice', to prevent isabelle process from flooding interactive front-ends (ProofGeneral/XEmacs etc.)
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
#
wenzelm@11550
     6
# Isabelle process startup script.
wenzelm@11550
     7
wenzelm@15843
     8
if [ -L "$0" ]; then
wenzelm@15843
     9
  TARGET="$(LC_ALL=C ls -l "$0" | sed 's/.* -> //')"
wenzelm@15967
    10
  exec "$(cd "$(dirname "$0")"; cd "$(pwd -P)"; cd "$(dirname "$TARGET")"; pwd)/$(basename "$TARGET")" "$@"
wenzelm@15843
    11
fi
wenzelm@15843
    12
wenzelm@11550
    13
wenzelm@11550
    14
## settings
wenzelm@11550
    15
wenzelm@11550
    16
PRG="$(basename "$0")"
wenzelm@11550
    17
wenzelm@15967
    18
ISABELLE_HOME="$(cd "$(dirname "$0")"; cd "$(pwd -P)"; cd ..; pwd)"
wenzelm@15967
    19
source "$ISABELLE_HOME/lib/scripts/getsettings" || exit 2
wenzelm@11550
    20
wenzelm@11550
    21
wenzelm@11550
    22
## diagnostics
wenzelm@11550
    23
wenzelm@11550
    24
function usage()
wenzelm@11550
    25
{
wenzelm@11550
    26
  echo
wenzelm@11550
    27
  echo "Usage: $PRG [OPTIONS] [INPUT] [OUTPUT]"
wenzelm@11550
    28
  echo
wenzelm@11550
    29
  echo "  Options are:"
wenzelm@11550
    30
  echo "    -C           tell ML system to copy output image"
wenzelm@11550
    31
  echo "    -I           startup Isar interaction mode"
wenzelm@11550
    32
  echo "    -P           startup Proof General interaction mode"
wenzelm@20929
    33
  echo "    -S           secure mode -- disallow critical operations"
aspinall@16101
    34
  echo "    -X           startup PGIP interaction mode"
wenzelm@25523
    35
  echo "    -W           startup process wrapper (interaction via external program)"
wenzelm@11550
    36
  echo "    -c           tell ML system to compress output image"
wenzelm@11550
    37
  echo "    -e MLTEXT    pass MLTEXT to the ML session"
wenzelm@11550
    38
  echo "    -f           pass 'Session.finish();' to the ML session"
wenzelm@11550
    39
  echo "    -m MODE      add print mode for output"
wenzelm@11550
    40
  echo "    -q           non-interactive session"
wenzelm@11550
    41
  echo "    -r           open heap file read-only"
wenzelm@11550
    42
  echo "    -u           pass 'use\"ROOT.ML\";' to the ML session"
wenzelm@11550
    43
  echo "    -w           reset write permissions on OUTPUT"
wenzelm@11550
    44
  echo
wenzelm@11550
    45
  echo "  INPUT (default \"$ISABELLE_LOGIC\") and OUTPUT specify in/out heaps."
wenzelm@11550
    46
  echo "  These are either names to be searched in the Isabelle path, or"
wenzelm@11550
    47
  echo "  actual file names (containing at least one /)."
wenzelm@11550
    48
  echo "  If INPUT is \"RAW_ML_SYSTEM\", just start the bare bones ML system."
wenzelm@11550
    49
  echo
wenzelm@11550
    50
  exit 1
wenzelm@11550
    51
}
wenzelm@11550
    52
wenzelm@11550
    53
function fail()
wenzelm@11550
    54
{
wenzelm@11550
    55
  echo "$1" >&2
wenzelm@11550
    56
  exit 2
wenzelm@11550
    57
}
wenzelm@11550
    58
wenzelm@11550
    59
wenzelm@11550
    60
## process command line
wenzelm@11550
    61
wenzelm@11550
    62
# options
wenzelm@11550
    63
wenzelm@11550
    64
COPYDB=""
wenzelm@11550
    65
ISAR=false
wenzelm@11550
    66
PROOFGENERAL=""
wenzelm@20923
    67
SECURE=""
wenzelm@25523
    68
WRAPPER=""
wenzelm@25523
    69
PGIP=""
wenzelm@11550
    70
COMPRESS=""
wenzelm@11550
    71
MLTEXT=""
wenzelm@11550
    72
MODES=""
wenzelm@11550
    73
TERMINATE=""
wenzelm@11550
    74
READONLY=""
wenzelm@11550
    75
NOWRITE=""
wenzelm@11550
    76
wenzelm@25523
    77
while getopts "CIPSWXce:fm:qruw" OPT
wenzelm@11550
    78
do
wenzelm@11550
    79
  case "$OPT" in
wenzelm@11550
    80
    C)
wenzelm@11550
    81
      COPYDB=true
wenzelm@11550
    82
      ;;
wenzelm@11550
    83
    I)
wenzelm@11550
    84
      ISAR=true
wenzelm@11550
    85
      ;;
wenzelm@11550
    86
    P)
wenzelm@11550
    87
      PROOFGENERAL=true
wenzelm@11550
    88
      ;;
wenzelm@20923
    89
    S)
wenzelm@20923
    90
      SECURE=true
wenzelm@20923
    91
      ;;
wenzelm@25523
    92
    W)
wenzelm@25523
    93
      WRAPPER=true
wenzelm@25523
    94
      ;;
aspinall@16101
    95
    X)
aspinall@16101
    96
      PGIP=true
aspinall@16101
    97
      ;;
wenzelm@11550
    98
    c)
wenzelm@11550
    99
      COMPRESS=true
wenzelm@11550
   100
      ;;
wenzelm@11550
   101
    e)
wenzelm@11550
   102
      MLTEXT="$MLTEXT $OPTARG"
wenzelm@11550
   103
      ;;
wenzelm@11550
   104
    f)
wenzelm@11550
   105
      MLTEXT="$MLTEXT Session.finish();"
wenzelm@11550
   106
      ;;
wenzelm@11550
   107
    m)
wenzelm@11550
   108
      if [ -z "$MODES" ]; then
wenzelm@11550
   109
        MODES="\"$OPTARG\""
wenzelm@11550
   110
      else
wenzelm@11550
   111
        MODES="\"$OPTARG\", $MODES"
wenzelm@11550
   112
      fi
wenzelm@11550
   113
      ;;
wenzelm@11550
   114
    q)
wenzelm@11550
   115
      TERMINATE=true
wenzelm@11550
   116
      ;;
wenzelm@11550
   117
    r)
wenzelm@11550
   118
      READONLY=true
wenzelm@11550
   119
      ;;
wenzelm@11550
   120
    u)
wenzelm@11550
   121
      MLTEXT="$MLTEXT use\"ROOT.ML\";"
wenzelm@11550
   122
      ;;
wenzelm@11550
   123
    w)
wenzelm@11550
   124
      NOWRITE=true
wenzelm@11550
   125
      ;;
wenzelm@11550
   126
    \?)
wenzelm@11550
   127
      usage
wenzelm@11550
   128
      ;;
wenzelm@11550
   129
  esac
wenzelm@11550
   130
done
wenzelm@11550
   131
wenzelm@11550
   132
shift $(($OPTIND - 1))
wenzelm@11550
   133
wenzelm@11550
   134
wenzelm@11550
   135
# args
wenzelm@11550
   136
wenzelm@11550
   137
INPUT=""
wenzelm@11550
   138
OUTPUT=""
wenzelm@11550
   139
wenzelm@11550
   140
if [ "$#" -ge 1 ]; then
wenzelm@11550
   141
  INPUT="$1"
wenzelm@11550
   142
  shift
wenzelm@11550
   143
fi
wenzelm@11550
   144
wenzelm@11550
   145
if [ "$#" -ge 1 ]; then
wenzelm@11550
   146
  OUTPUT="$1"
wenzelm@11550
   147
  shift
wenzelm@11550
   148
fi
wenzelm@11550
   149
wenzelm@11550
   150
[ "$#" -ne 0 ] && { echo "Bad args: $*"; usage; }
wenzelm@11550
   151
wenzelm@11550
   152
wenzelm@11550
   153
## check ML system
wenzelm@11550
   154
wenzelm@11550
   155
[ -z "$ML_SYSTEM" ] && fail "Missing ML system settings! Unable to run Isabelle."
wenzelm@11550
   156
wenzelm@11550
   157
wenzelm@11550
   158
## input heap file
wenzelm@11550
   159
wenzelm@11550
   160
[ -z "$INPUT" ] && INPUT="$ISABELLE_LOGIC"
wenzelm@11550
   161
wenzelm@11550
   162
case "$INPUT" in
wenzelm@11550
   163
  RAW_ML_SYSTEM)
wenzelm@11550
   164
    INFILE=""
wenzelm@11550
   165
    ;;
wenzelm@11550
   166
  */*)
wenzelm@17792
   167
    INFILE="$INPUT$ML_SUFFIX"
wenzelm@11550
   168
    [ ! -f "$INFILE" ] && fail "Bad heap file: \"$INFILE\""
wenzelm@11550
   169
    ;;
wenzelm@11550
   170
  *)
wenzelm@11550
   171
    INFILE=""
wenzelm@11550
   172
    ISA_PATH=""
wenzelm@11550
   173
wenzelm@11550
   174
    ORIG_IFS="$IFS"
wenzelm@11550
   175
    IFS=":"
wenzelm@11550
   176
    for DIR in $ISABELLE_PATH
wenzelm@11550
   177
    do
wenzelm@11550
   178
      DIR="$DIR/$ML_IDENTIFIER"
wenzelm@11550
   179
      ISA_PATH="$ISA_PATH  $DIR\n"
wenzelm@17792
   180
      [ -z "$INFILE" -a -f "$DIR/$INPUT$ML_SUFFIX" ] && INFILE="$DIR/$INPUT$ML_SUFFIX"
wenzelm@11550
   181
    done
wenzelm@11550
   182
    IFS="$ORIG_IFS"
wenzelm@11550
   183
wenzelm@11550
   184
    if [ -z "$INFILE" ]; then
wenzelm@11550
   185
      echo "Unknown logic \"$INPUT\" -- no heap file found in:" >&2
wenzelm@11550
   186
      echo -ne "$ISA_PATH" >&2
wenzelm@11550
   187
      exit 2
wenzelm@11550
   188
    fi
wenzelm@11550
   189
    ;;
wenzelm@11550
   190
esac
wenzelm@11550
   191
wenzelm@11550
   192
wenzelm@11550
   193
## output heap file
wenzelm@11550
   194
wenzelm@11550
   195
case "$OUTPUT" in
wenzelm@11550
   196
  "")
wenzelm@11550
   197
    [ -z "$READONLY" -a -w "$INFILE" ] && OUTFILE="$INFILE"
wenzelm@11550
   198
    ;;
wenzelm@11550
   199
  */*)
wenzelm@17792
   200
    OUTFILE="$OUTPUT$ML_SUFFIX"
wenzelm@11550
   201
    ;;
wenzelm@11550
   202
  *)
wenzelm@11550
   203
    mkdir -p "$ISABELLE_OUTPUT"
wenzelm@17792
   204
    OUTFILE="$ISABELLE_OUTPUT/$OUTPUT$ML_SUFFIX"
wenzelm@11550
   205
    ;;
wenzelm@11550
   206
esac
wenzelm@11550
   207
wenzelm@11550
   208
wenzelm@11550
   209
## prepare tmp directory
wenzelm@11550
   210
wenzelm@11550
   211
[ -z "$ISABELLE_TMP_PREFIX" ] && ISABELLE_TMP_PREFIX=/tmp/isabelle
wenzelm@16874
   212
ISABELLE_PID="$$"
wenzelm@17792
   213
ISABELLE_TMP="$ISABELLE_TMP_PREFIX$ISABELLE_PID"
wenzelm@16874
   214
mkdir -p "$ISABELLE_TMP"
wenzelm@11550
   215
wenzelm@11550
   216
wenzelm@11550
   217
## run it!
wenzelm@11550
   218
wenzelm@11550
   219
ML_SYSTEM_BASE=$(echo "$ML_SYSTEM" | cut -f1 -d-)
wenzelm@11550
   220
wenzelm@11550
   221
[ -n "$MODES" ] && MLTEXT="print_mode := [$MODES]; $MLTEXT"
wenzelm@11550
   222
wenzelm@20923
   223
[ -n "$SECURE" ] && MLTEXT="$MLTEXT Secure.set_secure ();"
wenzelm@20923
   224
wenzelm@25645
   225
NICE="nice"
wenzelm@25523
   226
if [ -n "$WRAPPER" ]; then
wenzelm@25523
   227
  MLTEXT="$MLTEXT; IsabelleProcess.init();"
wenzelm@25523
   228
elif [ -n "$PGIP" ]; then
aspinall@21639
   229
  MLTEXT="$MLTEXT; ProofGeneralPgip.init_pgip $ISAR;"
aspinall@16101
   230
elif [ -n "$PROOFGENERAL" ]; then
wenzelm@11550
   231
  MLTEXT="$MLTEXT; ProofGeneral.init $ISAR;"
wenzelm@11550
   232
elif [ "$ISAR" = true ]; then
wenzelm@11550
   233
  MLTEXT="$MLTEXT; Isar.main();"
wenzelm@25645
   234
else
wenzelm@25645
   235
  NICE=""
wenzelm@11550
   236
fi
wenzelm@11550
   237
wenzelm@16874
   238
export INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE \
wenzelm@16874
   239
  ISABELLE_PID ISABELLE_TMP
wenzelm@11550
   240
wenzelm@11550
   241
if [ -f "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM" ]; then
wenzelm@25645
   242
  $NICE "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM"
wenzelm@11550
   243
else
wenzelm@25645
   244
  $NICE "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM_BASE"
wenzelm@11550
   245
fi
wenzelm@11550
   246
RC="$?"
wenzelm@11550
   247
wenzelm@11550
   248
rmdir "$ISABELLE_TMP"
wenzelm@11550
   249
wenzelm@11550
   250
exit "$RC"