aboutsummaryrefslogtreecommitdiff
path: root/sbofind
diff options
context:
space:
mode:
Diffstat (limited to 'sbofind')
-rwxr-xr-xsbofind40
1 files changed, 23 insertions, 17 deletions
diff --git a/sbofind b/sbofind
index 055ce9b..d977072 100755
--- a/sbofind
+++ b/sbofind
@@ -10,13 +10,12 @@
# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING>
use 5.12.3;
+use strict;
+use warnings FATAL => 'all';
use SBO::Lib;
use File::Basename;
use Getopt::Std;
-use strict;
-use warnings FATAL => 'all';
-my %config = %SBO::Lib::config;
my $self = basename ($0);
sub show_usage () {
@@ -51,26 +50,31 @@ my $search = $ARGV[0];
slackbuilds_or_fetch;
# find anything with $search in its name
-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";
-FIRST: while (my $line = <$fh>) {
- unless ($found) {
- $found++, next FIRST if $name = ($line =~ $name_regex)[0];
- } else {
- if (my ($location) = ($line =~ $loc_regex)[0]) {
- $found = 0;
- $location =~ s#^\.##;
- push @$findings, {$name => $config{SBO_HOME} . $location};
+sub perform_search ($) {
+ exists $_[0] or script_error 'perform_search requires an argument.';
+ my $search = shift;
+ my (@findings, $name, $found);
+ 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";
+ FIRST: while (my $line = <$fh>) {
+ unless ($found) {
+ $found++, next FIRST if $name = ($line =~ $name_regex)[0];
+ } else {
+ if (my ($location) = ($line =~ $loc_regex)[0]) {
+ $found = 0;
+ $location =~ s#^\.##;
+ push @findings, {$name => $config{SBO_HOME} . $location};
+ }
}
}
+ return \@findings;
}
+# pull the contents of a file into a variable and format it for output
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';
+ -f $_[0] or return "$_[0] doesn't exist.\n";
my $fh = open_read shift;
my $contents = do {local $/; <$fh>};
$contents =~ s/\n/\n /g;
@@ -78,6 +82,8 @@ sub get_file_contents ($) {
return $contents;
}
+perform_search $search;
+
# pretty formatting
if (exists $$findings[0]) {
my @listing = ("\n");