* fix: previous procedure skips files such as '...'
[lab.git] / misc / findcombinable.pl
index 3e5f51d..8d515d9 100755 (executable)
@@ -4,11 +4,17 @@ use strict;
 use warnings;
 use utf8;
 
+use Encode;
 use Unicode::Normalize qw(NFC NFKC);
+binmode STDOUT => 'encoding(utf8)';
+binmode STDERR => 'encoding(utf8)';
 
 my $top = shift @ARGV || exit;
 if (! -d $top) { exit; }
 
+my $utf8 = find_encoding("utf8");
+$top = $utf8->decode($top);
+
 checkdir($top);
 
 sub match {
@@ -17,9 +23,6 @@ sub match {
     if ($str ne NFC($str)) {
         return 1;
     }
-    if ($str ne NFKC($str)) {
-        return 1;
-    }
     
     return '';
 }
@@ -29,12 +32,12 @@ sub checkdir {
     
     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 =~ /^\.+$/);
+        $entry = $utf8->decode($entry);
         if (match($entry)) {
             print "'$target/$entry' can be composed\n";
             next;