author | ThomasE@UK-ThomasE.symbian.int |
Fri, 01 May 2009 15:07:37 +0100 | |
changeset 81 | 5e724ff842b4 |
parent 64 | 3554074ceb34 |
child 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 |
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 | 10 |
my $file1 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n"; |
11 |
my $file2 = shift or die "Usage: $0 file1 file2 | optional -I[ntersection]\n"; |
|
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 | 29 |
if (!defined $mode) { |
30 |
if (@difference > 0) { |
|
31 |
foreach (@difference){ |
|
32 |
print $_; |
|
33 |
} |
|
34 |
} else { |
|
35 |
print "* Files are identical\n"; |
|
36 |
} |
|
37 |
} elsif ($mode eq "-I") { |
|
38 |
if (@intersection > 0) { |
|
39 |
foreach (@intersection){ |
|
40 |
print $_; |
|
41 |
} |
|
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 | 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 |
} |