append a session's history on shell exit and unlimited history list
[lab.git] / misc / findnonsjis.pl
index 2469ca5..71e9a0a 100755 (executable)
@@ -18,7 +18,8 @@ sub match {
     
     my $sjis = encode("cp932", $utf8->decode($str), Encode::FB_HTMLCREF);
     if ($sjis =~ /&#\d{4,};/) {
-        return 1;
+        Encode::from_to($sjis, "cp932", "utf8");
+        return $sjis;
     }
     
     return '';
@@ -27,16 +28,15 @@ sub match {
 sub checkdir {
     my $target = shift @_;
     
-    print STDERR "checking '$target'\n";
+    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";
+        if (my $convert = match($entry)) {
+            print "'$target/$entry' can be converted to '$convert'\n";
             next;
         }
         if (-d "$target/$entry") {