+our %check_tsv_done;
+
+sub check_tsv_line ($$) {
+ my ($l, $bad_data_callback) = @_;
+ my $bad_data= sub { &$bad_data_callback("bad data: line $.: $_[0]"); };
+
+ chomp($l) or &$bad_data('missing end-of-line');
+
+ $l !~ m/\P{IsPrint}/ or &$bad_data('nonprinting char(s)');
+ $l !~ m/\\/ or &$bad_data('data contains backslashes');
+ my @v= split /\t/, $l, -1;
+ @v==6 or &$bad_data('wrong number of fields');
+ my ($commod,$stall) = @v;
+
+ !keys %commods or
+ defined $commods{$commod} or
+ &$bad_data("unknown commodity \`$commod'");
+
+ $stall =~ m/^\p{IsUpper}|^[0-9]/ or &$bad_data("stall not capitalised");
+ !exists $check_tsv_done{$commod,$stall} or &$bad_data("repeated data");
+ $check_tsv_done{$commod,$stall}= 1;
+ foreach my $i (2..5) {
+ my $f= $v[$i];
+ $f =~ m/^(|0|[1-9][0-9]{0,5}|\>1000)$/ or &$bad_data("bad field $i");
+ ($i % 2) or ($f !~ m/\>/) or &$bad_data("> in field $i price");
+ }
+ return @v;
+}
+