Bug 574821 - Add titlebar margin to browser-aero css for maximized windows - addresse...
[mozilla-central.git] / toolkit / locales / compare-locales.pl
blobb6d407f93ef418277ccda5e45caf99ec133e4bb4
1 #!/usr/bin/perl -w
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
15 # The Original Code is libxul build automation.
17 # The Initial Developer of the Original Code is
18 # Benjamin Smedberg <benjamin@smedbergs.us>
19 # Portions created by the Initial Developer are Copyright (C) 2004
20 # the Initial Developer. All Rights Reserved.
22 # Contributor(s):
23 # Soeren Munk Skroeder (sskroeder) @ 2005-08-24 -
24 # added support for inc files (defines)
25 # added to-do description with "add/remove these keys from your locale"
27 # Alternatively, the contents of this file may be used under the terms of
28 # either the GNU General Public License Version 2 or later (the "GPL"), or
29 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 # in which case the provisions of the GPL or the LGPL are applicable instead
31 # of those above. If you wish to allow use of your version of this file only
32 # under the terms of either the GPL or the LGPL, and not to allow others to
33 # use your version of this file under the terms of the MPL, indicate your
34 # decision by deleting the provisions above and replace them with the notice
35 # and other provisions required by the GPL or the LGPL. If you do not delete
36 # the provisions above, a recipient may use your version of this file under
37 # the terms of any one of the MPL, the GPL or the LGPL.
39 # ***** END LICENSE BLOCK *****
41 $failure = 0;
43 sub unJAR
45 my ($file, $dir) = @_;
47 -d $dir && system("rm -rf $dir");
48 system("unzip -q -d $dir $file") && die("Could not unZIP $file");
51 sub readDTD
53 my ($file) = @_;
55 open DTD, "<$file" || die ("Couldn't open file $file");
57 local $/ = undef;
58 my $contents = <DTD>;
59 close DTD;
61 $contents =~ s/<!--.*?-->//gs; # strip SGML comments
63 return $contents =~ /<!ENTITY\s+([\w\.]+)\s+(?:\"[^\"]*\"|\'[^\']*\')\s*>/g;
66 sub compareDTD
68 my ($path) = @_;
70 my @entities1 = readDTD("$gSourceDir1/$path");
71 my %entities2 = map { $_ => 1 } readDTD("$gSourceDir2/$path");
73 my @extra1;
75 foreach my $entity (@entities1) {
76 if (exists $entities2{$entity}) {
77 delete $entities2{$entity};
78 } else {
79 push @extra1, $entity;
83 if (@extra1 or keys %entities2) {
84 $failure = 1;
85 print "Entities in $path don't match:\n";
86 if (@extra1) {
87 print " In $gSource1: (add these keys to your localization)\n";
88 map { print " $_\n"; } @extra1;
91 if (keys %entities2) {
92 print " In $gSource2: (remove these keys from your localization)\n";
93 map {print " $_\n"; } keys %entities2;
95 print "\n";
99 sub readProperties
101 my ($file) = @_;
103 open PROPS, "<$file" || die ("Couldn't open file $file");
105 local $/ = undef;
106 my $contents = <PROPS>;
107 close PROPS;
109 $contents =~ s/\\$$//gm;
111 return $contents =~ /^\s*([^#!\s\r\n][^=:\r\n]*?)\s*[=:]/gm;
114 sub compareProperties
116 my ($path) = @_;
118 my @entities1 = readProperties("$gSourceDir1/$path");
119 my %entities2 = map { $_ => 1 } readProperties("$gSourceDir2/$path");
121 my @extra1;
123 foreach my $entity (@entities1) {
124 if (exists $entities2{$entity}) {
125 delete $entities2{$entity};
126 } else {
127 # hack to ignore non-fatal region.properties differences
128 if ($path !~ /chrome\/browser-region\/region\.properties$/ or
129 ($entity !~ /browser\.search\.order\.[1-9]/ and
130 $entity !~ /browser\.contentHandlers\.types\.[0-5]/ and
131 $entity !~ /gecko\.handlerService\.schemes\./ and
132 $entity !~ /gecko\.handlerService\.defaultHandlersVersion/)) {
133 push @extra1, $entity;
137 # hack to ignore non-fatal region.properties differences
138 if ($path =~ /chrome\/browser-region\/region\.properties$/) {
139 foreach $entity (keys(%entities2)) {
140 if ($entity =~ /browser\.search\.order\.[1-9]/ ||
141 $entity =~ /browser\.contentHandlers\.types\.[0-5]/ ||
142 $entity =~ /gecko\.handlerService\.schemes\./ ||
143 $entity =~ /gecko\.handlerService\.defaultHandlersVersion/) {
144 delete $entities2{$entity};
149 if (@extra1 or keys %entities2) {
150 $failure = 1;
151 print "Properties in $path don't match:\n";
152 if (@extra1) {
153 print " In $gSource1: (add these to your localization)\n";
154 map { print " $_\n"; } @extra1;
157 if (keys %entities2) {
158 print " In $gSource2: (remove these from your localization)\n";
159 map {print " $_\n"; } keys %entities2;
161 print "\n";
165 sub readDefines
167 my ($file) = @_;
169 open DEFS, "<$file" || die ("Couldn't open file $file");
171 local $/ = undef;
172 my $contents = <DEFS>;
173 close DEFS;
175 return $contents =~ /#define\s+(\w+)/gm;
178 sub compareDefines
180 my ($path) = @_;
182 my @entities1 = readDefines("$gSourceDir1/$path");
183 my %entities2 = map { $_ => 1 } readDefines("$gSourceDir2/$path");
185 my @extra1;
187 foreach my $entity (@entities1) {
188 if (exists $entities2{$entity}) {
189 delete $entities2{$entity};
190 } else {
191 push @extra1, $entity;
195 if (@extra1 or keys %entities2) {
196 $failure = 1;
197 print "Defines in $path don't match:\n";
198 if (@extra1) {
199 print " In $gSource1: (add these to your localization)\n";
200 map { print " $_\n"; } @extra1;
203 if (keys %entities2) {
204 print " In $gSource2: (remove these from your localization)\n";
205 map {print " $_\n"; } keys %entities2;
207 print "\n";
211 sub compareDir
213 my ($path) = @_;
215 my (@entries1, %entries2);
217 opendir(DIR1, "$gSourceDir1/$path") ||
218 die ("Couldn't list $gSourceDir1/$path");
219 @entries1 = grep(!(/^(\.|CVS)/ || /~$/), readdir(DIR1));
220 closedir(DIR1);
222 opendir(DIR2, "$gSourceDir2/$path") ||
223 die ("Couldn't list $gSourceDir2/$path");
224 %entries2 = map { $_ => 1 } grep(!(/^(\.|CVS)/ || /~$/), readdir(DIR2));
225 closedir(DIR2);
227 foreach my $file (@entries1) {
228 if (exists($entries2{$file})) {
229 delete $entries2{$file};
231 if (-d "$gSourceDir1/$path/$file") {
232 compareDir("$path/$file");
233 } else {
234 if ($file =~ /\.dtd$/) {
235 compareDTD("$path/$file");
236 } elsif ($file =~ /\.inc$/) {
237 compareDefines("$path/$file");
238 } elsif ($file =~ /\.properties$/) {
239 compareProperties("$path/$file");
240 } else {
241 print "no comparison for $path/$file\n";
244 } else {
245 push @gSource1Extra, "$path/$file";
249 foreach my $file (keys %entries2) {
250 push @gSource2Extra, "$path/$file";
254 local ($gSource1, $gSource2) = @ARGV;
255 ($gSource1 && $gSource2) || die("Specify two directories or ZIP files");
257 my ($gSource1IsZIP, $gSource2IsZIP);
258 local ($gSourceDir1, $gSourceDir2);
259 local (@gSource1Extra, @gSource2Extra);
261 if (-d $gSource1) {
262 $gSource1IsZIP = 0;
263 $gSourceDir1 = $gSource1;
264 } else {
265 $gSource1IsZIP = 1;
266 $gSourceDir1 = "temp1";
267 unJAR($gSource1, $gSourceDir1);
270 if (-d $gSource2) {
271 $gSource2IsZIP = 0;
272 $gSourceDir2 = $gSource2;
273 } else {
274 $gSource2IsZIP = 1;
275 $gSourceDir2 = "temp2";
276 unJAR($gSource2, $gSourceDir2);
279 compareDir(".");
281 if (@gSource1Extra) {
282 print "Files in $gSource1 not in $gSource2:\n";
283 map { print " $_\n"; } @gSource1Extra;
284 print "\n";
287 if (@gSource2Extra) {
288 print "Files in $gSource2 not in $gSource1:\n";
289 map { print " $_\n"; } @gSource2Extra;
290 print "\n";
293 $gSource1IsZIP && system("rm -rf $gSourceDir1");
294 $gSource2IsZIP && system("rm -rf $gSourceDir2");
296 exit $failure;