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