From 81ef1e9d043f826db9c00234d32a45f0e6eac186 Mon Sep 17 00:00:00 2001 From: Olivier Thauvin Date: Wed, 5 Sep 2007 15:37:15 +0000 Subject: - include file be file except with --all-name --- find-lang.pl | 65 ++++++++++++++++++++++++++++++++++++++++--------------- tests/findlang.pl | 15 +++++++++---- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/find-lang.pl b/find-lang.pl index 8b4f007..d87bef9 100644 --- a/find-lang.pl +++ b/find-lang.pl @@ -36,46 +36,52 @@ File::Find::find( my $file = substr($File::Find::name, length($buildroot)); -f $File::Find::name or return; debug("next file is %s", $file); - my ($pkg, $lang, $parent); my $langfile = $file; if ($file =~ m:^((.*/share/locale)/([^/@]+)[^/]*).*/([^/]+)\.mo:) { if ($withoutmo) { return; } - ($pkg, $lang, $parent, $langfile) = ($4, $3, $2, $1); - } elsif ($file =~ m:^((.*/gnome/help)/([^/]+)/([^/]+)).*$:) { + my ($pkg, $lang, $parent, $langfile) = ($4, $3, $2, $1); + if (pkg_match($pkg)) { + parent_to_own($langfile, $file, $lang); + } + } elsif ($file =~ m:^((.*/gnome/help)/([^/]+)/([^/]+)).*:) { if (!$withgnome) { return; } - ($pkg, $lang, $parent, $langfile) = ($3, $4, $2, $1); - } elsif ($file =~ m:^((.*/doc/kde)/HTML/([^/@]+)[^/]*)/([^/]+)/.*$:) { + my ($pkg, $lang, $parent, $langfile) = ($3, $4, $2, $1); + if (pkg_match($pkg)) { + parent_to_own($langfile, $file, $lang); + } + } elsif ($file =~ m:^((.*/doc/kde)/HTML/([^/@]+)[^/]*)/([^/]+)/.*:) { if (!$withkde) { return; } - ($pkg, $lang, $parent, $langfile) = ($4, $3, $2, $1); - } elsif ($file =~ m:^((.*/doc)/HTML/([^/@]+)[^/]*)/([^/_]+).*$:) { + my ($pkg, $lang, $parent, $langfile) = ($4, $3, $2, $1); + if (pkg_match($pkg)) { + parent_to_own($langfile, $file, $lang); + } + } elsif ($file =~ m:^((.*/doc)/HTML/([^/@]+)[^/]*)/([^/_]+).*:) { if (!$withhtml) { return; } - ($pkg, $lang, $parent, $langfile) = ($4, $3, $2, $1); - } elsif ($file =~ m:^((/+usr/share/man)/([^/@\.]+)[^/]*)/man[^/]+/([^/.]+)\.\d[^/]*$:) { + my ($pkg, $lang, $parent, $langfile) = ($4, $3, $2, $1); + if (pkg_match($pkg)) { + parent_to_own($langfile, $file, $lang); + } + } elsif ($file =~ m:^((/+usr/share/man)/([^/@\.]+)[^/]*)/man[^/]+/([^/.]+)\.\d[^/]*:) { if (!$withman) { return; } - ($pkg, $lang, $parent, $langfile) = ($4, $3, undef, $1); + my ($pkg, $lang, $parent, $langfile) = ($4, $3, undef, $1); $file =~ s/\.[^\.]+$//; $file .= '.*'; + if (pkg_match($pkg)) { + parent_to_own($langfile, $file, $lang); + } } else { return; } - if (! ((grep { $_ eq $pkg } @searchname) || $allname)) { - return; - } - - parent_to_own($parent, $langfile, $lang) if ($parent); - $finallist{$langfile}{'lang'}{$lang} = 1; - debug("File %s will be %s", $langfile, $lang); - }, $buildroot || '/' ); @@ -100,14 +106,37 @@ close($hlang); exit(0); +sub pkg_match { + my ($pkg) = @_; + if ($allname) { return 1 }; + if (grep { $_ eq $pkg } @searchname) { + return 1; + } + return; +} + sub parent_to_own { my ($parent, $file, $lang) = @_; + debug("parent_to_own: $parent, $file, $lang"); + if ($allname) { + #my @subdir = grep { $_ } split('/', substr($file, length($parent))); + #$parent .= '/' . shift(@subdir); + $finallist{$parent}{'lang'}{$lang} = 1; + debug("Parent %s will be %s", $parent, $lang); + } else { my @subdir = grep { $_ } split('/', substr($file, length($parent))); pop(@subdir); + $finallist{$parent}{dir} = 1; + $finallist{$parent}{'lang'}{$lang} = 1; + debug("Parent %s will be %s", $parent, $lang); while (my $part = shift(@subdir)) { $parent .= "/$part"; $finallist{$parent}{dir} = 1; $finallist{$parent}{'lang'}{$lang} = 1; debug("Parent %s will be %s", $parent, $lang); + } + $finallist{$file}{'lang'}{$lang} = 1; + debug("Parent %s will be %s", $file, $lang); + } } diff --git a/tests/findlang.pl b/tests/findlang.pl index fa6dbae..d601728 100644 --- a/tests/findlang.pl +++ b/tests/findlang.pl @@ -12,11 +12,17 @@ my $testarbo = "$pwd/find-lang-root"; my %files = ( # file => [ lang, is_%dir ] - '/usr/share/man/fr' => [ 'fr', 0 ], - '/usr/share/locale/pt_BR' => [ 'pt_BR', 0 ], - '/usr/share/gnome/help/lang/pt_BR' => [ 'pt_BR', 0 ], - '/usr/share/gnome/help/lang/en_GB' => [ 'en_GB', 0 ], + '/usr/share/man/fr' => [ 'fr', 1 ], + '/usr/share/man/fr/man1' => [ 'fr', 1 ], + '/usr/share/man/fr/man1/lang.1.*' => [ 'fr', 0 ], + '/usr/share/locale/pt_BR' => [ 'pt_BR', 1 ], + '/usr/share/gnome/help/lang/pt_BR' => [ 'pt_BR', 1 ], + '/usr/share/gnome/help/lang/pt_BR/any.html' => [ 'pt_BR', 0 ], + '/usr/share/gnome/help/lang/en_GB' => [ 'en_GB', 1 ], + '/usr/share/gnome/help/lang/en_GB/any.html' => [ 'en_GB', 0 ], '/usr/share/gnome/help/lang' => [ '', 1 ], + '/usr/share/locale/pt_BR/LC_MESSAGES' => [ 'pt_BR', 1 ], + '/usr/share/locale/pt_BR/LC_MESSAGES/lang.mo' => [ 'pt_BR', 0 ], ); system("/usr/bin/perl find-lang.pl $testarbo lang --with-man --with-gnome") and die "can't run find-lang $@"; @@ -31,6 +37,7 @@ while (my $line = <$h>) { $lang ||= ''; my $dir = $line =~ /%dir/; $dir ||= 0; + print STDERR "$file\n"; is($lang, $files{$file}[0], "lang is find"); is($dir, $files{$file}[1], "%dir is properly set if need"); } -- cgit v1.2.1