lib/Tools/document
author wenzelm
Sat, 09 Oct 1999 23:16:31 +0200
changeset 7814 ef6d84f16592
parent 7793 e0676a932348
child 7857 a49a3978fe3a
permissions -rwxr-xr-x
check format; support bibtex;

#!/bin/bash
#
# $Id$
#
# DESCRIPTION: prepare theory session document


PRG=$(basename $0)

function usage()
{
  echo
  echo "Usage: $PRG [OPTIONS] [DIR]"
  echo
  echo "  Options are:"
  echo "    -o FORMAT    specify output format: dvi (default), dvi.gz, ps, ps.gz, pdf"
  echo
  echo
  echo "  Prepare the theory session document in DIR (default .)"
  echo "  producing the speficied output format."
  echo
  exit 1
}

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


## process command line

# options

OUTFORMAT=dvi

while getopts "o:" OPT
do
  case "$OPT" in
    o)
      OUTFORMAT="$OPTARG"
      ;;
    \?)
      usage
      ;;
  esac
done

shift $(($OPTIND - 1))


# args

DIR="."
[ $# -ge 1 ] && { DIR="$1"; shift; }

[ $# -ne 0 ] && usage


## main

# check format

case "$OUTFORMAT" in
  dvi | dvi.gz | ps | ps.gz | pdf)
    ;;
  *)
    fail "Bad output format '$OUTFORMAT'"
    ;;
esac


# prepare document

cd "$DIR" || fail "Bad directory '$DIR'"

function pre_latex ()
{
  local FMT="$1"
  if [ -f root.bib ]
  then
    $ISATOOL latex -o "$FMT" && \
    $ISATOOL latex -o bbl && \
    $ISATOOL latex -o "$FMT"
  else
    $ISATOOL latex -o "$FMT"
  fi
}

if [ -f IsaMakefile ]; then
  $ISATOOL make "$OUTFORMAT"
  RC=$?   #FIXME !??
elif [ "$OUTFORMAT" = pdf ]; then
  pre_latex pdf && \
  $ISATOOL latex -o pdf
  RC=$?
else
  pre_latex dvi && \
  $ISATOOL latex -o "$OUTFORMAT"
  RC=$?
fi


# install

[ "$RC" -gt 0 -o ! -f "root.$OUTFORMAT" ] && fail "Failed to prepare document in directory '$DIR'"
cp -f "root.$OUTFORMAT" "../document.$OUTFORMAT"