index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Pierre Neidhardt <ambrevar@gmail.com> | 2014-02-14 13:18:56 +0100 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2014-03-03 11:25:55 +1000 |
commit | e5c714f5010e803465dbe57adc31687dffba10b2 (patch) | |
tree | ed66cc062e2906019e5c181b0c026a62673b9834 /contrib/pacsearch.in | |
parent | cfde337b7b5f4a7f56ff0a4e6142804f6e638f69 (diff) |
-rw-r--r-- | contrib/pacsearch.in | 55 |
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: |