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
     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 "$(dirname "$TARGET")"; pwd)/$(basename "$TARGET")" "$@"
    11 fi
    12 
    13 
    14 ## settings
    15 
    16 PRG="$(basename "$0")"
    17 
    18 ISABELLE_HOME="$(dirname "$0")/.."
    19 . "$ISABELLE_HOME/lib/scripts/getsettings" || \
    20   { echo "$PRG probably not called from its original place!"; exit 2; }
    21 
    22 
    23 ## diagnostics
    24 
    25 function usage()
    26 {
    27   echo
    28   echo "Usage: $PRG [OPTIONS] [INPUT] [OUTPUT]"
    29   echo
    30   echo "  Options are:"
    31   echo "    -C           tell ML system to copy output image"
    32   echo "    -I           startup Isar interaction mode"
    33   echo "    -P           startup Proof General 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 "CIPce: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     c)
    85       COMPRESS=true
    86       ;;
    87     e)
    88       MLTEXT="$MLTEXT $OPTARG"
    89       ;;
    90     f)
    91       MLTEXT="$MLTEXT Session.finish();"
    92       ;;
    93     m)
    94       if [ -z "$MODES" ]; then
    95         MODES="\"$OPTARG\""
    96       else
    97         MODES="\"$OPTARG\", $MODES"
    98       fi
    99       ;;
   100     q)
   101       TERMINATE=true
   102       ;;
   103     r)
   104       READONLY=true
   105       ;;
   106     u)
   107       MLTEXT="$MLTEXT use\"ROOT.ML\";"
   108       ;;
   109     w)
   110       NOWRITE=true
   111       ;;
   112     \?)
   113       usage
   114       ;;
   115   esac
   116 done
   117 
   118 shift $(($OPTIND - 1))
   119 
   120 
   121 # args
   122 
   123 INPUT=""
   124 OUTPUT=""
   125 
   126 if [ "$#" -ge 1 ]; then
   127   INPUT="$1"
   128   shift
   129 fi
   130 
   131 if [ "$#" -ge 1 ]; then
   132   OUTPUT="$1"
   133   shift
   134 fi
   135 
   136 [ "$#" -ne 0 ] && { echo "Bad args: $*"; usage; }
   137 
   138 
   139 ## check ML system
   140 
   141 [ -z "$ML_SYSTEM" ] && fail "Missing ML system settings! Unable to run Isabelle."
   142 
   143 
   144 ## input heap file
   145 
   146 [ -z "$INPUT" ] && INPUT="$ISABELLE_LOGIC"
   147 
   148 case "$INPUT" in
   149   RAW_ML_SYSTEM)
   150     INFILE=""
   151     ;;
   152   */*)
   153     INFILE="$INPUT"
   154     [ ! -f "$INFILE" ] && fail "Bad heap file: \"$INFILE\""
   155     ;;
   156   *)
   157     INFILE=""
   158     ISA_PATH=""
   159 
   160     ORIG_IFS="$IFS"
   161     IFS=":"
   162     for DIR in $ISABELLE_PATH
   163     do
   164       DIR="$DIR/$ML_IDENTIFIER"
   165       ISA_PATH="$ISA_PATH  $DIR\n"
   166       [ -z "$INFILE" -a -f "$DIR/$INPUT" ] && INFILE="$DIR/$INPUT"
   167     done
   168     IFS="$ORIG_IFS"
   169 
   170     if [ -z "$INFILE" ]; then
   171       echo "Unknown logic \"$INPUT\" -- no heap file found in:" >&2
   172       echo -ne "$ISA_PATH" >&2
   173       exit 2
   174     fi
   175     ;;
   176 esac
   177 
   178 
   179 ## output heap file
   180 
   181 case "$OUTPUT" in
   182   "")
   183     [ -z "$READONLY" -a -w "$INFILE" ] && OUTFILE="$INFILE"
   184     ;;
   185   */*)
   186     OUTFILE="$OUTPUT"
   187     ;;
   188   *)
   189     mkdir -p "$ISABELLE_OUTPUT"
   190     OUTFILE="$ISABELLE_OUTPUT/$OUTPUT"
   191     ;;
   192 esac
   193 
   194 
   195 ## prepare tmp directory
   196 
   197 [ -z "$ISABELLE_TMP_PREFIX" ] && ISABELLE_TMP_PREFIX=/tmp/isabelle
   198 
   199 ISABELLE_TMP="$ISABELLE_TMP_PREFIX$$"
   200 mkdir -p "$ISABELLE_TMP"
   201 
   202 
   203 ## run it!
   204 
   205 ML_SYSTEM_BASE=$(echo "$ML_SYSTEM" | cut -f1 -d-)
   206 
   207 [ -n "$MODES" ] && MLTEXT="print_mode := [$MODES]; $MLTEXT"
   208 
   209 if [ -n "$PROOFGENERAL" ]; then
   210   MLTEXT="$MLTEXT; ProofGeneral.init $ISAR;"
   211 elif [ "$ISAR" = true ]; then
   212   MLTEXT="$MLTEXT; Isar.main();"
   213 fi
   214 
   215 export INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE ISABELLE_TMP
   216 
   217 if [ -f "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM" ]; then
   218   "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM"
   219 else
   220   "$ISABELLE_HOME/lib/scripts/run-$ML_SYSTEM_BASE"
   221 fi
   222 RC="$?"
   223 
   224 rmdir "$ISABELLE_TMP"
   225 
   226 exit "$RC"