boy, was this easy with this module. all we need to do is mess around
with the output to get whatever leo needs.

with this struct (from leo with some minor changes):

struct xt {
        char x;
        struct yt {
                char i,k;
                int  j;
        } Y;
        char z;
} X;

and this trivial script (i pass the filename on the command line):

#!/usr/local/bin/perl -w

use strict ;

use Data::Dumper ;
use Convert::Binary::C ;

my $cbc = Convert::Binary::C->new() ;

$cbc->parse_file( @ARGV ) ;

#print Dumper $cbc->compound() ;

my @structs = $cbc->compound() ;

foreach my $struct ( @structs ) {

        print "$struct->{'type'} $struct->{'identifier'}\n" ;

        foreach my $declaration ( @{$struct->{'declarations'}} ) {

                my $type = $declaration->{'type'} ;

                foreach my $declarator ( @{$declaration->{'declarators'}} ) {

                        my $decl_name = $declarator->{'declarator'} ;
                        my $offset = $declarator->{'offset'} ;

                        print "\t$type $decl_name : offset $offset\n" ;
                }
        }
}


i get this lovely output:

struct yt
        char i : offset 0
        char k : offset 1
        int j : offset 2
struct xt
        char x : offset 0
        struct yt Y : offset 1
        char z : offset 7

this was part of the structure parse tree (via Dumper):

$VAR2 = {
          'context' => 'xyz.h(3)',
          'declarations' => [
                              {
                                'declarators' => [
                                                   {
                                                     'declarator' => 'x',
                                                     'offset' => 0,
                                                     'size' => 1
                                                   }
                                                 ],
                                'type' => 'char'
                              },
                              {
                                'declarators' => [
                                                   {
                                                     'declarator' => 'Y',
                                                     'offset' => 1,
                                                     'size' => 5
                                                   }
                                                 ],
                                'type' => 'struct yt'
                              },
                              {
                                'declarators' => [
                                                   {
                                                     'declarator' => 'z',
                                                     'offset' => 6,
                                                     'size' => 1
                                                   }
                                                 ],
                                'type' => 'char'
                              }
                            ],
          'pack' => 0,
          'align' => 1,
          'size' => 7,
          'identifier' => 'xt',
          'type' => 'struct'
        };



BTW, this was on a sparc/solaris box.

so what output formats do we need?


the structures parse tree (from the compound method) has everything you
could want and is very simple to navigate. this is one amazing module
and it should get more publicity for sure.

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

Reply via email to