| File: | /home/runner/work/check-spelling/check-spelling/check-dictionary.pl |
| Coverage: | 97.0% |
| line | stmt | bran | cond | sub | time | code |
|---|---|---|---|---|---|---|
| 1 | #!/usr/bin/env perl | |||||
| 2 | ||||||
| 3 | 2 2 2 | 2029 2 49 | use Cwd 'realpath'; | |||
| 4 | 2 2 2 | 3 2 17 | use File::Spec; | |||
| 5 | 2 2 2 | 238 2 33 | use CheckSpelling::Util; | |||
| 6 | 2 2 2 | 352 2 1234 | use CheckSpelling::CheckDictionary; | |||
| 7 | ||||||
| 8 | 2 2 2 2 | 40842 469 13 7 | open WARNINGS, ">>:encoding(UTF-8)", CheckSpelling::Util::get_file_from_env('early_warnings', '/dev/stderr'); | |||
| 9 | 2 | 812 | $ARGV[0] =~ /^(.*)/; | |||
| 10 | 2 | 2 | my $file = $1; | |||
| 11 | 2 | 24 | open FILE, "<:encoding(UTF-8)", $file; | |||
| 12 | 2 | 56 | $/ = undef; | |||
| 13 | 2 | 33 | my $content = <FILE>; | |||
| 14 | 2 | 24 | close FILE; | |||
| 15 | 2 | 79 | open FILE, ">:encoding(UTF-8)", $file; | |||
| 16 | ||||||
| 17 | 2 | 133 | $file = File::Spec->abs2rel(realpath($file)); | |||
| 18 | ||||||
| 19 | 2 | 2 | my $name = CheckSpelling::Util::get_file_from_env('file', $file); | |||
| 20 | ||||||
| 21 | 2 | 4 | $ENV{comment_char} = '$^' unless $ENV{comment_char} =~ /\S/; | |||
| 22 | ||||||
| 23 | 2 | 1 | my $first_end = undef; | |||
| 24 | 2 | 2 | my $messy = 0; | |||
| 25 | 2 | 2 | $. = 0; | |||
| 26 | ||||||
| 27 | 2 | 1 | my $remainder; | |||
| 28 | 2 | 5 | if ($content !~ /(?:\r\n|\n|\r|\x0b|\f|\x85|\x{2028}|\x{2029})$/) { | |||
| 29 | 1 | 4 | $remainder = $1 if $content =~ /([^\r\n\x0b\f\x85\x{2028}\x{2029}]+)$/; | |||
| 30 | } | |||||
| 31 | 2 | 6 | 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 | 10 | 7 | ++$.; | |||
| 33 | 10 | 10 | my ($line, $end) = ($1, $2); | |||
| 34 | 10 | 9 | unless (defined $first_end) { | |||
| 35 | 2 | 2 | $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 | 10 | 9 | my ($line, $warning) = CheckSpelling::CheckDictionary::process_line($name, $line); | |||
| 40 | 10 | 11 | if ($warning ne '') { | |||
| 41 | 2 | 7 | print WARNINGS $warning; | |||
| 42 | } elsif ($line ne '') { | |||||
| 43 | 6 | 10 | print FILE "$line\n"; | |||
| 44 | } | |||||
| 45 | } | |||||
| 46 | 2 | 2 | if ($remainder ne '') { | |||
| 47 | 1 | 1 | $remainder = CheckSpelling::CheckDictionary::process_line($name, $remainder); | |||
| 48 | 1 | 0 | print FILE $remainder; | |||
| 49 | } | |||||
| 50 | 2 | 0 | close WARNINGS; | |||