#!/usr/bin/env perl

use XML::Parser;

die "usage: report.pl file\n" unless @ARGV == 1;
my $p = new XML::Parser(Style=>'Stream');

$first_column = 1;
$column = 0;
$ncolumn = 0;

$p->parsefile($ARGV[0]);

exit;

sub StartTag {
    my ($expat, $eltype) = @_;
    if ($eltype eq 'td') {
	$column = 1;
	$ncolumn++;
    }
    return;
}

sub EndTag {
    my ($expat, $eltype) = @_;
    if ($eltype eq 'td') {
	$first_column = 0;
	$column = 0;
	print " ";
    } elsif ($eltype eq 'tr') {
	print "$title yes\n";
	$first_column = 1;
	$ncolumn = 0;
    }
    return;
}

sub Text {
    my $text = $_;
    $text =~ s/\n/ /g;
    if ($column) {
	if ($ncolumn == 1 && $text !~ /,/) {
	    print $text;
	    print "\n no comma\n";
	    exit;
	}
	$text =~ s/,\s+/ /;
	$text =~ s/^\s+//;
	$text =~ s/\s+$//;
	$text =~ s/Jefferson Lab/JLAB/;
	$text =~ s/University of Tenn/TENN/;
	$text =~ s/Old Dominion University/ODU/;
	$text =~ s/Regina University/REG/;
	$text =~ s/IHEP(Protvino)/IHEP/;
	$text =~ s/Glasgow University/GLAS/;
	$text =~ s/Florida State University/FSU/;
	$text =~ s/Christopher Newport University/CNU/;
	$text =~ s/Carnegie Mellon University/CMU/;
	$text =~ s/Indiana University/IU/;
	$text =~ s/University of Alberta/ALB/;
	$text =~ s/Catholic University/CUA/;
	$text =~ s/University of Connecticut/UCON/;
	if ($ncolumn == 5) {
	    $text =~ s/ //g;
	}
	if ($ncolumn == 4) {
	    $text =~ s/ /\\b/;
	    $title = $text;
	} else {
	    print $text;
	}
    }
	return;
    }

sub PI {
    print "PI called\n";
    return;
}

