bin/isabelle
author wenzelm
Mon, 01 Dec 2008 17:48:12 +0100
changeset 28934 801098c96f59
parent 28506 3ab515ee4e6f
child 32322 45cb4a86eca2
permissions -rwxr-xr-x
proper check of ISABELLE_TOOLS directories;

#!/usr/bin/env bash
#
# Author: Markus Wenzel, TU Muenchen
#
# Isabelle tool wrapper.

if [ -L "$0" ]; then
  TARGET="$(LC_ALL=C ls -l "$0" | sed 's/.* -> //')"
  exec "$(cd "$(dirname "$0")"; cd "$(pwd -P)"; cd "$(dirname "$TARGET")"; pwd)/$(basename "$TARGET")" "$@"
fi


## settings

PRG="$(basename "$0")"

ISABELLE_HOME="$(cd "$(dirname "$0")"; cd "$(pwd -P)"; cd ..; pwd)"
source "$ISABELLE_HOME/lib/scripts/getsettings" || exit 2


## diagnostics

function usage()
{
  echo
  echo "Usage: $PRG NAME [ARGS ...]"
  echo
  echo "  Start Isabelle tool NAME with ARGS; pass \"-?\" for tool specific help."
  echo
  echo "  Available tools are:"
  (
    ORIG_IFS="$IFS"
    IFS=":"
    for DIR in $ISABELLE_TOOLS
    do
      if [ -d "$DIR" ]; then
        cd "$DIR"
        for T in *
        do
          if [ -f "$T" -a -x "$T" ]; then
            DESCRLINE=$(fgrep DESCRIPTION: "$T" | sed -e 's/^.*DESCRIPTION: *//')
            echo "    $T - $DESCRLINE"
          fi
        done
      fi
    done
    IFS="$ORIG_IFS"
  )
  exit 1
}

function fail()
{
  echo "$1" >&2
  exit 2
}


## args

[ "$#" -lt 1 -o "$1" = "-?" ] && usage

TOOLNAME="$1"
shift


## main

ORIG_IFS="$IFS"
IFS=":"
for DIR in $ISABELLE_TOOLS
do
  TOOL="$DIR/$TOOLNAME"
  [ -f "$TOOL" -a -x "$TOOL" ] && exec "$TOOL" "$@"
done
IFS="$ORIG_IFS"

fail "Unknown Isabelle tool: $TOOLNAME"