| 1 |
#! /usr/bin/perl |
| 2 |
|
| 3 |
# |
| 4 |
# 英語版ドキュメントに日本語が含まれていないかを調べる。 |
| 5 |
# |
| 6 |
# Usage(ActivePerl): |
| 7 |
# perl check_sjis_code.pl > result.txt |
| 8 |
# |
| 9 |
|
| 10 |
use Encode::Guess qw/shift-jis 7bit-jis/; |
| 11 |
|
| 12 |
#my @exclude_files = qw(sourcecode.html); |
| 13 |
my @exclude_files = qw(); |
| 14 |
|
| 15 |
get_file_paths('../doc/en/html'); |
| 16 |
exit(0); |
| 17 |
|
| 18 |
sub get_file_paths { |
| 19 |
my ($top_dir)= @_; |
| 20 |
my @paths=(); |
| 21 |
my @temp = (); |
| 22 |
|
| 23 |
#-- カレントの一覧を取得 --# |
| 24 |
opendir(DIR, $top_dir); |
| 25 |
@temp = readdir(DIR); |
| 26 |
closedir(DIR); |
| 27 |
foreach my $path (sort @temp) { |
| 28 |
next if( $path =~ /^\.{1,2}$/ ); # '.' と '..' はスキップ |
| 29 |
next if( $path =~ /^\.svn$/ ); # '.svn' はスキップ |
| 30 |
|
| 31 |
my $full_path = "$top_dir" . '/' . "$path"; |
| 32 |
# print "$full_path\r\n"; # 表示だけなら全てを表示してくれる------- |
| 33 |
push(@paths, $full_path); # データとして取り込んでも前の取り込みが初期化される |
| 34 |
if( -d "$top_dir/$path" ){ #-- ディレクトリの場合は自分自身を呼び出す |
| 35 |
&get_file_paths("$full_path"); |
| 36 |
} elsif (-B $full_path) { |
| 37 |
# バイナリファイルはスキップ |
| 38 |
next; |
| 39 |
|
| 40 |
} elsif (&check_exclude_file($path)) { |
| 41 |
print "$full_path skipped\n"; |
| 42 |
next; |
| 43 |
|
| 44 |
} else { |
| 45 |
check_sjis_code($full_path); |
| 46 |
|
| 47 |
} |
| 48 |
} |
| 49 |
return \@paths; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
# 調査対象外のファイルかを調べる |
| 54 |
sub check_exclude_file { |
| 55 |
my($fn) = shift; |
| 56 |
my($s); |
| 57 |
|
| 58 |
foreach $s (@exclude_files) { |
| 59 |
if ($fn eq $s) { |
| 60 |
return 1; |
| 61 |
} |
| 62 |
} |
| 63 |
return 0; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
# cf. http://charset.7jp.net/sjis.html |
| 68 |
# ShiftJIS 文字 |
| 69 |
|
| 70 |
sub check_sjis_code { |
| 71 |
my($filename) = shift; |
| 72 |
local(*FP); |
| 73 |
my($line, $no); |
| 74 |
|
| 75 |
open(FP, "<$filename") || return; |
| 76 |
$no = 1; |
| 77 |
while ($line = <FP>) { |
| 78 |
# $line = chomp($line); |
| 79 |
# print "$line\n"; |
| 80 |
|
| 81 |
my $enc = guess_encoding( $line, qw/ euc-jp shiftjis 7bit-jis utf8 / ); |
| 82 |
|
| 83 |
if (ref $enc) { |
| 84 |
# printf "%s\n", $enc->name; |
| 85 |
if ($enc->name !~ /ascii/) { |
| 86 |
# printf "%s\n", $enc->name; |
| 87 |
if (!check_skipped_line($line)) { |
| 88 |
print "$filename:$no: $1\n"; |
| 89 |
print "$line\n"; |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
# if ($line =~ /([\xA1-\xDF]|[\x81-\x9F\xE0-\xEF][\x40-\x7E\x80-\xFC])/) { |
| 94 |
# print "$filename:$no: $1\n"; |
| 95 |
# print "$line\n"; |
| 96 |
# } |
| 97 |
$no++; |
| 98 |
} |
| 99 |
close(FP); |
| 100 |
} |
| 101 |
|
| 102 |
# 行が対象外かどうかをチェックする |
| 103 |
# true: 対象外である |
| 104 |
# false: 対象外ではない |
| 105 |
sub check_skipped_line { |
| 106 |
my($line) = shift; |
| 107 |
my($pos); |
| 108 |
|
| 109 |
# print "[$line]"; |
| 110 |
|
| 111 |
# UTF-8 BOM |
| 112 |
$pos = index($line, pack("C3", 0xef, 0xbb, 0xbf)); |
| 113 |
# print "$pos\n"; |
| 114 |
return 1 if ($pos != -1); |
| 115 |
|
| 116 |
return 0; |
| 117 |
} |