From 68d6d5b003efbd06a48bd9933929cbe463738ee2 Mon Sep 17 00:00:00 2001 From: mitty Date: Thu, 24 Jan 2013 06:48:36 +0000 Subject: [PATCH] * find file or directory that name can be combinable by NFC/NFKC git-svn-id: https://lab.mitty.jp/svn/lab/trunk@187 7d2118f6-f56c-43e7-95a2-4bb3031d96e7 --- misc/findcombinable.pl | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 misc/findcombinable.pl diff --git a/misc/findcombinable.pl b/misc/findcombinable.pl new file mode 100755 index 0000000..464ecb8 --- /dev/null +++ b/misc/findcombinable.pl @@ -0,0 +1,52 @@ +#! /usr/bin/perl -w + +use strict; +use warnings; +use utf8; +use encoding 'utf-8'; + +use Unicode::Normalize qw(NFC NFKC); + +my $top = shift @ARGV || exit; +if (! -d $top) { exit; } + +checkdir($top); + +sub combinable { + my $str = shift @_; + + if ($str ne NFC($str)) { + return 1; + } + if ($str ne NFKC($str)) { + 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 (combinable($entry)) { + print "'$target/$entry' can be composed\n"; + next; + } + if (-d "$target/$entry") { + push @dirs, $entry; + next; + } + } + + while (my $entry = pop @dirs) { + checkdir("$target/$entry"); + } +} -- 1.7.9.5