#!/usr/bin/perl -W

# parses the engine_t structure in global.h

# ParseStruct.pm is in bin/ directory, I was unlucky with:
# push (@INC, 'bin'); push (@INC, '.');
# therefore the bin:: hack:
use bin::ParseStruct;

# TODO: make it possible to accept 
# more than one in-files (config.txt tables.txt)
# and use STDOUT as output
if (@ARGV != 2) {
    print "usage:\n";
    print "\t test_engine.pl global.h engine_t \n\n";
    exit;
}


my ($headerfilename, $structname) = @ARGV;

$psobj = ParseStruct->new();
$psobj->wantedstructs( $structname );
$psobj->datasource( $headerfilename );
$psobj->readstructs();
my $vars = $psobj->getstructvars( $structname );


foreach $key (keys %$vars){
	my $siz = $psobj->{structs}->{$structname}->{sizes}->{$key};
	my $offset = $psobj->{structs}->{$structname}->{offsets}->{$key};

	print "var=$key; offset=$offset; size = $siz\n";
}

my $offsets = $psobj->{structs}->{$structname}->{offsets};
foreach $key ( sort {$a <=> $b} keys %$offsets  ){
	my $varname = $offsets->{$key};
	
	my $siz = $psobj->{structs}->{$structname}->{sizes}->{$varname};
	my $offset = $psobj->{structs}->{$structname}->{offsets}->{$varname};

	print "var=$varname; offset=$key; size = $siz\n";
}
