Last change
on this file since 197 was
197,
checked in by mitty, 11 years ago
|
- output string contains numeric character references
|
-
Property svn:executable set to
*
|
File size:
1.0 KB
|
Rev | Line | |
---|
[187] | 1 | #! /usr/bin/perl -w |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use utf8; |
---|
| 6 | |
---|
[190] | 7 | use Encode; |
---|
[187] | 8 | |
---|
| 9 | my $top = shift @ARGV || exit; |
---|
| 10 | if (! -d $top) { exit; } |
---|
| 11 | |
---|
[190] | 12 | my $utf8 = find_encoding("utf8"); |
---|
| 13 | |
---|
[187] | 14 | checkdir($top); |
---|
| 15 | |
---|
[188] | 16 | sub match { |
---|
[187] | 17 | my $str = shift @_; |
---|
| 18 | |
---|
[190] | 19 | my $sjis = encode("cp932", $utf8->decode($str), Encode::FB_HTMLCREF); |
---|
[189] | 20 | if ($sjis =~ /&#\d{4,};/) { |
---|
[197] | 21 | Encode::from_to($sjis, "cp932", "utf8"); |
---|
| 22 | return $sjis; |
---|
[187] | 23 | } |
---|
| 24 | |
---|
| 25 | return ''; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | sub checkdir { |
---|
| 29 | my $target = shift @_; |
---|
| 30 | |
---|
[195] | 31 | print STDERR "# checking '$target'\n"; |
---|
[187] | 32 | opendir(my $dir, $target) || return $target; |
---|
[193] | 33 | my @entries = sort grep { !m/^(\.|\.\.)$/g } readdir($dir); |
---|
[187] | 34 | closedir($dir); |
---|
| 35 | |
---|
| 36 | my @dirs; |
---|
| 37 | while (my $entry = shift @entries) { |
---|
[197] | 38 | if (my $convert = match($entry)) { |
---|
| 39 | print "'$target/$entry' can be converted to '$convert'\n"; |
---|
[187] | 40 | next; |
---|
| 41 | } |
---|
| 42 | if (-d "$target/$entry") { |
---|
| 43 | push @dirs, $entry; |
---|
| 44 | next; |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | while (my $entry = pop @dirs) { |
---|
| 49 | checkdir("$target/$entry"); |
---|
| 50 | } |
---|
| 51 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.