bin/isabelle-process
author wenzelm
Thu Nov 29 18:09:36 2007 +0100 (2007-11-29)
changeset 25504 dc960d760052
parent 21639 8ab7c4dbb524
child 25523 08b0feb07239
permissions -rwxr-xr-x
isabelle-process: option -p echos ISABELLE_PID;
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@11550
    35
  echo "    -c           tell ML system to compress output image"
wenzelm@11550
    36
  echo "    -e MLTEXT    pass MLTEXT to the ML session"
wenzelm@11550
    37
  echo "    -f           pass 'Session.finish();' to the ML session"
wenzelm@11550
    38
  echo "    -m MODE      add print mode for output"
wenzelm@25504
    39
  echo "    -p           echo ISABELLE_PID on startup"
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@11550
    68
COMPRESS=""
wenzelm@11550
    69
MLTEXT=""
wenzelm@11550
    70
MODES=""
wenzelm@25504
    71
ECHOPID=""
wenzelm@11550
    72
TERMINATE=""
wenzelm@11550
    73
READONLY=""
wenzelm@11550
    74
NOWRITE=""
wenzelm@11550
    75
wenzelm@25504
    76
while getopts "XCIPSce:fm:pqruw" OPT
wenzelm@11550
    77
do
wenzelm@11550
    78
  case "$OPT" in
wenzelm@11550
    79
    C)
wenzelm@11550
    80
      COPYDB=true
wenzelm@11550
    81
      ;;
wenzelm@11550
    82
    I)
wenzelm@11550
    83
      ISAR=true
wenzelm@11550
    84
      ;;
wenzelm@11550
    85
    P)
wenzelm@11550
    86
      PROOFGENERAL=true
wenzelm@11550
    87
      ;;
wenzelm@20923
    88
    S)
wenzelm@20923
    89
      SECURE=true
wenzelm@20923
    90
      ;;
aspinall@16101
    91
    X)
aspinall@16101
    92
      PGIP=true
aspinall@16101
    93
      ;;
wenzelm@11550
    94
    c)
wenzelm@11550
    95
      COMPRESS=true
wenzelm@11550
    96
      ;;
wenzelm@11550
    97
    e)
wenzelm@11550
    98
      MLTEXT="$MLTEXT $OPTARG"
wenzelm@11550
    99
      ;;
wenzelm@11550
   100
    f)
wenzelm@11550
   101
      MLTEXT="$MLTEXT Session.finish();"
wenzelm@11550
   102
      ;;
wenzelm@11550
   103
    m)
wenzelm@11550
   104
      if [ -z "$MODES" ]; then
wenzelm@11550
   105
        MODES="\"$OPTARG\""
wenzelm@11550
   106
      else
wenzelm@11550
   107
        MODES="\"$OPTARG\", $MODES"
wenzelm@11550
   108
      fi
wenzelm@11550
   109
      ;;
wenzelm@25504
   110
    p)
wenzelm@25504
   111
      ECHOPID=true
wenzelm@25504
   112
      ;;
wenzelm@11550
   113
    q)
wenzelm@11550
   114
      TERMINATE=true
wenzelm@11550
   115
      ;;
wenzelm@11550
   116
    r)
wenzelm@11550
   117
      READONLY=true
wenzelm@11550
   118
      ;;
wenzelm@11550
   119
    u)
wenzelm@11550
   120
      MLTEXT="$MLTEXT use\"ROOT.ML\";"
wenzelm@11550
   121
      ;;
wenzelm@11550
   122
    w)
wenzelm@11550
   123
      NOWRITE=true
wenzelm@11550
   124
      ;;
wenzelm@11550
   125
    \?)
wenzelm@11550
   126
      usage
wenzelm@11550
   127
      ;;
wenzelm@11550
   128
  esac
wenzelm@11550
   129
done
wenzelm@11550
   130
wenzelm@11550
   131
shift $(($OPTIND - 1))
wenzelm@11550
   132
wenzelm@11550
   133
wenzelm@11550
   134
# args
wenzelm@11550
   135
wenzelm@11550
   136
INPUT=""
wenzelm@11550
   137
OUTPUT=""
wenzelm@11550
   138
wenzelm@11550
   139
if [ "$#" -ge 1 ]; then
wenzelm@11550
   140
  INPUT="$1"
wenzelm@11550
   141
  shift
wenzelm@11550
   142
fi
wenzelm@11550
   143
wenzelm@11550
   144
if [ "$#" -ge 1 ]; then
wenzelm@11550
   145
  OUTPUT="$1"
wenzelm@11550
   146
  shift
wenzelm@11550
   147
fi
wenzelm@11550
   148
wenzelm@11550
   149
[ "$#" -ne 0 ] && { echo "Bad args: $*"; usage; }
wenzelm@11550
   150
wenzelm@11550
   151
wenzelm@11550
   152
## check ML system
wenzelm@11550
   153
wenzelm@11550
   154
[ -z "$ML_SYSTEM" ] && fail "Missing ML system settings! Unable to run Isabelle."
wenzelm@11550
   155
wenzelm@11550
   156
wenzelm@11550
   157
## input heap file
wenzelm@11550
   158
wenzelm@11550
   159
[ -z "$INPUT" ] && INPUT="$ISABELLE_LOGIC"
wenzelm@11550
   160
wenzelm@11550
   161
case "$INPUT" in
wenzelm@11550
   162
  RAW_ML_SYSTEM)
wenzelm@11550
   163
    INFILE=""
wenzelm@11550
   164
    ;;
wenzelm@11550
   165
  */*)
wenzelm@17792
   166
    INFILE="$INPUT$ML_SUFFIX"
wenzelm@11550
   167
    [ ! -f "$INFILE" ] && fail "Bad heap file: \"$INFILE\""
wenzelm@11550
   168
    ;;
wenzelm@11550
   169
  *)
wenzelm@11550
   170
    INFILE=""
wenzelm@11550
   171
    ISA_PATH=""
wenzelm@11550
   172
wenzelm@11550
   173
    ORIG_IFS="$IFS"
wenzelm@11550
   174
    IFS=":"
wenzelm@11550
   175
    for DIR in $ISABELLE_PATH
wenzelm@11550
   176
    do
wenzelm@11550
   177
      DIR="$DIR/$ML_IDENTIFIER"
wenzelm@11550
   178
      ISA_PATH="$ISA_PATH  $DIR\n"
wenzelm@17792
   179
      [ -z "$INFILE" -a -f "$DIR/$INPUT$ML_SUFFIX" ] && INFILE="$DIR/$INPUT$ML_SUFFIX"
wenzelm@11550
   180
    done
wenzelm@11550
   181
    IFS="$ORIG_IFS"
wenzelm@11550
   182
wenzelm@11550
   183
    if [ -z "$INFILE" ]; then
wenzelm@11550
   184
      echo "Unknown logic \"$INPUT\" -- no heap file found in:" >&2
wenzelm@11550
   185
      echo -ne "$ISA_PATH" >&2
wenzelm@11550
   186
      exit 2
wenzelm@11550
   187
    fi
wenzelm@11550
   188
    ;;
wenzelm@11550
   189
esac
wenzelm@11550
   190
wenzelm@11550
   191
wenzelm@11550
   192
## output heap file
wenzelm@11550
   193
wenzelm@11550
   194
case "$OUTPUT" in
wenzelm@11550
   195
  "")
wenzelm@11550
   196
    [ -z "$READONLY" -a -w "$INFILE" ] && OUTFILE="$INFILE"
wenzelm@11550
   197
    ;;
wenzelm@11550
   198
  */*)
wenzelm@17792
   199
    OUTFILE="$OUTPUT$ML_SUFFIX"
wenzelm@11550
   200
    ;;
wenzelm@11550
   201
  *)
wenzelm@11550
   202
    mkdir -p "$ISABELLE_OUTPUT"
wenzelm@17792
   203
    OUTFILE="$ISABELLE_OUTPUT/$OUTPUT$ML_SUFFIX"
wenzelm@11550
   204
    ;;
wenzelm@11550
   205
esac
wenzelm@11550
   206
wenzelm@11550
   207
wenzelm@11550
   208
## prepare tmp directory
wenzelm@11550
   209
wenzelm@11550
   210
[ -z "$ISABELLE_TMP_PREFIX" ] && ISABELLE_TMP_PREFIX=/tmp/isabelle
wenzelm@16874
   211
ISABELLE_PID="$$"
wenzelm@17792
   212
ISABELLE_TMP="$ISABELLE_TMP_PREFIX$ISABELLE_PID"
wenzelm@16874
   213
mkdir -p "$ISABELLE_TMP"
wenzelm@11550
   214
wenzelm@11550
   215
wenzelm@11550
   216
## run it!
wenzelm@11550
   217
wenzelm@11550
   218
ML_SYSTEM_BASE=$(echo "$ML_SYSTEM" | cut -f1 -d-)
wenzelm@11550
   219
wenzelm@11550
   220
[ -n "$MODES" ] && MLTEXT="print_mode := [$MODES]; $MLTEXT"
wenzelm@11550
   221
wenzelm@20923
   222
[ -n "$SECURE" ] && MLTEXT="$MLTEXT Secure.set_secure ();"
wenzelm@20923
   223
aspinall@16101
   224
if [ -n "$PGIP" ]; then
aspinall@21639
   225
  MLTEXT="$MLTEXT; ProofGeneralPgip.init_pgip $ISAR;"
aspinall@16101
   226
elif [ -n "$PROOFGENERAL" ]; then
wenzelm@11550
   227
  MLTEXT="$MLTEXT; ProofGeneral.init $ISAR;"
wenzelm@11550
   228
elif [ "$ISAR" = true ]; then
wenzelm@11550
   229
  MLTEXT="$MLTEXT; Isar.main();"
wenzelm@11550
   230
fi
wenzelm@11550
   231
wenzelm@16874
   232
export INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE \
wenzelm@16874
   233
  ISABELLE_PID ISABELLE_TMP
wenzelm@11550
   234
wenzelm@25504
   235
[ -n "$ECHOPID" ] && echo "ISABELLE_PID=$ISABELLE_PID"
wenzelm@25504
   236
wenzelm@11550
   237
if [ -f "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM" ]; then
wenzelm@11550
   238
  "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM"
wenzelm@11550
   239
else
wenzelm@11550
   240
  "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM_BASE"
wenzelm@11550
   241
fi
wenzelm@11550
   242
RC="$?"
wenzelm@11550
   243
wenzelm@11550
   244
rmdir "$ISABELLE_TMP"
wenzelm@11550
   245
wenzelm@11550
   246
exit "$RC"