#!/bin/sh
#
# Usage: test_driver [d1 d2 ...]
#

# if there was no argument given to the script, default to creating
# the manual for all subdirectories listed in the file "docdirs"
# otherwise use only those subdirectories given as arguments
if [ $# -ne 0 ] ; then
   DIRS="$*"
elif [ -f docdirs ] ; then
   DIRS=`cat docdirs`
else
   DIRS=""
fi

for DIR in $DIRS ; do
   echo "********************************"
   echo " Starting with directory $DIR..."
   echo "  testing tex (first LaTeX pass)"
   test_tex $DIR
   echo "  testing html"
   test_html $DIR

  cd $DIR
  echo "  Now in directory $DIR..."

  echo "  $DIR's second LaTeX pass "
  to_dvi 

  echo "  making $DIR's index "
  if [ -f wrapper.idx ] ; then
     makeindex wrapper
     index_fix wrapper.ind
  fi

  echo "  $DIR's bibtex "
  bibtex wrapper

  # add table of contents line for bibliography
  if [ -f wrapper.bbl ]; then
     sed 's/\\begin{thebibliography}{.*}/&\\lcTex{\\addcontentsline{toc}{chapter}{Bibliography}}/' wrapper.bbl > new_wrapper.bbl
     \mv new_wrapper.bbl wrapper.bbl
  fi


  echo "  $DIR's third LaTeX pass "
  to_dvi 

  # ???? 
  # maybe this will get rid of the warning about cross-references
  # not being right because labels may have changed.
  # ???
  if [ $DIR = "basic" ]; then
     echo "  $DIR's fourth LaTeX pass "
     to_dvi 
  fi

  echo "  sorting reference pages "
  if [ -f wrapper.ref ]; then
     /usr/bin/sort -f +2 -3 wrapper.ref > wrapper.ref_sorted
     cp wrapper.ref_sorted wrapper.ref
  fi
  # yes, this fourth pass is necessary because you may need 2 passes after the
  # bibliography is created, and the index and bibliography can't be done
  # after the first pass for testing since the .aux files are removed after
  # each separate test
  echo "  $DIR's final LaTeX pass"
  to_dvi 
  echo "  ...leaving directory $DIR"
  cd ..
  echo "  creating $DIR's postscript"
  to_postscript $DIR

  echo "  creating $DIR's HTML"
  if [ $DIR = "basic" -o $DIR = "support" ]; then
     to_html_w_parts $DIR
  else
     to_html $DIR
  fi
  echo 
  echo " Finished with directory $DIR "
  echo
done


syntax highlighted by Code2HTML, v. 0.9.1