61 lines
1.5 KiB
Perl
Executable File
61 lines
1.5 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
use Getopt::Long;
|
|
|
|
my $root = '.';
|
|
GetOptions('root=s' => \$root);
|
|
$root = "$root/" if ($root ne '');
|
|
|
|
my @fileList = @ARGV;
|
|
if ($#fileList < 0)
|
|
{
|
|
print "$0 <fileList>\n";
|
|
exit(42);
|
|
}
|
|
|
|
my %fileData;
|
|
my $index = 0;
|
|
|
|
open(OUTPUT, '>', 'LoadFile-gen.inc');
|
|
foreach my $fileName (@fileList)
|
|
{
|
|
local $/;
|
|
open(FILE, '<', $fileName);
|
|
my $fileContents = <FILE>;
|
|
close(FILE);
|
|
my $length = length($fileContents);
|
|
my @fileContents = split(//, $fileContents);
|
|
my $cname = "dat$index";
|
|
print OUTPUT "\nstatic unsigned char ${cname} [] = {\n";
|
|
for (my $byteNum = 0; $byteNum <= $#fileContents; $byteNum++)
|
|
{
|
|
print OUTPUT " " if ($byteNum % 12 == 0);
|
|
printf OUTPUT ("0x%02x", ord($fileContents[$byteNum]));
|
|
print OUTPUT ", " unless ($byteNum == $#fileContents);
|
|
print OUTPUT "\n" if ($byteNum % 12 == 11);
|
|
}
|
|
print OUTPUT "\n};\n";
|
|
$index++;
|
|
my $shortName = $fileName;
|
|
$shortName =~ s/^$root//;
|
|
$fileData{$shortName} = [$cname, $length];
|
|
}
|
|
|
|
print OUTPUT "\nfileref_t LoadFileData[] = {\n";
|
|
|
|
my @fileNames = keys(%fileData);
|
|
for (my $fileIndex = 0; $fileIndex <= $#fileNames; $fileIndex++)
|
|
{
|
|
my $fileName = $fileNames[$fileIndex];
|
|
printf OUTPUT (' {"%s", %s, %s}',
|
|
$fileName,
|
|
$fileData{$fileName}->[0],
|
|
$fileData{$fileName}->[1]);
|
|
print OUTPUT "," unless ($fileIndex == $#fileNames);
|
|
print OUTPUT "\n";
|
|
}
|
|
print OUTPUT "};\n";
|
|
close(OUTPUT);
|