chiark / gitweb /
Merge branch 'master' of ijackson@chiark:things/ypp-sc-tools
[ypp-sc-tools.db-test.git] / pctb / yppsc-decode-marketdata
index 787790c4a1349bfccd98898481d70975f870bb3c..d798aad03a1e8de8bc274e5de9837c5635801848 100755 (executable)
@@ -2,9 +2,10 @@
 
 use IO::Handle;
 
+open CM, "#commodmap#.tsv" or die $!;
+
 $debug=1 if @ARGV;
 
-open CM, "commodmap" or die $!;
 while (<CM>) {
     m/^(\S.*\S)\t(\d+)$/ or die;
     $commodmap[$2]= $1;
@@ -45,7 +46,7 @@ sub inmap($\@$) {
     my ($what,$ary,$ix) = @_;
     my $got= $ary->[$ix];
     return $got if defined $got;
-    warn "$what $ix ?";
+    die "$what $ix ?";
 }
     
 
@@ -67,9 +68,10 @@ unshift @stalls, undef;
 $|=1;
 
 foreach $bs qw(Buy Sell) {
-    $ncommods= getint("Buy ncommods");
-    for ($commodnum=0; $commodnum<$ncommods; $commodnum++) {
-       $commodix= getint("Buy $commodnum commodix");
+    $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("Buy $commodnum $offernum stallix");
@@ -83,6 +85,8 @@ foreach $bs qw(Buy Sell) {
            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;
        }
     }
 }