Admin/MacOS/App1/script
author wenzelm
Sun, 11 Sep 2011 19:52:09 +0200
changeset 44880 9fb612890ad9
parent 41644 a6c45c8d52fc
child 44881 ca2f585d1ebe
permissions -rw-r--r--
explicit choice of interface;

#!/bin/bash
#
# Author: Makarius
#
# Isabelle application wrapper

THIS="$(cd "$(dirname "$0")"; pwd)"
THIS_APP="$(cd "$THIS/../.."; pwd)"
SUPER_APP="$(cd "$THIS/../../.."; pwd)"


# sane environment defaults

cd "$HOME"
PATH="$PATH:/opt/local/bin"

[ -z "$LANG" ] && export LANG=en_US.UTF-8


# settings support

function choosefrom ()
{
  local RESULT=""
  local FILE=""

  for FILE in "$@"
  do
    [ -z "$RESULT" -a -e "$FILE" ] && RESULT="$FILE"
  done

  [ -z "$RESULT" ] && RESULT="$FILE"
  echo "$RESULT"
}


# Isabelle

ISABELLE_TOOL="$(choosefrom \
  "$THIS/Isabelle/bin/isabelle" \
  "$SUPER_APP/Isabelle/bin/isabelle" \
  "$HOME/bin/isabelle" \
  isabelle)"


# Proof General / Emacs

PROOFGENERAL_EMACS="$(choosefrom \
  "$THIS/Emacs.app/Contents/MacOS/Emacs" \
  "$SUPER_APP/Emacs.app/Contents/MacOS/Emacs" \
  /Applications/Emacs.app/Contents/MacOS/Emacs \
  "")"

declare -a EMACS_OPTIONS=()
if [ -n "$PROOFGENERAL_EMACS" ]; then
  EMACS_OPTIONS=(-p "$PROOFGENERAL_EMACS")
fi


# enforce fonts

if [ ! -f "$HOME/Library/Fonts/STIXGeneral.ttf" -a ! -f "$HOME/Library/Fonts/STIXGeneral.otf" ]
then
  cp -f "$THIS/STIXv1.0.0/Fonts"/STIXGeneral* "$HOME/Library/Fonts/"
  sleep 3
fi

EMACS_OPTIONS["${#EMACS_OPTIONS[@]}"]="-x"
EMACS_OPTIONS["${#EMACS_OPTIONS[@]}"]="true"


# run interface with error feedback

OUTPUT="/tmp/isabelle$$.out"

declare -a CHOICE
CHOICE=($("$THIS/CocoaDialog.app/Contents/MacOS/CocoaDialog" dropdown \
  --title Isabelle \
  --text "Which Isabelle interface?" \
  --items "Emacs / Proof General" "Isabelle/jEdit PIDE" \
  --button1 "OK"))

if [ "${CHOICE[1]}" = 0 ]; then
  ( "$ISABELLE_TOOL" emacs "${EMACS_OPTIONS[@]}" "$@" ) > "$OUTPUT" 2>&1
  RC=$?
else
  ( "$ISABELLE_TOOL" jedit "$@" ) > "$OUTPUT" 2>&1
  RC=$?
fi

if [ "$RC" != 0 ]; then
  echo >> "$OUTPUT"
  echo "Return code: $RC" >> "$OUTPUT"
fi

if [ $(stat -f "%z" "$OUTPUT") != 0 ]; then
  "$THIS/CocoaDialog.app/Contents/MacOS/CocoaDialog" textbox \
    --title "Isabelle" \
    --informative-text "Isabelle output" \
    --text-from-file "$OUTPUT" \
    --button1 "OK"
fi

rm -f "$OUTPUT"

exit "$RC"