File Coverage

File:check-dictionary.pl
Coverage:87.7%

linestmtbrancondsubtimecode
1#!/usr/bin/env perl
2
3
4
4
4
5069
5
123
use Cwd 'realpath';
4
4
4
4
7
3
40
use File::Spec;
5
4
4
4
590
4
72
use CheckSpelling::Util;
6
4
4
4
850
6
3035
use CheckSpelling::CheckDictionary;
7
8
4
4
4
4
132930
1062
28
10
open WARNINGS, ">>:encoding(UTF-8)", CheckSpelling::Util::get_file_from_env('early_warnings', '/dev/stderr');
9
4
1958
$ARGV[0] =~ /^(.*)/;
10
4
8
my $file = $1;
11
4
58
open FILE, "<:encoding(UTF-8)", $file;
12
4
85
$/ = undef;
13
4
125
my $content = <FILE>;
14
4
62
close FILE;
15
4
176
open FILE, ">:encoding(UTF-8)", $file;
16
17
4
385
$file = File::Spec->abs2rel(realpath($file));
18
19
4
18
$ENV{comment_char} = '$^' unless $ENV{comment_char} =~ /\S/;
20
21
4
7
my $first_end = undef;
22
4
4
my $messy = 0;
23
4
6
$. = 0;
24
25
4
3
my $remainder;
26
4
18
if ($content !~ /(?:\r\n|\n|\r|\x0b|\f|\x85|\x{2028}|\x{2029})$/) {
27
0
0
    $remainder = $1 if $content =~ /([^\r\n\x0b\f\x85\x{2028}\x{2029}]+)$/;
28}
29
4
16
while ($content =~ s/([^\r\n\x0b\f\x85\x{2028}\x{2029}]*)(\r\n|\n|\r|\x0b|\f|\x85|\x{2028}|\x{2029})//m) {
30
16
15
    ++$.;
31
16
17
    my ($line, $end) = ($1, $2);
32
16
17
    unless (defined $first_end) {
33
4
4
        $first_end = $end;
34    } elsif ($end ne $first_end) {
35        print WARNINGS "$file:$.:$-[0] ... $+[0], Warning - Entry has inconsistent line endings. (unexpected-line-ending)\n";
36    }
37
16
22
    my ($line, $warning) = CheckSpelling::CheckDictionary::process_line($file, $line);
38
16
21
    if ($warning ne '') {
39
4
19
        print WARNINGS $warning;
40    } elsif ($line ne '') {
41
10
17
        print FILE "$line\n";
42    }
43}
44
4
4
if ($remainder ne '') {
45
0
0
    $remainder = CheckSpelling::CheckDictionary::process_line($file, $remainder);
46
0
0
    print FILE $remainder;
47}
48
4
0
close WARNINGS;