* remove obsolete pragma "use encoding 'utf-8';"
[lab.git] / misc / findnonsjis.pl
1 #! /usr/bin/perl -w
2
3 use strict;
4 use warnings;
5 use utf8;
6
7 use Encode;
8
9 my $top = shift @ARGV || exit;
10 if (! -d $top) { exit; }
11
12 my $utf8 = find_encoding("utf8");
13
14 checkdir($top);
15
16 sub match {
17     my $str = shift @_;
18     
19     my $sjis = encode("cp932", $utf8->decode($str), Encode::FB_HTMLCREF);
20     if ($sjis =~ /&#\d{4,};/) {
21         return 1;
22     }
23     
24     return '';
25 }
26
27 sub checkdir {
28     my $target = shift @_;
29     
30     print STDERR "checking '$target'\n";
31     opendir(my $dir, $target) || return $target;
32     my @entries = sort readdir($dir);
33     closedir($dir);
34     
35     my @dirs;
36     while (my $entry = shift @entries) {
37         next if ($entry =~ /^\.+$/);
38         if (match($entry)) {
39             print "'$target/$entry' contains non Shift_JIS character\n";
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 }