From 0f24390fe8967f25d7fce4665d5b635fa66a3c4f Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 24 Jan 2011 15:20:10 -0600 Subject: pkgsearch: handle non-matching lines gracefully Before any non-matching line would trigger some perl warnings about undefined variables. If a line doesn't match, just show it to the user unprocessed; this is seen with warning and error messages pacman not so helpfully emits on stdout rather than stderr. Signed-off-by: Dan McGee --- contrib/pacsearch.in | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'contrib') diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index a20df265..dd848a73 100755 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -1,10 +1,10 @@ #!/usr/bin/perl # pacsearch - Adds color and install information to a 'pacman -Ss' search # -# Copyright (C) 2008, 2010 Dan McGee +# Copyright (C) 2008-2011 Dan McGee # # Based off original shell script version: -# Copyright (C) 2006-2007 Dan McGee +# Copyright (C) 2006-2007 Dan McGee # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -39,7 +39,7 @@ if ($#ARGV lt 0 || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") { if ($ARGV[0] eq "--version" || $ARGV[0] eq "-v") { print "$progname version $version\n"; - print "Copyright (C) 2006-2010 Dan McGee\n"; + print "Copyright (C) 2006-2011 Dan McGee\n"; exit 0; } @@ -65,6 +65,7 @@ sub to_color { $line =~ s/(^community\/.*)/$CLR3$1$BASE/; $line =~ s/(^testing\/.*)/$CLR4$1$BASE/; $line =~ s/(^community-testing\/.*)/$CLR5$1$BASE/; + $line =~ s/(^multilib\/.*)/$CLR6$1$BASE/; $line =~ s/(^local\/.*)/$CLR7$1$BASE/; # any other unknown repository $line =~ s/(^[\w-]*\/.*)/$CLR6$1$BASE/; @@ -86,6 +87,11 @@ my $cnt = 0; foreach $_ (@syncpkgs) { # we grab 4 fields here: repo, name/ver, installed, and desc my @pkgfields = /^(.*?)\/(.*?) ?(\[.*\])?\n(.*)$/s; + if(not @pkgfields) { + # skip any non-matching line and just print it for the user + print $_, "\n"; + next; + } # since installed is optional, we should fill it in if necessary $pkgfields[2] = "" if not defined $pkgfields[2]; # add a fifth field that indicates original order -- cgit v1.2.3-70-g09d2