source: lab.git/misc/findcombinable.pl @ e4e7407

trunk
Last change on this file since e4e7407 was e4e7407, checked in by mitty <mitty@…>, 11 years ago
  • fix: use Encode to correctly handle utf9 file or directory name
  • NFKC replaces much more than expected

git-svn-id: https://lab.mitty.jp/svn/lab/trunk@192 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

  • Property mode set to 100755
File size: 1.0 KB
Line 
1#! /usr/bin/perl -w
2
3use strict;
4use warnings;
5use utf8;
6
7use Encode;
8use Unicode::Normalize qw(NFC NFKC);
9binmode STDOUT => 'encoding(utf8)';
10binmode STDERR => 'encoding(utf8)';
11
12my $top = shift @ARGV || exit;
13if (! -d $top) { exit; }
14
15my $utf8 = find_encoding("utf8");
16$top = $utf8->decode($top);
17
18checkdir($top);
19
20sub match {
21    my $str = shift @_;
22   
23    if ($str ne NFC($str)) {
24        return 1;
25    }
26   
27    return '';
28}
29
30sub checkdir {
31    my $target = shift @_;
32   
33    print STDERR "checking '$target'\n";
34    opendir(my $dir, $target) || return $target;
35    my @entries = sort readdir($dir);
36    closedir($dir);
37   
38    my @dirs;
39    while (my $entry = shift @entries) {
40        next if ($entry =~ /^\.+$/);
41        $entry = $utf8->decode($entry);
42        if (match($entry)) {
43            print "'$target/$entry' can be composed\n";
44            next;
45        }
46        if (-d "$target/$entry") {
47            push @dirs, $entry;
48            next;
49        }
50    }
51   
52    while (my $entry = pop @dirs) {
53        checkdir("$target/$entry");
54    }
55}
Note: See TracBrowser for help on using the repository browser.