1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
#/bin/perl
#
# $Id$
#
# (C) 2006-2010 see AUTHORS
#
# This file is part of mplayerc.
#
# Mplayerc is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Mplayerc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Common function for rcfile.pl & patch.pl
#
# To use this program, you need a perl with PerlIO package installed.
#
use strict;
use PerlIO::encoding;
use Data::Dumper;
use vars qw(@InTags @TextTags $AdjustedDir);
@InTags = qw(DIALOGEX MENU STRINGTABLE VERSIONINFO DLGINIT DESIGNINFO TOOLBAR);
@TextTags = qw(BITMAP AVI ICON);
$AdjustedDir = q(..\\\\);
1;
###################################################################################################
sub analyseData {
my ($input, $outline) = (shift, shift);
my ($dialogs, $menus, $strings, $versionInfo) = @_;
my @inputs=();
push(@inputs, @{$input});
my $bInBlock=0;
my ($stack, $tagidx, $curline) = (0,0, "");
my @blocks=();
my @text=();
foreach (@inputs) {
chop;chop;
$curline=$_;
if(!$bInBlock) {
foreach my $tag(@InTags) {
if($curline=~/\b$tag\b/) {
$bInBlock=1;
last;
}
$tagidx++;
}
}
if($bInBlock) {
push(@blocks, $_);
if(@text) {
push(@{$outline}, ["__TEXT__",[@text]]);
@text=();
}
if(/\bBEGIN\b/) { $stack++; }
elsif(/\bEND\b/) {
$stack--;
if($stack==0) {
if($tagidx == 0) {
my $dlgname = readDialog($dialogs, \@blocks);
push(@{$outline}, ["DIALOG", [$dlgname, ""]]);
}
elsif($tagidx == 1) {
my $menuname = readMenu($menus, \@blocks);
push(@{$outline}, ["MENU", [$menuname, ""]]);
}
elsif($tagidx == 2) {
readStringTable($strings, \@blocks);
push(@{$outline}, ["STRINGTABLE", [@blocks]]);
}
elsif($tagidx ==3)
{
push(@{$outline},["VERSIONINFO",[@blocks]]);
push(@$versionInfo, @blocks);
}
elsif($tagidx < @InTags){
push(@{$outline},["BLOCK",[@blocks]]);
}
$tagidx=0;
@blocks = ();
$bInBlock = 0;
}
}
}
else {
push(@text, $curline);
$tagidx=0;
}
}
if(@text) { #flush last texts to outline
push(@{$outline}, ["__TEXT__",[@text]]);
@text=();
}
}
#--------------------------------------------------------------------------------------------------
sub readDialog {
my ($dialogs, $input) = @_;
my $dlgname;
my $linenum = 0;
my @data=();
foreach(@$input){
$linenum++;
if(/(ID\S+)\s+DIALOGEX\b/) {
$dlgname = $1;
next;
}
next if /^STYLE\b/;
next if /^BEGIN\b/;
next if /^END\b/;
my $line = skipNonTranslatedStr($_);
if ($line=~/("[^"](?:[^"]|"")*")/) {
push(@data, [$linenum, $1]);
}
}
$dialogs->{$dlgname}->{"__TEXT__"}=[@$input];
$dialogs->{$dlgname}->{"__DATA__"}=[@data];
$dialogs->{$dlgname}->{"__LINES__"} = $linenum;
$dlgname;
}
#--------------------------------------------------------------------------------------------------
sub readMenu {
my ($menus, $input) = @_;
my $menuname;
my $linenum = 0;
my @data=();
foreach(@$input){
$linenum++;
next if /\bBEGIN\b/;
next if /\bEND\b/;
next if /\bSEPARATOR\b/;
if(/(ID\S+)\s+MENU\b/) {
$menuname = $1;
next;
}
if( /^\s+MENUITEM\s+(".+"),\s+(\S+)\s*$/) {
my($key, $value) = ($2, $1);
push(@data, [$linenum, $value]);
}
elsif(/\bPOPUP\b\s+(".*")/){
push(@data, [$linenum, $1]);
}
}
$menus->{$menuname}->{"__DATA__"} = [@data];
$menus->{$menuname}->{"__TEXT__"} = [@$input];
$menus->{$menuname}->{"__LINES__"} = $linenum;
$menuname;
}
#--------------------------------------------------------------------------------------------------
sub readStringTable {
my ($strings, $input) = @_;
my $savekey;
foreach(@{$input}){
if(/^\s+(ID\S+)\s+(".+")/){
my ($key, $value) = ($1, $2);
$strings->{$key} = $value;
$savekey=undef;
}
elsif (/^\s+(ID\S+)/) {
$savekey = $1;
$strings->{$savekey} = "";
}
else {
if($savekey) {
s/^\s*//;
$strings->{$savekey}=$_;
$savekey=undef;
}
}
}
}
#--------------------------------------------------------------------------------------------------
sub skipNonTranslatedStr {
my $line = shift;
$line =~ s/"
(?:
Static|Button|msctls_updown32|SysListView32|msctls_trackbar32 #
|msctls_progress32|SysTreeView32|SysTabControl32|SysAnimate32|SysLink #skip built-in control names
|MS\sShell\sDlg|MS\sSans\sSerif|MS\sUI\sGothic #skip dialog font, but maybe should not because 3 asian languages need change this
|\\000|\.\.\.|(LANGUAGE.+)?\\r\\n|\+\/- #skip \r\n \000 ... etc
|<a>http.+<\/a>|http:\/\/ #skip http links
|Media\sPlayer\sClassic\s-?\sHome\sCinema|mpc-hc|MPC-HC\sTeam #skip app names
|Comments|CompanyName|FileDescription|FileVersion|InternalName|VarFileInfo|StringFileInfo|Translation
|LegalCopyright|OriginalFilename|ProductName|ProductVersion #skip versioninfo for locale rc not in mplayerc.rc
|[-&\/\d\s\.:,%]+(Hz)? #skip any thing like 6.4.0.0, 100%, 23.976Hz
)
"//gx;
$line;
}
#--------------------------------------------------------------------------------------------------
sub Trace {
my ($var, $name) = (shift, shift);
#$Data::Dumper::Indent = 0;
print ">>>>>>>>>>>>>>>>>>>>>>>>> $name >>>>>>>>>>>>>>>>>>>>>>>\n";
print Dumper($var);
print "<<<<<<<<<<<<<<<<<<<<<<<<< $name <<<<<<<<<<<<<<<<<<<<<<<\n\n";
}
#--------------------------------------------------------------------------------------------------
sub readFile {
my ($filename, $withBOM) = @_;
open(INPUT, "<$filename") || die "Cannot open $filename to read";
if($withBOM) {
binmode(INPUT, ":encoding(UTF16-LE)");
}
my @lines = <INPUT>;
close(INPUT);
@lines;
}
#--------------------------------------------------------------------------------------------------
sub writeFile {
my ($filename, $data, $withBOM) = @_;
open(OUTPUT, ">$filename")|| die "Cannot open $filename to write";
if($withBOM==1) {
binmode(OUTPUT);
print OUTPUT chr(0xff); print OUTPUT chr(0xfe); #write unicode bom
binmode(OUTPUT, ":raw:encoding(UTF16-LE)");
}
elsif($withBOM==2) {
binmode(OUTPUT, ":raw:encoding(UTF16-LE)");
}
foreach (@$data) {
print OUTPUT $_, "\r\n";
}
close(OUTPUT);
}
#--------------------------------------------------------------------------------------------------
#
# calculate the largest common set for array1 & array2
# TODO: too slow, should use something fast later.
sub lcs {
my($a1, $a2, $changes) = @_;
my $idx=0;
my $cols = @$a1;
my $rows = @$a2;
if (($rows==0) or ($cols==0)) { return;}
#optimize the equal test, convert string compare to integer equal test
my @leftIdx = ();
my @rightIdx = ();
my %stringIdx = ();
my $idx = 0;
my $key = 0;
foreach(@{$a1}) {
if(not exists $stringIdx{$_}) {
$stringIdx{$_} = $key++;
}
$leftIdx[$idx++] = $stringIdx{$_};
}
$idx=0;
foreach(@{$a2}) {
if(not exists $stringIdx{$_}) {
$stringIdx{$_} = $key++;
}
$rightIdx[$idx++] = $stringIdx{$_};
}
#Trace(\%stringIdx, "string index");
my ($r, $c, $i);
my $align=[[0,0],[0,0]];
for($r=0;$r<=$rows;$r++) {
for($c=0;$c<=$cols;$c++) {
$align->[$r][$c]=0;
}
}
for($r=1; $r<=$rows; $r++) {
for($c=1; $c<=$cols; $c++) {
if( $leftIdx[$c-1] == $rightIdx[$r-1]) {
$align->[$r][$c] = $align->[$r-1][$c-1] + 1;
}
else {
$align->[$r][$c] = ($align->[$r-1][$c] >= $align->[$r][$c-1])? $align->[$r-1][$c] : $align->[$r][$c-1];
}
}
}
$idx=0;
for($r=$rows, $c=$cols, $i=$align->[$r][$c];
$i>0 && $r>0 && $c>0;
$i=$align->[$r][$c])
{
if($align->[$r-1][$c] == $i) {
$r--;
}
elsif ($align->[$r][$c-1] == $i) {
$c--;
}
elsif ($align->[$r-1][$c-1] == $i-1) {
$r--;$c--;
$changes->[$idx++] = [$r,$c];
}
}
}
###################################################################################################
|