]>
pere.pagekite.me Git - homepage.git/blob - linux/glibc/check-locale
3 # Author: Petter Reinholdtsen
6 # Test the content of GNU libc locales, detect some common errors.
11 use vars
qw($locale $warncount $errcount);
15 $line =~ s/<U([0-9A-Za-z]{4})>/pack('U',hex($1))/ge;
22 print "error: $locale: $msg\n";
28 print "warning: $locale: $msg\n";
31 sub check_lc_identification
{
33 for my $line (@lines) {
34 if ($line =~ m/^category\s+(\S+)$/) {
35 warning
"LC_IDENTIFICATION: missing quotes around category standard ref: $1"
38 if ($line =~ m/^email\s+(\S+)\s*$/) {
40 warning
"LC_IDENTIFICATION: obsolete email: $email"
41 if ($email =~ m/"?bug-glibc\@gnu.org"?/);
50 $height = $1 if (m/^height\s*(\d+)\s*$/);
51 $width = $1 if (m/^width\s*(\d+)\s*$/);
52 return if (m/^copy\s+/); # Nothing to check
55 if (!defined $width || defined $height) {
56 # warning "LC_PAPER: Missing height or width.";
60 if (210 == $width && 297 == $height) { # ISO A4
61 } elsif (216 == $width && 279 == $height) { # US Letter
63 warning
"LC_PAPER: unknown paper size.";
67 sub check_lc_measurement
{
69 for my $line (@lines) {
70 if ($line =~ m/^\s*(measurement)\s+(\S+)\s*$/) {
72 if (defined $value && $value !~ m/^\d+$/) {
73 warning
"LC_MEASUREMENT: measurements should be number 1 or 2.";
74 } elsif ($value < 1 && 2 < $value) {
75 warning
"LC_MEASUREMENT: measurements should be 1 or 2.";
81 sub check_lc_numeric
{
83 for my $line (@lines) {
84 next if ($line eq "LC_NUMERIC" || $line eq "END LC_NUMERIC");
85 next if ($line =~ m/^$/);
86 if ($line =~ m/^\s*(grouping)\s+(\S+)\s*$/) {
88 if ($value =~ m/^-?\d+$/) {
89 # Only digits (or - digits)
90 if ( $value < 1 && $value != -1) {
91 warning
"LC_NUMERIC: grouping should positive or -1: $value";
94 if (defined $value && $value !~ m/\d+;\d+/) {
95 warning
"LC_NUMERIC: grouping should use ; as separator: $value";
98 } elsif ($line =~ m/^\s*(decimal_point)\s+(\S+)\s*$/) {
99 } elsif ($line =~ m/^\s*(thousands_sep)\s+(\S+)\s*$/) {
101 # print "P: '$sep'\n";
102 warning
"LC_NUMERIC: Unusual thousands_sep '$sep' [".
103 uxx_to_utf8
($sep)."]"
104 unless (grep { $_ eq $sep; } ('"<U0020>"',
110 } elsif ($line =~ m/^\s*(copy)\s+(\S+)\s*$/) {
112 warning
"LC_NUMERIC: Unknown keyword '$line'";
117 sub check_lc_messages
{
120 if (m/^\s*(yesexpr|noexpr)\s+(.+)$/) {
122 my $regex = uxx_to_utf8
($2);
123 unless ($regex =~ m/^"\^/) {
124 error
"LC_MESSAGES: $type missing '^' prefix: $regex";
126 unless ($regex =~ m/\[.+\]|\(.+\)/) {
127 error
"LC_MESSAGES: $type missing '[.+]|(.+)' content: $regex";
129 if ($regex =~ m/\.\*"$/) {
130 warning
"LC_MESSAGES: $type have '.*' postfix: $regex";
132 if ($regex =~ m/[0-9]/) {
133 warning
"LC_MESSAGES: $type have numbers in regex: $regex";
135 if ($type eq "yesexpr" && ($regex !~ m/y/ ||
137 warning
"LC_MESSAGES: $type missing 'yY' in content: $regex";
139 if ($type eq "noexpr" && ($regex !~ m/n/ ||
141 warning
"LC_MESSAGES: $type missing 'nN' in content: $regex";
150 for my $filename (@ARGV) {
151 open (FILE
, "<$filename") || die "Unable to read $filename";
158 s/%.*$//; # Remove comments
164 if (! defined $buf) {
169 if (!$section && m/^(LC_.*)\s*$/) {
172 #print "Found section $section\n";
175 if (m/^END (LC_.+)\s*$/) {
176 if (exists $sections{$section}) {
177 warning
"duplicate section $section";
179 push(@blocks, $section);
180 $sections{$section} = [@lines];
182 #print "Stored section $section\n";
188 check_order
(@blocks);
189 check_lc_identification
(@{$sections{'LC_IDENTIFICATION'}});
190 check_lc_messages
(@{$sections{'LC_MESSAGES'}});
191 check_lc_numeric
(@{$sections{'LC_NUMERIC'}});
192 check_lc_paper
(@{$sections{'LC_PAPER'}});
193 check_lc_measurement
(@{$sections{'LC_MEASUREMENT'}});
197 my @order= qw(LC_IDENTIFICATION
210 for my $section (@blocks) {
211 if ($section eq $order[$pos]) {
215 $pos++ while ($order[$pos] ne $section);
216 warning
"$section: not following section $order[$pos-1]";