summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorPierre Neidhardt <ambrevar@gmail.com>2014-02-14 13:18:56 +0100
committerAllan McRae <allan@archlinux.org>2014-03-03 02:25:55 +0100
commite5c714f5010e803465dbe57adc31687dffba10b2 (patch)
treeed66cc062e2906019e5c181b0c026a62673b9834 /contrib
parentcfde337b7b5f4a7f56ff0a4e6142804f6e638f69 (diff)
downloadpacman-e5c714f5010e803465dbe57adc31687dffba10b2.tar.gz
pacman-e5c714f5010e803465dbe57adc31687dffba10b2.tar.xz
pacsearch: factored -Ss and -Qs parts into one single function
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/pacsearch.in55
1 files changed, 20 insertions, 35 deletions
diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in
index 18d4641b..a89328d0 100644
--- a/contrib/pacsearch.in
+++ b/contrib/pacsearch.in
@@ -95,46 +95,31 @@ sub print_pkg {
print "$v[5]";
}
-my %allpkgs = ();
-my @pkglist = ();
-
-open (my $syncout, '-|', 'pacman', '-Ss', '--', @ARGV) or exit 1;
-while ( readline($syncout) ) {
- # We grab the following fields: repo, name, ver, group, installed, and
- # desc. We grab leading space for 'group' and 'installed' so that we do not
- # need to test if non-empty when printing.
- my @pkgfields = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?$/s;
- my $desc = readline($syncout);
- # since 'group' and 'installed' are optional, we should fill it in if necessary
- $pkgfields[3] = "" if not defined $pkgfields[3];
- $pkgfields[4] = "" if not defined $pkgfields[4];
- $pkgfields[5] = $desc;
- # Add each sync pkg by name/ver to a hash table.
- # Any value is good since we only check for existence.
- $allpkgs{$pkgfields[1] . $pkgfields[2]} = 1;
- push (@pkglist, \@pkgfields);
-}
-close ($syncout);
-
-open (my $queryout, '-|', 'pacman', '-Qs', '--', @ARGV) or exit 1;
-while ( readline($queryout) ) {
- # We grab the same field as before, even the "installed" which is always
- # empty for local searches. This allows us to reserve a cell in @pkgfields.
- my @pkgfields = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?$/s;
- my $desc = readline($queryout);
- # check if the package was listed in the sync out
- if (not exists $allpkgs{$pkgfields[1] . $pkgfields[2]}) {
- # since 'group' is optional, we should fill it in if necessary
+sub list_pkg {
+ my $db = shift;
+ open (my $out, '-|', 'pacman', $db, '--', @ARGV) or exit 1;
+ my @pkglist = ();
+ while ( readline($out) ) {
+ # We grab the following fields: repo, name, ver, group, installed, and
+ # desc. We grab leading space for 'group' and 'installed' so that we do
+ # not need to test if non-empty when printing.
+ my @pkgfields = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?$/s;
+ my $desc = readline($out);
+ # since 'group' and 'installed' are optional, we should fill it in if
+ # necessary
$pkgfields[3] = "" if not defined $pkgfields[3];
- $pkgfields[4] = " [$LC_INSTALLED]";
+ $pkgfields[4] = "" if not defined $pkgfields[4];
$pkgfields[5] = $desc;
push (@pkglist, \@pkgfields);
}
+ close ($out);
+ return @pkglist;
}
-close ($queryout);
-foreach (@pkglist) {
- print_pkg (@{$_});
-}
+my @sync = list_pkg('-Ss', @ARGV);
+my %allpkgs = map {$_->[1] . $_->[2] => 1} @sync;
+my @query = grep { not $allpkgs{$_->[1] . $_->[2]}} list_pkg('-Qs', @ARGV);
+$_->[4] = " [$LC_INSTALLED]" foreach @query;
+print_pkg (@{$_}) foreach (@sync, @query);
#vim: set noet: