X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=pctb%2Fdecode-pctb-marketdata;h=f7af70dbf200104883e6b9ce392bd45ca5dd9773;hp=6cdecc658d1e2065237e9f12c6aeea025adcdb12;hb=3c3e5dc8eae9b239f2dab871a3bd47222af09538;hpb=38e3d1bf1be975c8edd6a166106ab2729d15249c diff --git a/pctb/decode-pctb-marketdata b/pctb/decode-pctb-marketdata index 6cdecc6..f7af70d 100755 --- a/pctb/decode-pctb-marketdata +++ b/pctb/decode-pctb-marketdata @@ -1,27 +1,26 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # This specific file is hereby placed in the public domain, or nearest # equivalent in law, by me, Ian Jackson. 5th July 2009. -use IO::Handle; +use IO::File; +use strict (qw(vars)); -open CM, "_commodmap.tsv" or die $!; +use Commods; + +our ($debug)= 0; $debug=1 if @ARGV; -while () { - m/^(\S.*\S)\t(\d+)$/ or die; - $commodmap[$2]= $1; -} -die $! if CM->error; +parse_pctb_commodmap(); -%stallkinds= qw(A Apothecary - D Distilling - F Furnishing - I Ironworking - S Shipbuilding - T Tailor - W Weaving); +our %stallkinds= qw(A Apothecary + D Distilling + F Furnishing + I Ironworking + S Shipbuilding + T Tailor + W Weaving); sub getline ($) { my ($w)= @_; @@ -54,13 +53,14 @@ sub inmap($\@$) { printf "# Version: \"%s\"\n", getline("version"); -$nstalls= getline("nstalls")+0; +our $nstalls= getline("nstalls")+0; +our @stalls; while (@stalls < $nstalls) { $_= getline("stall name ".(@stalls+1)); if (s/\^([A-Z])$//) { - $kind= $1; - $sk= $stallkinds{$kind}; + my $kind= $1; + my $sk= $stallkinds{$kind}; die "kind $kind in $_ ?" unless defined $sk; $_ .= "'s $sk Stall"; } @@ -70,19 +70,20 @@ unshift @stalls, undef; $|=1; -foreach $bs qw(Buy Sell) { - $alloffers_want= getint("Buy ncommods"); - $alloffers_done=0; +foreach my $bs qw(Buy Sell) { + my $alloffers_want= getint("Buy ncommods"); + my $alloffers_done=0; while ($alloffers_done < $alloffers_want) { - $commodix= getint("Buy $alloffers_done/$alloffers_want commodix"); - $offers= getint("Buy $commodnum offers"); + my $commodix= getint("Buy $alloffers_done/$alloffers_want commodix"); + my $offers= getint("Buy $commodix offers"); + my $offernum; for ($offernum=0; $offernum<$offers; $offernum++) { - $stallix= getint("Buy $commodnum $offernum stallix"); - $price= getint("Buy $commodnum $offernum price"); - $qty= getint("Buy $commodnum $offernum qty"); + my $stallix= getint("Buy $commodix $offernum stallix"); + my $price= getint("Buy $commodix $offernum price"); + my $qty= getint("Buy $commodix $offernum qty"); printf("%s\t%s\t%s", $bs, - inmap('commod',@commodmap,$commodix), + inmap('commod',@pctb_commodmap,$commodix), inmap('stall',@stalls,$stallix)) or die $!; if ($bs eq 'Sell') { print "\t\t" or die $!; } printf("\t%d\t%d", $price, $qty) or die $!; @@ -94,7 +95,7 @@ foreach $bs qw(Buy Sell) { } } -$r= read STDIN,$b,1; +my $r= read STDIN,$b,1; STDIN->error and die $!; STDIN->eof or die; $b and die;