author | Maciej Seroka <maciejs@symbian.org> |
Wed, 06 Oct 2010 15:50:01 +0100 | |
changeset 1286 | 7ad2f93c7666 |
parent 108 | d33d43677cdf |
permissions | -rw-r--r-- |
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 | 2 |
# Copyright (c) 2009 Symbian Foundation Ltd |
3 |
# This component and the accompanying materials are made available |
|
4 |
# under the terms of the License "Eclipse Public License v1.0" |
|
5 |
# which accompanies this distribution, and is available |
|
6 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
# |
|
8 |
# Initial Contributors: |
|
9 |
# Symbian Foundation Ltd - initial contribution. |
|
10 |
# |
|
11 |
# Contributors: |
|
12 |
# |
|
13 |
# Description: |
|
14 |
# Compares two files |
|
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 | 24 |
my $file1 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n"; |
25 |
my $file2 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n"; |
|
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 | 43 |
if (!defined $mode) { |
44 |
if (@difference > 0) { |
|
45 |
foreach (@difference){ |
|
46 |
print $_; |
|
47 |
} |
|
48 |
} else { |
|
49 |
print "* Files are identical\n"; |
|
50 |
} |
|
51 |
} elsif ($mode eq "-I") { |
|
52 |
if (@intersection > 0) { |
|
53 |
foreach (@intersection){ |
|
54 |
print $_; |
|
55 |
} |
|
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 | 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 |
} |