File Coverage

File:check-dictionary.pl
Coverage:87.9%

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