#!/usr/local/bin/perl # # bibl2html -- convert a bibliography file to HTML # Copyright (C) 1994 Bryan O'Sullivan # # Author: Bryan O'Sullivan # Keywords: bibliographies, databases, World Wide Web # $Revision: 1.3 $ # $Date: 1995/05/23 22:12:47 $ # $Source: /u/other/ugrad/bosullvn/lib/elisp/bibl-mode/RCS/bibl2html,v $ # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # COMMENTARY: # # This script converts a bibl-mode file into a HTML file with # hyperlinks. Probably not very useful to anyone, but it beats # doing real work ;-) # # You should edit the header and footer text portions of this file # before running it yourself, and then run as follows: # bibl2html [bibliography-file] [html-file] # Defaults are to read from stdin and write to stdout. # # If you are including inline HTML, be sure to escape the angle # brackets you use with backslashes. require 5.000; # Set this to wherever your bibl-grep program lives. But note that # the form this string takes must be a URL! $biblgrep = "http://www.maths.tcd.ie/cgi-bin/bibl-grep"; # The only bits you should need to tweak below this are # Open the source and target files. $bibl = $#ARGV >= 0 ? $ARGV[0] : "-"; $html = $#ARGV >= 1 ? $ARGV[1] : "-"; open(BIBL, "<$bibl") or die "$bibl: $!"; open(HTML, ">$html") or die "$html: $!"; # Skip past the bib file header. while ( ne "\f\n") { # do nothing } $l = "<"; $g = ">"; $date = `date`; loop: while ($line = ) { # Blank lines are record separators. if ($line eq "\n" && $in_record) { $html_Output .= "\n
\n\n"; $in_record = $location = 0; # reset flags next loop; } # We don't want to print the dates of record modifications. if ($line =~ /^(Record|Updated):/) { next loop; } # Change angle brackets to their HTML equivalents. $line =~ s//$g/g unless ($line =~ /\\(\\\\)*>/); $line =~ s/\\(.)/$1/g; $in_record = 1; # we are inside a record # Special case headers. A record name gets a level-2 HTML header. if ($line =~ /^Name:\s(.*)$/) { $name = $1; $idx_name = $name; $idx_name =~ s/^(The|A|An)[\s]+(.*)/\u\2, \l\1/i; $link = $idx_name; $link =~ s/[-\s_,.:]+/-/g; $link =~ tr/A-Z/a-z/; $html_Output .= sprintf("

%s

\n

\n

\n", $link, $name); $name_index[++$#name_index] = "$idx_name
\n"; next loop; } # We only output the `Location' header once per record. Make # entries under such headers be hyperlinks. if ($line =~ /^Location:\s(.*)$/) { if (!$location) { $html_Output .= "
\n Location \n
\n$1\n"; $location = 1; } else { $html_Output .= "
\n$1\n"; } next loop; } if ($line =~ /^Keywords:\s(.*)$/) { $keywords .= "$1, "; $html_Output .= "
\n Key words \n
\n$1\n"; next loop; } # Other headers. if ($line =~ /^([a-zA-Z]+):\s(.*)$/) { $html_Output .= "
\n $1 \n
\n$2\n"; next loop; } $html_Output .= $line; } # End of file. if ($in_record) { $html_Output .= "
\n"; } # Mess with our indices. @name_index = sort {$a cmp $b;} @name_index; @keywords = split(/,\s/, $keywords); @keywords = sort no_case @keywords; # Keep unique key words. for ($i = 1; $i < $#keywords; $i++) { if ((uc $keywords[$i]) ne (uc $keywords[$i-1])) { $keys[++$#keys] = $keywords[$i]; } } $keywords = '