[pacman-dev] [PATCH v2 6/6] pacsearch: pattern arguments work as for pacman
Andrew Gregory
andrew.gregory.8 at gmail.com
Wed Feb 5 09:51:17 EST 2014
On 02/04/14 at 12:16am, Pierre Neidhardt wrote:
> Previously only one pattern was allowed.
>
> $ pacsearch foo bar
> Search for packages containing 'foo bar'.
>
> $ pacman -Ss foo bar
> Search for packages containing both 'foo' and 'bar'.
>
> Note that removing the quotes from the call was not enough since
> $ pacsearch 'foo|bar'
> would then fail.
>
> Signed-off-by: Pierre Neidhardt <ambrevar at gmail.com>
> ---
> contrib/pacsearch.in | 34 +++++++++++++---------------------
> 1 file changed, 13 insertions(+), 21 deletions(-)
>
> diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in
> index 2fde52f..f8ebfbd 100644
> --- a/contrib/pacsearch.in
> +++ b/contrib/pacsearch.in
> @@ -92,24 +92,18 @@ sub print_pkg {
> print "$MAGENTA";
> }
> print "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]$BLUE$v[3]$CYAN$v[4]$RESET\n";
> - print "$v[5]\n";
> + print "$v[5]";
> }
>
> my %allpkgs = ();
>
> -my $syncout = `pacman -Ss '@ARGV'`;
> -# split each sync search entry into its own array entry
> -my @syncpkgs = split(/\n^(?=\w)/m, $syncout);
> -# remove the extra \n from the last desc entry
> -if ($#syncpkgs >= 0) {
> - chomp($syncpkgs[$#syncpkgs]);
> -}
> -
> -foreach $_ (@syncpkgs) {
> +open (my $syncout, '-|', 'pacman', '-Ss', @ARGV);
You should check the return value from open.
> +while (<$syncout>) {
Style nitpick: I'd prefer readline() over <> for readability.
> # 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 = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?\n(.*)$/s;
> + my @pkgfields = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?$/s;
> + my $desc = <$syncout>;
The description needs to be read after the check for a regex match,
otherwise that line will just be lost on failures.
> if(not @pkgfields) {
> # skip any non-matching line and just print it for the user
> print $_, "\n";
This newline needs to be removed.
> @@ -118,24 +112,20 @@ foreach $_ (@syncpkgs) {
> # 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;
> print_pkg(@pkgfields);
> }
> +close ($syncout);
>
> -my $queryout = `pacman -Qs '@ARGV'`;
> -# split each querysearch entry into its own array entry
> -my @querypkgs = split(/\n^(?=\w)/m, $queryout);
> -# remove the extra \n from the last desc entry
> -if ($#querypkgs >= 0) {
> - chomp ($querypkgs[$#querypkgs]);
> -}
> -
> -foreach $_ (@querypkgs) {
Comments for sync search apply here too.
> +open (my $queryout, '-|', 'pacman', '-Qs', @ARGV);
> +while (<$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 = /^(.*?)\/(.*?) (.*?)( \(.*?\))?()?\n(.*)$/s;
> + my @pkgfields = /^(.*?)\/(.*?) (.*?)( \(.*?\))?()?$/s;
> + my $desc = <$queryout>;
> # skip any non-matching line
> next if not defined $pkgfields[1];
> # check if the package was listed in the sync out
> @@ -143,8 +133,10 @@ foreach $_ (@querypkgs) {
> # since 'group' is optional, we should fill it in if necessary
> $pkgfields[3] = "" if not defined $pkgfields[3];
> $pkgfields[4] = " [$LC_INSTALLED]";
> + $pkgfields[5] = $desc;
> print_pkg(@pkgfields);
> }
> }
> +close ($queryout);
>
> #vim: set noet:
> --
> 1.8.5.3
More information about the pacman-dev
mailing list