Synthesizer @ Sequencer-Forum

Hi,

hier ein weiteres Perl-Skript. Es gibt ja diese DX7-Patch-Sammlung "alltheweb". Die ".zip"-Datei wird zu einem Verzeichnis "DX7_AllTheWeb" mit zahlreichen Unterverzeichnissen entpackt, in denen sich viele ".SYX"-Dateien befinden.
Aber in welcher Dateien befindet sich jetzt ein bestimmter Patch, den man (anhand des Namens) sucht?

Dazu das Skript. Man tut es in das Verzeichnis "DX7_AllTheWeb". Oder in eins der Unterverzeichnisse. Bei "Big Mamma" ist z.B. viel zu finden, man kann das Skript also auch in "../DX7_AllTheWeb/Big Mamma" tun, und dann da ausführen.
Den Patch-Namen gibt man mit, also z.B. "./finddx7patch.pl jazz".

Das Skript sucht dann in dem Verzeichnis und in allen Unterverzeichnissen nach ".SYX"-Dateien, führt auf diesen den bash-Befehl "strings" aus, erhält so die ASCII-Inhalte innerhalb der Dateien und gleicht diese mit dem Suchstring ab.
Wenn es Übereinstimmungen findet, gibt es die Dateinamen aus (und wenn man als Zweites noch die Option "-v" für "verbose" mitgibt, auch die gefundenen Strings). Das ist nützlich. :)

(Alternativ könnte man auch was mit bashs "grep" bauen, aber ich fand's so schöner.)

Perl:
#!/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";
}
Zurück
Oben