1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-04-18 00:47:36 -04:00

check-accelerator-contexts.pl has --help, --version, and exit codes.

It can also check multiple files listed on the command line.
This commit is contained in:
Kalle Olavi Niemitalo 2006-01-13 23:33:52 +02:00 committed by Kalle Olavi Niemitalo
parent 9deceafa0b
commit c8c4d087bf

View File

@ -1,40 +1,72 @@
#! /usr/bin/perl #! /usr/bin/perl
# The copyright notice and license are in the POD at the bottom.
use strict; use strict;
use warnings; use warnings;
use Locale::PO qw(); use Locale::PO qw();
use Getopt::Long qw(GetOptions);
use autouse 'Pod::Usage' => qw(pod2usage);
my %contexts; my $VERSION = "1.0";
my($pofile) = @ARGV;
my $pos = do { sub check_po_file
# Locale::PO 0.16 doesn't understand "#~" obsolete lines and spews warnings. {
local $SIG{__WARN__} = sub {}; my($po_file_name) = @_;
Locale::PO->load_file_asarray($pofile) or die "$pofile: $!"; my %contexts;
}; my $warnings = 0;
foreach my $po (@$pos) { my $pos = do {
next if $po->fuzzy(); # Locale::PO 0.16 doesn't understand "#~" obsolete lines and
my $msgstr = $po->msgstr() # spews warnings.
or next; local $SIG{__WARN__} = sub {};
my($accelerator) = ($msgstr =~ /~(.)/) Locale::PO->load_file_asarray($po_file_name)
or next; or warn "$po_file_name: $!\n", return 2;
$accelerator = uc($accelerator); };
my $automatic = $po->automatic() foreach my $po (@$pos) {
or next; next if $po->fuzzy();
my($contexts) = ($automatic =~ /^accelerator_context\(([^\)]*)\)/) my $msgstr = $po->msgstr()
or next; or next;
foreach my $context (split(/\s*,\s*/, $contexts)) { my($accelerator) = ($msgstr =~ /~(.)/)
my $prev = $contexts{$context}{$accelerator}; or next;
if (defined($prev)) { $accelerator = uc($accelerator);
warn "$pofile: Accelerator conflict for \"$accelerator\" in \"$context\":\n"; my $automatic = $po->automatic()
warn "$pofile: 1st msgid " . $prev->msgid() . "\n"; or next;
warn "$pofile: 1st msgstr " . $prev->msgstr() . "\n"; my($contexts) = ($automatic =~ /^accelerator_context\(([^\)]*)\)/)
warn "$pofile: 2nd msgid " . $po->msgid() . "\n"; or next;
warn "$pofile: 2nd msgstr " . $po->msgstr() . "\n"; foreach my $context (split(/\s*,\s*/, $contexts)) {
} else { my $prev = $contexts{$context}{$accelerator};
$contexts{$context}{$accelerator} = $po; if (defined($prev)) {
warn "$po_file_name: Accelerator conflict for \"$accelerator\" in \"$context\":\n";
warn "$po_file_name: 1st msgid " . $prev->msgid() . "\n";
warn "$po_file_name: 1st msgstr " . $prev->msgstr() . "\n";
warn "$po_file_name: 2nd msgid " . $po->msgid() . "\n";
warn "$po_file_name: 2nd msgstr " . $po->msgstr() . "\n";
$warnings++;
} else {
$contexts{$context}{$accelerator} = $po;
}
} }
} }
return $warnings ? 1 : 0;
} }
sub show_version
{
print "check-accelerator-contexts.pl $VERSION\n";
pod2usage({-verbose => 99, -sections => "COPYRIGHT AND LICENSE",
-exitval => 0});
}
GetOptions("help" => sub { pod2usage(-verbose => 1, -exitval => 0) },
"version" => \&show_version)
or exit 2;
print(STDERR "$0: missing file operand\n"), exit 2 unless @ARGV;
my $max_error = 0;
foreach my $po_file_name (@ARGV) {
my $error = check_po_file($po_file_name);
$max_error = $error if $error > $max_error;
}
exit $max_error;
__END__ __END__
=head1 NAME =head1 NAME
@ -44,7 +76,19 @@ accelerator keys.
=head1 SYNOPSIS =head1 SYNOPSIS
B<check-accelerator-contexts.pl> F<I<language>.pot> B<check-accelerator-contexts.pl> F<I<language>.po> [...]
=head1 ARGUMENTS
=over
=item F<I<language>.po> [...]
The PO files to be scanned for conflicts. These files must include the
"accelerator_context" comments added by B<gather-accelerator-contexts.pl>.
If the special comments are missing, no conflicts will be found.
=back
=head1 DESCRIPTION =head1 DESCRIPTION
@ -66,17 +110,13 @@ B<check-accelerator-contexts.pl> does not access the source files to
which F<I<language>.po> refers. Thus, it does not matter if the line which F<I<language>.po> refers. Thus, it does not matter if the line
numbers in "#:" lines are out of date. numbers in "#:" lines are out of date.
=head1 ARGUMENTS =head1 EXIT CODE
=over 0 if no conflicts were found.
=item F<I<language>.po> 1 if some conflicts were found.
The PO file to be scanned for conflicts. This file must include the 2 if the command line is invalid or a file cannot be read.
"accelerator_context" comments added by B<gather-accelerator-contexts.pl>.
If the special comments are missing, no conflicts will be found.
=back
=head1 BUGS =head1 BUGS