Skip to content

Commit

Permalink
extend port extraction in command arrays to recursively check inside …
Browse files Browse the repository at this point in the history
…elements which are themselves arrays
  • Loading branch information
dozy committed Mar 4, 2020
1 parent c1a1865 commit 6ca9c1d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions bin/vtfp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1809,29 +1809,32 @@ sub delete_port {
}

sub _extract_ports {
my ($cmd, $id) = @_;
my %ports;
my ($cmd, $id, $ports) = @_;
$ports //= {};

unless($cmd and ref $cmd eq q[ARRAY]) {
return;
}

for my $i (0..$#{$cmd}) {
my $elem = $cmd->[$i];
if(ref $elem eq q[HASH]) {
if(ref $elem eq q[ARRAY]) {
$ports = _extract_ports($elem, $id, $ports);
}
elsif(ref $elem eq q[HASH]) {
if($elem->{port}) {
$ports{$elem->{port}}->{attribs} = reconcile_port_info($elem, $ports{$elem->{port}}->{attribs});
$ports{$elem->{port}}->{occurrences} ||= [];
push @{$ports{$elem->{port}}->{occurrences}}, {arr => $cmd, idx => $i}; # note location for later substitution
$ports->{$elem->{port}}->{attribs} = reconcile_port_info($elem, $ports->{$elem->{port}}->{attribs});
$ports->{$elem->{port}}->{occurrences} ||= [];
push @{$ports->{$elem->{port}}->{occurrences}}, {arr => $cmd, idx => $i}; # note location for later substitution
}
elsif($elem->{packflag}) {
if(ref $elem->{packflag} eq q[ARRAY]) {
for my $j (0..$#{$elem->{packflag}}) {
my $pf_elem = $elem->{packflag}->[$j];
if(ref $pf_elem eq q[HASH] and $pf_elem->{port}) {
$ports{$pf_elem->{port}}->{attribs} = reconcile_port_info($pf_elem, $ports{$pf_elem->{port}}->{attribs});
$ports{$pf_elem->{port}}->{occurrences} ||= [];
push @{$ports{$pf_elem->{port}}->{occurrences}}, {arr => $elem->{packflag}, idx => $j}; # note location for later substitution
$ports->{$pf_elem->{port}}->{attribs} = reconcile_port_info($pf_elem, $ports->{$pf_elem->{port}}->{attribs});
$ports->{$pf_elem->{port}}->{occurrences} ||= [];
push @{$ports->{$pf_elem->{port}}->{occurrences}}, {arr => $elem->{packflag}, idx => $j}; # note location for later substitution
}
}
}
Expand All @@ -1842,7 +1845,7 @@ sub _extract_ports {
}
}

return \%ports;
return $ports;
}

sub reconcile_port_info {
Expand Down

0 comments on commit 6ca9c1d

Please sign in to comment.