diff options
Diffstat (limited to 'sbofind')
-rwxr-xr-x | sbofind | 53 |
1 files changed, 27 insertions, 26 deletions
@@ -9,6 +9,7 @@ # date: Boomtime, the 39th day of Discord in the YOLD 3178 # license: WTFPL <http://sam.zoy.org/wtfpl/COPYING> +use 5.16.0; use SBO::Lib; use File::Basename; use Getopt::Std; @@ -18,7 +19,7 @@ use warnings FATAL => 'all'; my %config = %SBO::Lib::config; my $self = basename ($0); -sub show_usage { +sub show_usage () { print <<EOF Usage: $self (search_term) @@ -37,40 +38,40 @@ EOF my %options; getopts ('hvir', \%options); -show_usage () and exit (0) if (exists $options{h}); -show_version () and exit (0) if (exists $options{v}); +show_usage and exit 0 if exists $options{h}; +show_version and exit 0 if exists $options{v}; -my $show_readme = exists $options{r} ? 'TRUE' : 'FALSE'; -my $show_info = exists $options{i} ? 'TRUE' : 'FALSE'; +my $show_readme = exists $options{r} ? 1 : 0; +my $show_info = exists $options{i} ? 1 : 0; -show_usage () and exit (1) unless exists $ARGV[0]; +show_usage and exit 1 unless exists $ARGV[0]; my $search = $ARGV[0]; # if we can't find SLACKBUILDS.TXT in $config{HOME}, prompt to fetch the tree -slackbuilds_or_fetch (); +slackbuilds_or_fetch; # find anything with $search in its name -my (@findings, $name); -my $found = 'FALSE'; +my ($findings, $name); +my $found = 0; my $name_regex = qr/NAME:\s+(.*\Q$search\E.*)$/i; my $loc_regex = qr/LOCATION:\s+(.*)$/; -my $fh = open_read ("$config{SBO_HOME}/SLACKBUILDS.TXT"); +my $fh = open_read "$config{SBO_HOME}/SLACKBUILDS.TXT"; FIRST: while (my $line = <$fh>) { - if ($found eq 'FALSE') { - $found = 'TRUE', next FIRST if $name = ($line =~ $name_regex)[0]; + unless ($found) { + $found++, next FIRST if $name = ($line =~ $name_regex)[0]; } else { if (my ($location) = ($line =~ $loc_regex)[0]) { - $found = 'FALSE'; + $found = 0; $location =~ s#^\.##; - push @findings, {$name => $config{SBO_HOME} . $location}; + push @$findings, {$name => $config{SBO_HOME} . $location}; } } } -sub get_file_contents { - exists $_[0] or script_error ('get_file_contents requires an argument'); - -f $_[0] or script_error ('get_file_contents argument is not a file'); - my $fh = open_read (shift); +sub get_file_contents ($) { + exists $_[0] or script_error 'get_file_contents requires an argument'; + -f $_[0] or return "$_[0] doesn't exist.\n"; + my $fh = open_read shift; my $contents = do {local $/; <$fh>}; $contents =~ s/\n/\n /g; $contents =~ s/ $//g; @@ -78,22 +79,22 @@ sub get_file_contents { } # pretty formatting -if (exists $findings[0]) { +if (exists $$findings[0]) { my @listing = ("\n"); - for my $hash (@findings) { - while (my ($key, $value) = each %{$hash}) { + for my $hash (@$findings) { + while (my ($key, $value) = each %$hash) { push @listing, "SBo: $key\n"; push @listing, "Path: $value\n"; - push @listing, "info: ". get_file_contents ("$value/$key.info") - if $show_info eq 'TRUE'; - push @listing, "README: ". get_file_contents ("$value/README") - if $show_readme eq 'TRUE'; + push @listing, "info: ". get_file_contents "$value/$key.info" + if $show_info; + push @listing, "README: ". get_file_contents "$value/README" + if $show_readme; push @listing, "\n"; } } print $_ for @listing; } else { - print "Nothing found for search term: $search\n"; + say "Nothing found for search term: $search"; } exit 0; |