* find file or directory that name contains non sjis character
authormitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Thu, 24 Jan 2013 12:17:01 +0000 (12:17 +0000)
committermitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Thu, 24 Jan 2013 12:17:01 +0000 (12:17 +0000)
git-svn-id: https://lab.mitty.jp/svn/lab/trunk@189 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

misc/findnonsjis.pl [new file with mode: 0755]

diff --git a/misc/findnonsjis.pl b/misc/findnonsjis.pl
new file mode 100755 (executable)
index 0000000..7e25e48
--- /dev/null
@@ -0,0 +1,50 @@
+#! /usr/bin/perl -w
+
+use strict;
+use warnings;
+use utf8;
+use encoding 'utf-8';
+
+use Unicode::Japanese qw(unijp);
+
+my $top = shift @ARGV || exit;
+if (! -d $top) { exit; }
+
+checkdir($top);
+
+sub match {
+    my $str = shift @_;
+    
+    my $sjis = unijp($str)->sjis;
+    if ($sjis =~ /&#\d{4,};/) {
+        return 1;
+    }
+    
+    return '';
+}
+
+sub checkdir {
+    my $target = shift @_;
+    
+    print STDERR "checking '$target'\n";
+    opendir(my $dir, $target) || return $target;
+    my @entries = sort 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;
+        }
+        if (-d "$target/$entry") {
+            push @dirs, $entry;
+            next;
+        }
+    }
+    
+    while (my $entry = pop @dirs) {
+        checkdir("$target/$entry");
+    }
+}