]>
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.
8 # The latest version is available from
9 # <URL:http://www.student.uit.no/~pere/linux/glibc/>.
14 use vars
qw($locale $warncount $errcount);
18 $line =~ s/<U([0-9A-Za-z]{4})>/pack('U',hex($1))/ge;
25 print "error: $locale: $msg\n";
31 print "warning: $locale: $msg\n";
34 sub check_lc_identification
{
36 for my $line (@lines) {
37 if ($line =~ m/^category\s+(\S+)$/) {
38 warning
"LC_IDENTIFICATION: missing quotes around category standard ref: $1"
41 if ($line =~ m/^email\s+(\S+)\s*$/) {
43 warning
"LC_IDENTIFICATION: obsolete email: $email"
44 if ($email =~ m/"?bug-glibc\@gnu.org"?/);
53 $height = $1 if (m/^height\s*(\d+)\s*$/);
54 $width = $1 if (m/^width\s*(\d+)\s*$/);
55 return if (m/^copy\s+/); # Nothing to check
58 if (!defined $width || defined $height) {
59 # warning "LC_PAPER: Missing height or width.";
63 if (210 == $width && 297 == $height) { # ISO A4
64 } elsif (216 == $width && 279 == $height) { # US Letter
66 warning
"LC_PAPER: unknown paper size.";
70 sub check_lc_measurement
{
72 for my $line (@lines) {
73 if ($line =~ m/^\s*(measurement)\s+(\S+)\s*$/) {
75 if (defined $value && $value !~ m/^\d+$/) {
76 warning
"LC_MEASUREMENT: measurements should be number 1 or 2.";
77 } elsif ($value < 1 && 2 < $value) {
78 warning
"LC_MEASUREMENT: measurements should be 1 or 2.";
84 sub check_lc_numeric
{
86 for my $line (@lines) {
87 next if ($line eq "LC_NUMERIC" || $line eq "END LC_NUMERIC");
88 next if ($line =~ m/^$/);
89 if ($line =~ m/^\s*(grouping)\s+(\S+)\s*$/) {
91 if ($value =~ m/^-?\d+$/) {
92 # Only digits (or - digits)
93 if ( $value < 1 && $value != -1) {
94 warning
"LC_NUMERIC: grouping should positive or -1: $value";
97 if (defined $value && $value !~ m/\d+;\d+/) {
98 warning
"LC_NUMERIC: grouping should use ; as separator: $value";
101 } elsif ($line =~ m/^\s*(decimal_point)\s+(\S+)\s*$/) {
102 } elsif ($line =~ m/^\s*(thousands_sep)\s+(\S+)\s*$/) {
104 # print "P: '$sep'\n";
105 warning
"LC_NUMERIC: Unusual thousands_sep '$sep' [".
106 uxx_to_utf8
($sep)."]"
107 unless (grep { $_ eq $sep; } ('"<U0020>"',
113 } elsif ($line =~ m/^\s*(copy)\s+(\S+)\s*$/) {
115 warning
"LC_NUMERIC: Unknown keyword '$line'";
120 sub check_lc_messages
{
123 if (m/^\s*(yesexpr|noexpr)\s+(.+)$/) {
125 my $regex = uxx_to_utf8
($2);
126 unless ($regex =~ m/^"\^/) {
127 error
"LC_MESSAGES: $type missing '^' prefix: $regex";
129 unless ($regex =~ m/\[.+\]|\(.+\)/) {
130 error
"LC_MESSAGES: $type missing '[.+]|(.+)' content: $regex";
132 if ($regex =~ m/\.\*"$/) {
133 warning
"LC_MESSAGES: $type have '.*' postfix: $regex";
135 if ($regex =~ m/[0-9]/) {
136 warning
"LC_MESSAGES: $type have numbers in regex: $regex";
138 if ($type eq "yesexpr" && ($regex !~ m/y/ ||
140 warning
"LC_MESSAGES: $type missing 'yY' in content: $regex";
142 if ($type eq "noexpr" && ($regex !~ m/n/ ||
144 warning
"LC_MESSAGES: $type missing 'nN' in content: $regex";
153 for my $filename (@ARGV) {
154 open (FILE
, "<$filename") || die "Unable to read $filename";
161 s/%.*$//; # Remove comments
167 if (! defined $buf) {
172 if (!$section && m/^(LC_.*)\s*$/) {
175 #print "Found section $section\n";
178 if (m/^END (LC_.+)\s*$/) {
179 if (exists $sections{$section}) {
180 warning
"duplicate section $section";
182 push(@blocks, $section);
183 $sections{$section} = [@lines];
185 #print "Stored section $section\n";
191 check_order
(@blocks);
192 check_lc_identification
(@{$sections{'LC_IDENTIFICATION'}});
193 check_lc_messages
(@{$sections{'LC_MESSAGES'}});
194 check_lc_numeric
(@{$sections{'LC_NUMERIC'}});
195 check_lc_paper
(@{$sections{'LC_PAPER'}});
196 check_lc_measurement
(@{$sections{'LC_MEASUREMENT'}});
200 my @order= qw(LC_IDENTIFICATION
213 for my $section (@blocks) {
214 if ($section eq $order[$pos]) {
218 $pos++ while ($order[$pos] ne $section);
219 warning
"$section: not following section $order[$pos-1]";