src/Tools/jEdit/dist-template/interface
author wenzelm
Tue, 02 Jun 2009 21:20:22 +0200
changeset 34582 5d5d253c7c29
parent 34581 abab3a577e10
child 34622 b1b88879c515
permissions -rwxr-xr-x
superficial tuning;

#!/usr/bin/env bash
#
# Isabelle/jEdit interface wrapper

## diagnostics

usage()
{
  echo
  echo "Usage: isabelle jedit [OPTIONS] [FILES ...]"
  echo
  echo "  Options are:"
  echo "    -J OPTION    add JVM runtime option"
  echo "                 (default JEDIT_JAVA_OPTIONS=$JEDIT_JAVA_OPTIONS)"
  echo "    -j OPTION    add jEdit runtime option"
  echo "                 (default JEDIT_OPTIONS=$JEDIT_OPTIONS)"
  echo "    -l NAME      logic image name (default ISABELLE_LOGIC=$ISABELLE_LOGIC)"
  echo "    -m MODE      add print mode for output"
  echo
  echo "Starts jEdit with Isabelle plugin setup and opens theory FILES"
  echo "(default ~/Scratch.thy)."
  echo
  exit 1
}

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


## process command line

# options

JEDIT_LOGIC="$ISABELLE_LOGIC"
JEDIT_PRINT_MODE=""

declare -a JAVA_OPTIONS; eval "JAVA_OPTIONS=($JEDIT_JAVA_OPTIONS)"
declare -a OPTIONS; eval "OPTIONS=($JEDIT_OPTIONS)"

while getopts "J:j:l:m:" OPT
do
  case "$OPT" in
    J)
      JAVA_OPTIONS+=("$OPTARG")
      ;;
    j)
      OPTIONS+=("$OPTARG")
      ;;
    l)
      JEDIT_LOGIC="$OPTARG"
      ;;
    m)
      if [ -z "$PRINT_MODE" ]; then
        PRINT_MODE="$OPTARG"
      else
        PRINT_MODE="$PRINT_MODE,$OPTARG"
      fi
      ;;
    \?)
      usage
      ;;
  esac
done

shift $(($OPTIND - 1))


# args

declare -a FILES=()

if [ "$#" -eq 0 ]; then
  FILES+=("isabelle:$HOME/Scratch.thy")
else
  while [ "$#" -gt 0 ]; do
    FILES+=("isabelle:$1")
    shift
  done
fi


## main

case "$JEDIT_LOGIC" in
  /*)
    ;;
  */*)
    JEDIT_LOGIC="$(pwd -P)/$JEDIT_LOGIC"
    ;;
esac

export JEDIT_LOGIC JEDIT_PRINT_MODE

exec "$ISABELLE_TOOL" java "${JAVA_OPTIONS[@]}" \
  -jar "$(jvmpath "$JEDIT_HOME/jedit.jar")" \
  "-settings=$(jvmpath "$ISABELLE_HOME_USER/jedit")" "${OPTIONS[@]}" "${FILES[@]}"