From: Ian Jackson Date: Tue, 9 Jun 2009 23:56:04 +0000 (+0100) Subject: Merge branch 'master' of chiark:/home/ijackson/things/ypp-sc-tools X-Git-Tag: 1.9.2~124^2~13 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=commitdiff_plain;h=d72b57e4670133db5ff022ab2284e75e73ce146c;hp=-c;p=ypp-sc-tools.db-test.git Merge branch 'master' of chiark:/home/ijackson/things/ypp-sc-tools Conflicts: pctb/yppsc-decode-marketdata --- d72b57e4670133db5ff022ab2284e75e73ce146c diff --combined pctb/yppsc-decode-marketdata index b093589,e8f0ef0..d798aad --- a/pctb/yppsc-decode-marketdata +++ b/pctb/yppsc-decode-marketdata @@@ -2,7 -2,9 +2,10 @@@ use IO::Handle; +open CM, "#commodmap#.tsv" or die $!; ++ + $debug=1 if @ARGV; + -open CM, "commodmap" or die $!; while () { m/^(\S.*\S)\t(\d+)$/ or die; $commodmap[$2]= $1; @@@ -17,20 -19,25 +20,25 @@@ die $! if CM->error T Tailor W Weaving); - sub getline() { + sub getline ($) { + my ($w)= @_; $!=0; my $l= ; die $! unless defined $l; die $! if STDIN->error; die unless chomp $l; - #print STDERR "GOT LINE [$l]\n"; + print "GOT FOR $w LINE [$l]\n" + if $debug; return $l; } - sub getint() { + sub getint ($) { + my ($w)= @_; my $b; + my $t= tell STDIN; $t>=0 or die $!; my $r= read STDIN,$b,2; die $! if STDIN->error; die unless $r==2; my $v= scalar unpack "v", $b; - #printf STDERR "GOT INT %d 0x%x\n", $v, $v; + printf "GOT AT 0x%x INT FOR %s VALUE %d 0x%x\n", $t, $w, $v, $v + if $debug; return $v; } @@@ -42,12 -49,12 +50,12 @@@ sub inmap($\@$) } - printf "# Version: \"%s\"\n", getline(); - $nstalls= getline()+0; + printf "# Version: \"%s\"\n", getline("version"); + $nstalls= getline("nstalls")+0; while (@stalls < $nstalls) { - $_= getline(); - if (s/\^[A-Z]$//) { + $_= getline("stall name ".(@stalls+1)); + if (s/\^([A-Z])$//) { $kind= $1; $sk= $stallkinds{$kind}; die "kind $kind in $_ ?" unless defined $sk; @@@ -60,14 -67,15 +68,15 @@@ unshift @stalls, undef $|=1; foreach $bs qw(Buy Sell) { - $ncommods= getint(); - for ($commodnum=0; $commodnum<$ncommods; $commodnum++) { - $commodix= getint(); - $offers= getint(); + $alloffers_want= getint("Buy ncommods"); + $alloffers_done=0; + while ($alloffers_done < $alloffers_want) { + $commodix= getint("Buy $alloffers_done/$alloffers_want commodix"); + $offers= getint("Buy $commodnum offers"); for ($offernum=0; $offernum<$offers; $offernum++) { - $stallix= getint(); - $price= getint(); - $qty= getint(); + $stallix= getint("Buy $commodnum $offernum stallix"); + $price= getint("Buy $commodnum $offernum price"); + $qty= getint("Buy $commodnum $offernum qty"); printf("%s\t%s\t%s", $bs, inmap('commod',@commodmap,$commodix), @@@ -76,6 -84,13 +85,13 @@@ printf("\t%d\t%d", $price, $qty) or die $!; if ($bs eq 'Buy') { print "\t\t" or die $!; } print "\n" or die $!; + $alloffers_done++; + die if $alloffers_done > $alloffers_want; } } } + + $r= read STDIN,$b,1; + STDIN->error and die $!; + STDIN->eof or die; + $b and die;