#!/bin/csh -f
#
# bib2html - make an html file that is equivalent to the bib files,
#   using one of the html bib styles
#
# usage: 
set usage='usage: bib2html {alpha|abstract} file.bib...'
# Output is to bib.html. 
#    alpha makes a bibliography like bibstyle{alpha}
#    abstract makes a bibliography like bibstyle{abstract}
#
# David Kotz 7/94
# dfk@cs.dartmouth.edu
# URL: http://www.cs.dartmouth.edu/faculty/kotz.html

set tmp=/tmp/bib2html$$
onintr cleanup

if ($#argv < 2) then
	   echo "$usage"
	   exit 1
endif

set style=$1
set files=($2:r)

foreach file ($argv[3-])
   set files=($files,$file:r)
end

echo creating $tmp.aux for $files

cat > $tmp.aux <<EOF
\relax 
\citation{*}
\bibstyle{html-$style}
\bibdata{$files}
EOF

rm -f $tmp.{bbl,blg}

echo bibtex $tmp
bibtex $tmp

# the first five rules are to deal with my (DFK) macros, but the last
# few rules are needed to compensate for BibTeX's way of splitting
# long words over two lines by sticking a % (TeX comment character) at
# the end of the line.  The last two rules join the lines and delete
# the % and newline.  This works when one word (usually a URL) is
# split over more than one line.
sed > bib.html \
   -e 's/\\ie/i.e./g' \
   -e 's/\\eg/e.g./g' \
   -e 's/\\etc/etc./g' \
   -e 's+\\vs\\+<EM>vs.</EM>+g' \
   -e 's/\\usec/usec/g' \
   -e ':again' \
   -e '/%$/N' \
   -e 's/%\n//' \
   -e 't again' \
  $tmp.bbl

echo ""
echo output is in bib.html

cleanup:
rm -f $tmp.{aux,bbl,blg}

