common/tools/difflist.pl
author SimonH <simonh@symbian.org>
Fri, 12 Mar 2010 14:16:11 +0000
changeset 924 a5ed0e6ca679
parent 108 d33d43677cdf
permissions -rw-r--r--
findphysicaldrive.pl - Fixed so it works with empty (freshly formatted) drives.
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
108
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
     2
# Copyright (c) 2009 Symbian Foundation Ltd
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
     3
# This component and the accompanying materials are made available
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
     4
# under the terms of the License "Eclipse Public License v1.0"
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
     5
# which accompanies this distribution, and is available
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
     7
#
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
     8
# Initial Contributors:
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
     9
# Symbian Foundation Ltd - initial contribution.
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
    10
# 
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
    11
# Contributors:
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
    12
#
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
    13
# Description:
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
    14
# Compares two files
d33d43677cdf Added license header
Simon Howkins <simonh@symbian.org>
parents: 64
diff changeset
    15
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    16
use strict;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    17
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    18
my $element;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    19
my @union = ();
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    20
my @intersection = ();
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    21
my @difference = ();
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    22
my %count = ();
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    23
64
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    24
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
    25
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
    26
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
    27
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
    28
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
    29
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    30
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
    31
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
    32
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    33
close FILE1;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    34
close FILE2;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    35
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    36
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
    37
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
    38
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
    39
    push @union, $element;
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    40
    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
    41
}
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    42
64
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    43
if (!defined $mode) {
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    44
	if (@difference > 0) {
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    45
		foreach (@difference){
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    46
			print $_;
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    47
		}
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    48
	} else {
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    49
		print "* Files are identical\n";
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    50
	}
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    51
} elsif ($mode eq "-I") {
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    52
	if (@intersection > 0) {
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    53
		foreach (@intersection){
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    54
			print $_;
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    55
		}
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    56
	}
39
9edae8fe1416 Add tools to create file tree deltas and integrate them into build f/w
ShabeR@UK-SHABER
parents:
diff changeset
    57
} else {
64
3554074ceb34 Add intersection option for difflist.pl
ShabeR@UK-SHABER
parents: 39
diff changeset
    58
	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
    59
}