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