From a959ae3fcf49b2f3ca26d14e7e02ccb2ef29898f Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Tue, 6 Aug 2013 14:07:27 +0200 Subject: [PATCH] added support for groups --- xml-db/get.pl | 125 ++++++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 59 deletions(-) diff --git a/xml-db/get.pl b/xml-db/get.pl index e2eaf95..08e721e 100755 --- a/xml-db/get.pl +++ b/xml-db/get.pl @@ -13,7 +13,7 @@ use FindBin qw($RealBin); use Storable qw(lock_retrieve); use Text::TabularDisplay; use feature "switch"; - +use CGI::Carp qw(fatalsToBrowser); my $help = 0; my $verbose = 0; @@ -50,13 +50,14 @@ die "Unable to read cache file\n" unless defined $db; die "Name not found in entity file\n" unless(exists $db->{$name}); -my $obj = $db->{$name}; - -print DumpTree($obj) if $verbose; - +############################### +#### Main "do the job" +############################### +runandprint($db->{$name},$name); + ############################### #### Formatting of values ############################### @@ -90,73 +91,79 @@ sub FormatPretty { } # -############################### -#### Do Trbcmd access -############################### -my $o; -if($obj->{type} eq "register" || $obj->{type} eq "registerfield" || $obj->{type} eq "field") { - $o = trb_register_read($netaddr,$obj->{address}); - print DumpTree($o) if $verbose>1; - } - + ############################### -#### Prepare table header line +#### Analyze Object & print contents ############################### +sub runandprint { + my ($obj,$name) = @_; + my $o; + print DumpTree($obj) if $verbose; + #### Iterate if group + if($obj->{type} eq "group") { + foreach my $c (@{$obj->{children}}) { + runandprint($db->{$c},$c); + } + } + + #### print if entry is a register or field + elsif($obj->{type} eq "register" || $obj->{type} eq "registerfield" || $obj->{type} eq "field") { + $o = trb_register_read($netaddr,$obj->{address}); + print DumpTree($o) if $verbose>1; + + #### Prepare table header line + my @fieldlist; + push(@fieldlist,("Board","Reg.")); + if($obj->{type} eq "register" || $obj->{type} eq "registerfield" || $obj->{type} eq "field") { + push(@fieldlist,"raw"); + } -my @fieldlist; -push(@fieldlist,("Board","Reg.")); -if($obj->{type} eq "register" || $obj->{type} eq "registerfield" || $obj->{type} eq "field") { - push(@fieldlist,"raw"); - } - -if($obj->{type} eq "registerfield"){ - push(@fieldlist,$name) ; - } + if($obj->{type} eq "registerfield"){ + push(@fieldlist,$name) ; + } -if($obj->{type} eq "field"){ - push(@fieldlist,$name) ; - } - -if($obj->{type} eq "register"){ - foreach my $c (@{$obj->{children}}){ - push(@fieldlist,$c); + if($obj->{type} eq "field"){ + push(@fieldlist,$name) ; + } + + if($obj->{type} eq "register"){ + foreach my $c (@{$obj->{children}}){ + push(@fieldlist,$c); + } + } + + my $t = Text::TabularDisplay->new(@fieldlist); + + #### Fill table with information + foreach my $b (sort keys %$o) { + my @l; + push(@l,sprintf("%04x",$b)); + push(@l,sprintf("%04x",$obj->{address})); + push(@l,sprintf("%08x",$o->{$b})); + if($obj->{type} eq "register") { + foreach my $c (@{$obj->{children}}) { + push(@l,FormatPretty($o->{$b},$db->{$c})); + } + } + elsif($obj->{type} eq "field" || $obj->{type} eq "registerfield") { + push(@l,FormatPretty($o->{$b},$obj)); + } + $t->add(@l); + } + + #### Show the beautiful result... + print $t->render; + print "\n"; } } -my $t = Text::TabularDisplay->new(@fieldlist); - -############################### -#### Fill table with information -############################### -foreach my $b (sort keys %$o) { - my @l; - push(@l,sprintf("%04x",$b)); - push(@l,sprintf("%04x",$obj->{address})); - push(@l,sprintf("%08x",$o->{$b})); - if($obj->{type} eq "register") { - foreach my $c (@{$obj->{children}}) { - push(@l,FormatPretty($o->{$b},$db->{$c})); - } - } - elsif($obj->{type} eq "field" || $obj->{type} eq "registerfield") { - push(@l,FormatPretty($o->{$b},$obj)); - } - $t->add(@l); - } - -############################### -#### Show the beautiful result... -############################### -print $t->render; - -print "\n"; - + ############################### #### Feierabend! ############################### -- 2.43.0