| 1 |
maya |
1184 |
# |
| 2 |
|
|
# 言語ファイルのチェックを行う |
| 3 |
|
|
# |
| 4 |
|
|
# [実行方法] |
| 5 |
|
|
# >perl langfile.pl |
| 6 |
|
|
# |
| 7 |
|
|
# [改版履歴] |
| 8 |
|
|
# 1.0 (2008.02.23 Yutaka Hirata) |
| 9 |
|
|
# |
| 10 |
|
|
|
| 11 |
|
|
$langfile = '..\release\lang\*.lng'; |
| 12 |
|
|
$secpattern = '^\[(.+)\]'; |
| 13 |
|
|
|
| 14 |
|
|
while (glob($langfile)) { |
| 15 |
|
|
do_main($_); |
| 16 |
|
|
# last; |
| 17 |
|
|
} |
| 18 |
|
|
|
| 19 |
|
|
exit(0); |
| 20 |
|
|
|
| 21 |
|
|
sub do_main { |
| 22 |
|
|
my($file) = @_; |
| 23 |
|
|
local(@lines, $pos, %hash); |
| 24 |
|
|
my($section); |
| 25 |
|
|
|
| 26 |
|
|
print "===== $file を検証中\n"; |
| 27 |
|
|
open(FP, $file) || die; |
| 28 |
|
|
@lines = <FP>; |
| 29 |
|
|
$pos = 0; |
| 30 |
|
|
close(FP); |
| 31 |
|
|
|
| 32 |
|
|
# print @lines; |
| 33 |
|
|
|
| 34 |
|
|
print "使用禁止ショートカットを検索中\n"; |
| 35 |
|
|
do { |
| 36 |
|
|
$section = read_section(); |
| 37 |
|
|
print "$section セクション\n"; |
| 38 |
|
|
read_entry(); |
| 39 |
|
|
} while ($pos < @lines); |
| 40 |
|
|
|
| 41 |
|
|
print "ショートカットの重複を検索中\n"; |
| 42 |
|
|
check_conflict(); |
| 43 |
|
|
|
| 44 |
|
|
} |
| 45 |
|
|
|
| 46 |
|
|
sub read_section { |
| 47 |
|
|
my($line, $i, $s); |
| 48 |
|
|
|
| 49 |
|
|
$s = ''; |
| 50 |
|
|
for ($i = $pos ; $i < @lines ; $i++) { |
| 51 |
|
|
# chomp($lines[$i]); |
| 52 |
|
|
if ($lines[$i] =~ /$secpattern/) { |
| 53 |
|
|
$s = $1; |
| 54 |
|
|
# print "Section: $s\n"; |
| 55 |
|
|
$pos = $i + 1; |
| 56 |
|
|
last; |
| 57 |
|
|
} |
| 58 |
|
|
} |
| 59 |
|
|
return ($s); |
| 60 |
|
|
} |
| 61 |
|
|
|
| 62 |
|
|
sub read_entry { |
| 63 |
|
|
my($line, $i, $s); |
| 64 |
|
|
my($id, $val); |
| 65 |
|
|
|
| 66 |
|
|
for ($i = $pos ; $i < @lines ; $i++) { |
| 67 |
|
|
# chomp($lines[$i]); |
| 68 |
|
|
# print "$i: $lines[$i]"; |
| 69 |
|
|
if ($lines[$i] =~ /^[\s\n]+$/ || |
| 70 |
|
|
$lines[$i] =~ /^\s*;/ |
| 71 |
|
|
) { |
| 72 |
|
|
# ignore |
| 73 |
|
|
# print "無視\n"; |
| 74 |
|
|
|
| 75 |
|
|
} elsif ($lines[$i] =~ /$secpattern/) { |
| 76 |
|
|
last; |
| 77 |
|
|
|
| 78 |
|
|
} elsif ($lines[$i] =~ /(\w+)\s*=\s*(.+)/) { |
| 79 |
|
|
$id = $1; |
| 80 |
|
|
$val = $2; |
| 81 |
|
|
# print "$id と $val\n"; |
| 82 |
|
|
|
| 83 |
|
|
# トップメニューのチェック |
| 84 |
|
|
if ($id eq 'MENU_FILE' || |
| 85 |
|
|
$id eq 'MENU_EDIT' || |
| 86 |
|
|
$id eq 'MENU_SETUP' || |
| 87 |
|
|
$id eq 'MENU_CONTROL' || |
| 88 |
|
|
$id eq 'MENU_WINDOW' || |
| 89 |
|
|
$id eq 'MENU_HELP' || |
| 90 |
|
|
$id eq 'MENU_KANJI') { |
| 91 |
|
|
if (check_invalid_key($val)) { |
| 92 |
|
|
print "$id エントリの $val には使用禁止のショートカットキーがあります\n"; |
| 93 |
|
|
} |
| 94 |
|
|
} |
| 95 |
|
|
|
| 96 |
|
|
# ハッシュへ登録 |
| 97 |
|
|
$hash{$id} = $val; |
| 98 |
|
|
|
| 99 |
|
|
} else { |
| 100 |
|
|
print "Unknown error.\n"; |
| 101 |
|
|
} |
| 102 |
|
|
} |
| 103 |
|
|
|
| 104 |
|
|
$pos = $i; |
| 105 |
|
|
} |
| 106 |
|
|
|
| 107 |
|
|
sub check_invalid_key { |
| 108 |
|
|
my($arg) = @_; |
| 109 |
|
|
my($keys) = "TCIQNVRPBGD"; |
| 110 |
|
|
my($key); |
| 111 |
|
|
|
| 112 |
|
|
if ($arg =~ /&(\w)/) { |
| 113 |
|
|
$key = uc($1); |
| 114 |
|
|
if (index($keys, $key) != -1) { # NG! |
| 115 |
|
|
return 1; |
| 116 |
|
|
} |
| 117 |
|
|
} |
| 118 |
|
|
return 0; # safe |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
sub check_conflict { |
| 122 |
|
|
my($line, @lines2); |
| 123 |
|
|
my($section, $key, $val); |
| 124 |
|
|
my($line2, $shortcut, $samelevel); |
| 125 |
|
|
my($key2, $val2); |
| 126 |
|
|
|
| 127 |
|
|
@lines2 = @lines; |
| 128 |
|
|
foreach $line (@lines) { |
| 129 |
|
|
if ($line =~ /^\[(.+)\]$/) { |
| 130 |
|
|
$section = $1; |
| 131 |
|
|
next; |
| 132 |
|
|
} |
| 133 |
|
|
elsif ($line =~ /^(.+)=(.+)$/) { |
| 134 |
|
|
$key = $1; |
| 135 |
|
|
$val = $2; |
| 136 |
|
|
if ($val =~ /&(\w)/) { |
| 137 |
|
|
$shortcut = $1; |
| 138 |
|
|
$samelevel = $key; |
| 139 |
|
|
$samelevel =~ s/(\w+)_[a-zA-Z0-9]+/\1/; |
| 140 |
|
|
# print "$key $samelevel $shortcut\n"; |
| 141 |
|
|
foreach $line2 (@lines2) { |
| 142 |
|
|
if ($line2 =~ /^\[(.+)\]$/) { |
| 143 |
|
|
$section2 = $1; |
| 144 |
|
|
next; |
| 145 |
|
|
} |
| 146 |
|
|
if ($section ne $section2) { |
| 147 |
|
|
next; |
| 148 |
|
|
} |
| 149 |
|
|
elsif ($line2 =~ /^(${samelevel}_[a-zA-Z0-9]+)=(.+)$/) { |
| 150 |
|
|
$key2 = $1; |
| 151 |
|
|
$val2 = $2; |
| 152 |
|
|
if ($key2 eq $key) { |
| 153 |
|
|
next; |
| 154 |
|
|
} |
| 155 |
|
|
if ($val2 =~ /&$shortcut/i) { |
| 156 |
|
|
print "[$key=$val] and [$key2=$val2] conflict [&$shortcut]\n"; |
| 157 |
|
|
} |
| 158 |
|
|
} |
| 159 |
|
|
} |
| 160 |
|
|
} |
| 161 |
|
|
} |
| 162 |
|
|
} |
| 163 |
|
|
|
| 164 |
|
|
} |