* fix: previous procedure skips files such as '...'
[lab.git] / misc / findnonsjis.pl
index 7e25e48..87c8ea5 100755 (executable)
@@ -3,19 +3,20 @@
 use strict;
 use warnings;
 use utf8;
-use encoding 'utf-8';
 
-use Unicode::Japanese qw(unijp);
+use Encode;
 
 my $top = shift @ARGV || exit;
 if (! -d $top) { exit; }
 
+my $utf8 = find_encoding("utf8");
+
 checkdir($top);
 
 sub match {
     my $str = shift @_;
     
-    my $sjis = unijp($str)->sjis;
+    my $sjis = encode("cp932", $utf8->decode($str), Encode::FB_HTMLCREF);
     if ($sjis =~ /&#\d{4,};/) {
         return 1;
     }
@@ -28,12 +29,11 @@ sub checkdir {
     
     print STDERR "checking '$target'\n";
     opendir(my $dir, $target) || return $target;
-    my @entries = sort readdir($dir);
+    my @entries = sort grep { !m/^(\.|\.\.)$/g } readdir($dir);
     closedir($dir);
     
     my @dirs;
     while (my $entry = shift @entries) {
-        next if ($entry =~ /^\.+$/);
         if (match($entry)) {
             print "'$target/$entry' contains non Shift_JIS character\n";
             next;