common/tools/difflist.pl
author ThomasE@UK-ThomasE.symbian.int
Wed, 13 May 2009 17:39:47 +0100
changeset 96 d9f19d792d0c
parent 64 3554074ceb34
child 108 d33d43677cdf
permissions -rw-r--r--
Fixed "zip.cfg.xml.ftl.template" to use "oss" and not "epl" in the configuration name.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
     1
#! perl -w
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
     2
use strict;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
     3
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
     4
my $element;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
     5
my @union = ();
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
     6
my @intersection = ();
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
     7
my @difference = ();
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
     8
my %count = ();
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
     9
64
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    10
my $file1 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n";
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    11
my $file2 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n";
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    12
my $mode  = shift;
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    13
open FILE1, "<$file1" or die "ERROR: Can't read $file1";
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    14
open FILE2, "<$file2" or die "ERROR: Can't read $file2";
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    15
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    16
my @file1_content = <FILE1>;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    17
my @file2_content = <FILE2>;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    18
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    19
close FILE1;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    20
close FILE2;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    21
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    22
print "* Comparing $file1 and $file2\n";
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    23
foreach $element (@file1_content, @file2_content) { $count{$element}++ }
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    24
foreach $element (keys %count) {
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    25
    push @union, $element;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    26
    push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    27
}
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    28
64
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    29
if (!defined $mode) {
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    30
	if (@difference > 0) {
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    31
		foreach (@difference){
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    32
			print $_;
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    33
		}
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    34
	} else {
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    35
		print "* Files are identical\n";
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    36
	}
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    37
} elsif ($mode eq "-I") {
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    38
	if (@intersection > 0) {
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    39
		foreach (@intersection){
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    40
			print $_;
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    41
		}
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    42
	}
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    43
} else {
64
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    44
	print "Usage: $0 file1 file2 | optional -I[ntersection]\n";
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    45
}