make-css-file-arrays.pl [plain text]
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../bindings/scripts";
use Getopt::Long;
my $defines;
my $preprocessor;
GetOptions('defines=s' => \$defines,
'preprocessor=s' => \$preprocessor);
my $header = $ARGV[0];
shift;
my $out = $ARGV[0];
shift;
open HEADER, ">", $header or die;
open OUT, ">", $out or die;
print HEADER "namespace WebCore {\n";
print OUT "namespace WebCore {\n";
for my $in (@ARGV) {
$in =~ /(\w+)\.css$/ or $in =~ /(\w+)\.js$/ or die;
my $name = $1;
my $text;
require preprocessor;
$text = join('', applyPreprocessor($in, $defines, $preprocessor));
$text =~ s|/\*.*?\*/||gs;
$text =~ s|\s+| |gs;
$text =~ s|^ ||;
$text =~ s| $||;
my $length = length $text;
if ($in =~ /(\w+)\.css$/) {
print HEADER "extern const char ${name}UserAgentStyleSheet[${length}];\n";
print OUT "extern const char ${name}UserAgentStyleSheet[${length}] = {\n";
} else {
print HEADER "extern const char ${name}JavaScript[${length}];\n";
print OUT "extern const char ${name}JavaScript[${length}] = {\n";
}
my $i = 0;
while ($i < $length) {
print OUT " ";
my $j = 0;
while ($j < 16 && $i < $length) {
print OUT ", " unless $j == 0;
print OUT ord substr $text, $i, 1;
++$i;
++$j;
}
print OUT "," unless $i == $length;
print OUT "\n";
}
print OUT "};\n";
}
print HEADER "}\n";
print OUT "}\n";