small tool to compare to files which are produced for swish-e -S prog
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 1 Jan 2005 18:35:23 +0000 (18:35 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 1 Jan 2005 18:35:23 +0000 (18:35 +0000)
git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@621 13eb9ef6-21d5-0310-b721-a9d68796d827

tools/swishdiff.pl [new file with mode: 0755]

diff --git a/tools/swishdiff.pl b/tools/swishdiff.pl
new file mode 100755 (executable)
index 0000000..438eaca
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/perl -w
+
+use strict;
+use XML::Simple;
+use Data::Diff;
+use Data::Dumper;
+
+die "usage: $0 swish-prog-input-1 swish-prog-input-2" if ($#ARGV < 1);
+
+my ($file1, $file2) = @ARGV;
+
+my ($in1, $in2);
+
+open($in1, $file1) || die "$file1: $!";
+open($in2, $file2) || die "$file2: $!";
+
+sub read_record {
+       my $fh = shift || die;
+
+       my $header = 1;
+
+       my ($path, $size);
+
+       while(<$fh>) {
+               chomp;
+               $path = $1 if (/^Path-Name:\s*(.+)$/i);
+               $size = $1 if (/^Content-Length:\s*(.+)$/);
+
+               if (/^$/) {
+                       $header = 0;
+               }
+
+               next if ($header);
+
+               print STDERR "$path  [$size]\n";
+
+               my $xml;
+               my $s = read *{$fh}, $xml, $size;
+               warn "read differs from decleared size! $s != $size" if ($s != $size);
+
+               $xml =~ s/md5=[a-zA-Z0-9]{32}//gs;
+               $xml =~ s/_userid=\d+//gs;
+
+               return $xml;
+       }
+}
+
+while(! eof($in1) && ! eof($in2)) {
+       my $a = read_record($in1);
+       my $b = read_record($in2);
+
+       next if ($a eq $b);
+
+       my $diff = Data::Diff->new( XMLin($a), XMLin($b) );
+
+       my $raw = $diff->raw;
+
+       print Dumper($raw->{diff}) if ($raw->{diff});
+}