source: git/lib/checkshortcut.pl @ 8377f15

line_contentsproj-api-updatestereo
Last change on this file since 8377f15 was f4c18a9, checked in by Olly Betts <olly@…>, 9 years ago

lib/checkshortcut.pl: Fix shortcut checking to allow for non-ASCII
shortcuts.

  • Property mode set to 100755
File size: 1.4 KB
Line 
1#!/usr/bin/perl -w
2require 5.008;
3use bytes;
4use strict;
5
6my %menu = ();
7my $srcdir = $ENV{'srcdir'} || '';
8$srcdir .= '/' if $srcdir;
9
10open I, "<$srcdir../src/mainfrm.cc" or die $!;
11while (<I>) {
12    m!(\w+)->Append[A-Za-z]*\(.*\(/\*.*?\*/(\d+)! && push @{$menu{$1}}, $2;
13}
14close I;
15
16#for (sort keys %menu) { print "$_:".join("|", @{$menu{$_}})."\n" }
17
18my $exitcode = 0;
19for my $lang (@ARGV) {
20    $lang =~ s/\.msg$//; # allow en or en.msg
21    my $hdr = "Lang $lang:\n";
22    # .msg files could be in srcdir or build directory when building outside
23    # the source tree
24    open L, "<$srcdir$lang.msg" or open L, "<$lang.msg" or die $!;
25    my $buf;
26    read L, $buf, 20;
27    read L, $buf, 999999;
28    close L;
29    my @msg = split /\0/, $buf;
30    for my $menu (sort keys %menu) {
31        my %sc = ();
32        my $bad = 0;
33        for (@{$menu{$menu}}) {
34            my ($acc) = ($msg[$_] =~ /\&([\x00-\x7f]|[\xc2-\xdf].|[\xe0-\xef]..|[\xf0-\xf4]...)/);
35            if (!defined $acc) {
36                print "Lang $lang : message $_ '$msg[$_]' has no shortcut\n";
37            } else {
38                $acc = lc $acc;
39                if (exists $sc{$acc}) {
40                    if (defined $hdr) {
41                        print $hdr;
42                        $hdr = undef;
43                    }
44                    print "Menu $menu : '$msg[$sc{$acc}]' and '$msg[$_]' both use shortcut '$acc'\n";
45                    $bad = 1;
46                } else {
47                    $sc{$acc} = $_;
48                }
49            }
50        }
51        if ($bad) {
52            print "Unused letters: ", grep {!exists $sc{$_}} ('a' .. 'z'), "\n";
53            $exitcode = 1;
54        }
55    }
56    print "\n" unless defined $hdr;
57}
58exit $exitcode;
Note: See TracBrowser for help on using the repository browser.