#!/usr/tools/bin/perl
#
# $Id: bibtex2sgml.pl,v 1.1 1994/04/26 15:19:23 connolly Exp $
#
# USAGE:
#   perl bibtex2sgml.pl <README-prospero-documents >>bibtextest.sgml
#   vi bibtextest.sgml # fix up stuff
#

$* = 1;

while(<>){
    next unless s/@(\w+)\{\s*//;

    local($gi) = $1;

    print "\n<$gi ";

    s/([^,]+),// && print "id = $1";

    print ">\n";

    $_ .= <> until /\}\s*$/;

    while(s/^\s*(\w+)\s*=\s*//){
	local($gi) = $1;
	local($content);

	if(s/^"([^\"]*)"//){
	    $content = $1;
	}
	else{
	    s/^([^,]+),?\s*//;
	    $content = $1;
	}
	$content =~ s/[\{\}]//g;
	$content =~ s/\\\w+//g;
	print " <$gi>", &no_markup($content), "\n";
    }

    print "</$gi>\n";
}

sub no_markup{
    local($_) = @_;

    s/([<>&])/"&#" . sprintf("%d", ord($1)). ";"/ge;
    return $_;
}
