| 1 | |||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Encode qw(encode is_utf8); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Unicode::UCD qw(charinfo); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | my $init; | |||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | my $source_file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | if ($source_file and $source_file eq '--init') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$source_file and $source_file eq "--init"
MC/DC0%0/2
$source_file and $source_file eq "--init"
$source_file
$source_file eq "--init"
Truth table33%1/3
A and B
A= $source_fileB= $source_file eq "--init"
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | $init = 1; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | $source_file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | open $fh, '<', $source_file or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | my $source = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | if ($init) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | $source =~ | |||||||||||||||||||||||||||||||||||||||||
| 21 | s{(/\* Begin auto-generated maps \*/).*(/\* End of auto-generated maps \*/)} | ||||||||||||||||||||||||||||||||||||||||||
| 22 | {$1\n\n$2}s | ||||||||||||||||||||||||||||||||||||||||||
| 23 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my $output = build_map(); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | $source =~ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | s{(/\* Begin auto-generated maps \*/).*(/\* End of auto-generated maps \*/)} | ||||||||||||||||||||||||||||||||||||||||||
| 27 | {$1\n\n$output$2}s | ||||||||||||||||||||||||||||||||||||||||||
| 28 | or die; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | unlink "$source_file.old"; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | rename $source_file, "$source_file.old" or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | open $fh, '>', $source_file or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | print $fh $source; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | sub build_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_map: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $map = {}; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | print STDERR "Loading property"; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | for (my $cp = 0x0; $cp <= 0x3FFFF; $cp++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 262144 | ▶ | print STDERR '.' unless $cp & 0xFFF; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 262144 | my $charprop = charinfo($cp); | |||||||||||||||||||||||||||||||||||||||||
| 44 | 262144 | ▶ | next unless $charprop and %$charprop; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$charprop and %$charprop
MC/DC50%1/2
$charprop and %$charprop
$charprop
%$charprop
Truth table66%2/3
A and B
A= $charpropB= %$charprop
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 167977 | my $category = $charprop->{category}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 167977 | ▶ | if ($category and $category eq 'Zs' and $cp != 0x20) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$category and $category eq "Zs" and $cp != 32
$category and $category eq "Zs"
MC/DC66%2/3
$category and $category eq "Zs" and $cp != 32
$category
$category eq "Zs"
$cp != 32
Truth table75%3/4
A and B and C
A= $categoryB= $category eq "Zs"C= $cp != 32
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 16 | ▶ | die sprintf 'Out of range: U+%02X', $cp | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | if $cp < 0x80; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 16 | add_map($map, 'space', $cp, "\x20"); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 167977 | my $decomposition = $charprop->{decomposition}; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 167977 | ▶ | if ($decomposition and $decomposition =~ s/<(?:wide|narrow)>\s*//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$decomposition and $decomposition =~ s/<(?:wide|narrow)>\s*//
MC/DC100%2/2
$decomposition and $decomposition =~ s/<(?:wide|narrow)>\s*//
$decomposition
$decomposition =~ s/<(?:wide|narrow)>\s*//
Truth table100%3/3
A and B
A= $decompositionB= $decomposition =~ s/<(?:wide|narrow)>\s*//
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 226 | ▶ | die sprintf 'Out of range: U+%02X', $cp | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | if $cp < 0x80; | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | add_map($map, 'widthdecomp', $cp, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 226 | pack('U*', map { hex "0x$_" } split(/\s+/, $decomposition))); | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | print STDERR "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | my $output = ''; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | foreach my $mapname (reverse sort keys %$map) { | |||||||||||||||||||||||||||||||||||||||||
| 67 | $output .= sprintf "static void *%s[%d] = {\n", $mapname, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 17 | scalar(@{$map->{$mapname}}); | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 17 | my $len = 3; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 17 | $output .= ' '; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 17 | ▶ | while (@{$map->{$mapname}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1088 | my $c = shift @{$map->{$mapname}}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 1088 | ▶ | $c ||= 'NULL'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$c ||= "NULL"
MC/DC100%1/1
$c ||= "NULL"
$c
Truth table100%2/2
A
A= $c
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 1088 | ▶ | if (75 < $len + length(" $c,")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 110 | $output .= "\n "; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 110 | $len = 3; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 1088 | $len += length(" $c,"); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1088 | $output .= " $c"; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 1088 | ▶ | $output .= ',' if @{$map->{$mapname}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 17 | $output .= "\n};\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | return $output; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 242 | ▶ | sub add_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_map: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 242 | my $map = shift; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 242 | my $mapname = shift() . '_map'; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 242 | my $cp = shift; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 242 | my $dest = shift; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 242 | my $uc = pack 'U', $cp; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 242 | my $str = encode('UTF-8', $uc); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 242 | my @str = map { ord $_ } split //, $str; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 242 | ▶ | for (my $i = 0; $i < scalar(@str) - 1; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 483 | my $c = $str[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 483 | my $newmapname = sprintf '%s_%02X', $mapname, $c; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 483 | ▶ | $map->{$mapname} ||= [(undef) x 64]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$map->{$mapname} ||= [(undef) x 64]
MC/DC100%1/1
$map->{$mapname} ||= [(undef) x 64]
$map->{$mapname}
Truth table100%2/2
A
A= $map->{$mapname}
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 483 | $map->{$mapname}->[$c & 0x3F] = $newmapname; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 483 | $mapname = $newmapname; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 242 | ▶ | $map->{$mapname} ||= [(undef) x 64]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$map->{$mapname} ||= [(undef) x 64]
MC/DC100%1/1
$map->{$mapname} ||= [(undef) x 64]
$map->{$mapname}
Truth table100%2/2
A
A= $map->{$mapname}
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 242 | $map->{$mapname}->[$str[-1] & 0x3F] = sprintf '"%s"', esc($dest); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 242 | ▶ | sub esc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
esc: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 242 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 242 | ▶ | $str = encode('UTF-8', $str) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | if is_utf8($str); | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 242 | $str =~ s{(.)}{sprintf '\\x%02X', ord $1}eg; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 242 | $str; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||