script/sdif

filter: Statementstmt 65.8% 438 / 665 Branchbran 51.2% 168 / 328 Conditioncond 42.8% 90 / 210 MC/DCmcdc 26.5% 31 / 117 Subroutinesub 54.5% 36 / 66 Podpod n/a totaltotal 55.0% 763 / 1386 CC 125 SCAR 38.3
CC
125
Cov
58%
flush_buffer_3
272.0
print_column_23
79.3
flush_buffer
30.7
CRAP 46.1
↑ Summary blib/lib/App/cdif/Command.pm »
1 #!/usr/bin/env perl
2  
3 ##
4 ## sdif: sdiff clone
5 ##
6 ## Copyright (c) 1992- Kazumasa Utashiro
7 ##
8 ## Original version on Jul 24 1991
9 ##
10  
11 =pod
12  
13 =head1 NAME
14  
15 sdif - side-by-side diff viewer for ANSI terminal
16  
17 =head1 VERSION
18  
19 Version 4.49
20  
21 =head1 SYNOPSIS
22  
23 sdif file_1 file_2
24  
25 diff ... | sdif
26  
27 OPTIONS:
28  
29 -i, --ignore-case
30 -b, --ignore-space-change
31 -w, --ignore-all-space
32 -B, --ignore-blank-lines
33  
34 --[no]number, -n print line number
35 --digit=# set the line number digits (default 4)
36 --truncate, -t truncate long line
37 --boundary=# line folding boundary (default word)
38 --context, -c, -C# context diff
39 --unified, -u, -U# unified diff
40  
41 --width=#, -W# width of output (default 80)
42 --margin=# margin column number (default 0)
43 --runin=# run-in column number (default --margin)
44 --runout=# run-out column number (default --margin)
45 --mark=position mark position (right, left, center, side) or no
46 --column=order column order (default ONM)
47 --view, -v viewer mode
48 --parallel[=#], -V treat unknown text as common part (default 2)
49 --ambiguous=s ambiguous character width (detect, wide, narrow)
50 --[no-]command print diff control command (default on)
51 --[no-]filename print diff filename (default on)
52 --[no-]prefix process git --graph output (default on)
53 --prefix-pattern prefix pattern
54  
55 --color=when 'always' (default), 'never' or 'auto'
56 --nocolor --color=never
57 --colormap, --cm specify color map
58 --colortable[=#] show color table (optional #: 6, 12, 24)
59 --[no-]256 on/off ANSI 256 color mode (default on)
60 --[no-]cc color command line (default true)
61 --[no-]fc file name (default true)
62 --[no-]lc line number (default true)
63 --[no-]mc diff mark (default true)
64 --[no-]tc normal text (default true)
65 --[no-]uc unknown text (default true)
66  
67 --man display manual page
68 --version show version
69 --diff=s set diff command
70 --diffopts=s set diff command options
71  
72 --[no-]lenience suppress unexpected input warning (default on)
73 --limit key=val set limit (line, length)
74 --visible xx=1 set visible chars
75 --tabhead=char set tabhead char
76 --tabspace=char set tabspace char
77 --tabstyle=style set tabstyle (dot, symbol, shade, bar, dash...)
78 --tabstop=# set tabstop width (default 8)
79  
80 --[no-]cdif use ``cdif'' as word context diff backend
81 --unit=s pass through to cdif (word, letter, char, mecab)
82 --cdifopts=s set cdif command options
83  
84 =cut
85  
86 10 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 10 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 10 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 10 ▶use open IO => ':utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
91 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 10 ▶use charnames ':full';
Subroutine BEGIN: called CC=1 SCAR=0.0
93 10 ▶use List::Util qw(min max reduce sum pairmap first);
Subroutine BEGIN: called CC=1 SCAR=0.0
94 10 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
95 10 ▶use Text::ParseWords qw(shellwords);
Subroutine BEGIN: called CC=1 SCAR=0.0
96 10 ▶use Data::Dumper; {
Subroutine BEGIN: called CC=1 SCAR=0.0
97 10 $Data::Dumper::Terse = 1;
98 }
99  
100 10 ▶use App::sdif;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 10 my $version = $App::sdif::VERSION;
102  
103 10 ▶use App::sdif::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 10 ▶use IO::Divert;
Subroutine BEGIN: called CC=1 SCAR=0.0
105  
106 10 my $default_cdif = 'cdif';
107 10 my @default_cdifopts = qw(--sdif);
108 10 my $default_lenience = 1;
109 10 my $default_256 = 1;
110 10 my $default_prefix = 1;
111 10 my $default_prefix_pattern = q/(?:\\| )*(?: )?/;
112 10 my @cdifopts;
113 my $read_stdin;
114  
115 10 our $screen_width;
116  
117 10 ▶if (my $env = $ENV{'SDIFOPTS'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $env = $ENV{"SDIFOPTS"}) 0 10 10
118 0 unshift @ARGV, shellwords($env);
119 }
120  
121 10 ▶use open IO => ':utf8', ':std';
Subroutine BEGIN: called CC=1 SCAR=0.0
122 10 ▶map { $_ = decode 'utf8', $_ unless utf8::is_utf8($_) } @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8($_) 36 0 36
123  
124 10 my $app;
125  
126 10 ▶use Getopt::EX::Hashed; {
Subroutine BEGIN: called CC=1 SCAR=0.0
127  
128 10 Getopt::EX::Hashed->configure( DEFAULT => [ is => 'rw' ] );
129  
130 10 has help => ' h ' ;
131 10 has version => ' ' ;
132 10 has man => ' ' ;
133 10 has debug => 'd + ' ;
134 10 has number => 'n ! ' ;
135 10 has digit => ' =i ' , default => 4 ;
136 10 has column => ' =s ' ;
137 10 has truncate => 't ! ' ;
138 10 has boundary => ' =s ' , default => 'word' ;
139 10 has onword => ' ! ' ;
140 10 has mark => ' =s ' , default => 'center' ;
141 10 has prefix => ' ! ' , default => $default_prefix ;
142 10 has prefix_pattern => ' =s ' , default => $default_prefix_pattern ;
143 10 has width => 'W =i ' ;
144 10 has margin => ' =i ' , default => 0 ;
145 10 has runin => ' =i ' ;
146 10 has runout => ' =i ' ;
147 10 has view => 'v ! ' ;
148 10 has parallel => 'V :2 ' , default => 0 ;
149 10 has ambiguous => ' =s ' , default => 'narrow' ;
150 10 has filename => ' ! ' , default => 1 ;
151 10 has command => ' ! ' , default => 1 ;
152 10 has diff => ' =s ' , default => 'diff' ;
153 10 has diffopts => ' =s@' , default => [] ;
154 10 has color => ' =s ' , default => 'always' ;
155 10 has colormap => 'cm=s@' , default => [] ;
156 10 has colordump => ' ' ;
157 10 has 256 => ' ! ' , default => $default_256 ;
158 10 has commandcolor => 'cc! ' , default => 1 ;
159 10 has filecolor => 'fc! ' , default => 1 ;
160 10 has linecolor => 'lc! ' , default => 1 ;
161 10 has markcolor => 'mc! ' , default => 1 ;
162 10 has textcolor => 'tc! ' , default => 1 ;
163 10 has unknowncolor => 'uc! ' , default => 1 ;
164 10 has cdif => ' :s ' , default => '' ;
165 10 has cdifopts => ' =s ' ;
166 10 has colortable => ' :s ' , any => qr/^(|6|12|24)$/ ;
167 10 has lenience => ' ! ' , default => $default_lenience ;
168 10 has limit => ' =s%' , default => { length => 10000 } ;
169 10 has visible => ' =i%' , default => {} ;
170 10 has tabstop => ' =i ' , default => 8 ;
171 10 has tabhead => ' =s ' ;
172 10 has tabstyle => 'ts=s ' ;
173 10 has tabspace => ' =s ' ;
174 10 has unit => 'by:s ' ;
175  
176 10 has ignore_case => 'i ' ;
177 10 has ignore_space_change => 'b ' ;
178 10 has ignore_all_space => 'w ' ;
179 10 has ignore_blank_lines => 'B ' ;
180 10 has context => 'C =i' ;
181 10 has unified => 'U =i' ;
182 10 has c => ' ' ;
183 10 has u => ' ' ;
184  
185 has '+onword'
186 0 ▶ => sub { $_->boundary = $_[1] ? 'word' : '' } ;
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
187  
188 has '+cdifopts'
189 0 ▶ => sub { push @cdifopts, shellwords $_[1] } ;
Subroutine __ANON__: not called CC=1 SCAR=1.2
190  
191 has '+ignore_case'
192 0 ▶ => sub { push @{$app->diffopts}, '-i'; push @cdifopts, '-i' } ;
Subroutine __ANON__: not called CC=1 SCAR=3.5
193 has '+ignore_space_change'
194 0 ▶ => sub { push @{$app->diffopts}, '-b'; push @cdifopts, '-w' } ;
Subroutine __ANON__: not called CC=1 SCAR=3.5
195 has '+ignore_all_space'
196 0 ▶ => sub { push @{$app->diffopts}, '-w'; push @cdifopts, '-w' } ;
Subroutine __ANON__: not called CC=1 SCAR=3.5
197 has '+ignore_blank_lines'
198 0 ▶ => sub { push @{$app->diffopts}, '-B' } ;
Subroutine __ANON__: not called CC=1 SCAR=2.6
199  
200 0 ▶ has '+c' => sub { push @{$app->diffopts}, '-c' } ;
Subroutine __ANON__: not called CC=1 SCAR=2.6
201 0 ▶ has '+u' => sub { push @{$app->diffopts}, '-u' } ;
Subroutine __ANON__: not called CC=1 SCAR=2.6
202 0 ▶ has '+context' => sub { push @{$app->diffopts}, '-C' . $_[1] } ;
Subroutine __ANON__: not called CC=1 SCAR=2.6
203 0 ▶ has '+unified' => sub { push @{$app->diffopts}, '-U' . $_[1] } ;
Subroutine __ANON__: not called CC=1 SCAR=2.6
204  
205 0 ▶ has nocolor => 'no-color' , action => sub { $app->color = 'never' } ;
Subroutine __ANON__: not called CC=1 SCAR=1.2
206 10 ▶ has nocdif => 'no-cdif' , action => sub { $app->cdif = undef } ;
Subroutine __ANON__: called CC=1 SCAR=0.0
207  
208 0 ▶ has mecab => '!' , action => sub { $app->unit = $_[1] ? 'mecab' : undef } ;
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
209  
210 0 ▶ has '+ambiguous' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
211 0 ▶ if ($_[1] =~ /^(?:wide|full)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ /^(?:wide|full)/u) 0 0 0
212 0 $Text::VisualWidth::PP::EastAsian = 1;
213 0 Text::ANSI::Fold->configure(ambiguous => 'wide');
214 }
215 10 } ;
216  
217 0 ▶ has '+help' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
218 0 pod2usage
219 -verbose => 99,
220 -sections => [ qw(SYNOPSIS VERSION) ];
221 10 } ;
222 0 ▶ has '+version' => sub { print "$version\n"; exit 0 } ;
Subroutine __ANON__: not called CC=1 SCAR=2.6
223 0 ▶ has '+man' => sub { pod2usage {-verbose => 2} } ;
Subroutine __ANON__: not called CC=1 SCAR=1.2
224  
225 10 ▶} no Getopt::EX::Hashed;
Subroutine BEGIN: called CC=1 SCAR=0.0
226  
227 10 ▶$app = Getopt::EX::Hashed->new() or die;
Branch: 1 branch
BranchTrueFalseTotal
$app = "Getopt::EX::Hashed"->new or die 10 0 10
228  
229 10 my @SAVEDARGV = @ARGV;
230 10 ▶use Getopt::EX::Long qw(:DEFAULT Configure ExConfigure);
Subroutine BEGIN: called CC=1 SCAR=0.0
231 10 ExConfigure BASECLASS => [ "App::sdif", "Getopt::EX" ];
232 10 Configure "bundling";
233 10 ▶$app->getopt or usage({status => 1});
Branch: 1 branch
BranchTrueFalseTotal
$app->getopt or usage({"status", 1}) 10 0 10
234  
235 10 ▶warn "\@ARGV = (@SAVEDARGV)\n" if $app->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $app->debug 0 10 10
236  
237 10 $App::sdif::Util::NO_WARNINGS = $app->lenience;
238  
239 10 ▶use Text::VisualWidth::PP qw(vwidth);
Subroutine BEGIN: called CC=1 SCAR=0.0
240 10 ▶use Text::ANSI::Fold qw(ansi_fold :constants); {
Subroutine BEGIN: called CC=1 SCAR=0.0
241 10 Text::ANSI::Fold->configure(padding => 1,
242 expand => 1,
243 tabstop => $app->tabstop);
244 }
245  
246 10 ▶$app->visible->{ht} //= 1 if $app->tabstyle;
Branch: 1 branch
BranchTrueFalseTotal
if $app->tabstyle 0 10 10
Condition0%0/2
$app->visible->{"ht"} //= 1
l!l
00
MC/DC0%0/1
$app->visible->{"ht"} //= 1
$app->visible->{"ht"}
Truth table0%0/2
A
A= $app->visible->{"ht"}
Aresult
11
00
247 10 ▶if ($app->visible->{ht}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->visible->{"ht"}) 0 10 10
248 Text::ANSI::Fold->configure(
249 tabstyle => $app->tabstyle,
250 0 map { $_->[0] => unicode($_->[1]) }
251 0 grep { $_->[1] }
252 [ tabhead => $app->tabhead ],
253 [ tabspace => $app->tabspace ],
254 );
255 }
256  
257 0 ▶sub unicode {
Subroutine unicode: not called CC=4 SCAR=30.0
258 0 ▶ my $char = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $char = shift() or return undef 0 0 0
259 0 ▶ if ($char =~ /^\X$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /^\X$/u) { } 0 0 0
260 0 $char;
261 } else {
262 0 ▶ eval qq["\\N{$char}"] or die "$!";
Branch: 1 branch
BranchTrueFalseTotal
eval qq["\\N{$char}"] or die "$!" 0 0 0
263 }
264 }
265  
266 10 ▶if ($app->margin > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->margin > 0) 0 10 10
267 0 ▶ if ($app->runin and $app->margin < $app->runin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->runin and $app->margin < $app->runin) 0 0 0
Condition0%0/3
$app->runin and $app->margin < $app->runin
!ll&&!rl&&r
000
MC/DC0%0/2
$app->runin and $app->margin < $app->runin
$app->runin $app->margin < $app->runin
Truth table0%0/3
A and B
A= $app->runinB= $app->margin < $app->runin
ABresult
0X0
100
111
268 0 die "margin must be >= runin\n";
269 }
270 Text::ANSI::Fold->configure(
271 0 ▶ linebreak => LINEBREAK_ALL,
Condition0%0/6
$app->runin // $app->margin
l!l&&r!l&&!r
000
$app->runout // $app->margin
l!l&&r!l&&!r
000
MC/DC0%0/2
$app->runin // $app->margin
$app->runin $app->margin
MC/DC0%0/2
$app->runout // $app->margin
$app->runout $app->margin
Truth table0%0/3
A // B
A= $app->runinB= $app->margin
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $app->runoutB= $app->margin
ABresult
1X1
011
000
272 margin => $app->margin,
273 runin => $app->runin // $app->margin,
274 runout => $app->runout // $app->margin,
275 );
276 }
277  
278 10 my %colormap = do {
279 10 ▶ my $col = $app->{256} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$app->{'256'} ? : 10 0 10
280 200 ▶ pairmap { $a => (ref $b eq 'ARRAY') ? $b->[$col] : $b } (
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $b eq 'ARRAY' ? : 150 50 200
281 10 UNKNOWN => "" ,
282 OCOMMAND => [ "555/010" , "GS" ],
283 NCOMMAND => [ "555/010" , "GS" ],
284 MCOMMAND => [ "555/010" , "GS" ],
285 OFILE => [ "551/010D" , "GDS" ],
286 NFILE => [ "551/010D" , "GDS" ],
287 MFILE => [ "551/010D" , "GDS" ],
288 OMARK => [ "010/444" , "G/W" ],
289 NMARK => [ "010/444" , "G/W" ],
290 MMARK => [ "010/444" , "G/W" ],
291 UMARK => "" ,
292 OLINE => [ "220" , "Y" ],
293 NLINE => [ "220" , "Y" ],
294 MLINE => [ "220" , "Y" ],
295 ULINE => "" ,
296 OTEXT => [ "K/454" , "G" ],
297 NTEXT => [ "K/454" , "G" ],
298 MTEXT => [ "K/454" , "G" ],
299 UTEXT => "" ,
300 NOTICE => "R" ,
301 );
302 };
303  
304 10 ▶use Getopt::EX::Colormap;
Subroutine BEGIN: called CC=1 SCAR=0.0
305 10 $Getopt::EX::Colormap::NO_RESET_EL = 1;
306 10 ▶use constant SGR_RESET => "\e[m";
Subroutine BEGIN: called CC=1 SCAR=0.0
307 my $color_handler = Getopt::EX::Colormap
308 ->new(HASH => \%colormap)
309 10 ->load_params(@{$app->colormap});
310  
311 10 ▶$colormap{OUMARK} ||= $colormap{UMARK} || $colormap{OMARK};
Condition33%2/6
$colormap{"OUMARK"} ||= $colormap{"UMARK"} || $colormap{"OMARK"}
l!l&&r!l&&!r
0100
$colormap{'UMARK'} || $colormap{'OMARK'}
l!l&&r!l&&!r
0100
MC/DC0%0/3
$colormap{"OUMARK"} ||= $colormap{"UMARK"} || $colormap{"OMARK"}
$colormap{"OUMARK"} $colormap{'UMARK'} $colormap{'OMARK'}
Truth table0%0/4
A ||= B || C
A= $colormap{"OUMARK"}B= $colormap{'UMARK'}C= $colormap{'OMARK'}
ABCresult
1XX1
01X1
0011
0000
312 10 ▶$colormap{NUMARK} ||= $colormap{UMARK} || $colormap{NMARK};
Condition33%2/6
$colormap{"NUMARK"} ||= $colormap{"UMARK"} || $colormap{"NMARK"}
l!l&&r!l&&!r
0100
$colormap{'UMARK'} || $colormap{'NMARK'}
l!l&&r!l&&!r
0100
MC/DC0%0/3
$colormap{"NUMARK"} ||= $colormap{"UMARK"} || $colormap{"NMARK"}
$colormap{"NUMARK"} $colormap{'UMARK'} $colormap{'NMARK'}
Truth table0%0/4
A ||= B || C
A= $colormap{"NUMARK"}B= $colormap{'UMARK'}C= $colormap{'NMARK'}
ABCresult
1XX1
01X1
0011
0000
313 10 ▶$colormap{OULINE} ||= $colormap{ULINE} || $colormap{OLINE};
Condition33%2/6
$colormap{"OULINE"} ||= $colormap{"ULINE"} || $colormap{"OLINE"}
l!l&&r!l&&!r
0100
$colormap{'ULINE'} || $colormap{'OLINE'}
l!l&&r!l&&!r
0100
MC/DC0%0/3
$colormap{"OULINE"} ||= $colormap{"ULINE"} || $colormap{"OLINE"}
$colormap{"OULINE"} $colormap{'ULINE'} $colormap{'OLINE'}
Truth table0%0/4
A ||= B || C
A= $colormap{"OULINE"}B= $colormap{'ULINE'}C= $colormap{'OLINE'}
ABCresult
1XX1
01X1
0011
0000
314 10 ▶$colormap{NULINE} ||= $colormap{ULINE} || $colormap{NLINE};
Condition33%2/6
$colormap{"NULINE"} ||= $colormap{"ULINE"} || $colormap{"NLINE"}
l!l&&r!l&&!r
0100
$colormap{'ULINE'} || $colormap{'NLINE'}
l!l&&r!l&&!r
0100
MC/DC0%0/3
$colormap{"NULINE"} ||= $colormap{"ULINE"} || $colormap{"NLINE"}
$colormap{"NULINE"} $colormap{'ULINE'} $colormap{'NLINE'}
Truth table0%0/4
A ||= B || C
A= $colormap{"NULINE"}B= $colormap{'ULINE'}C= $colormap{'NLINE'}
ABCresult
1XX1
01X1
0011
0000
315  
316 10 for (
317 [ $app->unknowncolor => q/UNKNOWN/ ],
318 [ $app->commandcolor => q/COMMAND/ ],
319 [ $app->filecolor => q/FILE/ ],
320 [ $app->linecolor => q/LINE/ ],
321 [ $app->markcolor => q/MARK/ ],
322 [ $app->textcolor => q/TEXT/ ],
323 ) {
324 60 my($color, $label) = @$_;
325 60 ▶ $color and next;
Branch: 1 branch
BranchTrueFalseTotal
$color and next 60 0 60
326 0 for (grep /$label/, keys %colormap) {
327 0 $colormap{$_} = '';
328 }
329 }
330  
331 10 ▶if ($app->colordump) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->colordump) 0 10 10
332 0 print $color_handler->colormap(
333 name => '--changeme', option => '--colormap');
334 0 exit;
335 }
336  
337 10 my $painter = do {
338 10 ▶ if (($app->color eq 'always')
Branch: 1 branch
BranchTrueFalseTotal
if ($app->color eq 'always' or $app->color eq 'auto' and -t STDOUT) { } 10 0 10
Condition16%1/6
$app->color eq "always" or $app->color eq "auto" and -t STDOUT
l!l&&r!l&&!r
1000
$app->color eq "auto" and -t STDOUT
!ll&&!rl&&r
000
MC/DC0%0/3
$app->color eq "always" or $app->color eq "auto" and -t STDOUT
$app->color eq "always" $app->color eq "auto" -t STDOUT
Truth table25%1/4
A or B and C
A= $app->color eq "always"B= $app->color eq "auto"C= -t STDOUT
ABCresult
1XX1
0111
00X0
0100
339 or (($app->color eq 'auto') and (-t STDOUT))) {
340 10 ▶ sub { $color_handler->color(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
341 } else {
342 0 ▶ sub { $_[1] } ;
Subroutine __ANON__: not called CC=1 SCAR=6.9
343 }
344 };
345  
346 ##
347 ## setup cdif command and option
348 ##
349 10 ▶if (defined $app->cdif and $app->cdif eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $app->cdif and $app->cdif eq "") 5 5 10
Condition66%2/3
defined $app->cdif and $app->cdif eq ""
!ll&&!rl&&r
505
MC/DC50%1/2
defined $app->cdif and $app->cdif eq ""
defined $app->cdif $app->cdif eq ""
Truth table66%2/3
A and B
A= defined $app->cdifB= $app->cdif eq ""
ABresult
0X0
100
111
350 5 $app->cdif = $default_cdif;
351 }
352  
353 10 for (
354 [ "unit" , "=" , $app->unit , undef ] ,
355 [ "256" , "!" , $app->{256} , $default_256 ] ,
356 [ "prefix" , "!" , $app->prefix , $default_prefix ] ,
357 [ "lenience" , "!" , $app->lenience , $default_lenience ] ,
358 )
359 {
360 40 my($name, $type, $var, $default) = @$_;
361 40 ▶ if ($type eq "!") {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '!') { } 30 10 40
elsif ($type eq '=') { } 10 0 10
362 30 ▶ next if not defined $var;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $var 0 30 30
363 30 ▶ next if $var == $default;
Branch: 1 branch
BranchTrueFalseTotal
if $var == $default 30 0 30
364 0 ▶ unshift @cdifopts, sprintf("--%s%s", $var ? '' : 'no-', $name);
Branch: 1 branch
BranchTrueFalseTotal
$var ? : 0 0 0
365 } elsif ($type eq "=") {
366 10 ▶ next if not defined $var;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $var 10 0 10
367 0 unshift @cdifopts, sprintf("--%s=%s", $name, $var);
368 } else {
369 0 die;
370 }
371 }
372  
373 10 unshift @cdifopts, @default_cdifopts;
374  
375 10 my($OLD, $NEW, $DIFF);
376 10 ▶if (@ARGV == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (@ARGV == 2) { } 0 10 10
elsif (@ARGV < 2) { } 10 0 10
377 0 ($OLD, $NEW) = @ARGV;
378 0 $DIFF = "$app->{diff} @{$app->{diffopts}} $OLD $NEW |";
379 } elsif (@ARGV < 2) {
380 10 ▶ $DIFF = shift || '-';
Condition100%2/2
shift @ARGV || '-'
l!l
91
MC/DC100%1/1
shift @ARGV || '-'
shift @ARGV
Truth table100%2/2
A
A= shift @ARGV
Aresult
11
00
381 10 $read_stdin++;
382 } else {
383 0 usage({status => 1}, "Unexpected arguments.\n\n");
384 }
385 my $readfile =
386 0 ▶ ($OLD and $NEW) && !$read_stdin && !(grep { /^-[cuCU]/ } @{$app->diffopts});
Condition33%3/9
$OLD && $NEW && !$read_stdin && !grep({/^-[cuCU]/u;} @{$app->diffopts;})
!ll&&!rl&&r
1000
$OLD and $NEW and not $read_stdin
!ll&&!rl&&r
1000
$OLD and $NEW
!ll&&!rl&&r
1000
MC/DC0%0/4
$OLD && $NEW && !$read_stdin && !grep({/^-[cuCU]/u;} @{$app->diffopts;})
$OLD $NEW not $read_stdin !grep({/^-[cuCU]/u;} @{$app->diffopts;})
Truth table20%1/5
A and B and not(C) && not(D)
A= $OLDB= $NEWC= not $read_stdinD= !grep({/^-[cuCU]/u;} @{$app->diffopts;})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
387  
388 10 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
389 10 RIGHT => 'right',
390 LEFT => 'left',
391 NO => 'no',
392 10 };
393 10 my %markpos = (
394 center => [ RIGHT , LEFT , LEFT ],
395 side => [ LEFT , RIGHT , LEFT ],
396 right => [ RIGHT , RIGHT , RIGHT ],
397 left => [ LEFT , LEFT , LEFT ],
398 no => [ NO , NO , NO ],
399 none => [ NO , NO , NO ],
400 );
401 10 ▶unless ($markpos{$app->mark}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($markpos{$app->mark}) 0 10 10
402 0 my @keys = sort keys %markpos;
403 0 usage "Use one from (@keys) for option --mark\n\n";
404 }
405 10 my @markpos = @{$markpos{$app->mark}};
406 10 my($omarkpos, $nmarkpos, $mmarkpos) = @markpos;
407  
408 10 my $num_format = sprintf '%%%dd', $app->digit;
409  
410 10 ▶$screen_width = $app->width || &terminal_width;
Condition66%2/3
$app->width || &terminal_width
l!l&&r!l&&!r
910
MC/DC0%0/2
$app->width || &terminal_width
$app->width &terminal_width
Truth table66%2/3
A || B
A= $app->widthB= &terminal_width
ABresult
1X1
011
000
411  
412 156 ▶sub column_width {
Subroutine column_width: called CC=3 SCAR=11.1
413 156 my $column = shift;
414 156 state %column_width;
415 156 ▶ $column_width{$screen_width * 1000 + $column} //= do {
Condition66%2/3
$column_width{$main::screen_width * 1000 + $column} //= do { use integer; my $w = $main::screen_width; $w -= $column if $app->mark; &max(1, $w / $column) }
l!l&&r!l&&!r
14790
MC/DC0%0/2
$column_width{$main::screen_width * 1000 + $column} //= do { use integer; my $w = $main::screen_width; $w -= $column if $app->mark; &max(1, $w / $column) }
$column_width{$main::screen_width * 1000 + $column} do { use integer; my $w = $main::screen_width; $w -= $column if $app->mark; &max(1, $w / $column) }
Truth table66%2/3
A //= B
A= $column_width{$main::screen_width * 1000 + $column}B= do { use integer; my $w = $main::screen_width; $w -= $column if $app->mark; &max(1, $w / $column) }
ABresult
1X1
011
000
416 10 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
417 9 my $w = $screen_width;
418 9 ▶ $w -= $column if $app->mark;
Branch: 1 branch
BranchTrueFalseTotal
if $app->mark 9 0 9
419 9 max 1, $w / $column;
420 };
421 }
422  
423 ##
424 ## --colortable
425 ##
426 10 ▶if (defined(my $n = $app->colortable)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $n = $app->colortable)) 1 9 10
427 10 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
428 1 &{"Getopt::EX::Colormap::colortable$n"}($screen_width);
429 1 exit;
430 }
431  
432 ##
433 ## Column order
434 ##
435 9 ▶my @column = !$app->column ? () : do {
Branch: 1 branch
BranchTrueFalseTotal
!$app->column ? : 9 0 9
436 0 map { $_ - 1 }
437 0 ▶ map { { O=>1, N=>2, M=>3 }->{$_} // $_ }
Condition0%0/3
{"O", 1, "N", 2, "M", 3}->{$_} // $_
l!l&&r!l&&!r
000
MC/DC0%0/2
{"O", 1, "N", 2, "M", 3}->{$_} // $_
{"O", 1, "N", 2, "M", 3}->{$_} $_
Truth table0%0/3
A // B
A= {"O", 1, "N", 2, "M", 3}->{$_}B= $_
ABresult
1X1
011
000
438 $app->column =~ /[0-9ONM]/g;
439 };
440  
441 ##
442 ## Git --graph prefix pattern
443 ##
444 9 my $prefix_re = do {
445 9 ▶ if ($app->prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->prefix) { } 9 0 9
446 9 qr/$app->{prefix_pattern}/;
447 } else {
448 0 "";
449 }
450 };
451  
452 9 ▶if ($app->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->debug) 0 9 9
453 0 ▶ printf STDERR "\$OLD = %s\n", $OLD // "undef";
Condition0%0/2
$OLD // "undef"
l!l
00
MC/DC0%0/1
$OLD // "undef"
$OLD
Truth table0%0/2
A
A= $OLD
Aresult
11
00
454 0 ▶ printf STDERR "\$NEW = %s\n", $NEW // "undef";
Condition0%0/2
$NEW // "undef"
l!l
00
MC/DC0%0/1
$NEW // "undef"
$NEW
Truth table0%0/2
A
A= $NEW
Aresult
11
00
455 0 ▶ printf STDERR "\$DIFF = %s\n", $DIFF // "undef";
Condition0%0/2
$DIFF // "undef"
l!l
00
MC/DC0%0/1
$DIFF // "undef"
$DIFF
Truth table0%0/2
A
A= $DIFF
Aresult
11
00
456 }
457  
458 9 ▶if ($app->cdif) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->cdif) { } 4 5 9
459 4 my $pid = open DIFF, '-|';
460 4 ▶ if (not defined $pid) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $pid) { } 0 4 4
elsif ($pid == 0) { } 0 4 4
461 0 ▶ die "$!" if not defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 0 0
462 }
463 ## child
464 elsif ($pid == 0) {
465 0 ▶ if ($DIFF ne '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($DIFF ne "-") 0 0 0
466 0 ▶ open(STDIN, $DIFF) || die "cannot open diff: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, $DIFF or die "cannot open diff: $!\n" 0 0 0
467 }
468 0 do { exec shellwords($app->cdif), @cdifopts } ;
469 0 warn "exec failed: $!";
470 0 ▶ print while <>;
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline ARGV) and do { print $_ } 0 0 0
471 0 exit;
472 }
473 ## parent
474 else {
475 ## nothing to do
476 }
477 } else {
478 5 ▶ open(DIFF, $DIFF) || die "cannot open diff: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open DIFF, $DIFF or die "cannot open diff: $!\n" 5 0 5
479 }
480  
481 9 ▶if ($readfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($readfile) 0 9 9
482  
483 0 binmode DIFF, ':raw';
484 0 my $DIFFOUT = do { local $/; <DIFF> };
485 0 close DIFF;
486 0 ▶ open DIFF, '<', \$DIFFOUT or die;
Branch: 1 branch
BranchTrueFalseTotal
open DIFF, "<", \$DIFFOUT or die 0 0 0
487  
488 0 ▶ open OLD, $OLD or die "$OLD: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open OLD, $OLD or die "${OLD}: $!\n" 0 0 0
489 0 ▶ open NEW, $NEW or die "$NEW: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open NEW, $NEW or die "${NEW}: $!\n" 0 0 0
490  
491 # For reading /dev/fd/*
492 0 ▶ seek OLD, 0, 0 or die unless -p OLD;
Branch: 1 branch
BranchTrueFalseTotal
unless -p OLD 0 0 0
Condition0%0/5
-p OLD || (seek(OLD, 0, 0) || die())
l!l&&r!l&&!r
000
seek OLD, 0, 0 or die
l!l
00
MC/DC0%0/2
-p OLD || (seek(OLD, 0, 0) || die())
-p OLD seek OLD, 0, 0
Truth table0%0/3
A || B
A= -p OLDB= seek OLD, 0, 0
ABresult
1X1
011
000
493 0 ▶ seek NEW, 0, 0 or die unless -p NEW;
Branch: 1 branch
BranchTrueFalseTotal
unless -p NEW 0 0 0
Condition0%0/5
-p NEW || (seek(NEW, 0, 0) || die())
l!l&&r!l&&!r
000
seek NEW, 0, 0 or die
l!l
00
MC/DC0%0/2
-p NEW || (seek(NEW, 0, 0) || die())
-p NEW seek NEW, 0, 0
Truth table0%0/3
A || B
A= -p NEWB= seek NEW, 0, 0
ABresult
1X1
011
000
494 }
495  
496 9 my @boundary = (boundary => $app->boundary);
497 9 my $color_re = qr{ \e \[ [\d;]* [mK] }x;
498  
499 9 our $oline = 1;
500 9 our $nline = 1;
501 9 our $mline = 1;
502  
503 9 ▶while (<DIFF>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DIFF)) 50 9 59
504 #
505 # normal diff
506 #
507 50 ▶ if (/^([\d,]+)([adc])([\d,]+)$/) {
Branch: 9 branches
BranchTrueFalseTotal
if (/^([\d,]+)([adc])([\d,]+)$/u) { } 5 45 50
elsif (/^\*\*\* /u) { } 1 44 45
elsif ($_ eq "***************\n") { } 1 43 44
elsif (/^($prefix_re)(--- (?s:.*))/u) { } 10 33 43
elsif (/^ (?<prefix>$prefix_re) (?<command> \@\@ [ ] \-(?<oline>\d+) (?:,(?<o>\d+))? [ ] \+(?<nline>\d+) (?:,(?<n>\d+))? [ ] \@\@ (?s:.*) ) /ux) { } 10 23 33
elsif (/^diff --(?:cc|combined)/u) { } 0 23 23
elsif (/^\@{3} -(\d+)(?:,(\d+))? -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? \@{3}/u) { } 0 23 23
elsif (/^<<<<<<<\h*+(.*)/u) { } 0 23 23
elsif (/^(\#ifdef|:{7,})\h++(.*)/u) { } 0 23 23
508 5 my(@old, @new);
509 5 my($left, $ctrl, $right) = ($1, $2, $3);
510 5 my($l1, $l2) = range($left);
511 5 my($r1, $r2) = range($right);
512 5 ▶ if ($readfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($readfile) 0 5 5
513 0 my $identical_line = $l1 - $oline + 1 - ($ctrl ne 'a');
514 0 print_identical($identical_line);
515 }
516 5 ▶ if ($app->debug || $read_stdin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->debug or $read_stdin) 5 0 5
Condition33%1/3
$app->debug or $read_stdin
l!l&&r!l&&!r
050
MC/DC0%0/2
$app->debug or $read_stdin
$app->debug $read_stdin
Truth table33%1/3
A or B
A= $app->debugB= $read_stdin
ABresult
1X1
011
000
517 5 print_command_n($_, $_);
518 }
519 5 ▶ if ($ctrl eq 'd' || $ctrl eq 'c') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctrl eq "d" or $ctrl eq "c") 4 1 5
Condition100%3/3
$ctrl eq "d" or $ctrl eq "c"
l!l&&r!l&&!r
131
MC/DC100%2/2
$ctrl eq "d" or $ctrl eq "c"
$ctrl eq "d" $ctrl eq "c"
Truth table100%3/3
A or B
A= $ctrl eq "d"B= $ctrl eq "c"
ABresult
1X1
011
000
520 4 ($oline) = $left =~ /^(\d+)/;
521 4 my $n = $l2 - $l1 + 1;
522 4 @old = read_line(*DIFF, $n);
523 4 ▶ $readfile and read_line(*OLD, $n);
Branch: 1 branch
BranchTrueFalseTotal
$readfile and &read_line(*OLD, $n) 0 4 4
524 }
525 5 ▶ read_line(*DIFF, 1) if $ctrl eq 'c';
Branch: 1 branch
BranchTrueFalseTotal
if $ctrl eq "c" 3 2 5
526 5 ▶ if ($ctrl eq 'a' || $ctrl eq 'c') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctrl eq "a" or $ctrl eq "c") 4 1 5
Condition100%3/3
$ctrl eq "a" or $ctrl eq "c"
l!l&&r!l&&!r
131
MC/DC100%2/2
$ctrl eq "a" or $ctrl eq "c"
$ctrl eq "a" $ctrl eq "c"
Truth table100%3/3
A or B
A= $ctrl eq "a"B= $ctrl eq "c"
ABresult
1X1
011
000
527 4 ($nline) = $right =~ /^(\d+)/;
528 4 my $n = $r2 - $r1 + 1;
529 4 @new = read_line(*DIFF, $n);
530 4 ▶ $readfile and read_line(*NEW, $n);
Branch: 1 branch
BranchTrueFalseTotal
$readfile and &read_line(*NEW, $n) 0 4 4
531 }
532 map {
533 5 s/^([<>])\s?/{'<' => '-', '>' => '+'}->{$1}/e
534 } @old, @new;
535 5 flush_buffer([], \@old, \@new);
536 }
537 #
538 # context diff
539 #
540 elsif (/^\*\*\* /) {
541 1 my $next = <DIFF>;
542 1 print_command_n({ type => 'FILE' }, $_, $next);
543 }
544 elsif ($_ eq "***************\n") {
545 1 my(@old, @new);
546 1 my $ohead = $_ = <DIFF>;
547 1 my($left, $right);
548 1 ▶ unless (($left) = /^\*\*\* ([\d,]+) \*\*\*\*$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($left) = /^\*\*\* ([\d,]+) \*\*\*\*$/u) 0 1 1
549 0 print;
550 0 next;
551 }
552 1 my $oline = range($left);
553 1 my $dline = 0;
554 1 my $cline = 0;
555 1 my $nhead = $_ = <DIFF>;
556 1 ▶ unless (($right) = /^--- ([\d,]+) ----$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($right) = /^--- ([\d,]+) ----$/u) 1 0 1
557 1 @old = read_line(*DIFF, $oline - 1, $nhead);
558 1 $nhead = $_ = <DIFF>;
559 1 ▶ unless (($right) = /^--- ([\d,]+) ----$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($right) = /^--- ([\d,]+) ----$/u) 0 1 1
560 0 print $ohead, @old, $_;
561 0 next;
562 }
563 1 for (@old) {
564 14 ▶ /^-/ and ++$dline;
Branch: 1 branch
BranchTrueFalseTotal
/^-/u and ++$dline 2 12 14
565 14 ▶ /^!/ and ++$cline;
Branch: 1 branch
BranchTrueFalseTotal
/^!/u and ++$cline 4 10 14
566 }
567 }
568 1 my $nline = range($right);
569 1 ▶ if (@old == 0 or $cline != 0 or ($oline - $dline != $nline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@old == 0 or $cline != 0 or $oline - $dline != $nline) 1 0 1
Condition33%2/6
@old == 0 or $cline != 0 or $oline - $dline != $nline
l!l&&r!l&&!r
100
@old == 0 or $cline != 0
l!l&&r!l&&!r
010
MC/DC0%0/3
@old == 0 or $cline != 0 or $oline - $dline != $nline
@old == 0 $cline != 0 $oline - $dline != $nline
Truth table25%1/4
A or B or C
A= @old == 0B= $cline != 0C= $oline - $dline != $nline
ABCresult
1XX1
01X1
0011
0000
570 1 @new = read_line(*DIFF, $nline);
571 }
572 1 print_command_n($ohead, $nhead);
573 1 ($oline) = $left =~ /^(\d+)/;
574 1 ($nline) = $right =~ /^(\d+)/;
575  
576 1 my @buf = merge_diffc(\@old, \@new);
577 1 flush_buffer(@buf);
578 }
579 #
580 # unified diff
581 #
582 elsif (/^($prefix_re)(--- (?s:.*))/) {
583 10 my($prefix, $left) = ($1, $2);
584 10 my $right = <DIFF>;
585 10 local $screen_width = $screen_width;
586 10 ▶ if ($prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix) 4 6 10
587 4 $right =~ s/^\Q$prefix//;
588 4 print $prefix;
589 4 $screen_width -= length $prefix;
590 }
591 10 print_command_n({ type => 'FILE' }, $left, $right);
592 }
593 elsif (m{^
594 (?<prefix>$prefix_re)
595 (?<command>
596 \@\@ [ ]
597 \-(?<oline>\d+) (?:,(?<o>\d+))? [ ]
598 \+(?<nline>\d+) (?:,(?<n>\d+))? [ ]
599 \@\@
600 (?s:.*)
601 )
602 }x) {
603 10 ($oline, $nline) = @+{qw(oline nline)};
604 10 ▶ my($o, $n) = ($+{o}//1, $+{n}//1);
Condition75%3/4
$+{"o"} // 1
l!l
100
$+{"n"} // 1
l!l
82
MC/DC0%0/1
$+{"o"} // 1
$+{"o"}
MC/DC100%1/1
$+{"n"} // 1
$+{"n"}
Truth table50%1/2
A
A= $+{"o"}
Aresult
11
00
Truth table100%2/2
A
A= $+{"n"}
Aresult
11
00
605 10 my($prefix, $command) = @+{qw(prefix command)};
606  
607 10 local $screen_width = $screen_width;
608 10 my($divert, %read_opt);
609 10 ▶ if ($prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix) 4 6 10
610 4 $screen_width -= length $prefix;
611 4 $read_opt{prefix} = $prefix;
612 4 ▶ $divert = IO::Divert->new(FINAL => sub { s/^/$prefix/mg });
Subroutine __ANON__: called CC=1 SCAR=0.0
613 }
614  
615 10 print_command_n({ type => 'COMMAND' }, $command, $command);
616 10 my @buf = read_unified_2 \%read_opt, *DIFF, $o, $n;
617  
618 10 flush_buffer(@buf);
619 }
620 #
621 # diff --combined (only support 3 files)
622 #
623 elsif (/^diff --(?:cc|combined)/) {
624 0 my @lines = ($_);
625 0 ▶ push @lines, read_until { /^\+\+\+/ } *DIFF;
Subroutine __ANON__: not called CC=1 SCAR=6.9
626 0 ▶ if (not defined $lines[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $lines[-1]) 0 0 0
627 0 pop @lines;
628 0 print @lines;
629 0 next;
630 }
631 0 print @lines;
632 }
633 elsif (/^\@{3} -(\d+)(?:,(\d+))? -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? \@{3}/) {
634 0 print_command_n({ type => 'COMMAND' }, $_, $_, $_);
635  
636 0 ($oline, $nline, $mline) = ($1, $3, $5);
637 0 state $read_unified_3 = read_unified_sub(3);
638 0 ▶ my @buf = $read_unified_3->(*DIFF, $2 // 1, $4 // 1, $6 // 1);
Condition0%0/6
$2 // 1
l!l
00
$4 // 1
l!l
00
$6 // 1
l!l
00
MC/DC0%0/1
$2 // 1
$2
MC/DC0%0/1
$4 // 1
$4
MC/DC0%0/1
$6 // 1
$6
Truth table0%0/2
A
A= $2
Aresult
11
00
Truth table0%0/2
A
A= $4
Aresult
11
00
Truth table0%0/2
A
A= $6
Aresult
11
00
639 0 flush_buffer_3(@buf);
640 }
641 #
642 # conflict marker
643 #
644 elsif (/^<<<<<<<\h*+(.*)/) {
645 CONFLICT:
646 {
647 0 my %name = (o => $_);
648 0 my($c1, $c2, $c3, $c4);
649 0 $c1 = $_;
650  
651 0 ▶ my @old = read_until { /^=======$/ } *DIFF;
Subroutine __ANON__: not called CC=1 SCAR=6.9
652 0 ▶ $c2 = pop @old // do {
Condition0%0/3
pop @old // do { flush_unknown($c1, @old); last }
l!l&&r!l&&!r
000
MC/DC0%0/2
pop @old // do { flush_unknown($c1, @old); last }
pop @old do { flush_unknown($c1, @old); last }
Truth table0%0/3
A // B
A= pop @oldB= do { flush_unknown($c1, @old); last }
ABresult
1X1
011
000
653 0 flush_unknown($c1, @old);
654 0 last;
655 };
656  
657 0 ▶ my @new = read_until { /^>>>>>>>\h*+(.*)/ } *DIFF;
Subroutine __ANON__: not called CC=1 SCAR=6.9
658 0 ▶ $c4 = pop @new // do {
Condition0%0/3
pop @new // do { flush_unknown($c1, @old, $c2, @new); last }
l!l&&r!l&&!r
000
MC/DC0%0/2
pop @new // do { flush_unknown($c1, @old, $c2, @new); last }
pop @new do { flush_unknown($c1, @old, $c2, @new); last }
Truth table0%0/3
A // B
A= pop @newB= do { flush_unknown($c1, @old, $c2, @new); last }
ABresult
1X1
011
000
659 0 flush_unknown($c1, @old, $c2, @new);
660 0 last;
661 };
662 0 $name{n} = $c4;
663  
664 0 my @mrg;
665 0 ▶ my $mrg = first { $old[$_] =~ /^\Q|||||||\E\h*+(.*)/ } keys @old;
Subroutine __ANON__: not called CC=1 SCAR=6.9
666 0 ▶ if (defined $mrg or $app->parallel > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mrg or $app->parallel > 2) { } 0 0 0
Condition0%0/3
defined $mrg or $app->parallel > 2
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $mrg or $app->parallel > 2
defined $mrg $app->parallel > 2
Truth table0%0/3
A or B
A= defined $mrgB= $app->parallel > 2
ABresult
1X1
011
000
667 0 ▶ if (defined $mrg) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mrg) { } 0 0 0
668 0 $name{m} = $old[$mrg];
669 0 ($c3, @mrg) = splice @old, $mrg;
670 } else {
671 0 $name{m} = $name{o};
672 0 $name{o} = $name{n};
673 0 @mrg = @old;
674 0 @old = @new;
675 }
676 0 s/^/--/ for @old, @mrg;
677 0 s/^/++/ for @new;
678 0 print_command_n({ type => 'FILE' }, @name{qw(o m n)});
679 0 flush_buffer_3([], \@old, \@mrg, \@new);
680 } else {
681 0 s/^/-/ for @old;
682 0 s/^/+/ for @new;
683 0 print_command_n({ type => 'FILE' }, @name{qw(o n)});
684 0 flush_buffer([], \@old, \@new);
685 }
686 }
687 }
688 #
689 # #ifdef custom container
690 #
691 # #ifdef JA ::::::: ja
692 # japanese text japanese text
693 # #endif :::::::
694 # #ifdef EN ::::::: en
695 # english text english text
696 # #endif :::::::
697 #
698 elsif (/^(\#ifdef|:{7,})\h++(.*)/) {
699 COLON:
700 {
701 0 my($c1, $c2, $c3, $c4) = ($_);
702 0 my $start = $1;
703 0 ▶ my $end = $start eq '#ifdef' ? qr/^#endif$/ : qr/^$start$/;
Branch: 1 branch
BranchTrueFalseTotal
$start eq '#ifdef' ? : 0 0 0
704 0 my($m1, $m2) = ($2);
705  
706 0 ▶ my @old = read_until { /$end/ } *DIFF;
Subroutine __ANON__: not called CC=1 SCAR=6.9
707 0 ▶ $c2 = pop @old // do {
Condition0%0/3
pop @old // do { flush_unknown($c1, @old); last }
l!l&&r!l&&!r
000
MC/DC0%0/2
pop @old // do { flush_unknown($c1, @old); last }
pop @old do { flush_unknown($c1, @old); last }
Truth table0%0/3
A // B
A= pop @oldB= do { flush_unknown($c1, @old); last }
ABresult
1X1
011
000
708 0 flush_unknown($c1, @old);
709 0 last;
710 };
711 0 $c3 = <DIFF>;
712 0 ▶ if ($c3 !~ /^${start}\h++(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c3 =~ /^$start\h++(.*)/u) 0 0 0
713 0 flush_unknown($c1, @old, $c2, $c3);
714 0 last;
715 }
716 0 $m2 = $1;
717 0 ▶ my @new = read_until { /$end/ } *DIFF;
Subroutine __ANON__: not called CC=1 SCAR=6.9
718 0 ▶ $c4 = pop @new // do {
Condition0%0/3
pop @new // do { flush_unknown($c1, @old, $c2, $c3, @new); last }
l!l&&r!l&&!r
000
MC/DC0%0/2
pop @new // do { flush_unknown($c1, @old, $c2, $c3, @new); last }
pop @new do { flush_unknown($c1, @old, $c2, $c3, @new); last }
Truth table0%0/3
A // B
A= pop @newB= do { flush_unknown($c1, @old, $c2, $c3, @new); last }
ABresult
1X1
011
000
719 0 flush_unknown($c1, @old, $c2, $c3, @new);
720 0 last;
721 };
722  
723 0 @old = (" $c1", map(s/^/-/r, @old), " $c2");
724 0 @new = (" $c3", map(s/^/+/r, @new), " $c4");
725 0 flush_buffer([], \@old, \@new);
726 }
727 }
728 else {
729 23 flush_unknown($_);
730 }
731 }
732 continue {
733 50 STDOUT->flush;
734 }
735  
736 9 close DIFF;
737 9 ▶my $exit = $DIFF =~ /\|$/ ? $? >> 8 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$DIFF =~ /\|$/u ? : 0 9 9
738  
739 9 ▶if ($readfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($readfile) 0 9 9
740 0 ▶ if ($exit < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exit < 2) 0 0 0
741 0 print_identical(-1);
742 }
743 0 close OLD;
744 0 close NEW;
745 }
746  
747 9 exit($exit > 1);
748  
749 ######################################################################
750  
751 ##
752 ## Convert diff -c output to -u compatible format.
753 ##
754 1 ▶sub merge_diffc {
Subroutine merge_diffc: called CC=20 SCAR=30.0
755 1 my @o = @{+shift};
756 1 my @n = @{+shift};
757 1 for (@o, @n) {
758 28 ▶ s/(?<= ^[ \-\+\!] ) [\t ]//x or die "Format error (-c).\n";
Branch: 1 branch
BranchTrueFalseTotal
s/(?<= ^[ \-\+\!] ) [\t ]//ux or die "Format error (-c). " 28 0 28
759 }
760  
761 1 my @buf;
762 1 ▶ while (@o or @n) {
Branch: 1 branch
BranchTrueFalseTotal
if (@o or @n) 6 1 7
Condition66%2/3
@o or @n
l!l&&r!l&&!r
601
MC/DC50%1/2
@o or @n
@o @n
Truth table66%2/3
A or B
A= @oB= @n
ABresult
1X1
011
000
763  
764 6 push @buf, \( my( @common, @old, @new ) );
765  
766 6 ▶ while (@o and $o[0] =~ /^ /) {
Branch: 1 branch
BranchTrueFalseTotal
if (@o and $o[0] =~ /^ /u) 8 6 14
Condition100%3/3
@o and $o[0] =~ /^ /u
!ll&&!rl&&r
158
MC/DC100%2/2
@o and $o[0] =~ /^ /u
@o $o[0] =~ /^ /u
Truth table100%3/3
A and B
A= @oB= $o[0] =~ /^ /u
ABresult
0X0
100
111
767 8 push @common, shift @o;
768 8 ▶ shift @n if @n;
Branch: 1 branch
BranchTrueFalseTotal
if @n 6 2 8
769 }
770 6 ▶ while (@n and $n[0] =~ /^ /) {
Branch: 1 branch
BranchTrueFalseTotal
if (@n and $n[0] =~ /^ /u) 3 6 9
Condition100%3/3
@n and $n[0] =~ /^ /u
!ll&&!rl&&r
243
MC/DC100%2/2
@n and $n[0] =~ /^ /u
@n $n[0] =~ /^ /u
Truth table100%3/3
A and B
A= @nB= $n[0] =~ /^ /u
ABresult
0X0
100
111
771 3 push @common, shift @n;
772 }
773  
774 6 ▶ push @old, shift @o while @o and $o[0] =~ /^\-/;
Branch: 1 branch
BranchTrueFalseTotal
@o and $o[0] =~ /^\-/u and do { push @old, shift @o } 2 6 8
Condition100%3/3
@o and $o[0] =~ /^\-/u
!ll&&!rl&&r
152
MC/DC100%2/2
@o and $o[0] =~ /^\-/u
@o $o[0] =~ /^\-/u
Truth table100%3/3
A and B
A= @oB= $o[0] =~ /^\-/u
ABresult
0X0
100
111
775 6 ▶ next if @old;
Branch: 1 branch
BranchTrueFalseTotal
if @old 1 5 6
776  
777 5 ▶ push @new, shift @n while @n and $n[0] =~ /^\+/;
Branch: 1 branch
BranchTrueFalseTotal
@n and $n[0] =~ /^\+/u and do { push @new, shift @n } 2 5 7
Condition100%3/3
@n and $n[0] =~ /^\+/u
!ll&&!rl&&r
232
MC/DC100%2/2
@n and $n[0] =~ /^\+/u
@n $n[0] =~ /^\+/u
Truth table100%3/3
A and B
A= @nB= $n[0] =~ /^\+/u
ABresult
0X0
100
111
778 5 ▶ next if @new;
Branch: 1 branch
BranchTrueFalseTotal
if @new 1 4 5
779  
780 4 ▶ push @old, shift @o while @o and $o[0] =~ s/^!/-/;
Branch: 1 branch
BranchTrueFalseTotal
@o and $o[0] =~ s/^!/-/u and do { push @old, shift @o } 4 4 8
Condition100%3/3
@o and $o[0] =~ s/^!/-/u
!ll&&!rl&&r
134
MC/DC100%2/2
@o and $o[0] =~ s/^!/-/u
@o $o[0] =~ s/^!/-/u
Truth table100%3/3
A and B
A= @oB= $o[0] =~ s/^!/-/u
ABresult
0X0
100
111
781 4 ▶ push @new, shift @n while @n and $n[0] =~ s/^!/+/;
Branch: 1 branch
BranchTrueFalseTotal
@n and $n[0] =~ s/^!/+/u and do { push @new, shift @n } 3 4 7
Condition100%3/3
@n and $n[0] =~ s/^!/+/u
!ll&&!rl&&r
223
MC/DC100%2/2
@n and $n[0] =~ s/^!/+/u
@n $n[0] =~ s/^!/+/u
Truth table100%3/3
A and B
A= @nB= $n[0] =~ s/^!/+/u
ABresult
0X0
100
111
782 }
783  
784 1 @buf;
785 }
786  
787 23 ▶sub flush_unknown {
Subroutine flush_unknown: called CC=4 SCAR=17.9
788 23 ▶ if ($app->parallel > 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($app->parallel > 2) { } 0 23 23
elsif ($app->parallel > 1) { } 0 23 23
789 0 flush_buffer_3( [ map s/^/ /r, @_ ] );
790 }
791 elsif ($app->parallel > 1) {
792 0 flush_buffer( [ map s/^/ /r, @_ ] );
793 }
794 else {
795 23 print $painter->('UNKNOWN', $_) for @_;
796 }
797 }
798  
799 16 ▶sub flush_buffer {
Subroutine flush_buffer: called CC=23 SCAR=34.2
800  
801 16 ▶ push @_, [] while @_ % 3;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 3 and do { push @_, [] } 0 16 16
802  
803 16 ▶ if ($app->view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->view) 0 16 16
804 0 @_ = do {
805 0 map { @$_ }
806 0 ▶ reduce {
Subroutine __ANON__: not called CC=1 SCAR=6.9
807 [ [] ,
808 0 [ map { @$_ } $a->[1], $b->[0], $b->[1] ] ,
809 0 [ map { @$_ } $a->[2], $b->[0], $b->[2] ] ] }
810 0 ▶ map { $_ ? [ ( splice @_, 0, 3 ) ] : [ [], [], [] ] }
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
811 0 .. @_ / 3 ;
812 };
813 }
814  
815 16 ▶ while (my($s, $o, $n) = splice @_, 0, 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 3)) 31 16 47
816 31 for (@$s) {
817 32 ▶ s/^(.)// or die;
Branch: 1 branch
BranchTrueFalseTotal
s/^(.)//u or die 32 0 32
818 32 print_column_23($1, $_, $1, $_);
819 32 $oline++;
820 32 $nline++;
821 }
822  
823 31 my $max = $app->limit->{line};
824 31 ▶ my $one_side = !@$o || !@$n;
Condition100%3/3
@$o && @$n
!ll&&!rl&&r
13612
MC/DC100%2/2
@$o && @$n
@$o @$n
Truth table100%3/3
A && B
A= @$oB= @$n
ABresult
0X0
100
111
825 31 my $count = 0;
826 31 ▶ while (@$o or @$n) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$o or @$n) 95 29 124
Condition100%3/3
@$o or @$n
l!l&&r!l&&!r
464929
MC/DC100%2/2
@$o or @$n
@$o @$n
Truth table100%3/3
A or B
A= @$oB= @$n
ABresult
1X1
011
000
827 95 my $old = shift @$o;
828 95 my $new = shift @$n;
829 95 ▶ my $omark = $old ? $old =~ s/^(.)// && $1 : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$old ? : 46 49 95
Condition33%1/3
$old =~ s/^(.)//u and $1
!ll&&!rl&&r
0046
MC/DC0%0/2
$old =~ s/^(.)//u and $1
$old =~ s/^(.)//u $1
Truth table33%1/3
A and B
A= $old =~ s/^(.)//uB= $1
ABresult
0X0
100
111
830 95 ▶ my $nmark = $new ? $new =~ s/^(.)// && $1 : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$new ? : 83 12 95
Condition33%1/3
$new =~ s/^(.)//u and $1
!ll&&!rl&&r
0083
MC/DC0%0/2
$new =~ s/^(.)//u and $1
$new =~ s/^(.)//u $1
Truth table33%1/3
A and B
A= $new =~ s/^(.)//uB= $1
ABresult
0X0
100
111
831  
832 95 print_column_23($omark, $old, $nmark, $new);
833  
834 95 ▶ $oline++ if defined $old;
Branch: 1 branch
BranchTrueFalseTotal
if defined $old 46 49 95
835 95 ▶ $nline++ if defined $new;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new 83 12 95
836  
837 # truncate one-sided (add/delete) section exceeding max lines
838 95 ▶ if ($max and $one_side and ++$count >= $max and @$o + @$n > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max and $one_side and ++$count >= $max and @$o + @$n > 0) 2 93 95
Condition88%8/9
$max and $one_side and ++$count >= $max and @$o + @$n > 0
!ll&&!rl&&r
9302
$max and $one_side and ++$count >= $max
!ll&&!rl&&r
8762
$max and $one_side
!ll&&!rl&&r
67208
MC/DC75%3/4
$max and $one_side and ++$count >= $max and @$o + @$n > 0
$max $one_side ++$count >= $max @$o + @$n > 0
Truth table80%4/5
A and B and C and D
A= $maxB= $one_sideC= ++$count >= $maxD= @$o + @$n > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
839 2 my $rest = @$o + @$n;
840 2 my $msg = $painter->(
841 'NOTICE',
842 sprintf "... %d lines omitted ...\n", $rest,
843 );
844 # show message on the side that has content
845 # suppress line number by localizing $oline/$nline
846 {
847 2 local($oline, $nline) = (undef, undef);
848 2 ▶ if (@$n) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$n) { } 2 0 2
849 2 print_column_23(' ', undef, ' ', $msg);
850 } else {
851 0 print_column_23(' ', $msg, ' ', undef);
852 }
853 }
854 # advance line counter past omitted lines
855 2 ▶ $oline += $rest if !@$n;
Branch: 1 branch
BranchTrueFalseTotal
unless @$n 0 2 2
856 2 ▶ $nline += $rest if !@$o;
Branch: 1 branch
BranchTrueFalseTotal
unless @$o 2 0 2
857 2 last;
858 }
859 }
860 }
861 }
862  
863 0 ▶sub flush_buffer_3 {
Subroutine flush_buffer_3: not called CC=16 SCAR=56.1
864  
865 0 ▶ push @_, [] while @_ % 4;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 4 and do { push @_, [] } 0 0 0
866  
867 0 ▶ if ($app->view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app->view) 0 0 0
868 0 @_ = do {
869 0 map { @$_ }
870 0 ▶ reduce {
Subroutine __ANON__: not called CC=1 SCAR=6.9
871 [ [] ,
872 0 [ map { @$_ } $a->[1], $b->[0], $b->[1] ] ,
873 0 [ map { @$_ } $a->[2], $b->[0], $b->[2] ] ,
874 0 [ map { @$_ } $a->[3], $b->[0], $b->[3] ] ] }
875 0 ▶ map { $_ ? [ splice @_, 0, 4 ] : [ [], [], [], [] ] }
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
876 0 .. @_ / 4;
877 };
878 }
879  
880 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
881 0 my @d = splice @_, 0, 4;
882  
883 0 for my $common (@{shift @d}) {
884 0 $common =~ s/^ //;
885 0 print_column_23(' ', $common, ' ', $common, ' ', $common);
886 0 $oline++;
887 0 $nline++;
888 0 $mline++;
889 }
890  
891 0 ▶ while (first { @$_ > 0 } @d) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&first(sub { @$_ > 0; } , @d)) 0 0 0
892 0 my $old = shift @{$d[0]};
893 0 my $new = shift @{$d[1]};
894 0 my $mrg = shift @{$d[2]};
895 0 ▶ my $om = $old ? $old =~ s/^(?|(\-).| (\+)|( ) )// && $1 : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$old ? : 0 0 0
Condition0%0/3
$old =~ s/^(?|(\-).| (\+)|( ) )//u and $1
!ll&&!rl&&r
000
MC/DC0%0/2
$old =~ s/^(?|(\-).| (\+)|( ) )//u and $1
$old =~ s/^(?|(\-).| (\+)|( ) )//u $1
Truth table0%0/3
A and B
A= $old =~ s/^(?|(\-).| (\+)|( ) )//uB= $1
ABresult
0X0
100
111
896 0 ▶ my $nm = $new ? $new =~ s/^(?|.(\-)|(\+) |( ) )// && $1 : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$new ? : 0 0 0
Condition0%0/3
$new =~ s/^(?|.(\-)|(\+) |( ) )//u and $1
!ll&&!rl&&r
000
MC/DC0%0/2
$new =~ s/^(?|.(\-)|(\+) |( ) )//u and $1
$new =~ s/^(?|.(\-)|(\+) |( ) )//u $1
Truth table0%0/3
A and B
A= $new =~ s/^(?|.(\-)|(\+) |( ) )//uB= $1
ABresult
0X0
100
111
897 0 ▶ my $mm = $mrg ? $mrg =~ s/^(?|(\+).|.(\+)|( ) )// && $1 : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$mrg ? : 0 0 0
Condition0%0/3
$mrg =~ s/^(?|(\+).|.(\+)|( ) )//u and $1
!ll&&!rl&&r
000
MC/DC0%0/2
$mrg =~ s/^(?|(\+).|.(\+)|( ) )//u and $1
$mrg =~ s/^(?|(\+).|.(\+)|( ) )//u $1
Truth table0%0/3
A and B
A= $mrg =~ s/^(?|(\+).|.(\+)|( ) )//uB= $1
ABresult
0X0
100
111
898  
899 0 print_column_23($om, $old, $nm, $new, $mm, $mrg);
900  
901 0 ▶ $oline++ if defined $old;
Branch: 1 branch
BranchTrueFalseTotal
if defined $old 0 0 0
902 0 ▶ $nline++ if defined $new;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new 0 0 0
903 0 ▶ $mline++ if defined $mrg;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mrg 0 0 0
904 }
905 }
906 }
907  
908 0 ▶sub print_identical {
Subroutine print_identical: not called CC=4 SCAR=30.0
909 0 my $n = shift;
910 0 ▶ while ($n--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n--) 0 0 0
911 0 my $old = <OLD>;
912 0 my $new = <NEW>;
913 0 ▶ defined $old or defined $new or last;
Branch: 1 branch
BranchTrueFalseTotal
defined $old or defined $new or last 0 0 0
Condition0%0/3
defined $old or defined $new
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $old or defined $new
defined $old defined $new
Truth table0%0/3
A or B
A= defined $oldB= defined $new
ABresult
1X1
011
000
914 0 print_column_23(' ', $old, ' ', $new);
915 0 $oline++;
916 0 $nline++;
917 0 $mline++;
918 }
919 }
920  
921 0 ▶sub linenum {
Subroutine linenum: not called CC=2 SCAR=17.9
922 0 my $n = shift;
923 0 ▶ defined $n ? (sprintf $num_format, $n) : (' ' x $app->digit);
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 0 0 0
924 }
925  
926 129 ▶sub print_column_23 {
Subroutine print_column_23: called CC=35 SCAR=43.7
927 129 my $column = @_ / 2;
928 129 my $width = column_width $column;
929 129 my($omark, $old, $nmark, $new, $mmark, $mrg) = @_;
930 129 my $print_number = $app->number;
931  
932 129 my($onum, $nnum, $mnum) = ('', '', '');
933 129 ▶ my $nspace = $print_number ? ' ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$print_number ? : 0 129 129
934 129 ▶ if (defined $old) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) 78 51 129
935 78 $old =~ s/\R\z//;
936 78 ▶ $onum = linenum($oline) if $print_number;
Branch: 1 branch
BranchTrueFalseTotal
if $print_number 0 78 78
937 }
938 129 ▶ if (defined $new) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) 117 12 129
939 117 $new =~ s/\R\z//;
940 117 ▶ $nnum = linenum($nline) if $print_number;
Branch: 1 branch
BranchTrueFalseTotal
if $print_number 0 117 117
941 }
942 129 ▶ if (defined $mrg) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mrg) 0 129 129
943 0 $mrg =~ s/\R\z//;
944 0 ▶ $mnum = linenum($mline) if $print_number;
Branch: 1 branch
BranchTrueFalseTotal
if $print_number 0 0 0
945 }
946  
947 # truncate long lines before processing
948 129 ▶ if (my $max = $app->limit->{length}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $max = $app->limit->{"length"}) 128 1 129
949 128 for ($old, $new, $mrg) {
950 384 ▶ defined and length > $max or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ > $max or next 1 383 384
Condition100%3/3
defined $_ and length $_ > $max
!ll&&!rl&&r
1901931
MC/DC100%2/2
defined $_ and length $_ > $max
defined $_ length $_ > $max
Truth table100%3/3
A and B
A= defined $_B= length $_ > $max
ABresult
0X0
100
111
951 1 state $fold = Text::ANSI::Fold->new;
952 1 my $orig_len = length;
953 1 ($_, undef) = $fold->fold($_, width => $max);
954 1 my $truncated = $orig_len - length;
955 1 $_ .= $painter->('NOTICE',
956 sprintf " ... %d characters omitted ...", $truncated);
957 }
958 }
959  
960 129 ▶ my($OTEXT, $OLINE, $OMARK) =
Branch: 1 branch
BranchTrueFalseTotal
$omark =~ /\S/u ? : 46 83 129
961 $omark =~ /\S/ ? qw(OTEXT OLINE OMARK) : qw(UTEXT OULINE OUMARK);
962 129 ▶ my($NTEXT, $NLINE, $NMARK) =
Branch: 1 branch
BranchTrueFalseTotal
$nmark =~ /\S/u ? : 83 46 129
963 $nmark =~ /\S/ ? qw(NTEXT NLINE NMARK) : qw(UTEXT NULINE NUMARK);
964 129 ▶ my($MTEXT, $MLINE, $MMARK) =
Branch: 2 branches
BranchTrueFalseTotal
if $column >= 3 0 129 129
$mmark =~ /\S/u ? : 0 0 0
965 $mmark =~ /\S/ ? qw(MTEXT MLINE MMARK) : qw(UTEXT NULINE NUMARK)
966 if $column >= 3;
967  
968 129 while (1) {
969 135 (my $o, $old) = ansi_fold($old,
970 max(1, $width - length($onum . $nspace)),
971 @boundary);
972 135 (my $n, $new) = ansi_fold($new,
973 max(1, $width - length($nnum . $nspace)),
974 @boundary);
975 135 ▶ (my $m, $mrg) = ansi_fold($mrg,
Branch: 1 branch
BranchTrueFalseTotal
if $column >= 3 0 135 135
976 max(1, $width - length($mnum . $nspace)),
977 @boundary)
978 if $column >= 3;
979  
980 135 my @f;
981 135 $f[0]{MARK} = $painter->($OMARK, $omark);
982 135 ▶ $f[0]{LINE} = $painter->($OLINE, $onum) . $nspace if $print_number;
Branch: 1 branch
BranchTrueFalseTotal
if $print_number 0 135 135
983 135 ▶ $f[0]{TEXT} = $painter->($OTEXT, $o) if $o ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $o ne "" 135 0 135
984 135 $f[1]{MARK} = $painter->($NMARK, $nmark);
985 135 ▶ $f[1]{LINE} = $painter->($NLINE, $nnum) . $nspace if $print_number;
Branch: 1 branch
BranchTrueFalseTotal
if $print_number 0 135 135
986 135 ▶ $f[1]{TEXT} = $painter->($NTEXT, $n) if $n ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $n ne "" 135 0 135
987 135 ▶ if ($column >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($column >= 3) 0 135 135
988 0 $f[2]{MARK} = $painter->($MMARK, $mmark);
989 0 ▶ $f[2]{LINE} = $painter->($MLINE, $mnum) . $nspace if $print_number;
Branch: 1 branch
BranchTrueFalseTotal
if $print_number 0 0 0
990 0 ▶ $f[2]{TEXT} = $painter->($MTEXT, $m) if $m ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $m ne "" 0 0 0
991 }
992 135 print_field_n(@f);
993  
994 135 ▶ last if $app->truncate;
Branch: 1 branch
BranchTrueFalseTotal
if $app->truncate 0 135 135
995 135 ▶ last unless $old ne '' or $new ne '' or ($mrg and $mrg ne '');
Branch: 1 branch
BranchTrueFalseTotal
unless $old ne "" or $new ne "" or $mrg and $mrg ne "" 129 6 135
Condition55%5/9
$old ne "" or $new ne "" or $mrg and $mrg ne ""
l!l&&r!l&&!r
60129
$old ne "" or $new ne ""
l!l&&r!l&&!r
06129
$mrg and $mrg ne ""
!ll&&!rl&&r
12900
MC/DC25%1/4
$old ne "" or $new ne "" or $mrg and $mrg ne ""
$old ne "" $new ne "" $mrg $mrg ne ""
Truth table40%2/5
A or B or C and D
A= $old ne ""B= $new ne ""C= $mrgD= $mrg ne ""
ABCDresult
1XXX1
01XX1
00111
000X0
00100
996  
997 6 ▶ if ($print_number) {
Branch: 1 branch
BranchTrueFalseTotal
if ($print_number) 0 6 6
998 0 $onum =~ s/./ /g;
999 0 $nnum =~ s/./ /g;
1000 0 ▶ $mnum =~ s/./ /g if $column >= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $column >= 3 0 0 0
1001 }
1002 6 ▶ $omark = $old ne '' ? '.' : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$old ne '' ? : 0 6 6
1003 6 ▶ $nmark = $new ne '' ? '.' : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$new ne '' ? : 6 0 6
1004 6 ▶ $mmark = $mrg ne '' ? '.' : ' ' if $column >= 3;
Branch: 2 branches
BranchTrueFalseTotal
if $column >= 3 0 6 6
$mrg ne '' ? : 0 0 0
1005 }
1006 }
1007  
1008 27 ▶sub print_command_n {
Subroutine print_command_n: called CC=10 SCAR=23.3
1009 27 ▶ my $opt = ref $_[0] ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 21 6 27
1010 27 my $column = @_;
1011 27 my $width = column_width $column;
1012 27 my @f;
1013  
1014 27 ▶ $opt->{type} //= 'COMMAND';
Condition100%2/2
$opt->{"type"} //= "COMMAND"
l!l
216
MC/DC100%1/1
$opt->{"type"} //= "COMMAND"
$opt->{"type"}
Truth table100%2/2
A
A= $opt->{"type"}
Aresult
11
00
1015  
1016 27 ▶ $app->command or return if $opt->{type} eq 'COMMAND';
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"type"} eq "COMMAND" 16 11 27
Condition60%3/5
$opt->{'type'} eq 'COMMAND' && ($app->command || (return))
!ll
11160
$app->command or return
l!l
160
MC/DC0%0/2
$opt->{'type'} eq 'COMMAND' && ($app->command || (return))
$opt->{'type'} eq 'COMMAND' $app->command
Truth table33%1/3
A && B
A= $opt->{'type'} eq 'COMMAND'B= $app->command
ABresult
0X0
100
111
1017 27 ▶ $app->filename or return if $opt->{type} eq 'FILE';
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"type"} eq "FILE" 11 16 27
Condition60%3/5
$opt->{'type'} eq 'FILE' && ($app->filename || (return))
!ll
16110
$app->filename or return
l!l
110
MC/DC0%0/2
$opt->{'type'} eq 'FILE' && ($app->filename || (return))
$opt->{'type'} eq 'FILE' $app->filename
Truth table33%1/3
A && B
A= $opt->{'type'} eq 'FILE'B= $app->filename
ABresult
0X0
100
111
1018  
1019 27 my @color = map { $_ . $opt->{type} } "O", "N", "M";
1020  
1021 27 for my $i (keys @_) {
1022 54 local $_ = $_[$i];
1023 54 ▶ chomp if defined;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ 54 0 54
1024 54 ($_) = ansi_fold($_, $width);
1025 54 my %f;
1026 54 ▶ my $color = $i < @color ? $color[$i] : $color[-1];
Branch: 1 branch
BranchTrueFalseTotal
$i < @color ? : 54 0 54
1027 54 $f{TEXT} = $painter->($color, $_);
1028 54 $f{MARK} = ' ';
1029 54 push @f, \%f;
1030 }
1031  
1032 27 print_field_n(@f);
1033 }
1034  
1035 162 ▶sub print_field_n {
Subroutine print_field_n: called CC=10 SCAR=25.5
1036 162 ▶ if (@column >= @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@column >= @_) 0 162 162
1037 0 @_ = @_[ @column[ keys @_ ] ];
1038 }
1039 162 ▶ while (my($i, $f) = each @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @_) 324 162 486
1040 324 ▶ my $markpos = $i < @markpos ? $markpos[$i] : $markpos[-1];
Branch: 1 branch
BranchTrueFalseTotal
$i < @markpos ? : 324 0 324
1041 324 local $_;
1042 324 ▶ $_ = $f->{"MARK"} and print if $markpos eq LEFT;
Branch: 1 branch
BranchTrueFalseTotal
if $markpos eq "left" 162 162 324
Condition50%3/6
$markpos eq 'left' && (($_ = $f->{'MARK'}) && print($_))
!ll
1621620
$_ = $f->{"MARK"} and print $_
!ll
01620
MC/DC0%0/3
$markpos eq 'left' && (($_ = $f->{'MARK'}) && print($_))
$markpos eq 'left' $_ = $f->{"MARK"} print $_
Truth table0%0/4
A && B and C
A= $markpos eq 'left'B= $_ = $f->{"MARK"}C= print $_
ABCresult
0XX0
10X0
1100
1111
1043 324 ▶ $_ = $f->{"LINE"} and print;
Branch: 1 branch
BranchTrueFalseTotal
$_ = $f->{"LINE"} and print $_ 0 324 324
1044 324 ▶ $_ = $f->{"TEXT"} and print;
Branch: 1 branch
BranchTrueFalseTotal
$_ = $f->{"TEXT"} and print $_ 324 0 324
1045 324 ▶ $_ = $f->{"MARK"} and print if $markpos eq RIGHT;
Branch: 1 branch
BranchTrueFalseTotal
if $markpos eq "right" 162 162 324
Condition50%3/6
$markpos eq 'right' && (($_ = $f->{'MARK'}) && print($_))
!ll
1621620
$_ = $f->{"MARK"} and print $_
!ll
01620
MC/DC0%0/3
$markpos eq 'right' && (($_ = $f->{'MARK'}) && print($_))
$markpos eq 'right' $_ = $f->{"MARK"} print $_
Truth table0%0/4
A && B and C
A= $markpos eq 'right'B= $_ = $f->{"MARK"}C= print $_
ABCresult
0XX0
10X0
1100
1111
1046 }
1047 162 print "\n";
1048 }
1049  
1050 __END__
↑ Summary blib/lib/App/cdif/Command.pm »