Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXhmikosR <xhmikosr@users.sourceforge.net>2010-10-01 14:29:33 +0400
committerXhmikosR <xhmikosr@users.sourceforge.net>2010-10-01 14:29:33 +0400
commit5067b0b48d4d15b24669c8032b28e90e45202801 (patch)
treed39e51c7ac00e7b42701baf82fedb7dc12856923 /src/apps/mplayerc/mpcresources/rcfile.pl
parent907cde437174371aac6741c1d435a0088d66f459 (diff)
legacy branch: merge changes from trunk 2635-2642,2645,2658-2660, updated apps project files
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/branches/legacy@2661 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/apps/mplayerc/mpcresources/rcfile.pl')
-rw-r--r--src/apps/mplayerc/mpcresources/rcfile.pl202
1 files changed, 60 insertions, 142 deletions
diff --git a/src/apps/mplayerc/mpcresources/rcfile.pl b/src/apps/mplayerc/mpcresources/rcfile.pl
index 48778d000..6d8487293 100644
--- a/src/apps/mplayerc/mpcresources/rcfile.pl
+++ b/src/apps/mplayerc/mpcresources/rcfile.pl
@@ -19,7 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-# Apply mplayerc.rc file changes to locale rc files, and generate patch files for translators.
+# Apply mplayerc.rc file changes to locale rc files.
#
# To use this program, you need a perl with PerlIO package installed.
# For help of usage, type: perl rcfile.pl -h
@@ -36,21 +36,19 @@ require "common.pl";
my $BaseFileName = "../mplayerc.rc";
my $NewFileName = "../mplayerc.rc";
-my $Extension=".txt";
my $help;
-my $result = GetOptions("base|b=s" =>\$BaseFileName, "new|n=s" =>\$NewFileName, "suffix|x=s"=>\$Extension, "help|h"=>\$help);
+my $result = GetOptions("base|b=s" =>\$BaseFileName, "new|n=s" =>\$NewFileName, "help|h"=>\$help);
if($help || !$result) {
print << 'USAGE';
Usage: perl rcfile.pl [Options] | -h --help
Copy all changes between two version of mplayerc.rc files to all rc files in the current directory,
-generate new rc files and texts for translators under the "newrc" subdirectory.
+generate new rc files under the "newrc" subdirectory.
Options:
--base -b base file, default "../mplayerc.rc" optional
--new -n modified file, default "../mplayerc.rc" optional
- --suffix -x output file suffix, default ".txt" optional
--help -h show this help
Base file: the previous revision of mplayerc.rc file
@@ -67,17 +65,18 @@ Options:
Second: >perl rcfile.pl -b mplayerc.rc.old
Or better yet use provided batch file: >rcfile.bat
- After running this script, you will find all new language rc files under "newrc" subdir, along with
- the string text files for translators to translate. These new rc files have all changes copied from your
- modified mplayerc.rc file and is ready to compile, except use english version strings.
- After recieved translated text files, use another script to merge back to rc files.
+ After running this script, you will find all new language rc files under "newrc" subdir.
+ These new rc files have all changes copied from your modified mplayerc.rc file and is ready to compile,
+ except use english version strings. Use rcstrings.pl to extract all strings for translators,
+ After recieved translated text files, use patch.pl script to merge back to rc files.
USAGE
exit(0);
}
my($BaseDialogs, $BaseMenus, $BaseStrings, @BaseOutline) = ({}, {}, {}, ());
my($NewDialogs, $NewMenus, $NewStrings, @NewOutline) = ({}, {}, {}, ());
-my ($MenuDiffs, $DialogDiffs) = ({}, {});
+my($MenuDiffs, $DialogDiffs) = ({}, {});
+my($BaseDesignInfos, $NewDesignInfos) = ({}, {});
my @BaseFile = readFile($BaseFileName, 1);
my @NewFile = readFile($NewFileName, 1);
@@ -91,41 +90,40 @@ getDifference();
#Trace($MenuDiffs, "MenuDiffs");
#Trace($DialogDiffs, "DialogDiffs");
-my @FileLists = <*.rc>;
+my @FileLists = ();
-#put all generted files under newrc sub dir.
+if(@ARGV) { @FileLists = @ARGV; }
+else { @FileLists = <*.rc>; }
+
+#put all generted files under "newrc" sub dir.
if(!-e "newrc"){
- mkdir(File::Spec->catdir(".", "newrc")) || die "Can not create sub directory newrc.";
+ mkdir(File::Spec->catdir(".", "newrc")) || die "Can not create \"newrc\" sub directory.";
}
-
foreach my $filename(@FileLists) {
print "Anaylse locale file: $filename...\n";
my @oldrcfile = readFile($filename, 1);
my($curDialogs, $curMenus, $curStrings, @curOutline) = ({},{},{}, ());
my @curVersionInfo = ();
- analyseData(\@oldrcfile, \@curOutline, $curDialogs, $curMenus, $curStrings, \@curVersionInfo);
-
+ my $curDesignInfos = {};
+ analyseData(\@oldrcfile, \@curOutline, $curDialogs, $curMenus, $curStrings, \@curVersionInfo, $curDesignInfos);
+
my $newrcfile = File::Spec->catfile(".", "newrc", $filename);
- my $txtfile = File::Spec->catfile(".", "newrc", $filename.$Extension);
my @newrc = ();
my @patches = ();
- writeData(\@newrc, \@patches, \@curOutline, $curDialogs, $curMenus, $curStrings, \@curVersionInfo);
+ writeData(\@newrc, \@patches, \@curOutline, $curDialogs, $curMenus, $curStrings, \@curVersionInfo, $curDesignInfos);
- print "Generate new locale file: $newrcfile...\n";
+ print "Generate new locale file: $newrcfile...\n\n";
writeFile($newrcfile, \@newrc, 2);
-
- print "Generate text file to translate: $txtfile...\n\n";
- writePatchFile($txtfile, \@patches, 1);
}
###################################################################################################
sub getDifference {
my @curVersionInfo = (); # no use for mplayerc.rc
- analyseData(\@BaseFile, \@BaseOutline,$BaseDialogs, $BaseMenus, $BaseStrings, \@curVersionInfo);
- analyseData(\@NewFile,\@NewOutline, $NewDialogs, $NewMenus, $NewStrings, \@curVersionInfo);
+ analyseData(\@BaseFile, \@BaseOutline,$BaseDialogs, $BaseMenus, $BaseStrings, \@curVersionInfo, $BaseDesignInfos);
+ analyseData(\@NewFile,\@NewOutline, $NewDialogs, $NewMenus, $NewStrings, \@curVersionInfo, $NewDesignInfos);
while (my ($key, $value) = each(%{$BaseMenus})) {
my $value1 = $NewMenus->{$key};
@@ -143,7 +141,9 @@ sub getDifference {
if($value1) {
my @changeset = ();
- lcs($value->{"__TEXT__"}, $value1->{"__TEXT__"}, \@changeset);
+ my @data0 = map{$_->[1]}@{$value->{"__DATA__"}};
+ my @data1 = map{$_->[1]}@{$value1->{"__DATA__"}};
+ lcs(\@data0, \@data1, \@changeset);
@changeset = @changeset[sort {$changeset[$a][0] <=> $changeset[$b][0];}(0..$#changeset)];
$DialogDiffs->{$key} = [@changeset];
}
@@ -154,9 +154,9 @@ sub getDifference {
#--------------------------------------------------------------------------------------------------
sub writeData {
my ($newrc, $patches) = (shift, shift);
- my ($curOutline, $curDialogs, $curMenus, $curStrings, $curVersionInfo) = @_;
+ my ($curOutline, $curDialogs, $curMenus, $curStrings, $curVersionInfo, $curDesignInfos) = @_;
- my ($curDialogName, $curMenuName);
+ my ($curDialogName, $curMenuName, $curDesignName);
my $headsection = 0;
my $tailsection = $#NewOutline;
@@ -188,6 +188,15 @@ sub writeData {
push(@{$newrc}, @_text); #in general use texts from new rc file
}
}
+ elsif($tag eq "DESIGNINFO") {
+ $curDesignName = $_->[1][0];
+ #if($curDesignInfos->{$curDesignName}) {
+ # push(@{$newrc}, @{$curDesignInfos->{$curDesignName}{"__TEXT__"}}); # use locale design info section
+ #}
+ #else {
+ push(@{$newrc}, @{$NewDesignInfos->{$curDesignName}{"__TEXT__"}}); # use new design info section
+ #}
+ }
elsif($tag eq "BLOCK") {
push(@{$newrc}, @{$_->[1]}); # use new file block section
}
@@ -244,8 +253,6 @@ sub writeStringTable {
my $localeStr = $refs->{$key};
if((!$localeStr) || (!$baseStr) || ($baseStr ne $value)) {
- #new string or changed string or not in locale files, use new one
- push(@{$patches},["STRINGTABLE",{$key=>$value}]);
}
else {
s/\Q$value\E/$localeStr/; #use locale string
@@ -259,59 +266,37 @@ sub writeDialogContent {
my @contents = ();
push(@contents, @{$NewDialogs->{$name}{"__TEXT__"}});
- my $contentLines = @contents;
- if(my $diffData = $DialogDiffs->{$name}) {
- # this dialog exists in old file
- my @changes = grep($_->[0] != $_->[1],@$diffData); #anything changed for this dialog?
- my $samelines = @$diffData;
-
- if((!@changes) && ($samelines == $contentLines)) { #no change then just use old data
- @contents = ();
- push(@contents, @{$refs->{$name}{"__TEXT__"}});
- }
- else { #change in this dialog
- my $curlines = $refs->{$name}{"__LINES__"};
- my $oldlines = $BaseDialogs->{$name}{"__LINES__"};
-
- if($oldlines == $curlines) {
- # if locale rc files have the same line numbers with the original main mplayerc.rc
- # TODO: need some other checks, though errors will be easier to spot.
- my @checkIdx=(1..$contentLines);
-
- my $idx = 0;
- foreach (@$diffData) {
- $contents[$_->[0]] = $refs->{$name}{"__TEXT__"}[$_->[1]]; #use those values from locale file
- $checkIdx[$_->[0]] = 0;
- }
+ my @newdatas = map{$_->[1]}@{$NewDialogs->{$name}{"__DATA__"}};
+ my @newidxs = map{$_->[0]}@{$NewDialogs->{$name}{"__DATA__"}};
+ my $newdataLines = @newdatas;
- @checkIdx=grep($_>0, @checkIdx); #the rest from new fc file, also put in patches
- my @data = grep{
- my $i=0;
- foreach $idx(@checkIdx) {
- if($_->[0]==$idx){
- $i = 1;
- last;
- }
- }
- $i;
- }@{$NewDialogs->{$name}{"__DATA__"}};
+ my @baseidxs = map{$_->[0]}@{$BaseDialogs->{$name}{"__DATA__"}};
+ my $basedataLines = @baseidxs;
- if(@data) {
- push(@{$patches}, ["DIALOG", {$name => [@data], "__LINES__" => $contentLines}]);
- }
- }
- else {
- # if locale rc files have different line numbers with original main mplayerc.rc,
- # don't try to use locale values, just use english version and to patch file
- push(@{$patches}, ["DIALOG",{$name =>$NewDialogs->{$name}{"__DATA__"}, "__LINES__" => $contentLines}]);
+ my @refdatas = map{$_->[1]}@{$refs->{$name}{"__DATA__"}};
+ my $refdataLines = @refdatas;
+
+ if($newdataLines && $basedataLines && $refdataLines) {
+ my $diffData = $DialogDiffs->{$name};
+
+ foreach(@$diffData) {
+ my $linenum = $newidxs[$_->[0]];
+
+ my $str = $newdatas[$_->[0]];
+ my $localstr = $refdatas[$_->[1]];
+
+ if($localstr) {
+ $contents[$linenum-1] =~ s/\Q$str\E/$localstr/;
}
}
}
- else { #new dialog, use english version
- push(@{$patches}, ["DIALOG",{$name =>$NewDialogs->{$name}{"__DATA__"}, "__LINES__" => $contentLines}]); #new dialog
- }
+ my $localfont = $refs->{$name}{"__FONT__"}[1];
+ if($localfont) {
+ $contents[$NewDialogs->{$name}{"__FONT__"}[0]-1] = $refs->{$name}{"__TEXT__"}[$refs->{$name}{"__FONT__"}[0]-1];
+ }
+
push(@{$output}, @contents);
}
@@ -339,27 +324,8 @@ sub writeMenuContent {
$contents[$_->[0]] = $refs->{$name}{"__TEXT__"}[$_->[1]]; #first use those values from locale file
$checkIdx[$_->[0]] = 0;
}
-
- @checkIdx=grep($_>0, @checkIdx);
- my @data = grep{
- my $i=0;
- foreach my $idx(@checkIdx) {
- if($_->[0]==$idx){
- $i = 1;
- last;
- }
- }
- $i;
- }@{$NewMenus->{$name}{"__DATA__"}};
-
- if(@data) {
- push(@{$patches}, ["MENU", {$name => [@data], "__LINES__" => $contentLines }]);
- }
}
}
- else {
- push(@{$patches}, ["MENU", {$name => $NewMenus->{$name}{"__DATA__"}, "__LINES__" => $contentLines }]); #new menu
- }
push(@{$output}, @contents);
}
@@ -380,52 +346,4 @@ sub writeVersionInfo{
push(@{$input}, "");
}
-#--------------------------------------------------------------------------------------------------
-sub writePatchFile {
- my ($output, $data, $withBOM) = @_;
-
- my @localData = ();
- foreach (@$data) {
- if($_->[0] eq "DIALOG") {
- my $lines = $_->[1]{"__LINES__"};
- while (my($key, $value)=each(%{$_->[1]})) {
- if($key eq "__LINES__") {
- next;
- }
- else {
- push(@localData, "BEGIN DIALOGEX ".$key." LINES $lines");
- foreach my $pair(@{$value}){
- push(@localData, "$pair->[0]\t\t$pair->[1]");
- }
- }
- }
- push(@localData, "END");
- push(@localData, "");
- }
- elsif($_->[0] eq "STRINGTABLE") {
- my($key, $value)=each(%{$_->[1]});
- push(@localData, "STRING $key\t\t$value");
- push(@localData, "");
- }
- elsif($_->[0] eq "MENU") {
- my $lines = $_->[1]{"__LINES__"};
- while (my($key, $value)=each(%{$_->[1]})) {
- if($key eq "__LINES__") {
- next;
- }
- else {
- push(@localData, "BEGIN MENU ".$key. " LINES $lines");
- foreach my $pair(@{$value}){
- push(@localData, "$pair->[0]\t\t$pair->[1]");
- }
- }
- }
- push(@localData, "END");
- push(@localData, "");
- }
- }
-
- writeFile($output, \@localData, $withBOM);
-}
-
###################################################################################################