1 | #!/usr/bin/env perl
|
---|
2 | #
|
---|
3 | # Copyright (C) 2006 Apple Inc.
|
---|
4 | #
|
---|
5 | # This library is free software; you can redistribute it and/or
|
---|
6 | # modify it under the terms of the GNU Library General Public
|
---|
7 | # License as published by the Free Software Foundation; either
|
---|
8 | # version 2 of the License, or (at your option) any later version.
|
---|
9 | #
|
---|
10 | # This library is distributed in the hope that it will be useful,
|
---|
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
13 | # Library General Public License for more details.
|
---|
14 | #
|
---|
15 | # You should have received a copy of the GNU Library General Public License
|
---|
16 | # along with this library; see the file COPYING.LIB. If not, write to
|
---|
17 | # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
---|
18 | # Boston, MA 02110-1301, USA.
|
---|
19 | #
|
---|
20 |
|
---|
21 | # Usage: make-css-file-arrays.pl <header> <output> <input> ...
|
---|
22 |
|
---|
23 | use strict;
|
---|
24 | use warnings;
|
---|
25 | use FindBin;
|
---|
26 | use lib "$FindBin::Bin/../bindings/scripts";
|
---|
27 |
|
---|
28 | use Getopt::Long;
|
---|
29 |
|
---|
30 | my $defines;
|
---|
31 | my $preprocessor;
|
---|
32 | GetOptions('defines=s' => \$defines,
|
---|
33 | 'preprocessor=s' => \$preprocessor);
|
---|
34 |
|
---|
35 | my $header = $ARGV[0];
|
---|
36 | shift;
|
---|
37 |
|
---|
38 | my $out = $ARGV[0];
|
---|
39 | shift;
|
---|
40 |
|
---|
41 | open HEADER, ">", $header or die;
|
---|
42 | open OUT, ">", $out or die;
|
---|
43 |
|
---|
44 | print HEADER "namespace WebCore {\n";
|
---|
45 | print OUT "namespace WebCore {\n";
|
---|
46 |
|
---|
47 | for my $in (@ARGV) {
|
---|
48 | $in =~ /(\w+)\.css$/ or $in =~ /(\w+)\.js$/ or die;
|
---|
49 | my $name = $1;
|
---|
50 |
|
---|
51 | # Slurp in the CSS file.
|
---|
52 | my $text;
|
---|
53 | require preprocessor;
|
---|
54 | $text = join('', applyPreprocessor($in, $defines, $preprocessor));
|
---|
55 |
|
---|
56 | # Remove comments in a simple-minded way that will work fine for our files.
|
---|
57 | # Could do this a fancier way if we were worried about arbitrary CSS source.
|
---|
58 | $text =~ s|/\*.*?\*/||gs;
|
---|
59 |
|
---|
60 | # Crunch whitespace just to make it a little smaller.
|
---|
61 | # Could do work to avoid doing this inside quote marks but our files don't have runs of spaces in quotes.
|
---|
62 | # Could crunch further based on places where whitespace is optional.
|
---|
63 | $text =~ s|\s+| |gs;
|
---|
64 | $text =~ s|^ ||;
|
---|
65 | $text =~ s| $||;
|
---|
66 |
|
---|
67 | # Write out a C array of the characters.
|
---|
68 | my $length = length $text;
|
---|
69 | if ($in =~ /(\w+)\.css$/) {
|
---|
70 | print HEADER "extern const char ${name}UserAgentStyleSheet[${length}];\n";
|
---|
71 | print OUT "extern const char ${name}UserAgentStyleSheet[${length}] = {\n";
|
---|
72 | } else {
|
---|
73 | print HEADER "extern const char ${name}JavaScript[${length}];\n";
|
---|
74 | print OUT "extern const char ${name}JavaScript[${length}] = {\n";
|
---|
75 | }
|
---|
76 | my $i = 0;
|
---|
77 | while ($i < $length) {
|
---|
78 | print OUT " ";
|
---|
79 | my $j = 0;
|
---|
80 | while ($j < 16 && $i < $length) {
|
---|
81 | my $character = ord substr $text, $i, 1;
|
---|
82 | die if $character >= 128;
|
---|
83 | print OUT ", " unless $j == 0;
|
---|
84 | print OUT $character;
|
---|
85 | ++$i;
|
---|
86 | ++$j;
|
---|
87 | }
|
---|
88 | print OUT "," unless $i == $length;
|
---|
89 | print OUT "\n";
|
---|
90 | }
|
---|
91 | print OUT "};\n";
|
---|
92 |
|
---|
93 | }
|
---|
94 |
|
---|
95 | print HEADER "}\n";
|
---|
96 | print OUT "}\n";
|
---|