]>
pere.pagekite.me Git - homepage.git/blob - linux/glibc/check-locale
3 # Author: Petter Reinholdtsen
6 # License: GPL v2 or later at your choice
8 # Test the content of GNU libc locales, detect some common errors.
10 # The latest version is available from
11 # <URL:http://www.hungry.com/~pere/linux/glibc/>.
16 use vars
qw($locale $warncount $errcount);
20 $line =~ s/<U([0-9A-Za-z]{4})>/pack('U',hex($1))/ge;
27 print "error: $locale: $msg\n";
33 print "warning: $locale: $msg\n";
36 sub check_lc_identification
{
38 for my $line (@lines) {
39 if ($line =~ m/^category\s+(\S+)$/) {
40 warning
"LC_IDENTIFICATION: missing quotes around category standard ref: $1"
43 if ($line =~ m/^email\s+(\S+)\s*$/) {
45 warning
"LC_IDENTIFICATION: obsolete email: $email"
46 if ($email =~ m/"?bug-glibc\@gnu.org"?/);
55 $height = $1 if (m/^height\s*(\d+)\s*$/);
56 $width = $1 if (m/^width\s*(\d+)\s*$/);
57 return if (m/^copy\s+/); # Nothing to check
60 if (!defined $width || defined $height) {
61 # warning "LC_PAPER: Missing height or width.";
65 if (210 == $width && 297 == $height) { # ISO A4
66 } elsif (216 == $width && 279 == $height) { # US Letter
68 warning
"LC_PAPER: unknown paper size.";
72 sub check_lc_measurement
{
74 for my $line (@lines) {
75 if ($line =~ m/^\s*(measurement)\s+(\S+)\s*$/) {
77 if (defined $value && $value !~ m/^\d+$/) {
78 warning
"LC_MEASUREMENT: measurements should be number 1 or 2.";
79 } elsif ($value < 1 && 2 < $value) {
80 warning
"LC_MEASUREMENT: measurements should be 1 or 2.";
86 sub check_lc_numeric
{
88 for my $line (@lines) {
89 next if ($line eq "LC_NUMERIC" || $line eq "END LC_NUMERIC");
90 next if ($line =~ m/^$/);
91 if ($line =~ m/^\s*(grouping)\s+(\S+)\s*$/) {
93 if ($value =~ m/^-?\d+$/) {
94 # Only digits (or - digits)
95 if ( $value < 1 && $value != -1) {
96 warning
"LC_NUMERIC: grouping should positive or -1: $value";
99 if (defined $value && $value !~ m/\d+;\d+/) {
100 warning
"LC_NUMERIC: grouping should use ; as separator: $value";
103 } elsif ($line =~ m/^\s*(decimal_point)\s+(\S+)\s*$/) {
104 } elsif ($line =~ m/^\s*(thousands_sep)\s+(\S+)\s*$/) {
106 # print "P: '$sep'\n";
107 warning
"LC_NUMERIC: Unusual thousands_sep '$sep' [".
108 uxx_to_utf8
($sep)."]"
109 unless (grep { $_ eq $sep; } ('"<U0020>"',
115 } elsif ($line =~ m/^\s*(copy)\s+(\S+)\s*$/) {
117 warning
"LC_NUMERIC: Unknown keyword '$line'";
122 sub check_lc_messages
{
125 if (m/^\s*(yesexpr|noexpr)\s+(.+)$/) {
127 my $regex = uxx_to_utf8
($2);
128 unless ($regex =~ m/^"\^/) {
129 error
"LC_MESSAGES: $type missing '^' prefix: $regex";
131 unless ($regex =~ m/\[.+\]|\(.+\)/) {
132 error
"LC_MESSAGES: $type missing '[.+]|(.+)' content: $regex";
134 if ($regex =~ m/\.\*"$/) {
135 warning
"LC_MESSAGES: $type have '.*' postfix: $regex";
137 if ($regex =~ m/[0-9]/) {
138 warning
"LC_MESSAGES: $type have numbers in regex: $regex";
140 if ($type eq "yesexpr" && ($regex !~ m/y/ ||
142 warning
"LC_MESSAGES: $type missing 'yY' in content: $regex";
144 if ($type eq "noexpr" && ($regex !~ m/n/ ||
146 warning
"LC_MESSAGES: $type missing 'nN' in content: $regex";
154 my @order= qw(LC_IDENTIFICATION
167 for my $section (@blocks) {
168 if ($section eq $order[$pos]) {
172 $pos++ while ($order[$pos] ne $section);
173 warning
"$section: not following section $order[$pos-1]";
180 for my $section (@blocks) {
181 if ($section =~ m/^%\s*[Cc]arset:\s*$/) {
185 warning
"Missing '% Charset: <charset>' info";
191 for my $filename (@ARGV) {
192 open (FILE
, "<$filename") || die "Unable to read $filename";
199 s/%.*$//; # Remove comments
205 if (! defined $buf) {
210 if (!$section && m/^(LC_.*)\s*$/) {
213 #print "Found section $section\n";
216 if (m/^END (LC_.+)\s*$/) {
217 if (exists $sections{$section}) {
218 warning
"duplicate section $section";
220 push(@blocks, $section);
221 $sections{$section} = [@lines];
223 #print "Stored section $section\n";
229 # check_order(@blocks);
230 check_charset
(@blocks);
231 check_lc_identification
(@{$sections{'LC_IDENTIFICATION'}});
232 check_lc_messages
(@{$sections{'LC_MESSAGES'}});
233 check_lc_numeric
(@{$sections{'LC_NUMERIC'}});
234 check_lc_paper
(@{$sections{'LC_PAPER'}});
235 check_lc_measurement
(@{$sections{'LC_MEASUREMENT'}});