3 # ***** BEGIN LICENSE BLOCK *****
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
16 # The Original Code is TomTom HOME build automation.
18 # The Initial Developer of the Original Code is
19 # Wladimir Palant <trev@adblockplus.org>.
20 # Portions created by the Initial Developer are Copyright (C) 2008
21 # the Initial Developer. All Rights Reserved.
25 # ***** END LICENSE BLOCK *****
30 die "Usage: $^X $0 directory\n" unless @ARGV;
39 opendir(local *DIR, $dir);
40 foreach my $file (readdir(DIR))
42 next if $file =~ /^\./;
43 my $path = "$dir/$file";
48 elsif ($file =~ /\.dtd$/)
50 processDTDFile($path);
52 elsif ($file =~ /\.properties$/)
54 processPropertiesFile($path);
63 my $data = validateUTF8($file);
64 return unless defined $data;
66 my $S = qr/[\x20\x09\x0D\x0A]/;
67 my $Name = qr/[A-Za-z_:][\w.\-:]*/;
68 my $Reference = qr/&$Name;|&#\d+;|&#x[\da-fA-F]+;/;
69 my $PEReference = qr/%$Name;/;
70 my $EntityValue = qr/"([^%&"]|$PEReference|$Reference)*"|'([^%&']|$PEReference|$Reference)*'/;
71 my $SystemLiteral = qr/"[^"]*"|'[^']*'/;
72 my $ExternalID = qr/SYSTEM$S+$SystemLiteral/;
73 my $EntityDef = qr/$EntityValue|$ExternalID/;
74 my $PEDef = qr/$EntityValue|$ExternalID/;
77 $data =~ s/<!--([^\-]|-[^\-])*-->//gs;
80 $data =~ s/<!ENTITY$S+$Name$S+$EntityDef$S*>//gs;
82 # Remove external entities
83 $data =~ s/<!ENTITY$S+%$S+$Name$S+$PEDef$S*>//gs;
85 # Remove external references
86 $data =~ s/$PEReference//gs;
96 warn "$0: Unrecognized data in file $file: $data\n";
101 sub processPropertiesFile
104 my $data = validateUTF8($file);
105 return unless defined $data;
107 foreach my $line (split(/[\r\n]+/, $data))
109 if ($line !~ /^\s*[#!]/ && $line !~ /=/ && $line =~ /\S/)
111 # Not a comment, not a property, trash?
113 warn "$0: Unrecognized data in file $file: $line\n";
122 open(local *FILE, "<", $file);
127 if ($data =~ /\xEF\xBB\xBF/)
130 warn "$0: Byte Order Mark found in file $file\n";
134 unless (utf8::decode($data))
137 warn "$0: File $file is not valid UTF-8\n";