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