aboutsummaryrefslogtreecommitdiff
path: root/sbofind
diff options
context:
space:
mode:
Diffstat (limited to 'sbofind')
-rwxr-xr-xsbofind33
1 files changed, 20 insertions, 13 deletions
diff --git a/sbofind b/sbofind
index e00f8de..16ad1b1 100755
--- a/sbofind
+++ b/sbofind
@@ -51,23 +51,28 @@ 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 return "$_[0] doesn't exist.\n";
@@ -78,6 +83,8 @@ sub get_file_contents ($) {
return $contents;
}
+perform_search $search;
+
# pretty formatting
if (exists $$findings[0]) {
my @listing = ("\n");