src/Tools/jEdit/dist-template/lib/Tools/jedit
author wenzelm
Fri, 11 Dec 2009 23:29:18 +0100
changeset 34780 d0ff1c3a91ea
parent 34691 f28c014bcbe3
child 34790 643c48774b17
permissions -rwxr-xr-x
more serious command line handling;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34333
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
     1
#!/usr/bin/env bash
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
     2
#
34664
8f5fbe4a80ff Isabelle component;
wenzelm
parents: 34663
diff changeset
     3
# Author: Makarius
8f5fbe4a80ff Isabelle component;
wenzelm
parents: 34663
diff changeset
     4
#
8f5fbe4a80ff Isabelle component;
wenzelm
parents: 34663
diff changeset
     5
# DESCRIPTION: Isabelle/jEdit interface wrapper
8f5fbe4a80ff Isabelle component;
wenzelm
parents: 34663
diff changeset
     6
34333
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
     7
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
     8
## diagnostics
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
     9
34664
8f5fbe4a80ff Isabelle component;
wenzelm
parents: 34663
diff changeset
    10
PRG="$(basename "$0")"
8f5fbe4a80ff Isabelle component;
wenzelm
parents: 34663
diff changeset
    11
34333
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    12
usage()
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    13
{
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    14
  echo
34664
8f5fbe4a80ff Isabelle component;
wenzelm
parents: 34663
diff changeset
    15
  echo "Usage: isabelle $PRG [OPTIONS] [FILES ...]"
34333
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    16
  echo
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    17
  echo "  Options are:"
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    18
  echo "    -J OPTION    add JVM runtime option"
34409
e61e2ab1f6f7 proper spelling of JEDIT_JAVA_OPTIONS;
wenzelm
parents: 34339
diff changeset
    19
  echo "                 (default JEDIT_JAVA_OPTIONS=$JEDIT_JAVA_OPTIONS)"
34691
f28c014bcbe3 option -d: enable debugger;
wenzelm
parents: 34664
diff changeset
    20
  echo "    -d           enable debugger"
34333
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    21
  echo "    -j OPTION    add jEdit runtime option"
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    22
  echo "                 (default JEDIT_OPTIONS=$JEDIT_OPTIONS)"
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    23
  echo "    -l NAME      logic image name (default ISABELLE_LOGIC=$ISABELLE_LOGIC)"
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    24
  echo "    -m MODE      add print mode for output"
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    25
  echo
34664
8f5fbe4a80ff Isabelle component;
wenzelm
parents: 34663
diff changeset
    26
  echo "Start jEdit with Isabelle plugin setup and opens theory FILES"
34336
c9a96ddfceab explicit home path for default file -- more robust;
wenzelm
parents: 34335
diff changeset
    27
  echo "(default ~/Scratch.thy)."
34333
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    28
  echo
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    29
  exit 1
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    30
}
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    31
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    32
fail()
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    33
{
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    34
  echo "$1" >&2
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    35
  exit 2
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    36
}
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    37
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    38
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    39
## process command line
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    40
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    41
# options
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    42
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    43
JEDIT_LOGIC="$ISABELLE_LOGIC"
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    44
JEDIT_PRINT_MODE=""
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    45
34780
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    46
getoptions()
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    47
{
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    48
  OPTIND=1
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    49
  while getopts "J:dj:l:m:" OPT
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    50
  do
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    51
    case "$OPT" in
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    52
      J)
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    53
        JAVA_ARGS["${#JAVA_ARGS[@]}"]="$OPTARG"
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    54
        ;;
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    55
      d)
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    56
        JAVA_ARGS["${#JAVA_ARGS[@]}"]="-Xdebug"
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    57
        JAVA_ARGS["${#JAVA_ARGS[@]}"]="-Xrunjdwp:transport=dt_socket,server=y,suspend=n"
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    58
        ;;
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    59
      j)
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    60
        ARGS["${#ARGS[@]}"]="$OPTARG"
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    61
        ;;
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    62
      l)
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    63
        JEDIT_LOGIC="$OPTARG"
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    64
        ;;
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    65
      m)
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    66
        if [ -z "$JEDIT_PRINT_MODE" ]; then
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    67
          JEDIT_PRINT_MODE="$OPTARG"
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    68
        else
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    69
          JEDIT_PRINT_MODE="$JEDIT_PRINT_MODE,$OPTARG"
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    70
        fi
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    71
        ;;
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    72
      \?)
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    73
        usage
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    74
        ;;
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    75
    esac
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    76
  done
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    77
}
34581
abab3a577e10 slightly more robust treatment of options via arrays;
wenzelm
parents: 34412
diff changeset
    78
34780
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    79
declare -a JAVA_ARGS; eval "JAVA_ARGS=($JEDIT_JAVA_ARGS)"
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    80
declare -a ARGS; eval "ARGS=($JEDIT_OPTIONS)"
34333
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    81
34780
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    82
declare -a OPTIONS; eval "OPTIONS=($ISABELLE_JEDIT_OPTIONS)"
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    83
getoptions "${OPTIONS[@]}"
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    84
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    85
getoptions "$@"
34333
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    86
shift $(($OPTIND - 1))
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    87
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    88
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    89
# args
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    90
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    91
if [ "$#" -eq 0 ]; then
34780
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    92
  ARGS["${#ARGS[@]}"]="Scratch.thy"
34333
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    93
else
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    94
  while [ "$#" -gt 0 ]; do
34780
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
    95
    ARGS["${#ARGS[@]}"]="$(jvmpath "$1")"
34333
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    96
    shift
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    97
  done
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    98
fi
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
    99
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   100
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   101
## main
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   102
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   103
case "$JEDIT_LOGIC" in
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   104
  /*)
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   105
    ;;
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   106
  */*)
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   107
    JEDIT_LOGIC="$(pwd -P)/$JEDIT_LOGIC"
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   108
    ;;
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   109
esac
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   110
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   111
export JEDIT_LOGIC JEDIT_PRINT_MODE
b353b4cd9bd4 Isabelle/jEdit interface wrapper.
wenzelm
parents:
diff changeset
   112
34780
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
   113
exec "$ISABELLE_TOOL" java "${JAVA_ARGS[@]}" \
34339
8c70469bc83a added jvmpath conversion for Cygwin;
wenzelm
parents: 34336
diff changeset
   114
  -jar "$(jvmpath "$JEDIT_HOME/jedit.jar")" \
34780
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34691
diff changeset
   115
  "-settings=$(jvmpath "$ISABELLE_HOME_USER/jedit")" "${ARGS[@]}"