lib/Tools/browser
author wenzelm
Mon, 20 Nov 2006 23:47:10 +0100
changeset 21426 87ac12bed1ab
parent 20569 c315ba088073
child 25650 ce061f5083d7
permissions -rwxr-xr-x
converted legacy ML scripts;

#!/usr/bin/env bash
#
# $Id$
# Author: Markus Wenzel, TU Muenchen
#
# DESCRIPTION: Isabelle graph browser


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

function usage()
{
  echo
  echo "Usage: $PRG [OPTIONS] [GRAPHFILE]"
  echo
  echo "  Options are:"
  echo "    -c           cleanup -- remove GRAPHFILE after use"
  echo "    -o FILE      output to FILE (ps, eps, pdf)"
  echo
  exit 1
}

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


## process command line

# options

CLEAN=""
OUTFILE=""

while getopts "co:" OPT
do
  case "$OPT" in
    c)
      CLEAN=true
      ;;
    o)
      OUTFILE="$OPTARG"
      ;;
    \?)
      usage
      ;;
  esac
done

shift $(($OPTIND - 1))


# args

GRAPHFILE=""
[ "$#" -gt 0 ] && { GRAPHFILE="$1"; shift; }
[ "$#" -ne 0 ] && usage


## main

export CLASSPATH="$ISABELLE_HOME/lib/browser/GraphBrowser.jar"
if [ -z "$GRAPHFILE" ]; then
  cd "$ISABELLE_BROWSER_INFO"
  exec java GraphBrowser.GraphBrowser
else
  PRIVATE_FILE="${ISABELLE_TMP:-/tmp}/$$"$(basename "$GRAPHFILE")
  if [ -n "$CLEAN" ]; then
    mv -f "$GRAPHFILE" "$PRIVATE_FILE" || fail "Cannot move file: $FILE"
  else
    cp -f "$GRAPHFILE" "$PRIVATE_FILE" || fail "Cannot copy file: $FILE"
  fi

  PDF=""
  case "$OUTFILE" in
    *.pdf)
      OUTFILE="${OUTFILE%%.pdf}.eps"
      PDF=true
      ;;
  esac

  if [ -z "$OUTFILE" ]; then
    java GraphBrowser.GraphBrowser "$PRIVATE_FILE"
  else
    java GraphBrowser.Console "$PRIVATE_FILE" "$OUTFILE"
  fi
  RC="$?"

  if [ -n "$PDF" ]; then
    "$ISABELLE_EPSTOPDF" "$OUTFILE" || fail "Failed to produce pdf output"
  fi

  rm -f "$PRIVATE_FILE"
fi

exit "$RC"