Admin/MacOS/App1/script
author wenzelm
Fri, 28 Jan 2011 11:19:12 +0100
changeset 41642 b9442d9ce7f5
parent 41610 9f99196ebd9f
child 41643 10b0d338d99e
permissions -rwxr-xr-x
enforce fonts;

#!/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"


# 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/IsabelleText.ttf" -o ! -f "$HOME/Library/Fonts/IsabelleTextBold.ttf" ]
then
  cp -f "$THIS/Isabelle/lib/fonts/IsabelleText.ttf" "$HOME/Library/Fonts/"
  cp -f "$THIS/Isabelle/lib/fonts/IsabelleTextBold.ttf" "$HOME/Library/Fonts/"
  sleep 3
fi

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

EMACS_OPTIONS["${#EMACS_OPTIONS[@]}"]="-f"
EMACS_OPTIONS["${#EMACS_OPTIONS[@]}"]="IsabelleText"


# run interface with error feedback

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

# ( "$ISABELLE_TOOL" jedit "$@" ) > "$OUTPUT" 2>&1
( "$ISABELLE_TOOL" emacs "${EMACS_OPTIONS[@]}" "$@" ) > "$OUTPUT" 2>&1
RC=$?

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"