| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::MultipleDiff; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22579
|
use 5.006; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
48
|
|
|
4
|
1
|
|
|
1
|
|
12
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
52
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings FATAL => 'all'; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
90
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
9
|
|
|
|
|
|
|
our @EXPORT = qw(multiple_file_diff); |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
6
|
use Carp ; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
88
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
1180
|
use Algorithm::Diff "sdiff"; |
|
|
1
|
|
|
|
|
6251
|
|
|
|
1
|
|
|
|
|
87
|
|
|
15
|
1
|
|
|
1
|
|
1383
|
use Tie::File ; |
|
|
1
|
|
|
|
|
23490
|
|
|
|
1
|
|
|
|
|
38
|
|
|
16
|
1
|
|
|
1
|
|
3265
|
use Term::ANSIColor; |
|
|
1
|
|
|
|
|
9388
|
|
|
|
1
|
|
|
|
|
97
|
|
|
17
|
1
|
|
|
1
|
|
11
|
use Cwd; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1192
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
##---------------------------------------------------------------------------## |
|
20
|
|
|
|
|
|
|
## Compares 2 files and finds out amount of differences between them ## |
|
21
|
|
|
|
|
|
|
##---------------------------------------------------------------------------## |
|
22
|
|
|
|
|
|
|
sub _CompareFiles |
|
23
|
|
|
|
|
|
|
{ |
|
24
|
0
|
|
|
0
|
|
|
my ($file_A, $file_B) = @_ ; |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
tie my @A, 'Tie::File', "$file_A" or die "Can't tie $file_A: $!"; |
|
27
|
0
|
0
|
|
|
|
|
tie my @B, 'Tie::File', "$file_B" or die "Can't tie $file_B: $!"; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# printf "CompareFiles: %-12s %-12s : %3d %3d\n", $file_A, $file_B, ($#A + 1), ($#B + 1) ; |
|
30
|
0
|
|
|
|
|
|
my @sdiffs = sdiff( \@A, \@B ); |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $diff_counter = 0; |
|
33
|
0
|
|
|
|
|
|
my $aref ; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
for $aref (@sdiffs) |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
0
|
0
|
|
|
|
|
if ($aref->[0] ne 'u') |
|
38
|
|
|
|
|
|
|
{ |
|
39
|
|
|
|
|
|
|
# printf "%-2s | %-40s | %-40s | %3d\n", $aref->[0], $aref->[1], $aref->[2], $diff_counter ; |
|
40
|
0
|
|
|
|
|
|
$diff_counter ++ ; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
0
|
|
|
|
|
|
untie @A; |
|
44
|
0
|
|
|
|
|
|
untie @B; |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return $diff_counter ; |
|
47
|
|
|
|
|
|
|
} # end of "sub _CompareFiles" |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
##---------------------------------------------------------------------------## |
|
51
|
|
|
|
|
|
|
sub multiple_file_diff |
|
52
|
|
|
|
|
|
|
{ |
|
53
|
0
|
|
|
0
|
1
|
|
my ($directory, $file_pattern, $colour, $digits) = @_; |
|
54
|
0
|
|
|
|
|
|
my $File_A; |
|
55
|
|
|
|
|
|
|
my $File_B; |
|
56
|
0
|
|
|
|
|
|
my $file ; |
|
57
|
0
|
|
|
|
|
|
my %file ; |
|
58
|
0
|
|
|
|
|
|
my $count ; |
|
59
|
0
|
|
|
|
|
|
my $title ; |
|
60
|
0
|
|
|
|
|
|
my $title_length ; |
|
61
|
0
|
|
|
|
|
|
my $field ; |
|
62
|
0
|
|
|
|
|
|
my $header ; |
|
63
|
0
|
|
|
|
|
|
my $name_length ; |
|
64
|
0
|
|
|
|
|
|
my $max_length =0; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $bold_red = qq() ; |
|
67
|
0
|
|
|
|
|
|
my $blue = qq() ; |
|
68
|
0
|
|
|
|
|
|
my $bold_blue = qq() ; |
|
69
|
0
|
|
|
|
|
|
my $bold_green = qq() ; |
|
70
|
0
|
|
|
|
|
|
my $color_over = "" ; |
|
71
|
0
|
|
|
|
|
|
my $bold_color_over = "" ; |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
0
|
0
|
|
|
|
unless ((defined $file_pattern) && $file_pattern) { $file_pattern = '.'; } |
|
|
0
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
0
|
0
|
|
|
|
unless ((defined $colour) && $colour) { $colour = 'b'; } |
|
|
0
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
if ($colour !~ /^[bc]$/) { croak "ERROR: colour parameter must be either 'c' or 'b' or empty"; } |
|
|
0
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if ($colour eq 'b') { $colour = ''; } |
|
|
0
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
0
|
0
|
|
|
|
unless ((defined $digits) && $digits) { $digits = 2; } |
|
|
0
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $start_dir = cwd; |
|
82
|
0
|
|
|
|
|
|
chdir $directory ; |
|
83
|
0
|
0
|
|
|
|
|
opendir (my $dh, '.') || croak "ERROR: can't opendir $directory: $!"; |
|
84
|
0
|
0
|
|
|
|
|
my @files = grep { /$file_pattern/ && -f "./$_" } readdir($dh); |
|
|
0
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
## foreach $file (<*>) { $file{ $file } = 0 ; } |
|
86
|
0
|
|
|
|
|
|
closedir $dh; |
|
87
|
0
|
|
|
|
|
|
for (@files) |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
0
|
|
|
|
|
|
$file{$_} = 0; |
|
90
|
0
|
|
|
|
|
|
$name_length = length ; |
|
91
|
0
|
0
|
|
|
|
|
if ($name_length > $max_length) { $max_length = $name_length; } |
|
|
0
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
95
|
0
|
|
|
|
|
|
my %count ; # HoH |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
foreach $File_A (sort keys %file) |
|
98
|
|
|
|
|
|
|
{ |
|
99
|
0
|
|
|
|
|
|
foreach $File_B (sort keys %file) |
|
100
|
|
|
|
|
|
|
{ |
|
101
|
0
|
0
|
|
|
|
|
if ($File_B ge $File_A) |
|
102
|
|
|
|
|
|
|
{ |
|
103
|
0
|
|
|
|
|
|
$count{$File_A}{$File_B} = &_CompareFiles ($File_A, $File_B) ; |
|
104
|
0
|
0
|
0
|
|
|
|
if (($count{$File_A}{$File_B} > 9) && ($digits <= 2)) { $digits = 3; } |
|
|
0
|
|
|
|
|
|
|
|
105
|
0
|
0
|
0
|
|
|
|
if (($count{$File_A}{$File_B} > 99) && ($digits <= 3)) { $digits = 4; } |
|
|
0
|
|
|
|
|
|
|
|
106
|
0
|
0
|
0
|
|
|
|
if (($count{$File_A}{$File_B} > 999) && ($digits <= 4)) { $digits = 5; } |
|
|
0
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my %HoA ; |
|
113
|
0
|
|
|
|
|
|
foreach (sort keys %file) { $HoA{ $_ } = [ split (//) ] ; } |
|
|
0
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $cnt = 0; |
|
116
|
0
|
|
|
|
|
|
while ($cnt < $max_length) |
|
117
|
|
|
|
|
|
|
{ |
|
118
|
0
|
|
|
|
|
|
$title .= " " x $max_length . " |" ; |
|
119
|
0
|
|
|
|
|
|
foreach (sort keys %file) |
|
120
|
|
|
|
|
|
|
{ |
|
121
|
0
|
0
|
|
|
|
|
if ( exists $HoA{ $_ }[$cnt] ) { $title .= sprintf " %${digits}s ", $HoA{ $_ }[$cnt] ; } |
|
|
0
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
else { $title .= sprintf " %${digits}s ", " " ; } |
|
123
|
|
|
|
|
|
|
} |
|
124
|
0
|
0
|
|
|
|
|
unless ($cnt) { $title_length = length $title ; } |
|
|
0
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$title .= "\n" ; |
|
126
|
0
|
|
|
|
|
|
$cnt ++; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
$header = sprintf "%s\n", "-" x $title_length ; |
|
130
|
0
|
|
|
|
|
|
$header .= sprintf "%s", $title ; |
|
131
|
0
|
|
|
|
|
|
$header .= sprintf "%s", "-" x $title_length ; |
|
132
|
0
|
0
|
|
|
|
|
if ($colour) { print colored ['bold blue'], "$header\n" ; } |
|
|
0
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
else { print "$header\n" ; } |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
chdir $start_dir; |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
#----------------------------------------------------------------------------------- |
|
138
|
0
|
|
|
|
|
|
foreach $File_A (sort keys %file) |
|
139
|
|
|
|
|
|
|
{ |
|
140
|
0
|
|
|
|
|
|
$field = sprintf "%-${max_length}s | ", $File_A ; |
|
141
|
0
|
0
|
|
|
|
|
if ($colour) { print colored ['bold blue'], $field ; } |
|
|
0
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
else { print $field ; } |
|
143
|
0
|
|
|
|
|
|
foreach $File_B (sort keys %file) |
|
144
|
|
|
|
|
|
|
{ |
|
145
|
0
|
0
|
|
|
|
|
if ($File_B ge $File_A) |
|
146
|
|
|
|
|
|
|
{ |
|
147
|
0
|
|
|
|
|
|
$count = $count{$File_A}{$File_B} ; |
|
148
|
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$field = sprintf "%${digits}d ", $count ; |
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
if ($count) |
|
152
|
|
|
|
|
|
|
{ |
|
153
|
0
|
0
|
|
|
|
|
if ($colour) { print colored ['bold red'], $field; } |
|
|
0
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
else { print $field; } |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
else |
|
157
|
|
|
|
|
|
|
{ |
|
158
|
0
|
0
|
|
|
|
|
if ($colour) { print colored ['bold green'], $field; } |
|
|
0
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
else { print $field ; } |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
else |
|
163
|
|
|
|
|
|
|
{ |
|
164
|
0
|
|
|
|
|
|
printf "%${digits}s ", "-" ; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
} |
|
167
|
0
|
|
|
|
|
|
print "\n"; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
} # end of "sub multiple_file_diff" |
|
170
|
|
|
|
|
|
|
1; |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
__END__ |