summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndras Timar <timar@fsf.hu>2011-03-07 14:03:19 +0100
committerAndras Timar <timar@fsf.hu>2011-03-07 14:03:19 +0100
commitd074b3afe9ebef27a5fa7bc73386848fcc7fd2da (patch)
treef88ba98927047192df4e5fe4cbe2d38b6b60d29b
compare.pl - compares 2 SDF files
-rwxr-xr-xcompare.pl131
1 files changed, 131 insertions, 0 deletions
diff --git a/compare.pl b/compare.pl
new file mode 100755
index 0000000..e0d654b
--- /dev/null
+++ b/compare.pl
@@ -0,0 +1,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;
+