Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / make-css-file-arrays.pl
1 #!/usr/bin/perl -w
2 #
3 #  Copyright (C) 2006 Apple Computer, 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 Getopt::Long;
25
26 my $defines;
27 my $preprocessor;
28 GetOptions('defines=s' => \$defines,
29            'preprocessor=s' => \$preprocessor);
30
31 my $header = $ARGV[0];
32 shift;
33
34 my $out = $ARGV[0];
35 shift;
36
37 $header =~ s|\\|/|g;
38 $out =~ s|\\|/|g;
39 open HEADER, ">", $header or die "$!\n";
40 open OUT, ">", $out or die "$!\n";
41
42 print HEADER "namespace WebCore {\n";
43 print OUT "namespace WebCore {\n";
44
45 for my $in (@ARGV) {
46     $in =~ /(\w+)\.css$/ or $in =~ /(\w+)\.js$/ or die;
47     my $name = $1;
48
49     # Slurp in the CSS file.
50     my $text;
51     # We should not set --defines option and run "moc" preprocessor on Qt.
52     # See http://webkit.org/b/37296.
53     if (!$defines) {
54         open IN, "<", $in or die;
55         { local $/; $text = <IN>; }
56         close IN;
57         # Remove preprocessor directives.
58         $text =~ s|^#.*?$||mg;
59     } else {
60         require preprocessor;
61         $text = join('', applyPreprocessor($in, $defines, $preprocessor));
62     }
63
64     # Remove comments in a simple-minded way that will work fine for our files.
65     # Could do this a fancier way if we were worried about arbitrary CSS source.
66     $text =~ s|/\*.*?\*/||gs;
67
68     # Crunch whitespace just to make it a little smaller.
69     # Could do work to avoid doing this inside quote marks but our files don't have runs of spaces in quotes.
70     # Could crunch further based on places where whitespace is optional.
71     $text =~ s|\s+| |gs;
72     $text =~ s|^ ||;
73     $text =~ s| $||;
74
75     # Write out a C array of the characters.
76     my $length = length $text;
77     if ($in =~ /(\w+)\.css$/) {
78         print HEADER "extern const char ${name}UserAgentStyleSheet[${length}];\n";
79         print OUT "extern const char ${name}UserAgentStyleSheet[${length}] = {\n";
80     } else {
81         print HEADER "extern const char ${name}JavaScript[${length}];\n";
82         print OUT "extern const char ${name}JavaScript[${length}] = {\n";
83     }
84     my $i = 0;
85     while ($i < $length) {
86         print OUT "    ";
87         my $j = 0;
88         while ($j < 16 && $i < $length) {
89             print OUT ", " unless $j == 0;
90             print OUT ord substr $text, $i, 1;
91             ++$i;
92             ++$j;
93         }
94         print OUT "," unless $i == $length;
95         print OUT "\n";
96     }
97     print OUT "};\n";
98
99 }
100
101 print HEADER "}\n";
102 print OUT "}\n";