prt-auf: refactor the listorphans routine

This commit is contained in:
John McQuah 2023-02-15 16:13:39 -05:00
parent b31bc84259
commit 18b7b6fd3f
1 changed files with 10 additions and 7 deletions

View File

@ -83,13 +83,13 @@ if ($action eq "path") { @results = find_port_by_name($query[0],1,1,0);
$strf = "%s\n";
if (($action =~ /^(listinst|listorphans)/)
or (($action eq "dependent") and ($odepends{all}==0))) {
foreach my $result (@results) {
foreach my $result (sort @results) {
$result .= " $V_INST{$result}" if $osearch{verbose}==1;
$result .= " $V_INST{$result}\n$DESC{$result}\n" if $osearch{verbose}>1;
printf $strf, $result;
}
} elsif ($action =~ /^(list|search|dsearch|path|dependent)/) {
foreach my $result (@results) {
foreach my $result (sort @results) {
next if ((! $result) or ($result =~ /^\s*$/));
$result =~ s/.*\/(.*)$/$1/ if (($action ne "path") and ($osearch{path}==0));
$result .= " $V_REPO{$result}" if (($osearch{verbose}==1) and ($action ne "path"));
@ -508,22 +508,25 @@ sub list_ports {
} elsif ($subset eq "inst") { @found = keys %V_INST;
} elsif ($subset eq "locked") { @found=@LOCKED;
} elsif ($subset =~ /^(orphans|dependent)$/) {
my $seed=shift;
my $seed=shift if ($subset eq "dependent");
if (($subset eq "dependent") and (! find_port_by_name($seed,1,1,0))) {
print "$seed not found in the ports tree.\n"; return;
}
$seed =~ s/\+/\\\+/g; # workaround for any port with a plus sign in its name
# workaround for any port with a plus sign in its name
$seed =~ s/\+/\\\+/g if ($subset eq "dependent");
our @searchspace=(($subset eq "orphans") or ($odepends{all}==0)) ?
keys %V_INST : keys %DEPENDS;
@searchspace = grep { defined $DEPENDS{$_} } @searchspace;
if ($subset eq "orphans") {
my $inst_deps="";
my %not_orphans = map { $_ => 0 } keys %V_INST; my @ndd;
foreach my $port (@searchspace) {
$inst_deps .= " $DEPENDS{$port} " if ($DEPENDS{$port});
@ndd=split(/ /, $DEPENDS{$port});
map { $not_orphans{$_} = 1 } @ndd;
}
@found = grep { $inst_deps !~ / $_ / } @searchspace;
@found = grep { $not_orphans{$_} eq 0 } keys %V_INST;
} elsif (($subset eq "dependent") and ($odepends{recursive}==0)) {
@found = grep { " $DEPENDS{$_} " =~ / $seed / } @searchspace;
} elsif (($subset eq "dependent") and ($odepends{recursive}==1)) {