Last change
on this file since 199 was
199,
checked in by mitty, 11 years ago
|
- fix: convert non Shift_JIS character only
- skip needless convert (such as U+8C37 -> U+7A40)
|
-
Property svn:executable set to
*
|
File size:
1.2 KB
|
Rev | Line | |
---|
[187] | 1 | #! /usr/bin/perl -w |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use utf8; |
---|
| 6 | |
---|
[192] | 7 | use Encode; |
---|
[198] | 8 | use Kanconvit; # http://kanconvit.ta2o.net/ |
---|
[187] | 9 | |
---|
| 10 | my $top = shift @ARGV || exit; |
---|
| 11 | if (! -d $top) { exit; } |
---|
| 12 | |
---|
[192] | 13 | my $utf8 = find_encoding("utf8"); |
---|
[198] | 14 | my $ck = Kanconvit->new(); |
---|
[192] | 15 | |
---|
[187] | 16 | checkdir($top); |
---|
| 17 | |
---|
[188] | 18 | sub match { |
---|
[187] | 19 | my $str = shift @_; |
---|
| 20 | |
---|
[194] | 21 | $str = $utf8->decode($str); |
---|
[199] | 22 | my $sjis = encode("cp932", $str, Encode::FB_HTMLCREF); |
---|
| 23 | if ($sjis =~ /&#\d{4,};/) { |
---|
| 24 | my $jtext = $ck->conv_c2j($str); |
---|
| 25 | if ($str ne $jtext) { |
---|
| 26 | return $utf8->encode($jtext); |
---|
| 27 | } |
---|
[187] | 28 | } |
---|
| 29 | |
---|
| 30 | return ''; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | sub checkdir { |
---|
| 34 | my $target = shift @_; |
---|
| 35 | |
---|
[195] | 36 | print STDERR "# checking '$target'\n"; |
---|
[187] | 37 | opendir(my $dir, $target) || return $target; |
---|
[193] | 38 | my @entries = sort grep { !m/^(\.|\.\.)$/g } readdir($dir); |
---|
[187] | 39 | closedir($dir); |
---|
| 40 | |
---|
| 41 | my @dirs; |
---|
| 42 | while (my $entry = shift @entries) { |
---|
[198] | 43 | if (my $japanese = match($entry)) { |
---|
| 44 | print "mv '$target/$entry' \\\n"; |
---|
| 45 | print " '$target/$japanese'\n"; |
---|
[187] | 46 | next; |
---|
| 47 | } |
---|
| 48 | if (-d "$target/$entry") { |
---|
| 49 | push @dirs, $entry; |
---|
| 50 | next; |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | while (my $entry = pop @dirs) { |
---|
| 55 | checkdir("$target/$entry"); |
---|
| 56 | } |
---|
| 57 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.