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;
     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 "    -p           echo ISABELLE_PID on startup"
    40   echo "    -q           non-interactive session"
    41   echo "    -r           open heap file read-only"
    42   echo "    -u           pass 'use\"ROOT.ML\";' to the ML session"
    43   echo "    -w           reset write permissions on OUTPUT"
    44   echo
    45   echo "  INPUT (default \"$ISABELLE_LOGIC\") and OUTPUT specify in/out heaps."
    46   echo "  These are either names to be searched in the Isabelle path, or"
    47   echo "  actual file names (containing at least one /)."
    48   echo "  If INPUT is \"RAW_ML_SYSTEM\", just start the bare bones ML system."
    49   echo
    50   exit 1
    51 }
    52 
    53 function fail()
    54 {
    55   echo "$1" >&2
    56   exit 2
    57 }
    58 
    59 
    60 ## process command line
    61 
    62 # options
    63 
    64 COPYDB=""
    65 ISAR=false
    66 PROOFGENERAL=""
    67 SECURE=""
    68 COMPRESS=""
    69 MLTEXT=""
    70 MODES=""
    71 ECHOPID=""
    72 TERMINATE=""
    73 READONLY=""
    74 NOWRITE=""
    75 
    76 while getopts "XCIPSce:fm:pqruw" OPT
    77 do
    78   case "$OPT" in
    79     C)
    80       COPYDB=true
    81       ;;
    82     I)
    83       ISAR=true
    84       ;;
    85     P)
    86       PROOFGENERAL=true
    87       ;;
    88     S)
    89       SECURE=true
    90       ;;
    91     X)
    92       PGIP=true
    93       ;;
    94     c)
    95       COMPRESS=true
    96       ;;
    97     e)
    98       MLTEXT="$MLTEXT $OPTARG"
    99       ;;
   100     f)
   101       MLTEXT="$MLTEXT Session.finish();"
   102       ;;
   103     m)
   104       if [ -z "$MODES" ]; then
   105         MODES="\"$OPTARG\""
   106       else
   107         MODES="\"$OPTARG\", $MODES"
   108       fi
   109       ;;
   110     p)
   111       ECHOPID=true
   112       ;;
   113     q)
   114       TERMINATE=true
   115       ;;
   116     r)
   117       READONLY=true
   118       ;;
   119     u)
   120       MLTEXT="$MLTEXT use\"ROOT.ML\";"
   121       ;;
   122     w)
   123       NOWRITE=true
   124       ;;
   125     \?)
   126       usage
   127       ;;
   128   esac
   129 done
   130 
   131 shift $(($OPTIND - 1))
   132 
   133 
   134 # args
   135 
   136 INPUT=""
   137 OUTPUT=""
   138 
   139 if [ "$#" -ge 1 ]; then
   140   INPUT="$1"
   141   shift
   142 fi
   143 
   144 if [ "$#" -ge 1 ]; then
   145   OUTPUT="$1"
   146   shift
   147 fi
   148 
   149 [ "$#" -ne 0 ] && { echo "Bad args: $*"; usage; }
   150 
   151 
   152 ## check ML system
   153 
   154 [ -z "$ML_SYSTEM" ] && fail "Missing ML system settings! Unable to run Isabelle."
   155 
   156 
   157 ## input heap file
   158 
   159 [ -z "$INPUT" ] && INPUT="$ISABELLE_LOGIC"
   160 
   161 case "$INPUT" in
   162   RAW_ML_SYSTEM)
   163     INFILE=""
   164     ;;
   165   */*)
   166     INFILE="$INPUT$ML_SUFFIX"
   167     [ ! -f "$INFILE" ] && fail "Bad heap file: \"$INFILE\""
   168     ;;
   169   *)
   170     INFILE=""
   171     ISA_PATH=""
   172 
   173     ORIG_IFS="$IFS"
   174     IFS=":"
   175     for DIR in $ISABELLE_PATH
   176     do
   177       DIR="$DIR/$ML_IDENTIFIER"
   178       ISA_PATH="$ISA_PATH  $DIR\n"
   179       [ -z "$INFILE" -a -f "$DIR/$INPUT$ML_SUFFIX" ] && INFILE="$DIR/$INPUT$ML_SUFFIX"
   180     done
   181     IFS="$ORIG_IFS"
   182 
   183     if [ -z "$INFILE" ]; then
   184       echo "Unknown logic \"$INPUT\" -- no heap file found in:" >&2
   185       echo -ne "$ISA_PATH" >&2
   186       exit 2
   187     fi
   188     ;;
   189 esac
   190 
   191 
   192 ## output heap file
   193 
   194 case "$OUTPUT" in
   195   "")
   196     [ -z "$READONLY" -a -w "$INFILE" ] && OUTFILE="$INFILE"
   197     ;;
   198   */*)
   199     OUTFILE="$OUTPUT$ML_SUFFIX"
   200     ;;
   201   *)
   202     mkdir -p "$ISABELLE_OUTPUT"
   203     OUTFILE="$ISABELLE_OUTPUT/$OUTPUT$ML_SUFFIX"
   204     ;;
   205 esac
   206 
   207 
   208 ## prepare tmp directory
   209 
   210 [ -z "$ISABELLE_TMP_PREFIX" ] && ISABELLE_TMP_PREFIX=/tmp/isabelle
   211 ISABELLE_PID="$$"
   212 ISABELLE_TMP="$ISABELLE_TMP_PREFIX$ISABELLE_PID"
   213 mkdir -p "$ISABELLE_TMP"
   214 
   215 
   216 ## run it!
   217 
   218 ML_SYSTEM_BASE=$(echo "$ML_SYSTEM" | cut -f1 -d-)
   219 
   220 [ -n "$MODES" ] && MLTEXT="print_mode := [$MODES]; $MLTEXT"
   221 
   222 [ -n "$SECURE" ] && MLTEXT="$MLTEXT Secure.set_secure ();"
   223 
   224 if [ -n "$PGIP" ]; then
   225   MLTEXT="$MLTEXT; ProofGeneralPgip.init_pgip $ISAR;"
   226 elif [ -n "$PROOFGENERAL" ]; then
   227   MLTEXT="$MLTEXT; ProofGeneral.init $ISAR;"
   228 elif [ "$ISAR" = true ]; then
   229   MLTEXT="$MLTEXT; Isar.main();"
   230 fi
   231 
   232 export INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE \
   233   ISABELLE_PID ISABELLE_TMP
   234 
   235 [ -n "$ECHOPID" ] && echo "ISABELLE_PID=$ISABELLE_PID"
   236 
   237 if [ -f "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM" ]; then
   238   "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM"
   239 else
   240   "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM_BASE"
   241 fi
   242 RC="$?"
   243 
   244 rmdir "$ISABELLE_TMP"
   245 
   246 exit "$RC"