| OLD | NEW |
| (Empty) |
| 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 $header = $ARGV[0]; | |
| 27 shift; | |
| 28 | |
| 29 my $out = $ARGV[0]; | |
| 30 shift; | |
| 31 | |
| 32 $header =~ s|\\|/|g; | |
| 33 $out =~ s|\\|/|g; | |
| 34 open HEADER, ">", $header or die "$!\n"; | |
| 35 open OUT, ">", $out or die "$!\n"; | |
| 36 | |
| 37 print HEADER "namespace WebCore {\n"; | |
| 38 print OUT "namespace WebCore {\n"; | |
| 39 | |
| 40 for my $in (@ARGV) { | |
| 41 $in =~ /(\w+)\.css$/ or $in =~ /(\w+)\.js$/ or die; | |
| 42 my $name = $1; | |
| 43 | |
| 44 # Slurp in the CSS file. | |
| 45 my $text; | |
| 46 open IN, "<", $in or die; | |
| 47 { local $/; $text = <IN>; } | |
| 48 close IN; | |
| 49 | |
| 50 # Remove comments in a simple-minded way that will work fine for our files. | |
| 51 # Could do this a fancier way if we were worried about arbitrary CSS source. | |
| 52 $text =~ s|/\*.*?\*/||gs; | |
| 53 | |
| 54 # Crunch whitespace just to make it a little smaller. | |
| 55 # Could do work to avoid doing this inside quote marks but our files don't h
ave runs of spaces in quotes. | |
| 56 # Could crunch further based on places where whitespace is optional. | |
| 57 $text =~ s|\s+| |gs; | |
| 58 $text =~ s|^ ||; | |
| 59 $text =~ s| $||; | |
| 60 | |
| 61 # Write out a C array of the characters. | |
| 62 my $length = length $text; | |
| 63 if ($in =~ /(\w+)\.css$/) { | |
| 64 print HEADER "extern const char ${name}UserAgentStyleSheet[${length}];\n
"; | |
| 65 print OUT "extern const char ${name}UserAgentStyleSheet[${length}] = {\n
"; | |
| 66 } else { | |
| 67 print HEADER "extern const char ${name}JavaScript[${length}];\n"; | |
| 68 print OUT "extern const char ${name}JavaScript[${length}] = {\n"; | |
| 69 } | |
| 70 my $i = 0; | |
| 71 while ($i < $length) { | |
| 72 print OUT " "; | |
| 73 my $j = 0; | |
| 74 while ($j < 16 && $i < $length) { | |
| 75 print OUT ", " unless $j == 0; | |
| 76 print OUT ord substr $text, $i, 1; | |
| 77 ++$i; | |
| 78 ++$j; | |
| 79 } | |
| 80 print OUT "," unless $i == $length; | |
| 81 print OUT "\n"; | |
| 82 } | |
| 83 print OUT "};\n"; | |
| 84 | |
| 85 } | |
| 86 | |
| 87 print HEADER "}\n"; | |
| 88 print OUT "}\n"; | |
| OLD | NEW |