#!/usr/bin/perl
# simple interface; recognize an isbn, a upc, and some verbs...
sub clearvars {
    undef $ean;
    undef $upc;
    undef $isbn;
    undef $raw;
}

sub dumpone {
    print <<EOF;
  <book>
    <ean>$ean</ean>
    <isbn>isbn</isbn>
    <upc>$upc</upc>
    <title/>
    <author/>
    <raw>$raw</raw>
  </book>
EOF
    clearvars;
}

# assume both come over the same channel; write a reverse-t later
while(<>) {
    chomp;
    if (/^978/) {
	dumpone if defined $ean;
	$ean = $_;
    } elsif (/^\d\d\d\d\d/) {
	dumpone if defined $upc;
	$upc = $_;
    } elsif (/^$/) {
	# just RET means next book
	dumpone;
    } elsif (/^x$/) {
	clearvars;
    } elsif (/^i (\d*)$/ {
	$x_isbn = $1;
	dumpone if defined $isbn;
	$isbn = $x_isbn;
    }
    } elsif (/^r (.*)$/ {
	$x_raw = $1;
	dumpone if defined $raw;
	$raw = $x_raw;
    }
}


