line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Canonicalizer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18799
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
39
|
|
6
|
1
|
|
|
1
|
|
832
|
use English; |
|
1
|
|
|
|
|
4031
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
our @EXPORT = qw(file_canonicalizer); |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
480
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
586
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub file_canonicalizer { |
16
|
0
|
|
|
0
|
1
|
|
my ( $inp_file # 1 |
17
|
|
|
|
|
|
|
, $out_file # 2 |
18
|
|
|
|
|
|
|
, $remove_comments_started_with_RE # 3 |
19
|
|
|
|
|
|
|
, $replace_adjacent_tabs_and_spaces_with_1_space # 4 |
20
|
|
|
|
|
|
|
, $replace_adjacent_slashes_with_single_slash # 5 |
21
|
|
|
|
|
|
|
, $remove_white_char_from_line_edges # 6 |
22
|
|
|
|
|
|
|
, $remove_empty_lines # 7 |
23
|
|
|
|
|
|
|
, $convert_to_lowercased # 8 |
24
|
|
|
|
|
|
|
, $remove_leading_zeroes # 9 |
25
|
|
|
|
|
|
|
, $sort_lines #10 |
26
|
|
|
|
|
|
|
, $aref_replacements #11 |
27
|
|
|
|
|
|
|
) = @_ ; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my %lines ; |
30
|
|
|
|
|
|
|
my $INP; |
31
|
0
|
|
|
|
|
|
my $OUT; |
32
|
0
|
|
|
|
|
|
my $i ; |
33
|
0
|
|
|
|
|
|
my $replaced_pattern; |
34
|
0
|
|
|
|
|
|
my $replacement; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
unless ($inp_file) { $inp_file = '&STDIN'; } |
|
0
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
open ($INP, "<$inp_file") || croak "Error: Can't open file \"$inp_file\" for read: $!"; |
38
|
0
|
0
|
|
|
|
|
unless ($out_file) { $out_file = '&STDOUT'; } |
|
0
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
open ($OUT, ">$out_file") || croak "Error: Can't open file \"$out_file\" for write: $!" ; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
while (<$INP>) |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
|
|
|
chomp; |
44
|
0
|
0
|
|
|
|
|
if ($remove_comments_started_with_RE) { s/$remove_comments_started_with_RE.+$//; } |
|
0
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if ($replace_adjacent_tabs_and_spaces_with_1_space) { s/[ \t]+/ /g; } |
|
0
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ($replace_adjacent_slashes_with_single_slash) { s#/+#/#g; } |
|
0
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if ($remove_empty_lines) { (/^\s*$/) && next; } |
|
0
|
0
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if ($remove_white_char_from_line_edges) { s/(^[ \t]*|[ \t]*$)//g; } |
|
0
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ($convert_to_lowercased) { $_ = lc; } |
|
0
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
if ($remove_leading_zeroes) { s/(\W)0+(\d)/$1$2/g; } |
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if (defined $aref_replacements) |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
|
$i = 0; |
55
|
0
|
|
|
|
|
|
REPLACEMENTS: while (1) |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
|
|
|
($replaced_pattern, $replacement) = (@{$aref_replacements})[$i++,$i++]; |
|
0
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
(defined $replacement) || last REPLACEMENTS; |
59
|
0
|
|
|
|
|
|
s/$replaced_pattern/$replacement/g; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if ($sort_lines) { $lines{$_} = undef; next; } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
64
|
0
|
|
0
|
|
|
|
print $OUT "$_\n" || croak "Error: Can't write to $out_file: $!"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if ($sort_lines) |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
|
|
|
for (sort keys %lines) |
70
|
0
|
|
0
|
|
|
|
{ print $OUT "$_\n" || croak "Error: Can't write to $out_file: $!"; } |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
close $OUT; |
74
|
0
|
|
|
|
|
|
close $INP; |
75
|
|
|
|
|
|
|
} # end of 'sub file_canonicalizer' |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |