| OLD | NEW |
| 1 #!/usr/bin/perl -w | 1 #!/usr/bin/perl -w |
| 2 # | 2 # |
| 3 # Copyright (C) 2006 Apple Computer, Inc. | 3 # Copyright (C) 2006 Apple Computer, Inc. |
| 4 # | 4 # |
| 5 # This library is free software; you can redistribute it and/or | 5 # This library is free software; you can redistribute it and/or |
| 6 # modify it under the terms of the GNU Library General Public | 6 # modify it under the terms of the GNU Library General Public |
| 7 # License as published by the Free Software Foundation; either | 7 # License as published by the Free Software Foundation; either |
| 8 # version 2 of the License, or (at your option) any later version. | 8 # version 2 of the License, or (at your option) any later version. |
| 9 # | 9 # |
| 10 # This library is distributed in the hope that it will be useful, | 10 # This library is distributed in the hope that it will be useful, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 require preprocessor; | 58 require preprocessor; |
| 59 $text = join('', applyPreprocessor($in, $defines, $preprocessor)); | 59 $text = join('', applyPreprocessor($in, $defines, $preprocessor)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 # Remove comments in a simple-minded way that will work fine for our files. | 62 # Remove comments in a simple-minded way that will work fine for our files. |
| 63 # Could do this a fancier way if we were worried about arbitrary CSS source. | 63 # Could do this a fancier way if we were worried about arbitrary CSS source. |
| 64 $text =~ s|/\*.*?\*/||gs; | 64 $text =~ s|/\*.*?\*/||gs; |
| 65 | 65 |
| 66 # Crunch whitespace just to make it a little smaller. | 66 # Crunch whitespace just to make it a little smaller. |
| 67 # Could do work to avoid doing this inside quote marks but our files don't h
ave runs of spaces in quotes. | 67 # Could do work to avoid doing this inside quote marks but our files don't h
ave runs of spaces in quotes. |
| 68 # Could crunch further based on places where whitespace is optional. | 68 # FIXME: Use a proper css minifier to crunch this further. |
| 69 $text =~ s|\s+| |gs; | 69 $text =~ s|^[\s]+||gm; # remove optional leading spaces. |
| 70 $text =~ s|^ ||; | 70 $text =~ s|[\s]*:[\s]*|:|gm; # remove optional spaces around colons. |
| 71 $text =~ s| $||; | 71 $text =~ s|[\s]*{[\s]*|{|gm; # remove optional spaces around open braces. |
| 72 $text =~ s|[\s;]*}[\s]*|}|gm; # remove optional spaces around end braces and
semicolons before end braces. |
| 73 $text =~ s|[\s]*,[\s]*|,|gm; # remove optional spaces around commas. |
| 74 $text =~ s|\R||g; # remove newlines. |
| 72 | 75 |
| 73 # Write out a C array of the characters. | 76 # Write out a C array of the characters. |
| 74 my $length = length $text; | 77 my $length = length $text; |
| 75 if ($in =~ /(\w+)\.css$/) { | 78 if ($in =~ /(\w+)\.css$/) { |
| 76 print HEADER "extern const char ${name}UserAgentStyleSheet[${length}];\n
"; | 79 print HEADER "extern const char ${name}UserAgentStyleSheet[${length}];\n
"; |
| 77 print OUT "extern const char ${name}UserAgentStyleSheet[${length}] = {\n
"; | 80 print OUT "extern const char ${name}UserAgentStyleSheet[${length}] = {\n
"; |
| 78 } else { | 81 } else { |
| 79 print HEADER "extern const char ${name}JavaScript[${length}];\n"; | 82 print HEADER "extern const char ${name}JavaScript[${length}];\n"; |
| 80 print OUT "extern const char ${name}JavaScript[${length}] = {\n"; | 83 print OUT "extern const char ${name}JavaScript[${length}] = {\n"; |
| 81 } | 84 } |
| 82 my $i = 0; | 85 my $i = 0; |
| 83 while ($i < $length) { | 86 while ($i < $length) { |
| 84 print OUT " "; | 87 print OUT " "; |
| 85 my $j = 0; | 88 my $j = 0; |
| 86 while ($j < 16 && $i < $length) { | 89 while ($j < 16 && $i < $length) { |
| 87 print OUT ", " unless $j == 0; | 90 print OUT ", " unless $j == 0; |
| 88 print OUT ord substr $text, $i, 1; | 91 print OUT ord substr $text, $i, 1; |
| 89 ++$i; | 92 ++$i; |
| 90 ++$j; | 93 ++$j; |
| 91 } | 94 } |
| 92 print OUT "," unless $i == $length; | 95 print OUT "," unless $i == $length; |
| 93 print OUT "\n"; | 96 print OUT "\n"; |
| 94 } | 97 } |
| 95 print OUT "};\n"; | 98 print OUT "};\n"; |
| 96 | 99 |
| 97 } | 100 } |
| 98 | 101 |
| 99 print HEADER "}\n"; | 102 print HEADER "}\n"; |
| 100 print OUT "}\n"; | 103 print OUT "}\n"; |
| OLD | NEW |