File Coverage

File:check-dictionary.pl
Coverage:87.7%

linestmtbrancondsubtimecode
1#!/usr/bin/env perl
2
3
3
3
3
2795
4
63
use Cwd 'realpath';
4
3
3
3
6
0
24
use File::Spec;
5
3
3
3
259
3
44
use CheckSpelling::Util;
6
3
3
3
462
3
1774
use CheckSpelling::CheckDictionary;
7
8
3
3
3
3
71945
551
18
5
open WARNINGS, ">>:encoding(UTF-8)", CheckSpelling::Util::get_file_from_env('early_warnings', '/dev/stderr');
9
3
982
$ARGV[0] =~ /^(.*)/;
10
3
7
my $file = $1;
11
3
27
open FILE, "<:encoding(UTF-8)", $file;
12
3
47
$/ = undef;
13
3
45
my $content = <FILE>;
14
3
34
close FILE;
15
3
83
open FILE, ">:encoding(UTF-8)", $file;
16
17
3
216
$file = File::Spec->abs2rel(realpath($file));
18
19
3
9
$ENV{comment_char} = '$^' unless $ENV{comment_char} =~ /\S/;
20
21
3
2
my $first_end = undef;
22
3
2
my $messy = 0;
23
3
3
$. = 0;
24
25
3
3
my $remainder;
26
3
11
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
3
9
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
13
11
    ++$.;
31
13
14
    my ($line, $end) = ($1, $2);
32
13
14
    unless (defined $first_end) {
33
3
3
        $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
13
12
    my ($line, $warning) = CheckSpelling::CheckDictionary::process_line($file, $line);
38
13
12
    if ($warning ne '') {
39
3
11
        print WARNINGS $warning;
40    } elsif ($line ne '') {
41
8
16
        print FILE "$line\n";
42    }
43}
44
3
5
if ($remainder ne '') {
45
0
0
    $remainder = CheckSpelling::CheckDictionary::process_line($file, $remainder);
46
0
0
    print FILE $remainder;
47}
48
3
0
close WARNINGS;