source: lab/trunk/misc/findnonsjis.pl @ 195

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