prt-auf: improve parsing of format string in printf_ports()
This commit is contained in:
parent
787ba038e0
commit
d65af7889f
@ -32,9 +32,9 @@ my @basedirs = @{$bldirs[0]}; my @localports = @{$bldirs[1]};
|
|||||||
my ($action, @query) = parse_args(@ARGV);
|
my ($action, @query) = parse_args(@ARGV);
|
||||||
|
|
||||||
# load some data structures into memory for the actions that need them
|
# 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();
|
@allports = list_ports();
|
||||||
fill_hashes_from_pkgfiles() unless ($action eq "printf");
|
fill_hashes_from_pkgfiles();
|
||||||
}
|
}
|
||||||
if ($osearch{cache}==1) { fill_hashes_from_cache(); }
|
if ($osearch{cache}==1) { fill_hashes_from_cache(); }
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ if (($action =~ /^(listinst|listorphans)/)
|
|||||||
foreach my $result (@results) {
|
foreach my $result (@results) {
|
||||||
$result .= " $V_INST{$result}" if $osearch{verbose}==1;
|
$result .= " $V_INST{$result}" if $osearch{verbose}==1;
|
||||||
$result .= " $V_INST{$result}\n$DESC{$result}\n" 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)/) {
|
} elsif ($action =~ /^(list|search|dsearch|path|dependent)/) {
|
||||||
foreach my $result (@results) {
|
foreach my $result (@results) {
|
||||||
@ -126,7 +126,7 @@ if (($action =~ /^(listinst|listorphans)/)
|
|||||||
}
|
}
|
||||||
$depline .= " $V_REPO{$dep}" if $osearch{verbose}==1;
|
$depline .= " $V_REPO{$dep}" if $osearch{verbose}==1;
|
||||||
$depline .= " $V_REPO{$dep}\n$DESC{$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");
|
printf "%s ", $dep if ($action eq "quickdep");
|
||||||
}
|
}
|
||||||
print "\n" if ($action eq "quickdep");
|
print "\n" if ($action eq "quickdep");
|
||||||
@ -311,9 +311,9 @@ sub who_aliased_to {
|
|||||||
|
|
||||||
sub printf_ports {
|
sub printf_ports {
|
||||||
my $FS; my @pstats; my $p; my $inputf=shift; my @targets=@_;
|
my $FS; my @pstats; my $p; my $inputf=shift; my @targets=@_;
|
||||||
my @pos; my $strf; my $outputf;
|
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,
|
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 );
|
"u"=>6, "P"=>7, "M"=>8, "R"=>9, "E"=>10, "O"=>11, "l"=>12, "i"=>13 );
|
||||||
if ($inputf eq "CACHE") {
|
if ($inputf eq "CACHE") {
|
||||||
open (CACHE,'>',$prtcache) or die "cannot create a new cache file";
|
open (CACHE,'>',$prtcache) or die "cannot create a new cache file";
|
||||||
print CACHE "V5\n";
|
print CACHE "V5\n";
|
||||||
@ -325,17 +325,24 @@ sub printf_ports {
|
|||||||
} close (CACHE);
|
} close (CACHE);
|
||||||
print "cache created.\n";
|
print "cache created.\n";
|
||||||
} else {
|
} else {
|
||||||
$strf = $inputf;
|
@outfields = split /(\\t|\\n)/, $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);
|
foreach (@outfields) {
|
||||||
|
if (m/\\(t|n)/) { $outputf .= $FS{$1}; next; }
|
||||||
$outputf = "$inputf\n";
|
$strf = $_;
|
||||||
$outputf =~ s/(%p|%n|%v|%r|%d|%e|%u|%P|%M|%R|%E|%O|%l|%i)/%-14s/g;
|
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) {
|
foreach my $pp (@targets) {
|
||||||
$p = (split /\//, $pp)[-1];
|
$p = (split /\//, $pp)[-1];
|
||||||
@pstats = get_pkgfile_fields($pp,"all");
|
@pstats = get_pkgfile_fields($pp,"all");
|
||||||
$pstats[12] = (grep /^$p$/, @LOCKED) ? "yes" : "no";
|
$pstats[12] = (grep /^$p$/, @LOCKED) ? "yes" : "no";
|
||||||
$pstats[13] = (grep /^$p$/, keys %V_INST) ? "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];
|
printf STDOUT $outputf, @pstats[@pos];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user