prt-auf: improve parsing of format string in printf_ports()

This commit is contained in:
John McQuah 2022-12-25 19:05:00 -05:00
parent 787ba038e0
commit d65af7889f
1 changed files with 20 additions and 13 deletions

View File

@ -32,9 +32,9 @@ my @basedirs = @{$bldirs[0]}; my @localports = @{$bldirs[1]};
my ($action, @query) = parse_args(@ARGV);
# load some data structures into memory for the actions that need them
if ($action !~ /^(fsearch|isinst|current)$/) {
if (($action !~ /^(fsearch|isinst|current)$/) and ($osearch{cache}==0)) {
@allports = list_ports();
fill_hashes_from_pkgfiles() unless ($action eq "printf");
fill_hashes_from_pkgfiles();
}
if ($osearch{cache}==1) { fill_hashes_from_cache(); }
@ -86,7 +86,7 @@ if (($action =~ /^(listinst|listorphans)/)
foreach my $result (@results) {
$result .= " $V_INST{$result}" if $osearch{verbose}==1;
$result .= " $V_INST{$result}\n$DESC{$result}\n" if $osearch{verbose}>1;
printf "$strf", $result;
printf $strf, $result;
}
} elsif ($action =~ /^(list|search|dsearch|path|dependent)/) {
foreach my $result (@results) {
@ -126,7 +126,7 @@ if (($action =~ /^(listinst|listorphans)/)
}
$depline .= " $V_REPO{$dep}" if $osearch{verbose}==1;
$depline .= " $V_REPO{$dep}\n$DESC{$dep}" if $osearch{verbose}>1;
printf "$strf", $ind, $depline unless ($action eq "quickdep");
printf $strf, $ind, $depline unless ($action eq "quickdep");
printf "%s ", $dep if ($action eq "quickdep");
}
print "\n" if ($action eq "quickdep");
@ -311,9 +311,9 @@ sub who_aliased_to {
sub printf_ports {
my $FS; my @pstats; my $p; my $inputf=shift; my @targets=@_;
my @pos; my $strf; my $outputf;
my %subscripts = ( "%n"=>0, "%p"=>1, "%v"=>2, "%r"=>3, "%d"=>4, "%e"=>5,
"%u"=>6, "%P"=>7, "%M"=>8, "%R"=>9, "%E"=>10, "%O"=>11, "%l"=>12, "%i"=>13 );
my @pos; my @outfields; my $outputf; my %FS = ( "t"=>"\t", "n"=>"\n" );
my %subscripts = ( "n"=>0, "p"=>1, "v"=>2, "r"=>3, "d"=>4, "e"=>5,
"u"=>6, "P"=>7, "M"=>8, "R"=>9, "E"=>10, "O"=>11, "l"=>12, "i"=>13 );
if ($inputf eq "CACHE") {
open (CACHE,'>',$prtcache) or die "cannot create a new cache file";
print CACHE "V5\n";
@ -325,17 +325,24 @@ sub printf_ports {
} close (CACHE);
print "cache created.\n";
} else {
$strf = $inputf;
$strf =~ s/(%p|%n|%v|%r|%d|%e|%u|%P|%M|%R|%E|%O|%l|%i)/_Z_$subscripts{$1}/g;
@pos = grep { s/([0-9]+)(.*)/$1/ } (split /_Z_/, $strf);
$outputf = "$inputf\n";
$outputf =~ s/(%p|%n|%v|%r|%d|%e|%u|%P|%M|%R|%E|%O|%l|%i)/%-14s/g;
@outfields = split /(\\t|\\n)/, $inputf;
foreach (@outfields) {
if (m/\\(t|n)/) { $outputf .= $FS{$1}; next; }
$strf = $_;
s/%(p|n|v|r|d|e|u|P|M|R|E|O|l|i)/_Z_$subscripts{$1}/g;
push @pos, grep { s/([0-9]+)(.*)/$1/ } (split /_Z_/, $_);
$strf =~ s/%(p|n|v|r|d|e|u|P|M|R|E|O|l|i)/%s/g;
$outputf .= $strf;
}
foreach my $pp (@targets) {
$p = (split /\//, $pp)[-1];
@pstats = get_pkgfile_fields($pp,"all");
$pstats[12] = (grep /^$p$/, @LOCKED) ? "yes" : "no";
$pstats[13] = (grep /^$p$/, keys %V_INST) ? "yes" : "no";
if (($pstats[13] eq "yes") and ($V_INST{$p} ne $V_REPO{$p})) {
$pstats[13] = "diff" }
printf STDOUT $outputf, @pstats[@pos];
}
}