#!/usr/local/bin/perl
#
# Bibliography entry display
#
use CGI;
use DB_File;
use Fcntl;

$bitem = new CGI;

$dbprefix="/www/bib/";
@fields = ('author', 'date', 'title', 'journal', 'language', 'subject',
           'keywords', 'taxa', 'places', 'abstract');
%fldheads = ('abstract', '</DL><H3>Abstract</H3>%s');

my @isindexkeys = $bitem->keywords();
$reckey = sprintf("%7d\0", $isindexkeys[0]);
print($bitem->header);
print("<HTML><HEAD><TITLE>Display of bibliography entry</TITLE></HEAD>\n\n");
print("<BODY>\n<H3>Reference</H3>\n");
print("<DL>\n");
$listend = 0;
foreach $fd (@fields) {
   eval "tie(\%DATABASE, 'DB_File', '$dbprefix$fd', O_RDONLY, 0444, \$DB_HASH)";
   $@ && &cgidie("can't open $fd file");
   $val = (defined($DATABASE{$reckey})) ? $DATABASE{$reckey} : "\0";
   chop $val;
   if ($val && ($val =~ /\S/)) {
      if (defined($fldheads{$fd})) {
         printf($fldheads{$fd}, $val);
         $listend = 1;
      } else {
         printf("<DT><STRONG>\u$fd...</STRONG><DD>\n%s\n", $val);
      }
   }
   untie(%DATABASE) || &cgidie("can't close $fd file");
}
print("</DL>\n") unless $listend;
print("</BODY>\n</HTML>\n");

sub cgidie {
   local($errtext) = shift;
   print("<H2>$errtext, reference display abandoned.</H2>\n");
   print("Please contact <A HREF=\"mailto:webmaster\@LTRR.Arizona.EDU\">webmaster\@LTRR.Arizona.EDU</A>.\n");
   print("</BODY></HTML>\n");
   die "$errtext, stopped";
}
