svnno****@sourc*****
svnno****@sourc*****
2012年 4月 19日 (木) 22:38:51 JST
Revision: 24 http://sourceforge.jp/projects/miranda-jp/svn/view?view=rev&revision=24 Author: taguchi-ch Date: 2012-04-19 22:38:51 +0900 (Thu, 19 Apr 2012) Log Message: ----------- bug fix Modified Paths: -------------- trunk/miranda-tools/lpgen/lplink.pl -------------- next part -------------- Modified: trunk/miranda-tools/lpgen/lplink.pl =================================================================== --- trunk/miranda-tools/lpgen/lplink.pl 2012-04-18 15:20:51 UTC (rev 23) +++ trunk/miranda-tools/lpgen/lplink.pl 2012-04-19 13:38:51 UTC (rev 24) @@ -11,52 +11,64 @@ #Check argument if(@ARGV < 2) { - print "lplink <(new or old) langDB> <old langpack_* > [<next langpack_*> ...]\n"; + print " '$0' <(new or old) langDB> <old langpack_* > [<next langpack_*> ...]\n"; exit; } +my ($langDB_file, @lang_files) = @ARGV; -#Add all words to langDB. -my ($langDB_file, @lang_files) = @ARGV; +#Get words from exited langDB. my $key = ''; my %trans; -foreach my $lang_file (@lang_files) + +if ( open my $fh, '<', $langDB_file ) { - open my $fh1, '<', $lang_file or die "Error Cannot open '$lang_file': $!"; - while( my $get_key = <$fh1>) + while( my $get_line = <$fh>) { - chomp $get_key; - if( $get_key =~ /^\[(.*?\[.*?\])*.*?\]/ ) + chomp $get_line; + if( $get_line =~ /^\[(.*?)\]$/ ) { - $key = $get_key; - next; + $key = $get_line; + $get_line = <$fh>; + chomp $get_line; + $trans{$key} = $get_line; } - elsif( $get_key and !$trans{$get_key} and $get_key !~ /^;/ and $key ne '' ) + } + close $fh; +} + +#Get words from langpack_*. +foreach my $lang_file (@lang_files) +{ + open my $fh, '<', $lang_file + or die qq/Error : Cannot open "$lang_file": $!/; + while( my $get_line = <$fh>) + { + chomp $get_line; + if( $get_line =~ /^\[(.*?)\]$/ ) { - $trans{$key} = $get_key; + $key = $get_line; + $get_line = <$fh>; + chomp $get_line; + $trans{$key} = $get_line; } } - close $fh1; + close $fh; } #Sort orignal words in alphabetical order. my @keywords = sort( keys ( %trans )); -#All result write to langDB. -open my $fh, '>', $langDB_file or die "Error Cannot open '$langDB_file': $!"; +#All result write to tempfile. +my $temp_file = "\$file.\$\$."; +open my $fh1, '>', $temp_file + or die qq/Error : Cannot open "$temp_file": $!/; foreach my $keyword (@keywords) { - if( $keyword =~ /^\[(.*?\[.*?\])*.*?\]/ ) - { - print $fh $keyword; - print $fh "\n"; - print $fh $trans{$keyword}; - print $fh "\n"; - } - else - { - print $fh $keyword; - print $fh "\n"; - } + printf $fh1 "%s\n%s\n", $keyword, $trans{$keyword}; } -close $fh; +close $fh1; + +#Rename tempfile to langDB. +rename $temp_file, $langDB_file + or die qq/Error : Cannot move "$temp_file" to "$langDB_file": $!/;