-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_string_params.pl
72 lines (63 loc) · 1.78 KB
/
check_string_params.pl
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
#!perl --
use strict;
use warnings;
use File::Find;
use Data::Dump qw(dump);
use XML::Simple qw(:strict);
binmode(\*STDOUT,':encoding(utf8)');
binmode(\*STDERR,':encoding(utf8)');
my %known_param = map{ ($_,1) } qw( %1$s %2$s %3$s %4$s %1$d );
my %data = map{ ($_,{ files=>[] }) } qw( strings.xml build_variant.xml );
find( sub{
my $info = $data{ $_ };
$info and push @{$info->{files}},$File::Find::name;
}, 'app/src' );
while( my($basename,$info) = each %data ){
my %res;
for my $file ( @{$info->{files}} ){
my $xml = XMLin( $file
,KeyAttr => { string => 'name'}
,ForceArray => 'string'
);
warn "\n";
my $string_map = $xml->{string};
# print dump( $xml );
while( my($k,$v) = each %$string_map ){
my $text = $v->{content};
my @params;
while( $text =~ /(\%[\d\$]*[sdfxc])/gi ){
my $param = $1;
push @params,$1;
if( not $known_param{ $param }){
print "$file $k : bad parameter $param\n";
}
}
my $params_sign = join(',',sort { $a cmp $b } @params);
my $files = $res{$k};
$files or $files = $res{$k}=[];
push @$files,[$file,$text,$params_sign];
}
}
my $file_count = 0 + @{$info->{files}};
while( my($id,$files) = each %res ){
if( $file_count != 0+@$files ){
print "NG: $basename: $id is not decrared in all files.\n";
for my $file ( sort { $a->[0] cmp $b->[0] } @$files ){
print " $file->[0] : $file->[1]\n";
}
}else{
my $error = 0;
for( my $i=1; $i < @$files;++$i ){
if( $files->[0][2] ne $files->[$i][2] ){
$error = 1;
}
}
if( $error ){
print "NG: $basename $id : parameter not same.\n";
for my $file ( sort { $a->[0] cmp $b->[0] } @$files ){
print " $file->[0] : ($file->[2]) $file->[1]\n";
}
}
}
}
}