#!/usr/bin/perl
use warnings;
use strict;
my $program_description = q(
finddx7patch.pl
(C) 2019, PySeq. Licence: GNU GPL version 2.
Searches inside ".SYX"-files for strings (names of DX7-patches).
Start this script inside the "../DX7_AllTheWeb"-directory, or
for example in "../DX7_AllTheWeb/Big Mamma", if you want to
search for DX7-patches just in that directory.
-----
GNU GPL copyright notice:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. );
use File::Find;
use Cwd;
my $SEARCHSTRING;
my @OVERALLFOUND;
if ($#ARGV < 0) {
print "\nUsage: finddx7patch.pl SEARCHSTRING\n\n";
exit 1;
} else {
$SEARCHSTRING = $ARGV[0];
}
my $VERBOSE = 0;
if ($#ARGV >= 1 && $ARGV[1] eq "-v") {
$VERBOSE = 1;
}
sub wanted {
my $name = $File::Find::name;
if ($name !~ m/SYX$/i) {
return;
}
my @a = `strings "$name"`;
my @found = ();
my $i;
for $i (@a) {
chomp($i);
if ($i =~ m/$SEARCHSTRING/i) {
push(@found, $i);
}
}
if ($#found >= 0) {
print "$name\n";
push(@OVERALLFOUND, $name);
if ($VERBOSE) {
for $i (@found) {
print "$i\n";
}
}
if ($VERBOSE) {
print "\n";
}
}
}
my $dir = getcwd();
print "\n";
find(\&wanted, $dir);
if ($#OVERALLFOUND == -1) {
print "Sorry, \"$SEARCHSTRING\" not found in the DX7-files.\n\n";
} elsif (! $VERBOSE) {
print "\n";
}