#!/usr/bin/perl

sub prfield {
    my ($name, $val) = @_;
    return if not defined $val or $val eq '';
    if ($val =~ s/^\'//) {
	print "  $name = $val,\n";
    } else {
	print "  $name = \"$val\",\n";
    }
}

while(<>) {
    next if /^\s*$/;
    if (/^\@String/) {
	print;
	next;
    }
    chop;
    split /\t/;
    unshift @_, undef;
# header
    print "\@$_[24]\{$_[1],\n";
    
# basic fields
    prfield "author", $_[2];
    prfield "year", $_[3];
    prfield "title", $_[4];
    
# title fields
    prfield "booktitle", $_[5];
    prfield "journal", $_[6];
    prfield "series", $_[7];
    prfield "crossref", $_[8];

# publisher information
    prfield "publisher", $_[9];
    prfield "school", $_[10];
    prfield "organization", $_[11];
    prfield "institution", $_[12];
    prfield "howpublished", $_[13];
    prfield "address", $_[14];

# other author fields
    prfield "editor", $_[15];
#    prfield "translator", $_[16]; # I added this for the future

# other time fields
    prfield "edition", $_[17];
#    prfield "firstedition", $_[18];  # This is the year book was first published

# citation information
    prfield "volume", $_[19];
    prfield "number", $_[20];
    prfield "month", $_[21];
    prfield "chapter", $_[22];
    prfield "pages", $_[23];

# meta fields
#   prfield "entrytype", $_[24];  # This is the @ name in bibtex format
    prfield "type", $_[25];
    prfield "key", $_[26];

# note fields
    prfield "annote", $_[27];
    prfield "note", $_[28];

# my extra fields
#   prfield "category", $_[29];
#   prfield "got", $_[30];
    print "}\n\n";
}
