chiark
/
gitweb
/
~yarrgweb
/
ypp-sc-tools.db-test.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
WIP test decode-marketdata with example2
[ypp-sc-tools.db-test.git]
/
pctb
/
yppsc-decode-marketdata
diff --git
a/pctb/yppsc-decode-marketdata
b/pctb/yppsc-decode-marketdata
index 969ada0aa6e6f769c8c559b1f0df8648d46a0b19..787790c4a1349bfccd98898481d70975f870bb3c 100755
(executable)
--- a/
pctb/yppsc-decode-marketdata
+++ b/
pctb/yppsc-decode-marketdata
@@
-2,6
+2,8
@@
use IO::Handle;
use IO::Handle;
+$debug=1 if @ARGV;
+
open CM, "commodmap" or die $!;
while (<CM>) {
m/^(\S.*\S)\t(\d+)$/ or die;
open CM, "commodmap" or die $!;
while (<CM>) {
m/^(\S.*\S)\t(\d+)$/ or die;
@@
-17,20
+19,25
@@
die $! if CM->error;
T Tailor
W Weaving);
T Tailor
W Weaving);
-sub getline() {
+sub getline ($) {
+ my ($w)= @_;
$!=0; my $l= <STDIN>; die $! unless defined $l;
die $! if STDIN->error;
die unless chomp $l;
$!=0; my $l= <STDIN>; 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;
}
return $l;
}
-sub getint() {
+sub getint ($) {
+ my ($w)= @_;
my $b;
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;
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;
}
return $v;
}
@@
-38,16
+45,16
@@
sub inmap($\@$) {
my ($what,$ary,$ix) = @_;
my $got= $ary->[$ix];
return $got if defined $got;
my ($what,$ary,$ix) = @_;
my $got= $ary->[$ix];
return $got if defined $got;
-
die
"$what $ix ?";
+
warn
"$what $ix ?";
}
}
-printf "# Version: \"%s\"\n", getline();
-$nstalls= getline()+0;
+printf "# Version: \"%s\"\n", getline(
"version"
);
+$nstalls= getline(
"nstalls"
)+0;
while (@stalls < $nstalls) {
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;
$kind= $1;
$sk= $stallkinds{$kind};
die "kind $kind in $_ ?" unless defined $sk;
@@
-60,14
+67,14
@@
unshift @stalls, undef;
$|=1;
foreach $bs qw(Buy Sell) {
$|=1;
foreach $bs qw(Buy Sell) {
- $ncommods= getint();
+ $ncommods= getint(
"Buy ncommods"
);
for ($commodnum=0; $commodnum<$ncommods; $commodnum++) {
for ($commodnum=0; $commodnum<$ncommods; $commodnum++) {
- $commodix= getint();
- $offers= getint();
+ $commodix= getint(
"Buy $commodnum commodix"
);
+ $offers= getint(
"Buy $commodnum offers"
);
for ($offernum=0; $offernum<$offers; $offernum++) {
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),
printf("%s\t%s\t%s",
$bs,
inmap('commod',@commodmap,$commodix),
@@
-79,3
+86,8
@@
foreach $bs qw(Buy Sell) {
}
}
}
}
}
}
+
+$r= read STDIN,$b,1;
+STDIN->error and die $!;
+STDIN->eof or die;
+$b and die;