-
Notifications
You must be signed in to change notification settings - Fork 4
/
translate.pl
executable file
·102 lines (81 loc) · 2.15 KB
/
translate.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
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
#!/usr/bin/perl
use strict;
use warnings;
use XML::Simple;
use File::Find;
my (@dir, @dir2);
print "Looking for missing files... \n";
find(\&Wanted, $ARGV[0]);
sub Wanted
{
# only operate on Perl modules
/\.xml$/ or return;
my $path = $File::Find::name;
$path =~ s/$ARGV[0]//;
push (@dir, $path);
}
find(\&Wanted2, $ARGV[1]);
sub Wanted2
{
# only operate on Perl modules
/\.xml$/ or return;
my $path = $File::Find::name;
$path =~ s/$ARGV[1]//;
push (@dir2, $path);
}
my %second = map {$_=>1} @dir2;
my @only_in_first = grep { !$second{$_} } @dir;
if ($#only_in_first >= 0) {
print (($#only_in_first+1)." files only in $ARGV[0]: \n");
foreach (@only_in_first) {
print "\t$_\n";
}
}
my %first = map {$_=>1} @dir;
my @only_in_second = grep { !$first{$_} } @dir2;
if ($#only_in_second >= 0) {
print (($#only_in_second+1)." files only in $ARGV[1]: \n");
foreach (@only_in_second) {
print "\t$_\n";
}
}
%first = map {$_=>1} @dir;
my @in_both = grep { $first{$_} } @dir2;
print "\nLooking for missing xml tags...\n";
sub extract_tags{
my $xml_src=shift;
my (@tags, %tags);
for my $key (keys %{$xml_src}){
$tags{$key}++;
if (ref($xml_src->{$key}) eq 'HASH'){
map {$_++;} @tags{extract_tags($xml_src->{$key})}
}
}
push @tags , keys %tags;
return @tags;
}
foreach (@in_both) {
my $xml_src=XMLin($ARGV[0]."/".$_);
my @tags_in_first = extract_tags($xml_src);
$xml_src=XMLin($ARGV[1]."/".$_);
my @tags_in_second = extract_tags($xml_src);
my %first = map {$_=>1} @tags_in_first;
my @only_in_second = grep { !$first{$_} } @tags_in_second;
my %second = map {$_=>1} @tags_in_second;
my @only_in_first = grep { !$second{$_} } @tags_in_first;
if (($#only_in_first >= 0) or ($#only_in_second >= 0)) {
print "File: $_:\n";
if ($#only_in_first >= 0) {
print ("\t".($#only_in_first+1)." tags only in $ARGV[0]: \n");
foreach (@only_in_first) {
print "\t\t$_\n";
}
}
if ($#only_in_second >= 0) {
print ("\t".($#only_in_second+1)." tags only in $ARGV[1]: \n");
foreach (@only_in_second) {
print "\t\t$_\n";
}
}
}
}