+
+our (%stallmap, @stallmap);
+
+sub bs_gen_md ($$) {
+ my ($bs,$sortmul) = @_;
+ my $count= 0;
+ my $o= '';
+
+ foreach $commod (sort {
+ $commodmap{$a} <=> $commodmap{$b}
+ } keys %commod) {
+#print STDERR "COMMOD $commod\n";
+ $current= $commod{$commod};
+ my $l= bs_p($commod,$bs,$sortmul);
+ next unless @$l;
+#print STDERR "COMMOD $commod @$l\n";
+
+ $o .= writeint(scalar @$l);
+ foreach my $cs (@$l) {
+ $stall= $cs->{Stall};
+ my $stallix= $stallmap{$stall};
+ if (!defined $stallix) {
+ push @stallmap, $stall;
+ $stallmap{$stall}= $stallix= @stallmap;
+ }
+ my $qty= $cs->{Qty};
+ $qty =~ s/^\>\s*//;
+ $o .= writeint($stallix, $cs->{Price}, $qty+0);
+ }
+ $count++;
+ }
+#print STDERR "COMMOD $commod COUNT WAS $count\n";
+ return
+ writeint($count).$o;
+}
+
+sub writeint { return pack 'v*', @_; }