#! /usr/bin/perl
# DO NOT EDIT.  See version in sowing
#
# Minimal processing of a BibTeX database file to make it html
# Usage:
# bib2html filename > output.html
# bib2html -group gfilename filename > output.html
#     where gfilename is a file containing regular expressions for 
#     author's names and matching URLs.  See mpich.group for an example.
# -ignore value specifies a field to ignore (e.g., -ignore annote eliminates
# annote fields from the output.
#
# Add header/tail (with link to this code)
# Convert comments to %...<BR>
# Convert @<name>{ or ( to <B>@<name></B>
#
# To customize for yourself, change the following three lines.
$UserName = "TAO";
$userURL = "http://www.mcs.anl.gov/tao";
# This is W. or William (the W(\.|illiam)), optionally followed by D. (the 
# ( D\.)?), followed by Gropp.
$UserREName = "W(\.|illiam)( D\.)? Gropp";
# For names that have accents, e.g., \'e, use the HTML entity: 
#     J(\.|orge) Mor&eaccute;
# for Jorge Mor\'e
#
# Using styles
# You can define 
# <style type="text/css">
# <!--
# body { font-size: 10pt }
# p.petsc { background:#CCCCFF }
# p.other { background:#FFFFFF }
# -->
# </style>
# and then use 
# $EntryStart = "<p class=\"petsc\">\n";
# $EntryEnd = "</p>\n";
# to group an entry. 
# Other style elements that can be used are
#   font-family
#   font-weight
#   text-align
#   color
#   width
#   margin-left
#   margin-right
# 
$GroupEmphStart = "<B>";
$GroupEmphEnd   = "</B>";
#
$announce_oldstyle = 0;
$groupsize = 0;
$ignoresize = 0;
$outlist = 0;
$debug = 0;
$special_entity = 1;
$check_valid_fields = 0;
#
# Default Formats for outlist
# Book
    # title, author, publisher, year. 
    %htmlformatsBook = ( 'starttitle' => '<I>',
			 'endtitle' => '</I>' );
    @fieldlistBook = (title, author, publisher, note, year);
    @fieldlistoptionalBook = (address, pages, isbn, lccn, series, keywords,
			      editor, annote, pubaddress, key );
#
# Article 
    # title, author, journal, volume, number, pages, year.
    %htmlformatsArticle = ( 'starttitle' => '<I>',
			   'endtitle' => '</I>' );
    @fieldlistArticle = (title, author, journal, volume, number, pages, note, year);
    @fieldlistoptionalArticle = (month, annote, url, acknowledgement, 
				 bibdate, issn, coden, keywords,
				 classification, conflocation, corpsource, 
				 conftitle, sponsororg, treatment, key,
				 affiliation, thesaurus, key, journalabr );
# InBook
    # title, author, publisher, year.
    %htmlformatsInBook = ( 'starttitle' => '<I>',
			   'endtitle' => '</I>' );
    @fieldlistInBook = (title, author, booktitle, publisher, note, year);
    @fieldlistoptionalInBook = (address, pages, isbn, lccn, series, keywords,
			        editor, annote, pubaddress, key );

#
# InProceedings 
    # title, author, booktitle, editors, pages, year
    %htmlformatsInProc = ( 'starttitle' => '<I>',
			  'endtitle' => '</I>' );
    @fieldlistInProc = (title, author, booktitle, editor, pages, note, year);
    @fieldlistoptionalInProc = (number, month, series, publisher, address,
				volume, keywords, acknowledgement, treatment,
				corpsource, conftitle, classification, 
				isbn, organization, confdate,
				meetingdate, meetingdate2, sponsor, 
				sponsororg, thesaurus, affiliation, bibdate,
				annote, url, issn, confloc, eariler, owner,
				conflocation, crossref, editors,
				conference, meetingaddress, earlier, 
				coden, key, pubaddress, category, place,
				affiliationaddress, journalabr );

    %htmlformatsInColl = %htmlformatsInProc;
    @fieldlistInColl = @fieldlistInProc;
    @fieldlistoptionalInColl = @fieldlistoptionalInProc;
#
# Techreport 
    # title, author, institution, number, year
    %htmlformatsTech = ( 'starttitle' => '<I>',
			'endtitle' => '</I>' );
    @fieldlistTech = (title, author, institution, organization, number, note, year);
    @fieldlistoptionalTech = (month, keywords, url, language, notes, pages, 
			      bibdate, later, scope, type, abstract-url, 
			      annote, address, key, location, category );
#
# Misc 
    # title, author, institution, number, year
    %htmlformatsMisc = ( 'starttitle' => '<I>',
			'endtitle' => '</I>' );
    @fieldlistMisc = (title, author, institution, organization, number, note, year);
    @fieldlistoptionalMisc = ( month, annote, key, address, type );

# Manual, Unpublished come from Misc for now.  We don't need to define these
# because Misc is the default
  #%htmlformatsManual = %htmlformatsMisc;
  #@fieldlistManual = @fieldlistMisc;
  #%htmlformatsUnpublished = %htmlformatsUnpublished;
  #@fieldlistUnpublished = @fieldlistMisc;

# Bibtex entry type mappings
%shortentrynames = ( 'Book' => 'Book', 
		  'Article' => 'Article',
		  'Inproceedings' => 'InProc',
		  'Incollection' => 'InColl',
		  'Techreport' => 'Tech',
		  'Misc' => 'Misc',
		  'Unpublished' => 'Misc',
		  'Manual' => 'Misc' );

# Example Header entries for a listfile configuration file.
#  $HeaderRE = "Section:";
#  $HeaderStart = "<H2 style=\"color:blue;align=center\">";
#  $HeaderEnd   = "</H2>";
#
while ($_ = $ARGV[0]) {
    shift;
    if ($_ eq "-group") {
	# Read from group file $ARGV[0]
	# Format is RE!URL
        # (RE is regular expression for matching the name)
	$groupname = $ARGV[0];
	shift;
	open( GROUP, "<$groupname" ) || die "Could not open group $groupname!\n";
	while (<GROUP>) {
	    chop;
	    if ($_ ne "") {  # Do we want !/^\s*$/?
	        ($GroupREName[$groupsize],$GroupURL[$groupsize]) = split /!/;
	        $groupsize ++;
	    }
	}
    }
    elsif ($_ eq "-ignore") {
	# Read name from cmdline
	$IgnoreFields[$ignoresize] = lc( $ARGV[0] );
	$ignoresize++;
	shift;
    }
    elsif ($_ eq "-listfile") {
	$outlist = 1;
	$listfile = $ARGV[0];
	shift;
    }
    elsif ($_ eq "-listconfig") {
	$listconfig = $ARGV[0];
	shift;
    }
    elsif ($_ eq "-title") {
	$TitleString = $ARGV[0];
	shift;
    }
    elsif ($_ eq "-debug") {
	$debug = 1;
    }
    elsif ($_ eq "-nospecials") {
	$special_entity = 0;
    }
    elsif ($_ eq "-nooldstyle") {
        $announce_oldstyle = 1;
    }
    elsif ($_ eq "-check") {
	$check_valid_fields = 1;
    }
    elsif ($_ eq "-help") {
	print "bib2html [ -listfile name ] [ -listconfig name ] \
         [ -group name ] [ -ignore name ] [ -title name ] [ -nospecials ]\
         [ -nooldstyle ] [ -check ] filename \
         -listfile name  - output a bibliography listing on file name\
         -listconfig name - Use file name to control the format of\
                            the list file.  This is a Perl script defining\
                \$ListHeader - HTML file header (to BODY)\
                \$ListFooter - HTML file footer (from /BODY)\
                \$BibFileName - Name of bib file (used for links)\
                \$HeaderRE   - Regular expression that will be matched in
                               TeX comments\
                \$HeaderStart - HTML inserted in listfile before header\
                \$HeaderEnd   - HTML inserted in listfile after header\
                \$GroupEmphStart - HTML inserted before names found in the\
                                   group file\
                \$GroupEmphEnd - HTML inserted after names found in the\
                                 group file\
                \%htmlformatsBook - A Perl has containing HTML commands for\
                                    formatting a Book entry\
                \@fieldlistBook   - A Perl array containing the BibTeX fields\
                                 to use when formatting a book\
                   (Similarly for Article, Techreport, InProc (proceedings)\
                    and Misc)\
        A typical listconfig file might contain:\
\
           \$ListHeader = \"<HTML><HEAD><TITLE>Bib for me</TITLE></HEAD>\\\
           <style type=\"text/css\">\
           h2 { color:blue; align:center }\
           </style>\
           <BODY BGCOLOR=\\\"FFFFFF\\\">\\n\";\
           \$ListFooter = \"</BODY></HTML>\\n\";\
           \$BibFileName = \"mpich2-bib.htm\";\
           \$EntryStart = \"\";\
           \$EntryEnd = \"<P>\\n\";\
           \$HeaderRE = \"Section:\";\
           \$HeaderStart = \"<H2>\";\
           \$HeaderEnd   = \"</H2>\";\
           \$GroupEmphStart = \"<B>\";\
           \$GroupEmphEnd = \"</B>\";\
           1;\n\
       -group name   - File containing author names and associated URLs\
       -ignore name  - Ignore field \"name\" in each bib entry\
       -title name   - Name to use in the title of the BiBTeX page\
       -nospecials   - Do not use certain valid HTML character entities\
                       such as endash that some older browers do not \
                       recognize.\
       -nooldstyle   - Print uses of oldstyle LaTeX to stderr.\
       -check        - Warn about unrecogonized BibTeX fields names.\
\n";
	exit 0;
    }
    else {
	$bibfile=$_;
    }
}

open( BIB, "<$bibfile" ) || die "Could not open $bibfile!\n"; 

if ($outlist) {
    open( LISTFILE, ">$listfile" ) || die "Could not open $listfile\n";
    if ($listconfig ne "") {
	require $listconfig;
	print LISTFILE $ListHeader;
    }
}
if ($TitleString eq "") {
    $TitleString = "Bibliography for $UserName";
}
print "<HTML>\n<HEAD>\n";
print "<TITLE>$TitleString</TITLE>\n";
print "<! Automatically generated by bib2html available from\n";
print "   http://www.mcs.anl.gov/~gropp/bib2html >\n";
print "</HEAD>\n";
print "<BODY BGCOLOR=\"FFFFFF\">\n";
#
# Still to do: 
# Process @string(name=value); replace all uses of @name with
# value in formatted (listfile) version.
# Allow multiple HeaderRE's
# Allow fields in the entryinfo to modify the formatting.  For example,
# we might let @field@ be replaced by the value of entryinfo{'field'}.
#
%bibstrings = ();
$inrow   = "";
$intable = 0;
$dooutput = 1;
$line_count = 0;
$MakeBold = "";
# Format as table
while (<BIB>) {
    $line = $_;	
    $line_count++;		
    # Look for a new bib entry starting a line
    if (/^\s*\@string\s*\(\s*([^=\s]*)\s*=\s*(.*)\s*\)/) {
	# Found @string name = value
	$bibstrings{$1} = $2;
	next;
    }
    elsif (/^\s*@([a-zA-Z]*)\s*[({]/) { 
	# Found the beginning of a BibTeX entry (@....)
	$entry_type = lc( $1 );
	if ($intable == 1) {
	    # Finish off the previous table
            print "</TR></TABLE>\n";
	}
	#$line = $entryinfo{$fieldname};
	#$line =~ s%[^=]*=%%;
	#$entryinfo{$fieldname} = $line;
	%entryinfo = ();   # Clear entry info
	$entryinfo{"entry_type"} = $entry_type;
	$inrow = ""; 
        $intable = 1;
	$dooutput = 1;
        s%@([a-zA-Z]*)([({])\s*(.*)\s*,\s*$%@<B>$1</B>$2<A NAME=\"$3\">$3</A>,\n<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>%g;
	$entryinfo{'key'} = $3;
        # Setup the list of expected field names based on the entry_type
        %knownfields = ();
        $entryname = ucfirst $entry_type;
        if (defined($shortentrynames{$entryname})) {
	    $entryname = $shortentrynames{$entryname};
	}
	$fieldref = "fieldlist$entryname";
        # @$fieldref is the array @fieldlist$entryname
        #$fieldref->[i] accesses the ith element of the fieldlist
        %knownfields = ();			
	for ($k=0; $k <= $#$fieldref; $k++) {
	    $knownfields{$fieldref->[$k]} = 1;
	}
	$fieldoptref = "fieldlistoptional$entryname";
	for ($k=0; $k <= $#$fieldoptref; $k++) {
	    $knownfields{$fieldoptref->[$k]} = 1;
	}
	$knownfields{'abstract'} = 1;
    }
    elsif (/^\s*%\s*($HeaderRE)(.*)$/) {
	# Found a special comment that we want modified and added to the
	# LISTFILE.
	$headertext = $2;
        if ($outlist && 
            ($HeaderRE ne "" || $HeaderEnd ne "" || $HeaderStart ne "")) {
            print LISTFILE "$HeaderStart $headertext $HeaderEnd\n";
        }
    }
    else {
        # Look for a new item entry in a bib entry
	# We may want to skip some items
	# One thing to be careful of is multi-line items.
        if (/^[^%=]*\s*=/) {
	    # Found field = .... 
	    if ($intable == 0) {
		print STDERR "Missing bibtex entry type for line #$line_count:$_\n";
		print "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
		$intable = 1;
	    }
	    # Finish off the previous line
	    print "$MakeBold$inrow\n" ;
	    $inrow = "</TR>";
	    # Check to see if this line is one that we wish to 
	    # suppress
	    # ---- not completely implemented
	    /^\s*([^%=\s]*)\s*=/; 
	    print "matched $1 in $_" if $debug;
	    $fieldname = lc( $1 );
	    if ($fieldname eq "") {
		print STDERR "Matched empty field in $_";
	    }
	    for ($i = 0; $i <= $#IgnoreFields; $i++) {
		if ($IgnoreFields[$i] eq $fieldname) {
		    $dooutput=0; next;
		}
	    }
	    if ($check_valid_fields && !defined($knownfields{$fieldname})) {
		print STDERR "Field $fieldname not known for $entryname on line $line_count\n";
	    }
	    $entryinfo{$fieldname} = "";
	    $line =~ s/^\s*[^=%]*\s*=//;
	    # ----
	    # Make the "title" text bold, others regular
	    print "Found $fieldname\n" if $debug;
	    if ($fieldname eq "title") { $MakeBold="<B>"; } 
	    else { $MakeBold = ""; }
	    # Output this line
            s%^([^=]*)[ ]*=\s*(.*)\s*$%<TR VALIGN=TOP><TD WIDTH=20><TD><I>$1</I><TD ALIGN="CENTER" WIDTH=15> = <TD>$MakeBold$2%;
	    if ($MakeBold ne "") { $MakeBold = "</B>"; }
        }
 
        # Check of the end of entry (must be alone on a separate line)
        # fix emacs broken matching mode })}
        else {			
	    if (/^[ ]*[})][ ]*$/) {   
 	        if ($dooutput == 1) { #({
		    s%^[ ]*([})])[ ]*$%</TR></TABLE>\n$1%;
		    }
 	        else {
		    s%^[ ]*([})])[ ]*$%</TABLE>\n$1%;
	        }
 	        if ($outlist && defined($entryinfo{"entry_type"})) {
		    &PrintEntry( %entryinfo );
	        }
	        elsif ($debug && $outlist) {
		    print %entryinfo;
	        }
	        %entryinfo = ();   # Clear entry info
         	$fieldname = "";
	        $intable = 0;
	        $dooutput = 1;
            }
        }
    } 

    print "Current line = \"$line\"\n" if $debug;
    $original_line = $line;
    # Fix HTML reserved characters
    $line =~ s%[\\]+&%&amp;%;
    $line =~ s%[\\]+<%&lt;%;
    $line =~ s%[\\]+>%&gt;%;
    # Convert various TeX commands
    # $...$
    $line =~ s%\$([^\$]*)\$%<EM>$1</EM>%;
    # ~ (but not \~)
    $line =~ s%([^\\]{1})~%$1&nbsp;%;
    # \textrm{} (currently only strips out the command)
    $line =~ s%\\textrm{([^}]*)}%$1%;
    # \textem{} (set to em, won't work if nested)
    $line =~ s%\\textem{([^}]*)}%<EM>$1</EM>%;
    # \texttt{} (set to tt, won't work if nested)
    $line =~ s%\\texttt{([^}]*)}%<TT>$1</TT>%;
    # \url{} 
    $line =~ s%\\url{([^}]*)}%<A HREF=\"$1\">$1</A>%;
    # {\tt ... }
    if ($announce_oldstyle && /\\tt /) {
        print STDERR "line $line_count: \\tt in $original_line";
    }
    $line =~ s%{\\tt([^}]*)}%<TT>$1</TT>%;
    # {\it ... }
    if ($announce_oldstyle && /\\it /) {
        print STDERR "line $line_count: \\it in $original_line";
    }
    $line =~ s%{\\it([^}]*)}%<EM>$1</EM>%;
    # \~{ }
    $line =~ s%\\~\{\s*\}%~%g;
    # \#
    $line =~ s%\\#%#%g;
    # \o
    $line =~ s%\\o([^A-Za-z]{1})%&oslash;$1%;
    # \O
    $line =~ s%\\O([^A-Za-z]{1})%&Oslash;$1%;
    # _{} -> <SUB>...</SUB>
    # ^{} -> <SUP>...</SUP>
    # \_ -> _
    # \{ -> {
    # \} -> }
    # \(.*\) -> <EM>...</EM>
    # \'{letter} {} is optional
    $line =~ s%\\'\{([AEIOUYaeiouy]{1})\}%&$1acute;%;
    $line =~ s%\\'([AEIOUYaeiouy]{1})%&$1acute;%;
    # \~
    $line =~ s%\\~\{([ANOano]{1})\}%&$1tilde;%;
    $line =~ s%\\~([ANOano]{1})%&$1tilde;%;
    # \"
    $line =~ s%\\"\{([AEIOUaeiou]{1})\}%&$1uml;%;
    $line =~ s%\\"([AEIOUYaeiouy]{1})%&$1uml;%;
    $line =~ s%\\"\{([AEIOUaeiou]{1})\}%&$1uml;%;
    $line =~ s%\\"([AEIOUYaeiouy]{1})%&$1uml;%;
    # \`
    $line =~ s%\\`\{([AEIOUaeiou]{1})\}%&$1grave;%;
    $line =~ s%\\`([AEIOUaeiou]{1})%&$1grave;%;
    #
    # \.
    $line =~ s%\\`\{([AEIOUaeiou]{1})\}%&$1circ;%;
    $line =~ s%\\`([AEIOUaeiou]{1})%&$1circ;%;
    # --- -> &mdash;
    $line =~ s%---%&mdash;% if $special_entity;
    # -- -> &ndash;
    $line =~ s%--%&ndash;% if $special_entity;
    print "Adding field $fieldname with text $line" if $debug;
    $entryinfo{ $fieldname } .= $line;
    
    # Turn URLs into links in $_
    s%(http:[^ }"]*)%<A HREF="$1">$1</A>%g;
    s%(ftp:[^ }"]*)%<A HREF="$1">$1</A>%g;

    # Comment the following to not use links for author names
    # This also makes the author name bold
    s%($UserREName)%<A HREF="$userURL">$GroupEmphStart$1$GroupEmphEnd</A>%g;

    # For a group's bibliography, an array of UserREs and the corresponding
    # URLs could be used (preloaded as an option to this command)
    for ($i = 1; $i <= $#GroupURL; $i++) {
        s%($GroupREName[$i])%<A HREF="$GroupURL[$i]">$GroupEmphStart$1$GroupEmphEnd</B></A>%g;
    }

    # Add a BR to preserve formating outside of tables
    if ($intable == 0) { s/$/<BR>/; }
    print $_ if $dooutput == 1;
} 

$curtime = localtime;
print "Generated on $curtime with <A HREF=\"http://www.mcs.anl.gov/~gropp/bib2html\">bib2html</A>\n";
print "</BODY>\n";
print "</HTML>\n";

if ($listconfig ne "") {
    print LISTFILE $ListFooter;
}

#
# This routine replaces @xxx@ with the value of xxx in the entry info.
# This allows you to use bibtex fields to control formatting by using 
# the class=name style directive.
sub ReplaceParms {
    $textline = $_[0];
    $default  = $_[1];
    if ($textline =~ /@([a-z]*)@/) {
	$token = $1;
	$replacement = $entryinfo{$token};
	$replacement =~ s/^\s*//;
	if ($replacement eq "") { $replacement = $default; }
	$textline =~ s/\@$token@/$replacement/;
    }
    return $textline;
}

# Print out an entry
sub PrintEntry {
    $entry_type = $entryinfo{"entry_type"};
    print "Printing $entry_type\n" if $debug;
    # First, clean up values
    foreach $key (keys %entryinfo) {
        $value = $entryinfo{$key};
	$value =~ s/,\s*$//s;
	$value =~ s/^\s*(\"|\{){1}(.*)(\"|\}){1}/$2/s;
	chomp $value;
	$entryinfo{$key} = $value;
    }
    if ($debug) { print %entryinfo ; }
    if (defined($entryinfo{'key'})) {
	my $keyname = $entryinfo{'key'};
	print LISTFILE "<A NAME=\"$keyname\"></A>\n";
    }
    if ($EntryStart ne "") {
	$textline = &ReplaceParms( $EntryStart );
        print LISTFILE $textline;
    }
    if ($entry_type eq "book") {
	&PrintBook;
    }
    elsif ($entry_type eq "article") {
	&PrintArticle;
    }
    elsif ($entry_type eq "inproceedings" || $entry_type eq "incollection") {
	&PrintInProceedings;
    }
    elsif ($entry_type eq "techreport") {
	&PrintTechreport;
    }
    else {
	# Works for manual, unpublished, misc, etc 
	&PrintMisc;
    }
    if ($EntryEnd ne "") {
	$textline = &ReplaceParms( $EntryEnd );
        print LISTFILE $textline;
    }
}

sub TitleCase {
    # Convert to title case, but don't change case inside of {}.
}
sub AuthorList {
    my $fieldname = $_[0];
    # Convert all but last "and" into ,
    $author = $entryinfo{$fieldname};
    @authors = split /\s\s*and\s*\s/, $author;
    print @authors if $debug;
    print "n = $#authors\n" if $debug;
    if ($#authors > 1) {
        $author = "";
	for ($i=0; $i<$#authors; $i++) {
	    $author .= $authors[$i];
	    $author .= ", ";
        }
	$author .= "and $authors[$#authors]";
    }
    # Comment the following to not use links for author names
    # This also makes the author name bold
    $author =~ s%($UserREName)%<A HREF="$userURL">$GroupEmphStart$1$GroupEmphEnd</A>%g;

    # For a group's bibliography, an array of UserREs and the corresponding
    # URLs could be used (preloaded as an option to this command)
    for ($i = 1; $i <= $#GroupURL; $i++) {
        $author =~ s%($GroupREName[$i])%<A HREF="$GroupURL[$i]">$GroupEmphStart$1$GroupEmphEnd</A>%g;
    }
    $entryinfo{$fieldname} = $author;
}

sub PrintBook {
    # title, author, publisher, year.
    %htmlformats = %htmlformatsBook;
    # We should really check for author; if no author but an editor, 
    # use the editor field instead.
    @fieldlist = @fieldlistBook;
    if (!defined($entryinfo{'author'}) && 
	defined($entryinfo{'editor'})) {
	for ($i=0; $i<$#fieldlist; $i++) {
	    if ($fieldlist[$i] eq 'author') {
		$fieldlist[$i] = 'editor';
		last;
	    }
	}
    }
    &PrintGeneral;
}

sub PrintArticle {
    # title, author, journal, volume, number, pages, year.
    %htmlformats = %htmlformatsArticle;
    @fieldlist = @fieldlistArticle;
    &PrintGeneral;
}

sub PrintInProceedings {
    # title, author, booktitle, editors, pages, year
    %htmlformats = %htmlformatsInProc;
    @fieldlist = @fieldlistInProc;
    &PrintGeneral;
}

sub PrintTechreport {
    # title, author, institution, number, year
    %htmlformats = %htmlformatsTech;
    @fieldlist = @fieldlistTech;
    &PrintGeneral;
}

sub PrintMisc {
    # title, author, institution, number, year
    %htmlformats = %htmlformatsMisc;
    @fieldlist = @fieldlistMisc;
    &PrintGeneral;
}

sub CleanString {
    $value = $_[0];
    # Remove extra {} pairs
    $value =~ s/{([^{}]*)}/$1/gs;
    return $value;
}

sub PrintGeneral {
    &AuthorList( 'author' );
    &AuthorList( 'editor' );
    $firstitem = 1;
    foreach $key (@fieldlist) {
	if (!defined($entryinfo{$key})) { next; }
	$value = $entryinfo{$key};
        if ($value eq "") { next; }
	if (!$firstitem) { print LISTFILE ", ";}
	else { $firstitem = 0; }
	$keyname = "start$key";
	print LISTFILE "$htmlformats{$keyname}"; 
	$value = &CleanString( $value );
        #
        # Here is where we look for @name and then look up name 
	# in bibstrings.  Or we could just keep a list of strings and
	# replacements (just like the GroupREName and GroupURL)
	if ($key eq 'title' && defined($entryinfo{'url'})) {
	    $url = $entryinfo{'url'};
	    print LISTFILE "<A HREF=\"$url\">$value</A>";
        }
	else {
            print LISTFILE "$value";
        }
	$keyname = "end$key";
        print LISTFILE "$htmlformats{$keyname}";
    }
    print LISTFILE ".\n";
    print LISTFILE "<A HREF=\"$BibFileName#$entryinfo{'key'}\">BibTeX</A>\n";
}
