#!/usr/bin/env perl # # vim: set ts=4:noet # # sbofind # script to locate something in a local SlackBuilds tree. # # author: Jacob Pipkin # date: Boomtime, the 39th day of Discord in the YOLD 3178 # license: WTFPL 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 { print <) { if ($found eq 'FALSE') { $found = 'TRUE', next FIRST if $name = ($line =~ $name_regex)[0]; } else { if (my ($location) = ($line =~ $loc_regex)[0]) { $found = 'FALSE'; $location =~ s#^\.##; 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); my $contents = do {local $/; <$fh>}; $contents =~ s/\n/\n /g; $contents =~ s/ $//g; return $contents; } # pretty formatting if (exists $findings[0]) { my @listing = ("\n"); 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, "\n"; } } print $_ for @listing; } else { print "Nothing found for search term: $search\n"; } exit 0;