| 1 |
#!/usr/bin/perl
|
| 2 |
#
|
| 3 |
# Helper script to cleanup the scattered mess of text files in the SMC data
|
| 4 |
# path - to avoid overloading the spec file making it unreadable. It preserves
|
| 5 |
# the contents of those text files into a single credits file which gets
|
| 6 |
# installed in a sane location
|
| 7 |
#
|
| 8 |
use strict;
|
| 9 |
|
| 10 |
# File name
|
| 11 |
my $LICFILE = "credits.txt";
|
| 12 |
|
| 13 |
# Prefix to installed location
|
| 14 |
my $PREFIX = "/usr/share/smc";
|
| 15 |
|
| 16 |
# Starting directory
|
| 17 |
my $STARTDIR = "data";
|
| 18 |
|
| 19 |
# Open credits file
|
| 20 |
open (LIC, ">$LICFILE");
|
| 21 |
print LIC "# Generated automatically by dochelper.pl in the smc RPM.\n\n";
|
| 22 |
print LIC "Additional licenses and credits for Secret Mayro Chronicles.\n";
|
| 23 |
print LIC "------------------------------------------------------------\n\n";
|
| 24 |
close (LIC);
|
| 25 |
|
| 26 |
&traverse($STARTDIR);
|
| 27 |
|
| 28 |
exit 0;
|
| 29 |
|
| 30 |
sub traverse
|
| 31 |
{
|
| 32 |
my $cwd = $_[0];
|
| 33 |
system("cd $cwd");
|
| 34 |
opendir(DIR, $cwd);
|
| 35 |
my @entries = readdir(DIR);
|
| 36 |
closedir(DIR);
|
| 37 |
|
| 38 |
foreach my $entry (@entries)
|
| 39 |
{
|
| 40 |
# Don't recurse current or parent
|
| 41 |
next if $entry eq '.';
|
| 42 |
next if $entry eq '..';
|
| 43 |
|
| 44 |
# If it's a dir, recurse.
|
| 45 |
if (-d "$cwd/$entry") {&traverse("$cwd/$entry");}
|
| 46 |
|
| 47 |
# Filter out none text files.
|
| 48 |
next if ($entry !~ m/^.*txt/g);
|
| 49 |
|
| 50 |
# Skip txt files in this dir because they are configs
|
| 51 |
if ($cwd ne 'data/levels')
|
| 52 |
{
|
| 53 |
if ($entry eq 'all.txt')
|
| 54 |
{
|
| 55 |
system("echo \"$PREFIX/$cwd/\*\" >> $LICFILE ; cat $cwd/all.txt >> $LICFILE ; echo \"\n\" >> $LICFILE; rm -f $cwd/all.txt");
|
| 56 |
}
|
| 57 |
else
|
| 58 |
{
|
| 59 |
my $ext = $entry;
|
| 60 |
my $match = 0;
|
| 61 |
$ext =~ s/\.txt/\.ogg/g;
|
| 62 |
if (-e "$cwd/$ext") { system("echo \"$PREFIX/$cwd/$ext\" >> $LICFILE"); $match = 1;}
|
| 63 |
$ext =~ s/\.ogg/\.ttf/g;
|
| 64 |
if (-e "$cwd/$ext") { system("echo \"$PREFIX/$cwd/$ext\" >> $LICFILE"); $match = 1;}
|
| 65 |
$ext =~ s/\.ttf/\.png/g;
|
| 66 |
if (-e "$cwd/$ext") { system("echo \"$PREFIX/$cwd/$ext\" >> $LICFILE"); $match = 1;}
|
| 67 |
if ($match == 0) { system("echo \"$PREFIX/$cwd/$entry\" >> $LICFILE"); }
|
| 68 |
system("cat $cwd/$entry >> $LICFILE ; echo \"\n\" >> $LICFILE ; rm -f $cwd/$entry");
|
| 69 |
}
|
| 70 |
}
|
| 71 |
}
|
| 72 |
}
|