#!/bin/sh
#
# Usage: 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
  cd $DIR
  echo "Now in directory $DIR..."
  echo
  echo "  ...$DIR's first LaTeX pass"
  echo
  to_dvi 

  echo
  echo "  ...$DIR's bibtex "
  echo
  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

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

  echo 
  echo "  ...$DIR's second LaTeX pass "
  echo
  to_dvi 

#  echo 
#  echo "  ...$DIR's third LaTeX pass "
#  echo 
#  to_dvi 

  if [ -f wrapper.ref ]; then
      echo
      echo " ... sorting reference pages "
      echo
      sort -f +2 -3 wrapper.ref > wrapper.ref_sorted
      cp wrapper.ref_sorted wrapper.ref
  fi
     
  echo 
  echo "  ... $DIR's final LaTeX pass"
  echo 
  to_dvi 

  echo 
  echo "  ... creating $DIR's PostScript"
  echo 
  to_postscript 
  to_postscript_letter

  to_pdf

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


syntax highlighted by Code2HTML, v. 0.9.1