#!/usr/bin/perl -w $DEBUGGING = 0; our ($stIn, $offset); $ft2Offset = 316; #Offset to ft2 page # string $ft3Offset = 364; #Offset to ft3 footnote field. # do their file list OR start in current directory my @files = @ARGV || @{Ls('.', '', 1)}; print "Title\tSubtitle\tComposer\tSource\tDate\tEditor\tFootnote\tFronimo file\tPDF file\tMIDI file\tTAB file\n"; while ($file = shift @files) { $file =~ s@^\./@@; if (-d $file ) { # recurse through directories unshift @files, @{Ls($file, '', 1)}; next; } if ($file =~ /^@/) { # a file-of-filenames => read, chomp and unshift open X, "< $file"; my @tmp = ; close X; chomp @tmp; unshift @files, @tmp; next; } if ($file =~ /\.ft2$/) { DumpFt2($file); } elsif ($file =~ /\.ft3$/) { DumpFt3($file); } } exit 0; sub ShowBug { my ($errStr) = @_; if ($DEBUGGING == 0) { return undef; } print $errStr, "\n"; } sub DumpFt2 { my ($file) = @_; open TMP, "< $file" || die "$file: $!"; $stIn = join('', ); close TMP; $offset = $ft2Offset; my $pageNumString = getBstr(); #Discard page # string. my $footnote = clean(getBstr()); my ($source, $date, $editor) = ParseFootnote($footnote); $offset = index($stIn, "CPiece", $offset) + 14; my $title = clean(getBstr()); my $composer = clean(getBstr()); $composer =~ s/Anon\.$/Anonymous/; my $pdf = PDFFile($file); my $midi = MidiFile($file); my $tab = TabFile($file); print <<"GROK"; $title\t\t$composer\t$source\t$date\t$editor\t$footnote\t$file\t$pdf\t$midi\t$tab GROK } # DumpFt2 sub DumpFt3 { my ($file) = @_; open TMP, "zcat -S .ft3 $file |" || die "$file: $!"; $stIn = join('', ); close TMP; $offset = $ft3Offset; my $pageNumString = getBstr(); #Discard page # string. my $footnote = clean(getBstr()); my ($source, $date, $editor) = ParseFootnote($footnote); $offset = index($stIn, "CPiece") + 14; my $title = clean(getBstr()); my $subtitle = clean(getBstr()); my $composer = clean(getBstr()); $title = deRtf($title); $subtitle = deRtf($subtitle); $composer = deRtf($composer); $composer =~ s/Anon\.$/Anonymous/; my $pdf = PDFFile($file); my $midi = MidiFile($file); my $tab = TabFile($file); print <<"GROK"; $title\t$subtitle\t$composer\t$source\t$date\t$editor\t$footnote\t$file\t$pdf\t$midi\t$tab GROK } # DumpFt3 sub PDFFile { my($file) = @_; $file =~ s/\.ft[23]$/.pdf/; if (-e $file) { return($file); } $file =~ s@(.*)(/[^/]+$)@$1/pdf$2@; if (-e $file) { return($file); } return (""); } sub MidiFile { my($file) = @_; $file =~ s/\.ft[23]$/.mid/; if (-e $file) { return($file); } $file =~ s@(.*)(/[^/]+$)@$1/midi$2@; if (-e $file) { return($file); } return(""); } sub TabFile { my($file) = @_; $file =~ s/\.ft[23]$/.tab/; if (-e $file) { return $file; } $file =~ s@(.*)(/[^/]+$)@$1/tab$2@; if (-e $file) { return($file); } return(""); } sub ParseFootnote { my ($note) = @_; my ($source, $date, $editor); $source = ""; $date = ""; $editor = ""; chomp($note); if ($note eq "") { return ("","","",""); } $date = $note; if ($date =~ /\D1[0-9]{3}\D/) # if there is a date, get it { $date =~ s/.*\D([1-2][0-9]{3})\D*.*$/$1/; } else { $date = ""; } $source = $note; if ($source =~ /^.......*\./) { $source =~ s/^(.......*\.) *[EAT]..*$/$1/; } $editor = $note; if ($editor =~ /\. *[EAT][nrd]..*$/) { $editor =~ s/^......*\. *([EA][nrd]..*)$/$1/ } else { $editor = ""; } return ($source, $date, $editor); } sub clean { my($x) = @_; $x =~ s/^[\t ]+//g; $x =~ s/[\t ]+$//g; $x =~ s/[\t ]+/ /g; $x =~ s/[\r\n]+/, /g; return $x; } sub getBstr { my($retVal) = get(ord(get(1))); return $retVal; } sub get { my($numChars) = @_; return "" if ($numChars == 0); my $x = substr($stIn, $offset, $numChars); $offset += $numChars; return $x; } # L S sub Ls { my($dir, $match, $fFullName) = @_; my(@tmp); opendir(DIR, $dir) || return(undef); if ($match ne '') { @tmp = grep !/^\./ && /$match/, readdir(DIR); } else { @tmp = grep !/^\./, readdir(DIR); } closedir(DIR); if ($fFullName) { @tmp = map {"$dir/$_"} @tmp; } return(\@tmp) } # Ls sub deRtf { my ($string) = @_; if ($string !~ /^\{\\rtf/) { return ($string); } if (length($string) <= 100) { return ($string); } my $start = index($string, "\\f0\\fs"); $string = substr($string, $start + 8); $string = substr($string, index($string, " ") + 1); my $end = index($string, "\\par"); my $stOut = clean(substr($string, 0, $end)); return ($stOut); }