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