summaryrefslogtreecommitdiff
path: root/compare.pl
blob: e0d654b418207289ed0b04c7d22463a5c350b45e (plain)
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
#!/usr/bin/perl -w

# This script compares two SDF files and prints the changed, added and deleted lines (ignores 'width')

use strict;

my $sdffile1 = $ARGV[0];
my $sdffile2 = $ARGV[1];

if (!$sdffile1) {die "Usage: $0 old-sdf new-sdf\n";}
if (!$sdffile2) {die "Usage: $0 old-sdf new-sdf\n";}



         #        (                          leftpart                                                     )        (         rightpart                                   )    
         #           prj      file     dummy     type      gid        lid        helpid   pform     width     lang      text     helptext  qhelptext  title    timestamp
my $sdf_regex  = "((([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t])*\t([^\t]*))\t([^\t]*)\t([^\t]*)\t(([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t)([^\t]*))";
my %compare_en = ();
my %compare_loc = ();

# Changed lines

print "\n\nCHANGED LINES\n\n";

open FILE1 , "< $sdffile1" or die "Can't open '$sdffile1'\n";
    
while(<FILE1>){
         if( /$sdf_regex/ ){
            my $leftpart       = defined $2 ? $2 : '';
            my $rightpart      = defined $13 ? $13 : '';
            my $lang           = defined $12 ? $12 : '';
            if ($lang eq 'en-US') {$compare_en{$leftpart} = $rightpart;}
            else                  {$compare_loc{$leftpart} = $rightpart;}
         }
}

close(FILE1);

open FILE2 , "< $sdffile2" or die "Can't open '$sdffile2'\n";

while(<FILE2>){
         if( /$sdf_regex/ ){
            my $leftpart       = defined $2 ? $2 : '';
            my $rightpart      = defined $13 ? $13 : '';
            my $lang           = defined $12 ? $12 : '';
            if ($lang eq 'en-US' && exists $compare_en{$leftpart}) {  
                chomp;
	              if ($compare_en{$leftpart} ne $rightpart) {print "Leftpart: $leftpart\nNEW: $rightpart\nOLD: $compare_en{$leftpart}\n\n";}
            }
            elsif (exists $compare_loc{$leftpart}) {  
                chomp;
	              if ($compare_loc{$leftpart} ne $rightpart) {print "Leftpart: $leftpart\nNEW: $rightpart\nOLD: $compare_loc{$leftpart}\n\n";}
            }
	 }
}

close(FILE2);

# Deleted lines
print "\n\nDELETED LINES\n\n";

%compare_en = ();
%compare_loc = ();


open FILE1 , "< $sdffile2" or die "Can't open '$sdffile2'\n";
    
while(<FILE1>){
         if( /$sdf_regex/ ){
            my $leftpart       = defined $2 ? $2 : '';
            my $rightpart      = defined $13 ? $13 : '';
            my $lang           = defined $12 ? $12 : '';
            if ($lang eq 'en-US') {$compare_en{$leftpart} = $rightpart;}
            else                  {$compare_loc{$leftpart} = $rightpart;}
         }
}

close(FILE1);

open FILE2 , "< $sdffile1" or die "Can't open '$sdffile1'\n";

while(<FILE2>){
         if( /$sdf_regex/ ){
            my $leftpart       = defined $2 ? $2 : '';
            my $rightpart      = defined $13 ? $13 : '';
            my $lang           = defined $12 ? $12 : '';
            chomp;
            if ($lang eq 'en-US') {print "$_\n" if !exists $compare_en{ $leftpart };}
            else                  {print "$_\n" if !exists $compare_loc{ $leftpart };}
         }
}

close(FILE2);

# New lines
print "\n\nNEW LINES\n\n";

%compare_en = ();
%compare_loc = ();

open FILE1 , "< $sdffile1" or die "Can't open '$sdffile1'\n";
    
while(<FILE1>){
         if( /$sdf_regex/ ){
            my $leftpart       = defined $2 ? $2 : '';
            my $rightpart      = defined $13 ? $13 : '';
            my $lang           = defined $12 ? $12 : '';
            if ($lang eq 'en-US') {$compare_en{$leftpart} = $rightpart;}
            else                  {$compare_loc{$leftpart} = $rightpart;}
         }
}

close(FILE1);

open FILE2 , "< $sdffile2" or die "Can't open '$sdffile2'\n";

while(<FILE2>){
         if( /$sdf_regex/ ){
            my $leftpart       = defined $2 ? $2 : '';
            my $rightpart      = defined $13 ? $13 : '';
            my $lang           = defined $12 ? $12 : '';
            chomp;
            if ($lang eq 'en-US') {print "$_\n" if !exists $compare_en{ $leftpart };}
            else                  {print "$_\n" if !exists $compare_loc{ $leftpart };}
         }
}

close(FILE2);

exit 0;