blib/lib/Langertha/Holmgang/Shell/Filter.pm

filter: Statementstmt 73.6% 591 / 802 Branchbran 65.6% 415 / 632 Conditioncond 56.2% 216 / 384 MC/DCmcdc 36.1% 78 / 216 Subroutinesub 87.8% 58 / 66 Podpod 100% 1 / 1 totaltotal 64.6% 1359 / 2101 CC 794 SCAR 51.4
CC
794
Cov
67%
filter_output
540.0
filter_output
540.0
_cut
109.6
CRAP 170.8
« blib/lib/Langertha/Holmgang/Sim/Linux/Pki.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux.pm »
1 package Langertha::Holmgang::Shell::Filter;
2 # ABSTRACT: The text filters behind a pipe — grep, head, tail, wc, sort, uniq, cut, awk, tr, fold
3  
4 84 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 84 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 84 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 84 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 84 our $VERSION = '0.001';
11  
12  
13 # cut -d X -f N[,M|N-M] | cut -c N-M
14 3 ▶sub _cut {
Subroutine _cut: called CC=19 SCAR=47.0
15 0 ▶ my ( $lines, @a ) = @_;
Subroutine _cut: not called CC=19 SCAR=47.0
16 0 my ( $d, $f, $c ) = ("\t");
17 0 ▶ while (@a) {
Branch: 2 branches
BranchTrueFalseTotal
if (@a) 5 3 8
if (@a) 0 0 0
18 0 my $x = shift @a;
19 0 ▶ if ( $x =~ /\A-d(.+)\z/s ) { $d = $1 }
Branch: 12 branches
BranchTrueFalseTotal
if ($x =~ /\A-d(.+)\z/s) { } 2 3 5
elsif ($x eq '-d') { } 0 3 3
elsif ($x =~ /\A-f(.+)\z/) { } 2 1 3
elsif ($x eq '-f') { } 0 1 1
elsif ($x =~ /\A-c(.+)\z/) { } 1 0 1
elsif ($x eq '-c') { } 0 0 0
if ($x =~ /\A-d(.+)\z/s) { } 0 0 0
elsif ($x eq '-d') { } 0 0 0
elsif ($x =~ /\A-f(.+)\z/) { } 0 0 0
elsif ($x eq '-f') { } 0 0 0
elsif ($x =~ /\A-c(.+)\z/) { } 0 0 0
elsif ($x eq '-c') { } 0 0 0
20 0 elsif ( $x eq '-d' ) { $d = shift @a }
21 0 elsif ( $x =~ /\A-f(.+)\z/ ) { $f = $1 }
22 0 elsif ( $x eq '-f' ) { $f = shift @a }
23 0 elsif ( $x =~ /\A-c(.+)\z/ ) { $c = $1 }
24 0 elsif ( $x eq '-c' ) { $c = shift @a }
25 }
26 0 ▶ my $spec = $f // $c // return ( 'cut: you must specify a list of bytes, characters, or fields', 0 );
Condition30%3/10
($f // $c) // (return "cut: you must specify a list of bytes, characters, or fields", 0)
l!l
30
$f // $c
l!l&&r!l&&!r
210
($f // $c) // (return "cut: you must specify a list of bytes, characters, or fields", 0)
l!l
00
$f // $c
l!l&&r!l&&!r
000
MC/DC0%0/2
($f // $c) // (return "cut: you must specify a list of bytes, characters, or fields", 0)
$f $c
MC/DC0%0/2
($f // $c) // (return "cut: you must specify a list of bytes, characters, or fields", 0)
$f $c
Truth table66%2/3
A // B
A= $fB= $c
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $fB= $c
ABresult
1X1
011
000
27 0 my @want;
28 0 for my $p ( split /,/, $spec ) {
29 0 ▶ my ( $from, $to ) = $p =~ /\A(\d*)(?:-(\d*))?\z/ or return ( "cut: invalid field value '$p'", 0 );
Branch: 2 branches
BranchTrueFalseTotal
() = $p =~ /\A(\d*)(?:-(\d*))?\z/ or return "cut: invalid field value '${p}'", 0 3 0 3
() = $p =~ /\A(\d*)(?:-(\d*))?\z/ or return "cut: invalid field value '${p}'", 0 0 0 0
30 0 ▶ $from = 1 if $from eq '';
Branch: 2 branches
BranchTrueFalseTotal
if $from eq "" 0 3 3
if $from eq "" 0 0 0
31 0 ▶ push @want, [ $from, defined $2 ? ( $to eq '' ? 1e9 : $to ) : $from ];
Branch: 4 branches
BranchTrueFalseTotal
defined $2 ? : 1 2 3
$to eq '' ? : 0 1 1
defined $2 ? : 0 0 0
$to eq '' ? : 0 0 0
32 }
33 0 my @out;
34 0 for my $l (@$lines) {
35 0 ▶ if ( defined $c ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $c) 1 3 4
if (defined $c) 0 0 0
36 0 push @out, join '', map { substr( $l, $_->[0] - 1, $_->[1] - $_->[0] + 1 ) } @want;
37 0 next;
38 }
39 0 ▶ if ( index( $l, $d ) < 0 ) { push @out, $l; next }
Branch: 2 branches
BranchTrueFalseTotal
if (index($l, $d) == -1) 0 3 3
if (index($l, $d) == -1) 0 0 0
40 0 my @fld = split /\Q$d\E/, $l, -1;
41 0 ▶ push @out, join $d, map { my $w = $_; grep { defined } @fld[ ( $w->[0] - 1 ) .. ( $w->[1] > @fld ? $#fld : $w->[1] - 1 ) ] } @want;
Branch: 2 branches
BranchTrueFalseTotal
$w->[1] > @fld ? : 0 3 3
$w->[1] > @fld ? : 0 0 0
42 }
43 0 return ( join( "\n", @out ), 1 );
44 }
45  
46 # awk: die gaengigen Einzeiler — [-F sep] '[BEGIN {…}] [muster] { anweisungen } [END {…}]'
47 # mit Rechnen (+ - * / %), Variablen und Feldern (Arrays a[k]), Zuweisungen (= += -= *= /=
48 # %= ++ --), if/else, for (k in a), print/printf, length, int, substr, tolower, toupper;
49 # was darueber hinausgeht (andere Funktionen, Umleitungen, getline), ist eine Luecke (undef)
50 # statt einer stillen Leerstelle.
51 51 ▶sub _awk {
Subroutine _awk: called CC=42 SCAR=45.6
52 0 ▶ my ( $lines, @a ) = @_;
Subroutine _awk: not called CC=42 SCAR=45.6
53 0 my ( $sep, $prog, %var, %arr );
54 0 ▶ while (@a) {
Branch: 2 branches
BranchTrueFalseTotal
if (@a) 75 51 126
if (@a) 0 0 0
55 0 my $x = shift @a;
56 0 ▶ if ( $x =~ /\A-F(.+)\z/s ) { $sep = $1 }
Branch: 8 branches
BranchTrueFalseTotal
if ($x =~ /\A-F(.+)\z/s) { } 22 53 75
elsif ($x eq '-F') { } 1 52 53
elsif ($x eq '-v') { } 1 51 52
elsif (not defined $prog) { } 51 0 51
if ($x =~ /\A-F(.+)\z/s) { } 0 0 0
elsif ($x eq '-F') { } 0 0 0
elsif ($x eq '-v') { } 0 0 0
elsif (not defined $prog) { } 0 0 0
57 0 elsif ( $x eq '-F' ) { $sep = shift @a }
58 0 ▶ elsif ( $x eq '-v' ) { my ( $k, $v ) = ( shift(@a) // '' ) =~ /\A(\w+)=(.*)\z/s or return (undef); $var{$k} = $v }
Branch: 2 branches
BranchTrueFalseTotal
() = (shift @a // "") =~ /\A(\w+)=(.*)\z/s or return undef 1 0 1
() = (shift @a // "") =~ /\A(\w+)=(.*)\z/s or return undef 0 0 0
Condition25%1/4
shift @a // ""
l!l
10
shift @a // ""
l!l
00
MC/DC0%0/1
shift @a // ""
shift @a
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
Truth table0%0/2
A
A= shift @a
Aresult
11
00
59 0 elsif ( !defined $prog ) { $prog = $x }
60 }
61 0 ▶ return ( 'usage: awk [-F fs][-v var=value][prog | -f progfile][file ...]', 0 ) unless defined $prog;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $prog 0 51 51
unless defined $prog 0 0 0
62 0 my $ofs = ' ';
63 # Tokens: Zahlen, Texte, /re/, $, Namen, Operatoren, { } ( ) ; ,
64 0 my @t;
65 0 my $s = $prog;
66 0 my $prev = '';
67 0 ▶ while ( length $s ) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $s) 921 50 971
if (length $s) 0 0 0
68 0 ▶ if ( $s =~ s/\A\s+// ) { next }
Branch: 12 branches
BranchTrueFalseTotal
if ($s =~ s/\A\s+//) { } 291 630 921
elsif ($s =~ s/\A"((?:[^"\\]|\\.)*)"//) { } 25 605 630
elsif (not $prev =~ /\A(?:num|str|name|\)|field)\z/ and $s =~ s(\A/((?:[^/\\]|\\.)*)/)[]) { } 7 598 605
elsif ($s =~ s/\A(\d+(?:\.\d+)?)//) { } 109 489 598
elsif ($s =~ s/\A([A-Za-z_]\w*)//) { } 150 339 489
elsif ($s =~ s(\A(\+\+|--|\+=|-=|\*=|/=|%=|==|!=|<=|>=|!~|&&|\|\||[<>~!\$(){};,=+*/%\[\]-]))[]) { } 338 1 339
if ($s =~ s/\A\s+//) { } 0 0 0
elsif ($s =~ s/\A"((?:[^"\\]|\\.)*)"//) { } 0 0 0
elsif (not $prev =~ /\A(?:num|str|name|\)|field)\z/ and $s =~ s(\A/((?:[^/\\]|\\.)*)/)[]) { } 0 0 0
elsif ($s =~ s/\A(\d+(?:\.\d+)?)//) { } 0 0 0
elsif ($s =~ s/\A([A-Za-z_]\w*)//) { } 0 0 0
elsif ($s =~ s(\A(\+\+|--|\+=|-=|\*=|/=|%=|==|!=|<=|>=|!~|&&|\|\||[<>~!\$(){};,=+*/%\[\]-]))[]) { } 0 0 0
69 0 elsif ( $s =~ s/\A"((?:[^"\\]|\\.)*)"// ) { ( my $v = $1 ) =~ s/\\n/\n/g; $v =~ s/\\t/\t/g; $v =~ s/\\(.)/$1/g; push @t, [ 'str', $v ] }
70 0 ▶ elsif ( $prev !~ /\A(?:num|str|name|\)|field)\z/ && $s =~ s{\A/((?:[^/\\]|\\.)*)/}{} ) { push @t, [ 're', $1 ] }
Condition50%3/6
not $prev =~ /\A(?:num|str|name|\)|field)\z/ and $s =~ s(\A/((?:[^/\\]|\\.)*)/)[]
!ll&&!rl&&r
2893097
not $prev =~ /\A(?:num|str|name|\)|field)\z/ and $s =~ s(\A/((?:[^/\\]|\\.)*)/)[]
!ll&&!rl&&r
000
MC/DC100%2/2
not $prev =~ /\A(?:num|str|name|\)|field)\z/ and $s =~ s(\A/((?:[^/\\]|\\.)*)/)[]
not $prev =~ /\A(?:num|str|name|\)|field)\z/ $s =~ s(\A/((?:[^/\\]|\\.)*)/)[]
MC/DC0%0/2
not $prev =~ /\A(?:num|str|name|\)|field)\z/ and $s =~ s(\A/((?:[^/\\]|\\.)*)/)[]
not $prev =~ /\A(?:num|str|name|\)|field)\z/ $s =~ s(\A/((?:[^/\\]|\\.)*)/)[]
Truth table100%3/3
not(A) and B
A= not $prev =~ /\A(?:num|str|name|\)|field)\z/B= $s =~ s(\A/((?:[^/\\]|\\.)*)/)[]
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not $prev =~ /\A(?:num|str|name|\)|field)\z/B= $s =~ s(\A/((?:[^/\\]|\\.)*)/)[]
ABresult
0X0
100
111
71 0 elsif ( $s =~ s/\A(\d+(?:\.\d+)?)// ) { push @t, [ 'num', $1 ] }
72 0 elsif ( $s =~ s/\A([A-Za-z_]\w*)// ) { push @t, [ 'name', $1 ] }
73 0 elsif ( $s =~ s/\A(\+\+|--|\+=|-=|\*=|\/=|%=|==|!=|<=|>=|!~|&&|\|\||[<>~!\$(){};,=+*\/%\[\]-])// ) { push @t, [ 'op', $1 ] }
74 0 else { return (undef) }
75 0 ▶ $prev = $t[-1][0] eq 'op' ? $t[-1][1] : $t[-1][0];
Branch: 2 branches
BranchTrueFalseTotal
$t[-1][0] eq 'op' ? : 338 291 629
$t[-1][0] eq 'op' ? : 0 0 0
76 0 ▶ $prev = 'field' if $t[-1][0] eq 'num' && @t > 1 && $t[-2][0] eq 'op' && $t[-2][1] eq '$';
Branch: 2 branches
BranchTrueFalseTotal
if $t[-1][0] eq "num" and @t > 1 and $t[-2][0] eq "op" and $t[-2][1] eq "\$" 56 573 629
if $t[-1][0] eq "num" and @t > 1 and $t[-2][0] eq "op" and $t[-2][1] eq "\$" 0 0 0
Condition44%8/18
$t[-1][0] eq "num" and @t > 1 and $t[-2][0] eq "op" and $t[-2][1] eq "\$"
!ll&&!rl&&r
5235056
$t[-1][0] eq "num" and @t > 1 and $t[-2][0] eq "op"
!ll&&!rl&&r
5203106
$t[-1][0] eq "num" and @t > 1
!ll&&!rl&&r
5200109
$t[-1][0] eq "num" and @t > 1 and $t[-2][0] eq "op" and $t[-2][1] eq "\$"
!ll&&!rl&&r
000
$t[-1][0] eq "num" and @t > 1 and $t[-2][0] eq "op"
!ll&&!rl&&r
000
$t[-1][0] eq "num" and @t > 1
!ll&&!rl&&r
000
MC/DC75%3/4
$t[-1][0] eq "num" and @t > 1 and $t[-2][0] eq "op" and $t[-2][1] eq "\$"
$t[-1][0] eq "num" @t > 1 $t[-2][0] eq "op" $t[-2][1] eq "\$"
MC/DC0%0/4
$t[-1][0] eq "num" and @t > 1 and $t[-2][0] eq "op" and $t[-2][1] eq "\$"
$t[-1][0] eq "num" @t > 1 $t[-2][0] eq "op" $t[-2][1] eq "\$"
Truth table80%4/5
A and B and C and D
A= $t[-1][0] eq "num"B= @t > 1C= $t[-2][0] eq "op"D= $t[-2][1] eq "\$"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and C and D
A= $t[-1][0] eq "num"B= @t > 1C= $t[-2][0] eq "op"D= $t[-2][1] eq "\$"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
77 }
78 0 my $i = 0;
79 0 ▶ my $peek = sub { my $k = $t[$i]; $k && ( @_ ? $k->[0] eq 'op' && $k->[1] eq $_[0] : 1 ) };
Subroutine __ANON__: called CC=4 SCAR=14.1
Branch: 2 branches
BranchTrueFalseTotal
$k and @_ ? $k->[0] eq "op" && $k->[1] eq $_[0] : 1 1055 30 1085
@_ ? : 1055 0 1055
Condition100%3/3
$k->[0] eq "op" and $k->[1] eq $_[0]
!ll&&!rl&&r
382347326
MC/DC100%2/2
$k->[0] eq "op" and $k->[1] eq $_[0]
$k->[0] eq "op" $k->[1] eq $_[0]
Truth table100%3/3
A and B
A= $k->[0] eq "op"B= $k->[1] eq $_[0]
ABresult
0X0
100
111
80 0 ▶ my $take = sub { die "awk\n" unless $peek->(@_); $t[ $i++ ] };
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless &$peek(@_) 0 101 101
81 0 my ( $or, $cmp, $prim, $concat, $sum );
82 # Zahlwert wie awk (fuehrende Zahl, sonst 0) und Ausgabe einer Rechnung (OFMT %.6g)
83 0 ▶ my $num = sub { ( $_[0] // '' ) =~ /\A\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)/ ? $1 + 0 : 0 };
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
BranchTrueFalseTotal
($_[0] // '') =~ /\A\s*([-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)/ ? : 106 8 114
Condition50%1/2
$_[0] // ""
l!l
1140
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
84 0 ▶ my $fmt = sub { my ($v) = @_; $v == int($v) && abs($v) < 1e16 ? sprintf( '%d', $v ) : sprintf( '%.6g', $v ) };
Subroutine __ANON__: called CC=3 SCAR=11.3
Branch: 1 branch
BranchTrueFalseTotal
$v == int $v && abs $v < 1e+16 ? : 49 5 54
Condition66%2/3
$v == int $v and abs $v < "1e+16"
!ll&&!rl&&r
5049
MC/DC50%1/2
$v == int $v and abs $v < "1e+16"
$v == int $v abs $v < "1e+16"
Truth table66%2/3
A and B
A= $v == int $vB= abs $v < "1e+16"
ABresult
0X0
100
111
85 # Werte: Zahl oder Text wie awk (strnum: Felder, die wie Zahlen aussehen)
86 178 ▶ $prim = sub {
Subroutine __ANON__: called CC=45 SCAR=44.9
87 178 ▶ my $k = $t[$i] or die "awk\n";
Branch: 1 branch
BranchTrueFalseTotal
my $k = $t[$i] or die "awk\n" 178 0 178
88 178 ▶ if ( $k->[0] eq 'op' && $k->[1] eq '(' ) { $i++; my $e = $or->(); $take->(')'); return $e }
Branch: 1 branch
BranchTrueFalseTotal
if ($k->[0] eq "op" and $k->[1] eq "(") 3 175 178
Condition100%3/3
$k->[0] eq "op" and $k->[1] eq "("
!ll&&!rl&&r
118573
MC/DC100%2/2
$k->[0] eq "op" and $k->[1] eq "("
$k->[0] eq "op" $k->[1] eq "("
Truth table100%3/3
A and B
A= $k->[0] eq "op"B= $k->[1] eq "("
ABresult
0X0
100
111
89 175 ▶ if ( $k->[0] eq 'op' && $k->[1] eq '!' ) { $i++; my $e = $prim->(); return sub { $e->(@_) ? 0 : 1 } }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 2 branches
BranchTrueFalseTotal
if ($k->[0] eq "op" and $k->[1] eq "!") 1 174 175
&$e(@_) ? : 1 3 4
Condition100%3/3
$k->[0] eq "op" and $k->[1] eq "!"
!ll&&!rl&&r
118561
MC/DC100%2/2
$k->[0] eq "op" and $k->[1] eq "!"
$k->[0] eq "op" $k->[1] eq "!"
Truth table100%3/3
A and B
A= $k->[0] eq "op"B= $k->[1] eq "!"
ABresult
0X0
100
111
90 0 ▶ if ( $k->[0] eq 'op' && $k->[1] eq '-' ) { $i++; my $e = $prim->(); return sub { $fmt->( -$num->( $e->(@_) ) ) } }
Subroutine __ANON__: not called CC=1 SCAR=2.0
Branch: 1 branch
BranchTrueFalseTotal
if ($k->[0] eq "op" and $k->[1] eq "-") 0 174 174
Condition66%2/3
$k->[0] eq "op" and $k->[1] eq "-"
!ll&&!rl&&r
118560
MC/DC0%0/2
$k->[0] eq "op" and $k->[1] eq "-"
$k->[0] eq "op" $k->[1] eq "-"
Truth table66%2/3
A and B
A= $k->[0] eq "op"B= $k->[1] eq "-"
ABresult
0X0
100
111
91 174 ▶ if ( $k->[0] eq 'op' && $k->[1] eq '$' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k->[0] eq "op" and $k->[1] eq "\$") 56 118 174
Condition66%2/3
$k->[0] eq "op" and $k->[1] eq "\$"
!ll&&!rl&&r
118056
MC/DC50%1/2
$k->[0] eq "op" and $k->[1] eq "\$"
$k->[0] eq "op" $k->[1] eq "\$"
Truth table66%2/3
A and B
A= $k->[0] eq "op"B= $k->[1] eq "\$"
ABresult
0X0
100
111
92 56 $i++;
93 56 ▶ my $n = $t[$i] or die "awk\n";
Branch: 1 branch
BranchTrueFalseTotal
my $n = $t[$i] or die "awk\n" 56 0 56
94 56 ▶ if ( $n->[0] eq 'num' ) { $i++; my $f = $n->[1]; return sub { $f == 0 ? $_[0] : $_[1][ $f - 1 ] // '' } }
Subroutine __ANON__: called CC=3 SCAR=11.2
Branch: 2 branches
BranchTrueFalseTotal
if ($n->[0] eq "num") 54 2 56
$f == 0 ? : 0 140 140
Condition50%1/2
$_[1][$f - 1] // ""
l!l
1400
MC/DC0%0/1
$_[1][$f - 1] // ""
$_[1][$f - 1]
Truth table50%1/2
A
A= $_[1][$f - 1]
Aresult
11
00
95 2 ▶ if ( $n->[0] eq 'name' && $n->[1] eq 'NF' ) { $i++; return sub { $_[1][-1] // '' } }
Subroutine __ANON__: called CC=2 SCAR=7.8
Branch: 1 branch
BranchTrueFalseTotal
if ($n->[0] eq "name" and $n->[1] eq "NF") 2 0 2
Condition40%2/5
$n->[0] eq "name" and $n->[1] eq "NF"
!ll&&!rl&&r
002
$_[1][-1] // ""
l!l
90
MC/DC0%0/2
$n->[0] eq "name" and $n->[1] eq "NF"
$n->[0] eq "name" $n->[1] eq "NF"
MC/DC0%0/1
$_[1][-1] // ""
$_[1][-1]
Truth table33%1/3
A and B
A= $n->[0] eq "name"B= $n->[1] eq "NF"
ABresult
0X0
100
111
Truth table50%1/2
A
A= $_[1][-1]
Aresult
11
00
96 0 ▶ if ( $n->[0] eq 'op' && $n->[1] eq '(' ) { my $e = $prim->(); return sub { my $f = int $num->( $e->(@_) ); $f == 0 ? $_[0] : $f < 0 ? '' : $_[1][ $f - 1 ] // '' } }
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
if ($n->[0] eq "op" and $n->[1] eq "(") 0 0 0
$f == 0 ? : 0 0 0
$f < 0 ? : 0 0 0
Condition0%0/5
$n->[0] eq "op" and $n->[1] eq "("
!ll&&!rl&&r
000
$_[1][$f - 1] // ""
l!l
00
MC/DC0%0/2
$n->[0] eq "op" and $n->[1] eq "("
$n->[0] eq "op" $n->[1] eq "("
MC/DC0%0/1
$_[1][$f - 1] // ""
$_[1][$f - 1]
Truth table0%0/3
A and B
A= $n->[0] eq "op"B= $n->[1] eq "("
ABresult
0X0
100
111
Truth table0%0/2
A
A= $_[1][$f - 1]
Aresult
11
00
97 0 die "awk\n";
98 }
99 118 $i++;
100 118 ▶ return sub { $k->[1] } if $k->[0] eq 'num' || $k->[0] eq 'str';
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $k->[0] eq "num" or $k->[0] eq "str" 74 44 118
Condition100%3/3
$k->[0] eq "num" or $k->[0] eq "str"
l!l&&r!l&&!r
532144
MC/DC100%2/2
$k->[0] eq "num" or $k->[0] eq "str"
$k->[0] eq "num" $k->[0] eq "str"
Truth table100%3/3
A or B
A= $k->[0] eq "num"B= $k->[0] eq "str"
ABresult
1X1
011
000
101 44 ▶ if ( $k->[0] eq 're' ) { my $re = eval { qr/$k->[1]/ } // die "awk\n"; return sub { $_[0] =~ $re ? 1 : 0 } }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 2 branches
BranchTrueFalseTotal
if ($k->[0] eq "re") 3 41 44
$_[0] =~ /$re/ ? : 3 5 8
Condition50%1/2
eval { do { qr/$k->[1]/ } } // die("awk\n")
l!l
30
MC/DC0%0/1
eval { do { qr/$k->[1]/ } } // die("awk\n")
eval { do { qr/$k->[1]/ } }
Truth table50%1/2
A
A= eval { do { qr/$k->[1]/ } }
Aresult
11
00
102 41 ▶ if ( $k->[0] eq 'name' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k->[0] eq "name") 41 0 41
103 41 my $n = $k->[1];
104 41 ▶ return sub { $_[2] } if $n eq 'NR' || $n eq 'FNR';
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "NR" or $n eq "FNR" 13 28 41
Condition66%2/3
$n eq "NR" or $n eq "FNR"
l!l&&r!l&&!r
13028
MC/DC50%1/2
$n eq "NR" or $n eq "FNR"
$n eq "NR" $n eq "FNR"
Truth table66%2/3
A or B
A= $n eq "NR"B= $n eq "FNR"
ABresult
1X1
011
000
105 28 ▶ return sub { scalar @{ $_[1] } } if $n eq 'NF';
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "NF" 1 27 28
106 27 ▶ if ( $n eq 'length' ) { # length, length(), length(ausdruck), length(array)
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "length") 6 21 27
107 6 ▶ return sub { length $_[0] } unless $peek->('(');
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless &$peek("(") 1 5 6
108 5 $i++;
109 5 ▶ if ( $peek->(')') ) { $i++; return sub { length $_[0] } }
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek(")")) 1 4 5
110 4 ▶ my $an = $t[$i][0] eq 'name' && $t[ $i + 1 ] && $t[ $i + 1 ][1] eq ')' ? $t[$i][1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$t[$i][0] eq 'name' && $t[$i + 1] && $t[$i + 1][1] eq ')' ? : 0 4 4
Condition33%2/6
$t[$i][0] eq "name" and $t[$i + 1] and $t[$i + 1][1] eq ")"
!ll&&!rl&&r
400
$t[$i][0] eq "name" and $t[$i + 1]
!ll&&!rl&&r
400
MC/DC0%0/3
$t[$i][0] eq "name" and $t[$i + 1] and $t[$i + 1][1] eq ")"
$t[$i][0] eq "name" $t[$i + 1] $t[$i + 1][1] eq ")"
Truth table25%1/4
A and B and C
A= $t[$i][0] eq "name"B= $t[$i + 1]C= $t[$i + 1][1] eq ")"
ABCresult
0XX0
10X0
1100
1111
111 4 my $e = $or->();
112 4 $take->(')');
113 0 ▶ return sub { defined $an && $arr{$an} ? scalar keys %{ $arr{$an} } : length $e->(@_) };
Subroutine __ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
defined $an && $arr{$an} ? : 0 7 7
Condition33%1/3
defined $an and $arr{$an}
!ll&&!rl&&r
700
MC/DC0%0/2
defined $an and $arr{$an}
defined $an $arr{$an}
Truth table33%1/3
A and B
A= defined $anB= $arr{$an}
ABresult
0X0
100
111
114 }
115 21 ▶ if ( $n =~ /\A(?:int|tolower|toupper|substr)\z/ && $peek->('(') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /\A(?:int|tolower|toupper|substr)\z/ and &$peek("(")) 3 18 21
Condition66%2/3
$n =~ /\A(?:int|tolower|toupper|substr)\z/ and &$peek("(")
!ll&&!rl&&r
1803
MC/DC50%1/2
$n =~ /\A(?:int|tolower|toupper|substr)\z/ and &$peek("(")
$n =~ /\A(?:int|tolower|toupper|substr)\z/ &$peek("(")
Truth table66%2/3
A and B
A= $n =~ /\A(?:int|tolower|toupper|substr)\z/B= &$peek("(")
ABresult
0X0
100
111
116 3 $i++;
117 3 my @p = ( $or->() );
118 3 ▶ while ( $peek->(',') ) { $i++; push @p, $or->() }
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek(",")) 2 3 5
119 3 $take->(')');
120 3 ▶ return sub { int $num->( $p[0]->(@_) ) } if $n eq 'int' && @p == 1;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "int" and @p == 1 1 2 3
Condition66%2/3
$n eq "int" and @p == 1
!ll&&!rl&&r
201
MC/DC50%1/2
$n eq "int" and @p == 1
$n eq "int" @p == 1
Truth table66%2/3
A and B
A= $n eq "int"B= @p == 1
ABresult
0X0
100
111
121 0 ▶ return sub { lc $p[0]->(@_) } if $n eq 'tolower' && @p == 1;
Subroutine __ANON__: not called CC=1 SCAR=1.7
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "tolower" and @p == 1 0 2 2
Condition33%1/3
$n eq "tolower" and @p == 1
!ll&&!rl&&r
200
MC/DC0%0/2
$n eq "tolower" and @p == 1
$n eq "tolower" @p == 1
Truth table33%1/3
A and B
A= $n eq "tolower"B= @p == 1
ABresult
0X0
100
111
122 2 ▶ return sub { uc $p[0]->(@_) } if $n eq 'toupper' && @p == 1;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "toupper" and @p == 1 1 1 2
Condition66%2/3
$n eq "toupper" and @p == 1
!ll&&!rl&&r
101
MC/DC50%1/2
$n eq "toupper" and @p == 1
$n eq "toupper" @p == 1
Truth table66%2/3
A and B
A= $n eq "toupper"B= @p == 1
ABresult
0X0
100
111
123 1 ▶ if ( $n eq 'substr' && ( @p == 2 || @p == 3 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "substr" and @p == 2 || @p == 3) 1 0 1
Condition33%2/6
$n eq "substr" and @p == 2 || @p == 3
!ll&&!rl&&r
001
@p == 2 or @p == 3
l!l&&r!l&&!r
010
MC/DC0%0/3
$n eq "substr" and @p == 2 || @p == 3
$n eq "substr" @p == 2 @p == 3
Truth table25%1/4
A and B or C
A= $n eq "substr"B= @p == 2C= @p == 3
ABCresult
0XX0
1000
11X1
1011
124 4 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=19.9
125 4 ▶ my ( $str, $m ) = ( $p[0]->(@_) // '', int( $num->( $p[1]->(@_) ) + 0.5 ) );
Condition50%1/2
$p[0]->(@_) // ""
l!l
40
MC/DC0%0/1
$p[0]->(@_) // ""
$p[0]->(@_)
Truth table50%1/2
A
A= $p[0]->(@_)
Aresult
11
00
126 4 ▶ my $len = @p == 3 ? int( $num->( $p[2]->(@_) ) + 0.5 ) : length($str) + 1;
Branch: 1 branch
BranchTrueFalseTotal
@p == 3 ? : 4 0 4
127 4 ▶ my ( $from, $to ) = ( $m < 1 ? 1 : $m, $m + $len - 1 ); # wie POSIX awk: 1-basiert, gekappt
Branch: 1 branch
BranchTrueFalseTotal
$m < 1 ? : 0 4 4
128 4 ▶ $to = length $str if $to > length $str;
Branch: 1 branch
BranchTrueFalseTotal
if $to > length $str 0 4 4
129 4 ▶ return $to < $from ? '' : substr( $str, $from - 1, $to - $from + 1 );
Branch: 1 branch
BranchTrueFalseTotal
$to < $from ? : 0 4 4
130 1 };
131 }
132 0 die "awk\n";
133 }
134 18 ▶ die "awk\n" if $peek->('(') || $n =~ /\A(?:getline|in|if|else|for|while|do|next|exit|function|return|delete|BEGIN|END)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if &$peek("(") or $n =~ /\A(?:getline|in|if|else|for|while|do|next|exit|function|return|delete|BEGIN|END)\z/ 2 16 18
Condition66%2/3
&$peek("(") or $n =~ /\A(?:getline|in|if|else|for|while|do|next|exit|function|return|delete|BEGIN|END)\z/
l!l&&r!l&&!r
2016
MC/DC50%1/2
&$peek("(") or $n =~ /\A(?:getline|in|if|else|for|while|do|next|exit|function|return|delete|BEGIN|END)\z/
&$peek("(") $n =~ /\A(?:getline|in|if|else|for|while|do|next|exit|function|return|delete|BEGIN|END)\z/
Truth table66%2/3
A or B
A= &$peek("(")B= $n =~ /\A(?:getline|in|if|else|for|while|do|next|exit|function|return|delete|BEGIN|END)\z/
ABresult
1X1
011
000
135 16 ▶ if ( $peek->('[') ) { # Array-Element
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek("[")) 2 14 16
136 2 $i++;
137 2 my $ke = $or->();
138 2 $take->(']');
139 2 ▶ return sub { my $key = $ke->(@_); ( $arr{$n} || {} )->{$key} // '' };
Subroutine __ANON__: called CC=3 SCAR=11.7
Condition50%2/4
+($arr{$n} || {})->{$key} // ""
l!l
30
$arr{$n} || {}
l!l
30
MC/DC0%0/1
+($arr{$n} || {})->{$key} // ""
$arr{$n}
Truth table50%1/2
A
A= $arr{$n}
Aresult
11
00
140 }
141 14 ▶ return sub { $var{$n} // '' }; # nicht gesetzt: "" bzw. 0 wie awk
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$var{$n} // ""
l!l
164
MC/DC100%1/1
$var{$n} // ""
$var{$n}
Truth table100%2/2
A
A= $var{$n}
Aresult
11
00
142 }
143 0 die "awk\n";
144 0 };
145 0 ▶ my $isnum = sub { defined $_[0] && $_[0] =~ /\A\s*[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?\s*\z/ };
Subroutine __ANON__: called CC=2 SCAR=8.1
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and $_[0] =~ /\A\s*[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?\s*\z/ 132 0 132
146 # Rechnen: * / % vor + -
147 159 ▶ my $prod = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
148 159 my $l = $prim->();
149 157 ▶ while ( my $k = $t[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $k = $t[$i]) 174 1 175
150 174 ▶ last unless $k->[0] eq 'op' && $k->[1] =~ m{\A[*/%]\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $k->[0] eq "op" and $k->[1] =~ m[\A[*/%]\z] 156 18 174
Condition100%3/3
$k->[0] eq "op" and $k->[1] =~ m[\A[*/%]\z]
!ll&&!rl&&r
814818
MC/DC100%2/2
$k->[0] eq "op" and $k->[1] =~ m[\A[*/%]\z]
$k->[0] eq "op" $k->[1] =~ m[\A[*/%]\z]
Truth table100%3/3
A and B
A= $k->[0] eq "op"B= $k->[1] =~ m[\A[*/%]\z]
ABresult
0X0
100
111
151 18 $i++;
152 18 my ( $op, $a, $b ) = ( $k->[1], $l, $prim->() );
153 27 ▶ $l = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
154 27 my ( $x, $y ) = ( $num->( $a->(@_) ), $num->( $b->(@_) ) );
155 27 ▶ die "awk: cmd. line:1: fatal: division by zero attempted\n" if $op ne '*' && $y == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $op ne "*" and $y == 0 1 26 27
Condition100%3/3
$op ne "*" and $y == 0
!ll&&!rl&&r
11151
MC/DC100%2/2
$op ne "*" and $y == 0
$op ne "*" $y == 0
Truth table100%3/3
A and B
A= $op ne "*"B= $y == 0
ABresult
0X0
100
111
156 26 ▶ $fmt->( $op eq '*' ? $x * $y : $op eq '/' ? $x / $y : $x - $y * int( $x / $y ) );
Branch: 2 branches
BranchTrueFalseTotal
$op eq '*' ? : 11 15 26
$op eq '/' ? : 12 3 15
157 18 };
158 }
159 157 return $l;
160 0 };
161 154 ▶ $sum = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
162 154 my $l = $prod->();
163 152 ▶ while ( my $k = $t[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $k = $t[$i]) 156 1 157
164 156 ▶ last unless $k->[0] eq 'op' && $k->[1] =~ /\A[+-]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k->[0] eq "op" and $k->[1] =~ /\A[+-]\z/ 151 5 156
Condition100%3/3
$k->[0] eq "op" and $k->[1] =~ /\A[+-]\z/
!ll&&!rl&&r
81435
MC/DC100%2/2
$k->[0] eq "op" and $k->[1] =~ /\A[+-]\z/
$k->[0] eq "op" $k->[1] =~ /\A[+-]\z/
Truth table100%3/3
A and B
A= $k->[0] eq "op"B= $k->[1] =~ /\A[+-]\z/
ABresult
0X0
100
111
165 5 $i++;
166 5 my ( $op, $a, $b ) = ( $k->[1], $l, $prod->() );
167 5 ▶ $l = sub { my ( $x, $y ) = ( $num->( $a->(@_) ), $num->( $b->(@_) ) ); $fmt->( $op eq '+' ? $x + $y : $x - $y ) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$op eq '+' ? : 7 3 10
168 }
169 152 return $l;
170 0 };
171 146 ▶ $concat = sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
172 146 my @e = ( $sum->() );
173 144 ▶ while ( my $k = $t[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $k = $t[$i]) 151 1 152
174 151 ▶ last if $k->[0] eq 'op' && $k->[1] !~ /\A[\$(]\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $k->[0] eq "op" and not $k->[1] =~ /\A[\$(]\z/ 141 10 151
Condition100%3/3
$k->[0] eq "op" and not $k->[1] =~ /\A[\$(]\z/
!ll&&!rl&&r
82141
MC/DC100%2/2
$k->[0] eq "op" and not $k->[1] =~ /\A[\$(]\z/
$k->[0] eq "op" not $k->[1] =~ /\A[\$(]\z/
Truth table100%3/3
A and not(B)
A= $k->[0] eq "op"B= not $k->[1] =~ /\A[\$(]\z/
ABresult
0X0
100
111
175 10 ▶ last if $k->[0] eq 'name' && $k->[1] =~ /\A(?:print|printf|in|if|else|for|while)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $k->[0] eq "name" and $k->[1] =~ /\A(?:print|printf|in|if|else|for|while)\z/ 2 8 10
Condition100%3/3
$k->[0] eq "name" and $k->[1] =~ /\A(?:print|printf|in|if|else|for|while)\z/
!ll&&!rl&&r
712
MC/DC100%2/2
$k->[0] eq "name" and $k->[1] =~ /\A(?:print|printf|in|if|else|for|while)\z/
$k->[0] eq "name" $k->[1] =~ /\A(?:print|printf|in|if|else|for|while)\z/
Truth table100%3/3
A and B
A= $k->[0] eq "name"B= $k->[1] =~ /\A(?:print|printf|in|if|else|for|while)\z/
ABresult
0X0
100
111
176 8 ▶ last if $k->[0] eq 'op' && $k->[1] =~ /\A(?:\+\+|--|\+=|-=|\*=|\/=|%=|=|\])\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $k->[0] eq "op" and $k->[1] =~ m(\A(?:\+\+|--|\+=|-=|\*=|/=|%=|=|\])\z) 0 8 8
Condition66%2/3
$k->[0] eq "op" and $k->[1] =~ m(\A(?:\+\+|--|\+=|-=|\*=|/=|%=|=|\])\z)
!ll&&!rl&&r
620
MC/DC0%0/2
$k->[0] eq "op" and $k->[1] =~ m(\A(?:\+\+|--|\+=|-=|\*=|/=|%=|=|\])\z)
$k->[0] eq "op" $k->[1] =~ m(\A(?:\+\+|--|\+=|-=|\*=|/=|%=|=|\])\z)
Truth table66%2/3
A and B
A= $k->[0] eq "op"B= $k->[1] =~ m(\A(?:\+\+|--|\+=|-=|\*=|/=|%=|=|\])\z)
ABresult
0X0
100
111
177 8 push @e, $sum->();
178 }
179 144 ▶ return $e[0] if @e == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @e == 1 138 6 144
180 6 ▶ return sub { my @x = @_; join '', map { $_->(@x) } @e };
Subroutine __ANON__: called CC=1 SCAR=0.0
181 0 };
182 57 ▶ $cmp = sub {
Subroutine __ANON__: called CC=13 SCAR=27.2
183 57 my $l = $concat->();
184 57 ▶ if ( $t[$i] && $t[$i][0] eq 'name' && $t[$i][1] eq 'in' ) { # (schluessel in array)
Branch: 1 branch
BranchTrueFalseTotal
if ($t[$i] and $t[$i][0] eq "name" and $t[$i][1] eq "in") 2 55 57
Condition66%4/6
$t[$i] and $t[$i][0] eq "name" and $t[$i][1] eq "in"
!ll&&!rl&&r
5502
$t[$i] and $t[$i][0] eq "name"
!ll&&!rl&&r
0552
MC/DC33%1/3
$t[$i] and $t[$i][0] eq "name" and $t[$i][1] eq "in"
$t[$i] $t[$i][0] eq "name" $t[$i][1] eq "in"
Truth table50%2/4
A and B and C
A= $t[$i]B= $t[$i][0] eq "name"C= $t[$i][1] eq "in"
ABCresult
0XX0
10X0
1100
1111
185 2 $i++;
186 2 ▶ my $an = ( $t[ $i++ ] // die "awk\n" )->[1];
Condition50%1/2
$t[$i++] // die("awk\n")
l!l
20
MC/DC0%0/1
$t[$i++] // die("awk\n")
$t[$i++]
Truth table50%1/2
A
A= $t[$i++]
Aresult
11
00
187 2 ▶ return sub { exists( ( $arr{$an} || {} )->{ $l->(@_) } ) ? 1 : 0 };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
exists(($arr{$an} || {})->{&$l(@_)}) ? : 1 1 2
Condition100%2/2
$arr{$an} || {}
l!l
11
MC/DC100%1/1
$arr{$an} || {}
$arr{$an}
Truth table100%2/2
A
A= $arr{$an}
Aresult
11
00
188 }
189 55 my $k = $t[$i];
190 55 ▶ return $l unless $k && $k->[0] eq 'op' && $k->[1] =~ /\A(?:==|!=|<=|>=|<|>|~|!~)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k and $k->[0] eq "op" and $k->[1] =~ /\A(?:==|!=|<=|>=|<|>|~|!~)\z/ 34 21 55
Condition50%3/6
$k and $k->[0] eq "op" and $k->[1] =~ /\A(?:==|!=|<=|>=|<|>|~|!~)\z/
!ll&&!rl&&r
03421
$k and $k->[0] eq "op"
!ll&&!rl&&r
0055
MC/DC33%1/3
$k and $k->[0] eq "op" and $k->[1] =~ /\A(?:==|!=|<=|>=|<|>|~|!~)\z/
$k $k->[0] eq "op" $k->[1] =~ /\A(?:==|!=|<=|>=|<|>|~|!~)\z/
Truth table50%2/4
A and B and C
A= $kB= $k->[0] eq "op"C= $k->[1] =~ /\A(?:==|!=|<=|>=|<|>|~|!~)\z/
ABCresult
0XX0
10X0
1100
1111
191 21 my $op = $k->[1];
192 21 $i++;
193 21 ▶ if ( $op eq '~' || $op eq '!~' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "~" or $op eq "!~") 3 18 21
Condition100%3/3
$op eq "~" or $op eq "!~"
l!l&&r!l&&!r
2118
MC/DC100%2/2
$op eq "~" or $op eq "!~"
$op eq "~" $op eq "!~"
Truth table100%3/3
A or B
A= $op eq "~"B= $op eq "!~"
ABresult
1X1
011
000
194 3 my $r = $t[$i];
195 3 my $re;
196 3 ▶ if ( $r && $r->[0] eq 're' ) { $i++; $re = eval { qr/$r->[1]/ } // die "awk\n" }
Branch: 1 branch
BranchTrueFalseTotal
if ($r and $r->[0] eq 're') { } 3 0 3
Condition40%2/5
$r and $r->[0] eq "re"
!ll&&!rl&&r
003
eval { do { qr/$r->[1]/ } } // die("awk\n")
l!l
30
MC/DC0%0/2
$r and $r->[0] eq "re"
$r $r->[0] eq "re"
MC/DC0%0/1
eval { do { qr/$r->[1]/ } } // die("awk\n")
eval { do { qr/$r->[1]/ } }
Truth table33%1/3
A and B
A= $rB= $r->[0] eq "re"
ABresult
0X0
100
111
Truth table50%1/2
A
A= eval { do { qr/$r->[1]/ } }
Aresult
11
00
197 0 ▶ else { my $e = $concat->(); return sub { my $m = $l->(@_) =~ /${\ $e->(@_)}/ ? 1 : 0; $op eq '~' ? $m : 1 - $m } }
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
&$l(@_) =~ /${\&$e(@_);}/ ? : 0 0 0
$op eq '~' ? : 0 0 0
198 3 ▶ return sub { my $m = $l->(@_) =~ $re ? 1 : 0; $op eq '~' ? $m : 1 - $m };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
&$l(@_) =~ /$re/ ? : 3 8 11
$op eq '~' ? : 8 3 11
199 }
200 18 my $rt = $concat->();
201 68 ▶ return sub {
Subroutine __ANON__: called CC=9 SCAR=22.1
202 68 my ( $x, $y ) = ( $l->(@_), $rt->(@_) );
203 68 ▶ my $c = $isnum->($x) && $isnum->($y) ? ( $x <=> $y ) : ( "$x" cmp "$y" );
Branch: 1 branch
BranchTrueFalseTotal
&$isnum($x) && &$isnum($y) ? : 64 4 68
Condition66%2/3
&$isnum($x) and &$isnum($y)
!ll&&!rl&&r
4064
MC/DC50%1/2
&$isnum($x) and &$isnum($y)
&$isnum($x) &$isnum($y)
Truth table66%2/3
A and B
A= &$isnum($x)B= &$isnum($y)
ABresult
0X0
100
111
204 68 ▶ ( $op eq '==' ? $c == 0 : $op eq '!=' ? $c != 0 : $op eq '<' ? $c < 0 : $op eq '<=' ? $c <= 0 : $op eq '>' ? $c > 0 : $c >= 0 ) ? 1 : 0;
Branch: 6 branches
BranchTrueFalseTotal
($op eq '==' ? $c == 0 : ($op eq '!=' ? $c != 0 : ($op eq '<' ? $c < 0 : ($op eq '<=' ? $c <= 0 : ($op eq '>' ? $c > 0 : $c >= 0))))) ? : 36 32 68
$op eq '==' ? : 27 41 68
$op eq '!=' ? : 0 41 41
$op eq '<' ? : 7 34 41
$op eq '<=' ? : 3 31 34
$op eq '>' ? : 19 12 31
205 18 };
206 0 };
207 53 ▶ my $and = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
208 53 my @e = ( $cmp->() );
209 53 ▶ while ( $peek->('&&') ) { $i++; push @e, $cmp->() }
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek("&&")) 4 53 57
210 53 ▶ return @e == 1 ? $e[0] : sub { for my $f (@e) { return 0 unless $f->(@_) } 1 };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@e == 1 ? : 49 4 53
unless &$f(@_) 7 22 29
211 0 };
212 51 ▶ $or = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
213 51 my @e = ( $and->() );
214 51 ▶ while ( $peek->('||') ) { $i++; push @e, $and->() }
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek("||")) 2 51 53
215 51 ▶ return @e == 1 ? $e[0] : sub { for my $f (@e) { return 1 if $f->(@_) } 0 };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@e == 1 ? : 49 2 51
if &$f(@_) 4 10 14
216 0 };
217 # Anweisungen: print/printf, Zuweisungen (auch a[k], ++/--), if/else, for (k in a), { … };
218 # jede Anweisung ist ein Code, der ihre Ausgabe (Text) liefert
219 25 ▶ my $setv = sub { # Wert setzen: Variable (FS/OFS wirken), Array-Element
Subroutine __ANON__: called CC=4 SCAR=13.9
220 25 my ( $n, $key, $v ) = @_;
221 25 ▶ if ( defined $key ) { $arr{$n}{$key} = $v; return }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 6 19 25
222 19 $var{$n} = $v;
223 19 ▶ $sep = $v if $n eq 'FS';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "FS" 1 18 19
224 19 ▶ $ofs = $v if $n eq 'OFS';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "OFS" 1 18 19
225 0 };
226 0 my ( $stmt, $block );
227 62 ▶ $block = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
228 62 my @st;
229 62 ▶ while ( $t[$i] && !$peek->('}') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t[$i] and not &$peek("}")) 68 57 125
Condition66%2/3
$t[$i] and not &$peek("}")
!ll&&!rl&&r
05768
MC/DC50%1/2
$t[$i] and not &$peek("}")
$t[$i] not &$peek("}")
Truth table66%2/3
A and not(B)
A= $t[$i]B= not &$peek("}")
ABresult
0X0
100
111
230 68 ▶ if ( $peek->(';') ) { $i++; next }
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek(";")) 3 65 68
231 65 push @st, $stmt->();
232 }
233 57 ▶ return sub { my @x = @_; join '', map { $_->(@x) } @st };
Subroutine __ANON__: called CC=1 SCAR=0.0
234 0 };
235 70 ▶ $stmt = sub {
Subroutine __ANON__: called CC=50 SCAR=44.2
236 70 ▶ my $k = $t[$i] or die "awk\n";
Branch: 1 branch
BranchTrueFalseTotal
my $k = $t[$i] or die "awk\n" 70 0 70
237 0 ▶ if ( $peek->('{') ) { $i++; my $b = $block->(); $take->('}'); return $b }
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek("{")) 0 70 70
238 70 ▶ if ( $k->[0] eq 'name' && $k->[1] eq 'if' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k->[0] eq "name" and $k->[1] eq "if") 2 68 70
Condition66%2/3
$k->[0] eq "name" and $k->[1] eq "if"
!ll&&!rl&&r
0682
MC/DC50%1/2
$k->[0] eq "name" and $k->[1] eq "if"
$k->[0] eq "name" $k->[1] eq "if"
Truth table66%2/3
A and B
A= $k->[0] eq "name"B= $k->[1] eq "if"
ABresult
0X0
100
111
239 2 $i++;
240 2 $take->('(');
241 2 my $c = $or->();
242 2 $take->(')');
243 2 ▶ $i++ while $peek->(';');
Branch: 1 branch
BranchTrueFalseTotal
&$peek(";") and do { ++$i } 0 2 2
244 2 my $then = $stmt->();
245 2 my $save = $i;
246 2 ▶ $i++ while $peek->(';');
Branch: 1 branch
BranchTrueFalseTotal
&$peek(";") and do { ++$i } 1 2 3
247 2 my $else;
248 2 ▶ if ( $t[$i] && $t[$i][0] eq 'name' && $t[$i][1] eq 'else' ) { $i++; $else = $stmt->() }
Branch: 1 branch
BranchTrueFalseTotal
if ($t[$i] and $t[$i][0] eq 'name' and $t[$i][1] eq 'else') { } 1 1 2
Condition66%4/6
$t[$i] and $t[$i][0] eq "name" and $t[$i][1] eq "else"
!ll&&!rl&&r
101
$t[$i] and $t[$i][0] eq "name"
!ll&&!rl&&r
011
MC/DC33%1/3
$t[$i] and $t[$i][0] eq "name" and $t[$i][1] eq "else"
$t[$i] $t[$i][0] eq "name" $t[$i][1] eq "else"
Truth table50%2/4
A and B and C
A= $t[$i]B= $t[$i][0] eq "name"C= $t[$i][1] eq "else"
ABCresult
0XX0
10X0
1100
1111
249 1 else { $i = $save }
250 2 ▶ return sub { $c->(@_) ? $then->(@_) : $else ? $else->(@_) : '' };
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 2 branches
BranchTrueFalseTotal
&$c(@_) ? : 3 1 4
$else ? : 1 0 1
251 }
252 68 ▶ if ( $k->[0] eq 'name' && $k->[1] eq 'for' && $t[ $i + 1 ] && $t[ $i + 1 ][1] eq '(' && $t[ $i + 3 ] && $t[ $i + 3 ][1] eq 'in' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k->[0] eq "name" and $k->[1] eq "for" and $t[$i + 1] and $t[$i + 1][1] eq "(" and $t[$i + 3] and $t[$i + 3][1] eq "in") 2 66 68
Condition66%10/15
$k->[0] eq "name" and $k->[1] eq "for" and $t[$i + 1] and $t[$i + 1][1] eq "(" and $t[$i + 3] and $t[$i + 3][1] eq "in"
!ll&&!rl&&r
6602
$k->[0] eq "name" and $k->[1] eq "for" and $t[$i + 1] and $t[$i + 1][1] eq "(" and $t[$i + 3]
!ll&&!rl&&r
6602
$k->[0] eq "name" and $k->[1] eq "for" and $t[$i + 1] and $t[$i + 1][1] eq "("
!ll&&!rl&&r
6602
$k->[0] eq "name" and $k->[1] eq "for" and $t[$i + 1]
!ll&&!rl&&r
6602
$k->[0] eq "name" and $k->[1] eq "for"
!ll&&!rl&&r
0662
MC/DC16%1/6
$k->[0] eq "name" and $k->[1] eq "for" and $t[$i + 1] and $t[$i + 1][1] eq "(" and $t[$i + 3] and $t[$i + 3][1] eq "in"
$k->[0] eq "name" $k->[1] eq "for" $t[$i + 1] $t[$i + 1][1] eq "(" $t[$i + 3] $t[$i + 3][1] eq "in"
Truth table28%2/7
A and B and C and D and E and F
A= $k->[0] eq "name"B= $k->[1] eq "for"C= $t[$i + 1]D= $t[$i + 1][1] eq "("E= $t[$i + 3]F= $t[$i + 3][1] eq "in"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
253 2 $i += 2;
254 2 my $kv = $t[ $i++ ][1];
255 2 $i++;
256 2 ▶ my $an = ( $t[ $i++ ] // die "awk\n" )->[1];
Condition50%1/2
$t[$i++] // die("awk\n")
l!l
20
MC/DC0%0/1
$t[$i++] // die("awk\n")
$t[$i++]
Truth table50%1/2
A
A= $t[$i++]
Aresult
11
00
257 2 $take->(')');
258 2 ▶ $i++ while $peek->(';');
Branch: 1 branch
BranchTrueFalseTotal
&$peek(";") and do { ++$i } 0 2 2
259 2 my $body = $stmt->();
260 2 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
261 2 my @x = @_;
262 2 ▶ my @keys = keys %{ $arr{$an} || {} };
Condition50%1/2
$arr{$an} || {}
l!l
20
MC/DC0%0/1
$arr{$an} || {}
$arr{$an}
Truth table50%1/2
A
A= $arr{$an}
Aresult
11
00
263 0 ▶ @keys = ( grep { !/\A-?\d+(?:\.\d+)?\z/ } @keys ) ? sort @keys : sort { $a <=> $b } @keys;
Branch: 1 branch
BranchTrueFalseTotal
grep({not /\A-?\d+(?:\.\d+)?\z/;} @keys) ? : 2 0 2
264 2 my $o = '';
265 2 for my $key (@keys) { $var{$kv} = $key; $o .= $body->(@x) }
266 2 return $o;
267 2 };
268 }
269 66 ▶ if ( $k->[0] eq 'name' && $k->[1] =~ /\A(?:print|printf)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k->[0] eq "name" and $k->[1] =~ /\A(?:print|printf)\z/) 50 16 66
Condition66%2/3
$k->[0] eq "name" and $k->[1] =~ /\A(?:print|printf)\z/
!ll&&!rl&&r
01650
MC/DC50%1/2
$k->[0] eq "name" and $k->[1] =~ /\A(?:print|printf)\z/
$k->[0] eq "name" $k->[1] =~ /\A(?:print|printf)\z/
Truth table66%2/3
A and B
A= $k->[0] eq "name"B= $k->[1] =~ /\A(?:print|printf)\z/
ABresult
0X0
100
111
270 50 $i++;
271 50 my @items;
272 50 my $at = $i;
273 50 ▶ if ( $peek->('(') ) { # print( a, b ) / printf( fmt, … )
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek("(")) 2 48 50
274 2 $i++;
275 2 ▶ my @p = eval { my @x = ( $or->() ); while ( $peek->(',') ) { $i++; push @x, $or->() } $take->(')'); @x };
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek(",")) 1 2 3
276 2 ▶ if ( @p && ( !$t[$i] || $peek->(';') || $peek->('}') ) ) { @items = @p } else { $i = $at }
Branch: 1 branch
BranchTrueFalseTotal
if (@p and !$t[$i] || &$peek(';') || &$peek('}')) { } 1 1 2
Condition55%5/9
@p and !$t[$i] || &$peek(";") || &$peek("}")
!ll&&!rl&&r
011
not $t[$i] or &$peek(";") or &$peek("}")
l!l&&r!l&&!r
011
not $t[$i] or &$peek(";")
l!l&&r!l&&!r
002
MC/DC25%1/4
@p and !$t[$i] || &$peek(";") || &$peek("}")
@p not $t[$i] &$peek(";") &$peek("}")
Truth table40%2/5
A and not(B) or C or D
A= @pB= not $t[$i]C= &$peek(";")D= &$peek("}")
ABCDresult
0XXX0
10000
11XX1
101X1
10011
277 }
278 50 ▶ if ( !@items && $t[$i] && !$peek->(';') && !$peek->('}') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @items and $t[$i] and not &$peek(";") and not &$peek("}")) 48 2 50
Condition77%7/9
not @items and $t[$i] and not &$peek(";") and not &$peek("}")
!ll&&!rl&&r
1148
not @items and $t[$i] and not &$peek(";")
!ll&&!rl&&r
1049
not @items and $t[$i]
!ll&&!rl&&r
1049
MC/DC50%2/4
not @items and $t[$i] and not &$peek(";") and not &$peek("}")
not @items $t[$i] not &$peek(";") not &$peek("}")
Truth table60%3/5
not(A) and B and not(C) and not(D)
A= not @itemsB= $t[$i]C= not &$peek(";")D= not &$peek("}")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
279 48 push @items, $concat->();
280 46 ▶ while ( $peek->(',') ) { $i++; push @items, $concat->() }
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek(",")) 23 46 69
281 }
282 48 ▶ die "awk\n" if $t[$i] && !$peek->(';') && !$peek->('}') && !( $t[$i][0] eq 'name' && $t[$i][1] eq 'else' ); # print > datei, print | befehl
Branch: 1 branch
BranchTrueFalseTotal
if $t[$i] and not &$peek(";") and not &$peek("}") and not $t[$i][0] eq "name" && $t[$i][1] eq "else" 1 47 48
Condition50%6/12
$t[$i] and not &$peek(";") and not &$peek("}") and not $t[$i][0] eq "name" && $t[$i][1] eq "else"
!ll&&!rl&&r
4701
$t[$i] and not &$peek(";") and not &$peek("}")
!ll&&!rl&&r
0471
$t[$i] and not &$peek(";")
!ll&&!rl&&r
0048
$t[$i][0] eq 'name' && $t[$i][1] eq 'else'
!ll&&!rl&&r
100
MC/DC20%1/5
$t[$i] and not &$peek(";") and not &$peek("}") and not $t[$i][0] eq "name" && $t[$i][1] eq "else"
$t[$i] not &$peek(";") not &$peek("}") $t[$i][0] eq 'name' $t[$i][1] eq 'else'
Truth table33%2/6
A and not(B) and not(C) and not(D && E)
A= $t[$i]B= not &$peek(";")C= not &$peek("}")D= $t[$i][0] eq 'name'E= $t[$i][1] eq 'else'
ABCDEresult
0XXXX0
10XXX0
110XX0
111110
1110X1
111101
283 47 my $how = $k->[1];
284 87 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
285 87 my @x = @_;
286 87 my @v = map { $_->(@x) } @items;
287 86 ▶ return sprintf( shift(@v) // '', @v ) if $how eq 'printf';
Branch: 1 branch
BranchTrueFalseTotal
if $how eq "printf" 11 75 86
Condition50%1/2
shift @v // ""
l!l
110
MC/DC0%0/1
shift @v // ""
shift @v
Truth table50%1/2
A
A= shift @v
Aresult
11
00
288 75 ▶ return @v ? join( $ofs, @v ) . "\n" : "$x[0]\n";
Branch: 1 branch
BranchTrueFalseTotal
@v ? : 73 2 75
289 47 };
290 }
291 # Zuweisung: [++|--]name[[k]] [= += -= *= /= %= ++ --] ausdruck
292 16 my $pre;
293 0 ▶ if ( $peek->('++') || $peek->('--') ) { $pre = $t[ $i++ ][1] }
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek("++") or &$peek("--")) 0 16 16
Condition33%1/3
&$peek("++") or &$peek("--")
l!l&&r!l&&!r
0016
MC/DC0%0/2
&$peek("++") or &$peek("--")
&$peek("++") &$peek("--")
Truth table33%1/3
A or B
A= &$peek("++")B= &$peek("--")
ABresult
1X1
011
000
294 16 my $n = $t[$i];
295 16 ▶ die "awk\n" unless $n && $n->[0] eq 'name' && $n->[1] !~ /\A(?:NR|NF|FNR|getline|next|exit|delete|while|do|function|return)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $n and $n->[0] eq "name" and not $n->[1] =~ /\A(?:NR|NF|FNR|getline|next|exit|delete|while|do|function|return)\z/ 1 15 16
Condition50%3/6
$n and $n->[0] eq "name" and not $n->[1] =~ /\A(?:NR|NF|FNR|getline|next|exit|delete|while|do|function|return)\z/
!ll&&!rl&&r
0115
$n and $n->[0] eq "name"
!ll&&!rl&&r
0016
MC/DC33%1/3
$n and $n->[0] eq "name" and not $n->[1] =~ /\A(?:NR|NF|FNR|getline|next|exit|delete|while|do|function|return)\z/
$n $n->[0] eq "name" not $n->[1] =~ /\A(?:NR|NF|FNR|getline|next|exit|delete|while|do|function|return)\z/
Truth table50%2/4
A and B and not(C)
A= $nB= $n->[0] eq "name"C= not $n->[1] =~ /\A(?:NR|NF|FNR|getline|next|exit|delete|while|do|function|return)\z/
ABCresult
0XX0
10X0
1100
1111
296 15 $i++;
297 15 my $ke;
298 15 ▶ if ( $peek->('[') ) { $i++; $ke = $or->(); $take->(']') }
Branch: 1 branch
BranchTrueFalseTotal
if (&$peek("[")) 3 12 15
299 15 my $name = $n->[1];
300 15 ▶ my $get = sub { my $key = shift; defined $key ? ( $arr{$name} || {} )->{$key} // '' : $var{$name} // '' };
Subroutine __ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
defined $key ? : 5 13 18
Condition100%6/6
+($arr{$name} || {})->{$key} // ""
l!l
23
$arr{$name} || {}
l!l
32
$var{$name} // ""
l!l
85
MC/DC100%1/1
+($arr{$name} || {})->{$key} // ""
$arr{$name}
MC/DC100%1/1
$var{$name} // ""
$var{$name}
Truth table100%2/2
A
A= $arr{$name}
Aresult
11
00
Truth table100%2/2
A
A= $var{$name}
Aresult
11
00
301 0 ▶ if ($pre) { my $d = $pre eq '++' ? 1 : -1; return sub { my $key = $ke ? $ke->(@_) : undef; $setv->( $name, $key, $fmt->( $num->( $get->($key) ) + $d ) ); '' } }
Subroutine __ANON__: not called CC=2 SCAR=14.6
Branch: 3 branches
BranchTrueFalseTotal
if ($pre) 0 15 15
$pre eq '++' ? : 0 0 0
$ke ? : 0 0 0
302 15 ▶ my $op = $t[$i] && $t[$i][0] eq 'op' ? $t[$i][1] : '';
Branch: 1 branch
BranchTrueFalseTotal
$t[$i] && $t[$i][0] eq 'op' ? : 15 0 15
Condition33%1/3
$t[$i] and $t[$i][0] eq "op"
!ll&&!rl&&r
0015
MC/DC0%0/2
$t[$i] and $t[$i][0] eq "op"
$t[$i] $t[$i][0] eq "op"
Truth table33%1/3
A and B
A= $t[$i]B= $t[$i][0] eq "op"
ABresult
0X0
100
111
303 15 ▶ if ( $op eq '++' || $op eq '--' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "++" or $op eq "--") 3 12 15
Condition66%2/3
$op eq "++" or $op eq "--"
l!l&&r!l&&!r
3012
MC/DC50%1/2
$op eq "++" or $op eq "--"
$op eq "++" $op eq "--"
Truth table66%2/3
A or B
A= $op eq "++"B= $op eq "--"
ABresult
1X1
011
000
304 3 $i++;
305 3 ▶ my $d = $op eq '++' ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$op eq '++' ? : 3 0 3
306 3 ▶ return sub { my $key = $ke ? $ke->(@_) : undef; $setv->( $name, $key, $fmt->( $num->( $get->($key) ) + $d ) ); '' };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$ke ? : 2 3 5
307 }
308 12 ▶ die "awk\n" unless $op =~ /\A(?:=|\+=|-=|\*=|\/=|%=)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $op =~ m[\A(?:=|\+=|-=|\*=|/=|%=)\z] 1 11 12
309 11 $i++;
310 11 my $e = $or->();
311 20 ▶ return sub {
Subroutine __ANON__: called CC=10 SCAR=25.9
312 20 ▶ my $key = $ke ? $ke->(@_) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ke ? : 4 16 20
313 20 my $v = $e->(@_);
314 20 ▶ if ( $op ne '=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "=") 13 7 20
315 13 my ( $x, $y ) = ( $num->( $get->($key) ), $num->($v) );
316 13 ▶ die "awk: cmd. line:1: fatal: division by zero attempted\n" if ( $op eq '/=' || $op eq '%=' ) && $y == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "/=" || $op eq "%=" and $y == 0 0 13 13
Condition33%2/6
$op eq "/=" || $op eq "%=" and $y == 0
!ll&&!rl&&r
1300
$op eq "/=" or $op eq "%="
l!l&&r!l&&!r
0013
MC/DC0%0/3
$op eq "/=" || $op eq "%=" and $y == 0
$op eq "/=" $op eq "%=" $y == 0
Truth table20%1/5
A or B and C
A= $op eq "/="B= $op eq "%="C= $y == 0
ABCresult
00X0
1X00
0100
1X11
0111
317 13 ▶ $v = $fmt->( $op eq '+=' ? $x + $y : $op eq '-=' ? $x - $y : $op eq '*=' ? $x * $y : $op eq '/=' ? $x / $y : $x - $y * int( $x / $y ) );
Branch: 4 branches
BranchTrueFalseTotal
$op eq '+=' ? : 12 1 13
$op eq '-=' ? : 0 1 1
$op eq '*=' ? : 1 0 1
$op eq '/=' ? : 0 0 0
318 }
319 20 $setv->( $name, $key, $v );
320 20 '';
321 11 };
322 0 };
323 0 my ( @rules, @begin, @end );
324 0 my $ok = eval {
325 0 ▶ while ( $i < @t ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i < @t) 63 45 108
if ($i < @t) 0 0 0
326 0 ▶ if ( $peek->(';') ) { $i++; next }
Branch: 2 branches
BranchTrueFalseTotal
if (&$peek(";")) 0 63 63
if (&$peek(";")) 0 0 0
327 0 ▶ if ( $t[$i][0] eq 'name' && $t[$i][1] =~ /\A(BEGIN|END)\z/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t[$i][0] eq "name" and $t[$i][1] =~ /\A(BEGIN|END)\z/) 21 42 63
if ($t[$i][0] eq "name" and $t[$i][1] =~ /\A(BEGIN|END)\z/) 0 0 0
Condition50%3/6
$t[$i][0] eq "name" and $t[$i][1] =~ /\A(BEGIN|END)\z/
!ll&&!rl&&r
34821
$t[$i][0] eq "name" and $t[$i][1] =~ /\A(BEGIN|END)\z/
!ll&&!rl&&r
000
MC/DC100%2/2
$t[$i][0] eq "name" and $t[$i][1] =~ /\A(BEGIN|END)\z/
$t[$i][0] eq "name" $t[$i][1] =~ /\A(BEGIN|END)\z/
MC/DC0%0/2
$t[$i][0] eq "name" and $t[$i][1] =~ /\A(BEGIN|END)\z/
$t[$i][0] eq "name" $t[$i][1] =~ /\A(BEGIN|END)\z/
Truth table100%3/3
A and B
A= $t[$i][0] eq "name"B= $t[$i][1] =~ /\A(BEGIN|END)\z/
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $t[$i][0] eq "name"B= $t[$i][1] =~ /\A(BEGIN|END)\z/
ABresult
0X0
100
111
328 0 my $which = $1;
329 0 $i++;
330 0 $take->('{');
331 0 my $b = $block->();
332 0 $take->('}');
333 0 ▶ push @{ $which eq 'BEGIN' ? \@begin : \@end }, $b;
Branch: 2 branches
BranchTrueFalseTotal
$which eq 'BEGIN' ? : 10 11 21
$which eq 'BEGIN' ? : 0 0 0
334 0 next;
335 }
336 0 ▶ my $pat = $peek->('{') ? undef : $or->();
Branch: 2 branches
BranchTrueFalseTotal
&$peek('{') ? : 24 18 42
&$peek('{') ? : 0 0 0
337 0 my $act;
338 0 ▶ if ( $peek->('{') ) { $i++; $act = $block->(); $take->('}') }
Branch: 2 branches
BranchTrueFalseTotal
if (&$peek("{")) 41 1 42
if (&$peek("{")) 0 0 0
339 0 push @rules, [ $pat, $act ];
340 0 ▶ $i++ while $peek->(';');
Branch: 2 branches
BranchTrueFalseTotal
&$peek(";") and do { ++$i } 0 37 37
&$peek(";") and do { ++$i } 0 0 0
341 }
342 0 1;
343 };
344 0 ▶ return (undef) unless $ok;
Branch: 2 branches
BranchTrueFalseTotal
unless $ok 5 45 50
unless $ok 0 0 0
345 0 my $out = '';
346 0 my $nr = 0;
347 0 my ( $last, @lastf ) = ('');
348 0 my $run = eval {
349 0 $out .= join '', map { $_->( '', [], 0 ) } @begin;
350 0 ▶ for my $l ( @rules || @end ? @$lines : () ) { # nur BEGIN: awk liest keine Eingabe
Branch: 2 branches
BranchTrueFalseTotal
@rules || @end ? : 38 6 44
@rules || @end ? : 0 0 0
Condition50%3/6
@rules or @end
l!l&&r!l&&!r
3626
@rules or @end
l!l&&r!l&&!r
000
MC/DC100%2/2
@rules or @end
@rules @end
MC/DC0%0/2
@rules or @end
@rules @end
Truth table100%3/3
A or B
A= @rulesB= @end
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= @rulesB= @end
ABresult
1X1
011
000
351 0 $nr++;
352 0 ▶ my @f = !defined $sep || $sep eq ' ' ? split( ' ', $l ) : length($sep) == 1 ? split( /\Q$sep\E/, $l, -1 ) : split( /$sep/, $l, -1 );
Branch: 4 branches
BranchTrueFalseTotal
!defined($sep) || $sep eq ' ' ? : 48 81 129
length $sep == 1 ? : 81 0 81
!defined($sep) || $sep eq ' ' ? : 0 0 0
length $sep == 1 ? : 0 0 0
Condition33%2/6
not defined $sep or $sep eq " "
l!l&&r!l&&!r
48081
not defined $sep or $sep eq " "
l!l&&r!l&&!r
000
MC/DC50%1/2
not defined $sep or $sep eq " "
not defined $sep $sep eq " "
MC/DC0%0/2
not defined $sep or $sep eq " "
not defined $sep $sep eq " "
Truth table66%2/3
not(A) or B
A= not defined $sepB= $sep eq " "
ABresult
1X1
011
000
Truth table0%0/3
not(A) or B
A= not defined $sepB= $sep eq " "
ABresult
1X1
011
000
353 0 ( $last, @lastf ) = ( $l, @f );
354 0 for my $r (@rules) {
355 0 my ( $pat, $act ) = @$r;
356 0 ▶ next if $pat && !$pat->( $l, \@f, $nr );
Branch: 2 branches
BranchTrueFalseTotal
if $pat and not &$pat($l, \@f, $nr) 36 88 124
if $pat and not &$pat($l, \@f, $nr) 0 0 0
Condition50%3/6
$pat and not &$pat($l, \@f, $nr)
!ll&&!rl&&r
583036
$pat and not &$pat($l, \@f, $nr)
!ll&&!rl&&r
000
MC/DC100%2/2
$pat and not &$pat($l, \@f, $nr)
$pat not &$pat($l, \@f, $nr)
MC/DC0%0/2
$pat and not &$pat($l, \@f, $nr)
$pat not &$pat($l, \@f, $nr)
Truth table100%3/3
A and not(B)
A= $patB= not &$pat($l, \@f, $nr)
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $patB= not &$pat($l, \@f, $nr)
ABresult
0X0
100
111
357 0 ▶ $out .= $act ? $act->( $l, \@f, $nr ) : "$l\n";
Branch: 2 branches
BranchTrueFalseTotal
$act ? : 87 1 88
$act ? : 0 0 0
358 }
359 }
360 0 $out .= join '', map { $_->( $last, \@lastf, $nr ) } @end; # END: der letzte Satz und NR bleiben
361 0 1;
362 };
363 0 ▶ if ( !$run ) { ( my $e = $@ ) =~ s/\s+\z//; return ( $out . $e, 0 ) }
Branch: 2 branches
BranchTrueFalseTotal
unless ($run) 1 44 45
unless ($run) 0 0 0
364 0 $out =~ s/\n\z//;
365 0 return ( $out, 1 );
366 }
367  
368 # tr [-c|-C] [-d] [-s] SATZ1 [SATZ2] wie GNU tr: Escapes, Bereiche a-z, Klassen
369 # [:alpha:] …; SATZ2 wird mit seinem letzten Zeichen aufgefuellt. [=c=] und [c*n]: Luecke.
370 84 my %TR_CLASS = (
371 alpha => qr/[[:alpha:]]/, digit => qr/[0-9]/, alnum => qr/[[:alnum:]]/, upper => qr/[A-Z]/, lower => qr/[a-z]/,
372 space => qr/\s/, blank => qr/[ \t]/, punct => qr/[[:punct:]]/, print => qr/[^\x00-\x1f\x7f]/,
373 graph => qr/[^\x00-\x20\x7f]/, cntrl => qr/[\x00-\x1f\x7f]/, xdigit => qr/[0-9A-Fa-f]/,
374 );
375  
376 8 ▶sub _tr_set {
Subroutine _tr_set: called CC=14 SCAR=28.6
377 8 my ($s) = @_;
378 8 my %esc = ( n => "\n", t => "\t", r => "\r", '\\' => '\\', a => "\a", b => "\b", f => "\f", v => "\x0b" );
379 8 my @c;
380 8 my $i = 0;
381 8 ▶ while ( $i < length $s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $s) 9 8 17
382 9 ▶ if ( substr( $s, $i ) =~ /\A\[:(\w+):\]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($s, $i) =~ /\A\[:(\w+):\]/) 2 7 9
383 2 ▶ my $re = $TR_CLASS{$1} // return;
Condition50%1/2
$TR_CLASS{$1} // (return)
l!l
20
MC/DC0%0/1
$TR_CLASS{$1} // (return)
$TR_CLASS{$1}
Truth table50%1/2
A
A= $TR_CLASS{$1}
Aresult
11
00
384 2 push @c, grep { $_ =~ $re } map { chr } 0 .. 127;
385 2 $i += length "[:$1:]";
386 2 next;
387 }
388 7 ▶ return if substr( $s, $i ) =~ /\A\[(?:=.=|.\*\d*\])/;
Branch: 1 branch
BranchTrueFalseTotal
if substr($s, $i) =~ /\A\[(?:=.=|.\*\d*\])/ 0 7 7
389 7 my $c = substr( $s, $i, 1 );
390 7 ▶ if ( $c eq '\\' && $i + 1 < length $s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq '\\' and $i + 1 < length $s) { } 1 6 7
Condition66%2/3
$c eq "\\" and $i + 1 < length $s
!ll&&!rl&&r
601
MC/DC50%1/2
$c eq "\\" and $i + 1 < length $s
$c eq "\\" $i + 1 < length $s
Truth table66%2/3
A and B
A= $c eq "\\"B= $i + 1 < length $s
ABresult
0X0
100
111
391 1 my $n = substr( $s, $i + 1 );
392 0 ▶ if ( $n =~ /\A([0-7]{1,3})/ ) { $c = chr oct $1; $i += 1 + length $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /\A([0-7]{1,3})/) { } 0 1 1
393 1 ▶ else { $c = $esc{ substr( $n, 0, 1 ) } // substr( $n, 0, 1 ); $i += 2 }
Condition33%1/3
$esc{substr($n, 0, 1)} // substr($n, 0, 1)
l!l&&r!l&&!r
100
MC/DC0%0/2
$esc{substr($n, 0, 1)} // substr($n, 0, 1)
$esc{substr($n, 0, 1)} substr($n, 0, 1)
Truth table33%1/3
A // B
A= $esc{substr($n, 0, 1)}B= substr($n, 0, 1)
ABresult
1X1
011
000
394 }
395 6 else { $i++ }
396 7 ▶ if ( substr( $s, $i, 1 ) eq '-' && $i + 1 < length $s ) { # Bereich
Branch: 1 branch
BranchTrueFalseTotal
if (substr($s, $i, 1) eq "-" and $i + 1 < length $s) 3 4 7
Condition66%2/3
substr($s, $i, 1) eq "-" and $i + 1 < length $s
!ll&&!rl&&r
403
MC/DC50%1/2
substr($s, $i, 1) eq "-" and $i + 1 < length $s
substr($s, $i, 1) eq "-" $i + 1 < length $s
Truth table66%2/3
A and B
A= substr($s, $i, 1) eq "-"B= $i + 1 < length $s
ABresult
0X0
100
111
397 3 my $to = substr( $s, $i + 1, 1 );
398 3 $i += 2;
399 0 ▶ if ( $to eq '\\' ) { my $n = substr( $s, $i, 1 ); $to = $esc{$n} // $n; $i++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq "\\") 0 3 3
Condition0%0/3
$esc{$n} // $n
l!l&&r!l&&!r
000
MC/DC0%0/2
$esc{$n} // $n
$esc{$n} $n
Truth table0%0/3
A // B
A= $esc{$n}B= $n
ABresult
1X1
011
000
400 3 ▶ return if ord $to < ord $c;
Branch: 1 branch
BranchTrueFalseTotal
if ord $to < ord $c 0 3 3
401 3 push @c, map { chr } ord($c) .. ord($to);
402 3 next;
403 }
404 4 push @c, $c;
405 }
406 8 return \@c;
407 }
408  
409 5 ▶sub _tr {
Subroutine _tr: called CC=32 SCAR=37.7
410 5 my ( $text, @a ) = @_;
411 5 my ( %o, @sets );
412 5 for my $x (@a) {
413 11 ▶ if ( $x =~ /\A-([cCdst]+)\z/ ) { $o{ $_ eq 'C' ? 'c' : $_ } = 1 for split //, $1 }
Branch: 3 branches
BranchTrueFalseTotal
if ($x =~ /\A-([cCdst]+)\z/) { } 3 8 11
elsif ($x =~ /\A--/) { } 0 8 8
$_ eq 'C' ? : 0 3 3
414 0 elsif ( $x =~ /\A--/ ) { return (undef) }
415 8 else { push @sets, $x }
416 }
417 5 ▶ return ( 'tr: missing operand', 0 ) unless @sets;
Branch: 1 branch
BranchTrueFalseTotal
unless @sets 0 5 5
418 5 ▶ my $s1 = _tr_set( $sets[0] ) // return (undef);
Condition50%1/2
_tr_set($sets[0]) // (return undef)
l!l
50
MC/DC0%0/1
_tr_set($sets[0]) // (return undef)
_tr_set($sets[0])
Truth table50%1/2
A
A= _tr_set($sets[0])
Aresult
11
00
419 5 ▶ my $s2 = defined $sets[1] ? _tr_set( $sets[1] ) // return (undef) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $sets[1] ? : 3 2 5
Condition50%1/2
_tr_set($sets[1]) // (return undef)
l!l
30
MC/DC0%0/1
_tr_set($sets[1]) // (return undef)
_tr_set($sets[1])
Truth table50%1/2
A
A= _tr_set($sets[1])
Aresult
11
00
420 5 my %in1 = map { $_ => 1 } @$s1;
421 5 ▶ my $m1 = $o{c} ? sub { !$in1{ $_[0] } } : sub { $in1{ $_[0] } };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$o{'c'} ? : 1 4 5
422 5 my @out;
423 5 ▶ if ( $o{d} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($o{'d'}) { } 1 4 5
elsif ($s2 and not $o{'d'}) { } 3 1 4
elsif ($o{'s'}) { } 1 0 1
424 1 @out = grep { !$m1->($_) } split //, $text;
425 }
426 ▶ elsif ( $s2 && !$o{d} ) {
Condition66%2/3
$s2 and not $o{"d"}
!ll&&!rl&&r
103
MC/DC50%1/2
$s2 and not $o{"d"}
$s2 not $o{"d"}
Truth table66%2/3
A and not(B)
A= $s2B= not $o{"d"}
ABresult
0X0
100
111
427 3 ▶ return ( 'tr: when not truncating set1, string2 must be non-empty', 0 ) unless @$s2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$s2 0 3 3
428 3 my %map;
429 3 ▶ if ( $o{c} ) { %map = () }
Branch: 1 branch
BranchTrueFalseTotal
if ($o{'c'}) { } 1 2 3
430 2 ▶ else { $map{ $s1->[$_] } //= $s2->[ $_ < @$s2 ? $_ : -1 ] for 0 .. $#$s1 }
Branch: 1 branch
BranchTrueFalseTotal
$_ < @$s2 ? : 4 25 29
Condition33%1/3
$map{$s1->[$_]} //= $$s2[$_ < @$s2 ? $_ : -1]
l!l&&r!l&&!r
0290
MC/DC0%0/2
$map{$s1->[$_]} //= $$s2[$_ < @$s2 ? $_ : -1]
$map{$s1->[$_]} $$s2[$_ < @$s2 ? $_ : -1]
Truth table33%1/3
A //= B
A= $map{$s1->[$_]}B= $$s2[$_ < @$s2 ? $_ : -1]
ABresult
1X1
011
000
431 3 ▶ @out = map { $o{c} ? ( $m1->($_) ? $s2->[-1] : $_ ) : exists $map{$_} ? $map{$_} : $_ } split //, $text;
Branch: 3 branches
BranchTrueFalseTotal
$o{'c'} ? : 21 8 29
&$m1($_) ? : 0 21 21
exists $map{$_} ? : 8 0 8
432 }
433 1 elsif ( $o{s} ) { @out = split //, $text }
434 0 else { return ( "tr: missing operand after '$sets[0]'", 0 ) }
435 5 ▶ if ( $o{s} ) { # Wiederholungen aus dem letzten Satz zusammenziehen
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"s"}) 1 4 5
436 1 ▶ my %sq = map { $_ => 1 } @{ $s2 && !$o{d} ? $s2 : $s1 };
Branch: 1 branch
BranchTrueFalseTotal
$s2 && !$o{'d'} ? : 0 1 1
Condition33%1/3
$s2 and not $o{"d"}
!ll&&!rl&&r
100
MC/DC0%0/2
$s2 and not $o{"d"}
$s2 not $o{"d"}
Truth table33%1/3
A and not(B)
A= $s2B= not $o{"d"}
ABresult
0X0
100
111
437 0 ▶ my $msq = $s2 && !$o{d} ? sub { $sq{ $_[0] } } : $m1;
Subroutine __ANON__: not called CC=1 SCAR=1.7
Branch: 1 branch
BranchTrueFalseTotal
$s2 && !$o{'d'} ? : 0 1 1
Condition33%1/3
$s2 and not $o{"d"}
!ll&&!rl&&r
100
MC/DC0%0/2
$s2 and not $o{"d"}
$s2 not $o{"d"}
Truth table33%1/3
A and not(B)
A= $s2B= not $o{"d"}
ABresult
0X0
100
111
438 1 my @z;
439 1 ▶ for (@out) { push @z, $_ unless @z && $z[-1] eq $_ && $msq->($_) }
Branch: 1 branch
BranchTrueFalseTotal
unless @z and $z[-1] eq $_ and &$msq($_) 3 2 5
Condition83%5/6
@z and $z[-1] eq $_ and &$msq($_)
!ll&&!rl&&r
302
@z and $z[-1] eq $_
!ll&&!rl&&r
122
MC/DC66%2/3
@z and $z[-1] eq $_ and &$msq($_)
@z $z[-1] eq $_ &$msq($_)
Truth table75%3/4
A and B and C
A= @zB= $z[-1] eq $_C= &$msq($_)
ABCresult
0XX0
10X0
1100
1111
440 1 @out = @z;
441 }
442 5 return ( join( '', @out ), 1 );
443 }
444  
445  
446 # Grundlegender regulaerer Ausdruck (grep ohne -E) als Perl: \| \( \) \+ \? \{ \} sind
447 # besonders, ohne \ stehen | ( ) + ? { } fuer sich
448 89 ▶sub _bre {
Subroutine _bre: called CC=5 SCAR=16.1
449 89 my ($p) = @_;
450 89 my $out = '';
451 89 ▶ while ( $p =~ /\G(?:\\(.)|([|()+?{}])|(.))/gcs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ /\G(?:\\(.)|([|()+?{}])|(.))/cgs) 569 89 658
452 569 ▶ if ( defined $1 ) { my $c = $1; $out .= $c =~ /\A[|()+?{}]\z/ ? $c : "\\$c" }
Branch: 3 branches
BranchTrueFalseTotal
if (defined $1) { } 1 568 569
elsif (defined $2) { } 4 564 568
$c =~ /\A[|()+?{}]\z/ ? : 1 0 1
453 4 elsif ( defined $2 ) { $out .= "\\$2" }
454 564 else { $out .= $3 }
455 }
456 89 return $out;
457 }
458  
459 250 ▶sub filter_output {
Subroutine filter_output: called CC=108 SCAR=62.9
Pod documented
460 250 my ( $text, $argv ) = @_;
461 250 my ( $cmd, @a ) = @$argv;
462 250 ▶ my @lines = length $text ? split /\n/, $text, -1 : ();
Branch: 1 branch
BranchTrueFalseTotal
length $text ? : 242 8 250
463 250 ▶ pop @lines if @lines && $lines[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if @lines and $lines[-1] eq "" 82 168 250
Condition100%3/3
@lines and $lines[-1] eq ""
!ll&&!rl&&r
816082
MC/DC100%2/2
@lines and $lines[-1] eq ""
@lines $lines[-1] eq ""
Truth table100%3/3
A and B
A= @linesB= $lines[-1] eq ""
ABresult
0X0
100
111
464 250 ▶ if ( $cmd eq 'grep' || $cmd eq 'egrep' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "grep" or $cmd eq "egrep") 87 163 250
Condition66%2/3
$cmd eq "grep" or $cmd eq "egrep"
l!l&&r!l&&!r
870163
MC/DC50%1/2
$cmd eq "grep" or $cmd eq "egrep"
$cmd eq "grep" $cmd eq "egrep"
Truth table66%2/3
A or B
A= $cmd eq "grep"B= $cmd eq "egrep"
ABresult
1X1
011
000
465 87 my %f;
466 my @pat;
467 87 my %n = ( A => 0, B => 0 );
468 87 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 119 87 206
469 119 my $x = shift @a;
470 119 ▶ if ( $x =~ /\A-([ivEFwcnHhs]*)([ABCm])(\d*)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /\A-([ivEFwcnHhs]*)([ABCm])(\d*)\z/) 7 112 119
471 7 my ( $fl, $o, $num ) = ( $1, $2, $3 );
472 7 $f{$_} = 1 for split //, $fl;
473 7 ▶ my $v = length $num ? $num : shift(@a) // 0;
Branch: 1 branch
BranchTrueFalseTotal
length $num ? : 3 4 7
Condition50%1/2
shift @a // 0
l!l
40
MC/DC0%0/1
shift @a // 0
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
474 7 ▶ $v = $v =~ /\A(\d+)\z/ ? 0 + $1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /\A(\d+)\z/ ? : 7 0 7
475 7 ▶ if ( $o eq 'C' ) { @n{qw( A B )} = ( $v, $v ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($o eq 'C') { } 1 6 7
elsif ($o eq 'm') { } 1 5 6
476 1 elsif ( $o eq 'm' ) { $n{m} = $v }
477 5 else { $n{$o} = $v }
478 7 ▶ $f{ctx} = 1 if $o ne 'm';
Branch: 1 branch
BranchTrueFalseTotal
if $o ne "m" 6 1 7
479 7 next;
480 }
481 112 ▶ if ( $x =~ /\A-([ivEFwcnHhs]+)\z/ ) { $f{$_} = 1 for split //, $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /\A-([ivEFwcnHhs]+)\z/) 22 90 112
482 90 ▶ if ( $x eq '-e' ) { push @pat, shift @a; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "-e") 2 88 90
483 88 push @pat, $x;
484 }
485 87 ▶ return ( "Usage: grep [OPTION]... PATTERNS [FILE]...", 0 ) unless @pat;
Branch: 1 branch
BranchTrueFalseTotal
unless @pat 0 87 87
486 my @re = map {
487 87 my $p = $_;
488 90 ▶ $p = quotemeta $p if $f{F};
Branch: 1 branch
BranchTrueFalseTotal
if $f{"F"} 0 90 90
489 90 ▶ $p = _bre($p) unless $f{E} || $f{F} || $cmd eq 'egrep'; # BRE: \| ist Alternative, { steht fuer sich
Branch: 1 branch
BranchTrueFalseTotal
unless $f{"E"} or $f{"F"} or $cmd eq "egrep" 89 1 90
Condition66%4/6
$f{"E"} or $f{"F"} or $cmd eq "egrep"
l!l&&r!l&&!r
1089
$f{"E"} or $f{"F"}
l!l&&r!l&&!r
1089
MC/DC33%1/3
$f{"E"} or $f{"F"} or $cmd eq "egrep"
$f{"E"} $f{"F"} $cmd eq "egrep"
Truth table50%2/4
A or B or C
A= $f{"E"}B= $f{"F"}C= $cmd eq "egrep"
ABCresult
1XX1
01X1
0011
0000
490 90 ▶ $p = "\\b$p\\b" if $f{w};
Branch: 1 branch
BranchTrueFalseTotal
if $f{"w"} 0 90 90
491 90 ▶ my $re = eval { $f{i} ? qr/$p/i : qr/$p/ };
Branch: 1 branch
BranchTrueFalseTotal
$f{'i'} ? : 6 84 90
492 90 ▶ $re // qr/\Q$_\E/;
Condition50%1/2
$re // qr/\Q$_\E/
l!l
900
MC/DC0%0/1
$re // qr/\Q$_\E/
$re
Truth table50%1/2
A
A= $re
Aresult
11
00
493 } @pat;
494 87 ▶ my @idx = grep { my $l = $lines[$_]; my $m = grep { $l =~ $_ } @re; $f{v} ? !$m : $m } 0 .. $#lines;
Branch: 1 branch
BranchTrueFalseTotal
$f{'v'} ? : 0 552 552
495 87 ▶ @idx = @idx[ 0 .. $n{m} - 1 ] if defined $n{m} && @idx > $n{m};
Branch: 1 branch
BranchTrueFalseTotal
if defined $n{"m"} and @idx > $n{"m"} 1 86 87
Condition66%2/3
defined $n{"m"} and @idx > $n{"m"}
!ll&&!rl&&r
8601
MC/DC50%1/2
defined $n{"m"} and @idx > $n{"m"}
defined $n{"m"} @idx > $n{"m"}
Truth table66%2/3
A and B
A= defined $n{"m"}B= @idx > $n{"m"}
ABresult
0X0
100
111
496 87 ▶ return ( scalar(@idx), @idx ? 1 : 0 ) if $f{c};
Branch: 2 branches
BranchTrueFalseTotal
if $f{"c"} 9 78 87
@idx ? : 8 1 9
497 78 my %hit = map { $_ => 1 } @idx;
498 78 my ( @out, $last );
499 78 ▶ for my $i ( $f{ctx} ? ( map { ( $_ - $n{B} < 0 ? 0 : $_ - $n{B} ) .. ( $_ + $n{A} > $#lines ? $#lines : $_ + $n{A} ) } @idx ) : @idx ) {
Branch: 3 branches
BranchTrueFalseTotal
$f{'ctx'} ? : 6 72 78
$_ - $n{'B'} < 0 ? : 0 7 7
$_ + $n{'A'} > $#lines ? : 1 6 7
500 70 ▶ next if defined $last && $i <= $last;
Branch: 1 branch
BranchTrueFalseTotal
if defined $last and $i <= $last 0 70 70
Condition66%2/3
defined $last and $i <= $last
!ll&&!rl&&r
50200
MC/DC0%0/2
defined $last and $i <= $last
defined $last $i <= $last
Truth table66%2/3
A and B
A= defined $lastB= $i <= $last
ABresult
0X0
100
111
501 70 ▶ push @out, '--' if $f{ctx} && defined $last && $i > $last + 1;
Branch: 1 branch
BranchTrueFalseTotal
if $f{"ctx"} and defined $last and $i > $last + 1 1 69 70
Condition100%6/6
$f{"ctx"} and defined $last and $i > $last + 1
!ll&&!rl&&r
6451
$f{"ctx"} and defined $last
!ll&&!rl&&r
5866
MC/DC100%3/3
$f{"ctx"} and defined $last and $i > $last + 1
$f{"ctx"} defined $last $i > $last + 1
Truth table100%4/4
A and B and C
A= $f{"ctx"}B= defined $lastC= $i > $last + 1
ABCresult
0XX0
10X0
1100
1111
502 70 ▶ push @out, ( $f{n} ? ( $i + 1 ) . ( $hit{$i} ? ':' : '-' ) : '' ) . $lines[$i];
Branch: 2 branches
BranchTrueFalseTotal
$f{'n'} ? : 6 64 70
$hit{$i} ? : 5 1 6
503 70 $last = $i;
504 }
505 78 ▶ return ( join( "\n", @out ), @idx ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
@idx ? : 50 28 78
506 }
507 163 ▶ if ( $cmd eq 'head' || $cmd eq 'tail' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "head" or $cmd eq "tail") 27 136 163
Condition100%3/3
$cmd eq "head" or $cmd eq "tail"
l!l&&r!l&&!r
216136
MC/DC100%2/2
$cmd eq "head" or $cmd eq "tail"
$cmd eq "head" $cmd eq "tail"
Truth table100%3/3
A or B
A= $cmd eq "head"B= $cmd eq "tail"
ABresult
1X1
011
000
508 27 my $n = 10;
509 27 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 29 23 52
510 29 my $x = shift @a;
511 29 ▶ if ( $x eq '-n' || $x eq '--lines' ) { $n = shift(@a) // 10 }
Branch: 3 branches
BranchTrueFalseTotal
if ($x eq '-n' or $x eq '--lines') { } 13 16 29
elsif ($x =~ /\A(?:-n|--lines=)([-+]?\d+)\z/ or $x =~ /\A-(\d+)\z/) { } 12 4 16
elsif ($x =~ /\A-c(\d*)\z/) { } 4 0 4
Condition60%3/5
$x eq "-n" or $x eq "--lines"
l!l&&r!l&&!r
13016
shift @a // 10
l!l
130
MC/DC50%1/2
$x eq "-n" or $x eq "--lines"
$x eq "-n" $x eq "--lines"
MC/DC0%0/1
shift @a // 10
shift @a
Truth table66%2/3
A or B
A= $x eq "-n"B= $x eq "--lines"
ABresult
1X1
011
000
Truth table50%1/2
A
A= shift @a
Aresult
11
00
512 12 ▶ elsif ( $x =~ /\A(?:-n|--lines=)([-+]?\d+)\z/ || $x =~ /\A-(\d+)\z/ ) { $n = $1 }
Condition100%3/3
$x =~ /\A(?:-n|--lines=)([-+]?\d+)\z/ or $x =~ /\A-(\d+)\z/
l!l&&r!l&&!r
1114
MC/DC100%2/2
$x =~ /\A(?:-n|--lines=)([-+]?\d+)\z/ or $x =~ /\A-(\d+)\z/
$x =~ /\A(?:-n|--lines=)([-+]?\d+)\z/ $x =~ /\A-(\d+)\z/
Truth table100%3/3
A or B
A= $x =~ /\A(?:-n|--lines=)([-+]?\d+)\z/B= $x =~ /\A-(\d+)\z/
ABresult
1X1
011
000
513 elsif ( $x =~ /\A-c(\d*)\z/ ) { # Bytes statt Zeilen: -cN oder -c N
514 4 ▶ my $c = length $1 ? $1 : shift(@a) // 0;
Branch: 1 branch
BranchTrueFalseTotal
length $1 ? : 1 3 4
Condition50%1/2
shift @a // 0
l!l
30
MC/DC0%0/1
shift @a // 0
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
515 4 ▶ $c = 0 + ( $c =~ /(\d+)/ ? $1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$c =~ /(\d+)/ ? : 4 0 4
516 4 ▶ return ( $cmd eq 'head' ? substr( $text, 0, $c ) : substr( $text, length($text) > $c ? -$c : 0 ), 1 );
Branch: 2 branches
BranchTrueFalseTotal
$cmd eq 'head' ? : 2 2 4
length $text > $c ? : 2 0 2
517 }
518 }
519 23 ▶ return ( "$cmd: invalid number of lines: '$n'", 0 ) unless $n =~ /\A([-+]?)(\d+)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $n =~ /\A([-+]?)(\d+)\z/ 0 23 23
520 23 my ( $sg, $k ) = ( $1, 0 + $2 );
521 23 my @l;
522 23 ▶ if ( $cmd eq 'head' ) { # head -n -K: alles ausser den letzten K
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq 'head') { } 19 4 23
523 19 ▶ my $last = $sg eq '-' ? @lines - $k - 1 : ( $k < @lines ? $k : @lines ) - 1;
Branch: 2 branches
BranchTrueFalseTotal
$sg eq '-' ? : 1 18 19
$k < @lines ? : 9 9 18
524 19 @l = @lines[ 0 .. $last ];
525 }
526 else { # tail -n +K: ab Zeile K
527 4 ▶ @l = $sg eq '+' ? @lines[ ( $k > 0 ? $k - 1 : 0 ) .. $#lines ] : @lines[ ( @lines > $k ? @lines - $k : 0 ) .. $#lines ];
Branch: 3 branches
BranchTrueFalseTotal
$sg eq '+' ? : 1 3 4
$k > 0 ? : 1 0 1
@lines > $k ? : 3 0 3
528 }
529 23 return ( join( "\n", @l ), 1 );
530 }
531 136 ▶ return ( scalar(@lines), 1 ) if $cmd eq 'wc' && "@a" eq '-l';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "wc" and join($", @a) eq "-l" 12 124 136
Condition100%3/3
$cmd eq "wc" and join($", @a) eq "-l"
!ll&&!rl&&r
1141012
MC/DC100%2/2
$cmd eq "wc" and join($", @a) eq "-l"
$cmd eq "wc" join($", @a) eq "-l"
Truth table100%3/3
A and B
A= $cmd eq "wc"B= join($", @a) eq "-l"
ABresult
0X0
100
111
532 124 ▶ if ( $cmd eq 'wc' && !grep { !/\A-[lcwm]+\z/ } @a ) { # wc -l/-c/-w/-m, kombiniert bzw. alle; Bytes genau (aus einer Pipe ohne letztes Zeilenende)
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "wc" and not grep({not /\A-[lcwm]+\z/;} @a)) 10 114 124
Condition66%2/3
$cmd eq "wc" and not grep({not /\A-[lcwm]+\z/;} @a)
!ll&&!rl&&r
114010
MC/DC50%1/2
$cmd eq "wc" and not grep({not /\A-[lcwm]+\z/;} @a)
$cmd eq "wc" not grep({not /\A-[lcwm]+\z/;} @a)
Truth table66%2/3
A and not(B)
A= $cmd eq "wc"B= not grep({not /\A-[lcwm]+\z/;} @a)
ABresult
0X0
100
111
533 10 my $nw = () = $text =~ /\S+/g;
534 10 my %n = ( l => scalar(@lines), w => $nw, m => length $text, c => length Encode::encode( 'UTF-8', $text ) );
535 10 ▶ my @want = @a ? map { /\A-(\w+)\z/ ? split //, $1 : () } @a : qw( l w c );
Branch: 2 branches
BranchTrueFalseTotal
@a ? : 10 0 10
/\A-(\w+)\z/ ? : 10 0 10
536 10 return ( join( ' ', map { $n{$_} } grep { my $k = $_; grep { $_ eq $k } @want } qw( l w m c ) ), 1 );
537 }
538 114 ▶ if ( $cmd eq 'sort' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "sort") 2 112 114
539 2 ▶ my %o = map { $_ => 1 } map { /\A-(\w+)\z/ ? split( //, $1 ) : () } @a;
Branch: 1 branch
BranchTrueFalseTotal
/\A-(\w+)\z/ ? : 2 0 2
540 2 my %u = ( K => 1024, M => 1024**2, G => 1024**3, T => 1024**4 );
541 2 ▶ my $hv = sub { my ( $x, $s ) = $_[0] =~ /(-?\d+(?:\.\d+)?)([KMGT]?)/; $x //= 0; $s ? $x * $u{$s} : $x };
Subroutine __ANON__: called CC=3 SCAR=11.4
Branch: 1 branch
BranchTrueFalseTotal
$s ? : 10 0 10
Condition50%1/2
$x //= 0
l!l
100
MC/DC0%0/1
$x //= 0
$x
Truth table50%1/2
A
A= $x
Aresult
11
00
542 5 ▶ my @s = $o{h} ? sort { $hv->($a) <=> $hv->($b) } @lines
Branch: 1 branch
BranchTrueFalseTotal
$o{'n'} ? : 0 1 1
543 0 ▶ : $o{n} ? sort { ( ( $a =~ /(-?\d+)/ )[0] // 0 ) <=> ( ( $b =~ /(-?\d+)/ )[0] // 0 ) } @lines
Branch: 1 branch
BranchTrueFalseTotal
$o{'h'} ? : 1 1 2
Condition0%0/4
($a =~ /(-?\d+)/)[0] // 0
l!l
00
($b =~ /(-?\d+)/)[0] // 0
l!l
00
MC/DC0%0/1
($a =~ /(-?\d+)/)[0] // 0
($a =~ /(-?\d+)/)[0]
MC/DC0%0/1
($b =~ /(-?\d+)/)[0] // 0
($b =~ /(-?\d+)/)[0]
Truth table0%0/2
A
A= ($a =~ /(-?\d+)/)[0]
Aresult
11
00
Truth table0%0/2
A
A= ($b =~ /(-?\d+)/)[0]
Aresult
11
00
544 : sort @lines;
545 2 ▶ @s = reverse @s if $o{r};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"r"} 1 1 2
546 0 ▶ if ( $o{u} ) { my %seen; @s = grep { !$seen{$_}++ } @s }
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"u"}) 0 2 2
547 2 return ( join( "\n", @s ), 1 );
548 }
549 112 ▶ if ( $cmd eq 'uniq' ) { # -c zaehlt (wie GNU: %7d), -d nur doppelte, -u nur einzelne
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "uniq") 0 112 112
550 0 my %o;
551 0 ▶ for (@a) { return (undef) unless /\A-([cdu]+)\z/; $o{$_} = 1 for split //, $1 }
Branch: 1 branch
BranchTrueFalseTotal
unless /\A-([cdu]+)\z/ 0 0 0
552 0 my @u;
553 0 ▶ for (@lines) { if ( @u && $u[-1][0] eq $_ ) { $u[-1][1]++ } else { push @u, [ $_, 1 ] } }
Branch: 1 branch
BranchTrueFalseTotal
if (@u and $u[-1][0] eq $_) { } 0 0 0
Condition0%0/3
@u and $u[-1][0] eq $_
!ll&&!rl&&r
000
MC/DC0%0/2
@u and $u[-1][0] eq $_
@u $u[-1][0] eq $_
Truth table0%0/3
A and B
A= @uB= $u[-1][0] eq $_
ABresult
0X0
100
111
554 0 ▶ @u = grep { $_->[1] > 1 } @u if $o{d};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"d"} 0 0 0
555 0 ▶ @u = grep { $_->[1] == 1 } @u if $o{u};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"u"} 0 0 0
556 0 ▶ return ( join( "\n", map { $o{c} ? sprintf( '%7d %s', $_->[1], $_->[0] ) : $_->[0] } @u ), 1 );
Branch: 1 branch
BranchTrueFalseTotal
$o{'c'} ? : 0 0 0
557 }
558 112 ▶ return _cut( \@lines, @a ) if $cmd eq 'cut';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "cut" 3 109 112
559 109 ▶ return _awk( \@lines, @a ) if $cmd eq 'awk';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "awk" 51 58 109
560 58 ▶ return _tr( join( "\n", @lines ), @a ) if $cmd eq 'tr';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "tr" 5 53 58
561 53 ▶ if ( $cmd eq 'fold' ) { # fold [-b] [-s] [-w N]: Zeilen auf N Zeichen umbrechen
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "fold") 0 53 53
562 0 my ( $w, $sp ) = ( 80, 0 );
563 0 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 0 0 0
564 0 my $x = shift @a;
565 0 ▶ if ( $x =~ /\A-w(\d+)\z/ || $x =~ /\A--width=(\d+)\z/ ) { $w = $1 }
Branch: 4 branches
BranchTrueFalseTotal
if ($x =~ /\A-w(\d+)\z/ or $x =~ /\A--width=(\d+)\z/) { } 0 0 0
elsif ($x eq '-w') { } 0 0 0
elsif ($x =~ /\A-(\d+)\z/) { } 0 0 0
elsif ($x =~ /\A-[bs]+\z/) { } 0 0 0
Condition0%0/3
$x =~ /\A-w(\d+)\z/ or $x =~ /\A--width=(\d+)\z/
l!l&&r!l&&!r
000
MC/DC0%0/2
$x =~ /\A-w(\d+)\z/ or $x =~ /\A--width=(\d+)\z/
$x =~ /\A-w(\d+)\z/ $x =~ /\A--width=(\d+)\z/
Truth table0%0/3
A or B
A= $x =~ /\A-w(\d+)\z/B= $x =~ /\A--width=(\d+)\z/
ABresult
1X1
011
000
566 0 ▶ elsif ( $x eq '-w' ) { $w = shift(@a) // '' }
Condition0%0/2
shift @a // ""
l!l
00
MC/DC0%0/1
shift @a // ""
shift @a
Truth table0%0/2
A
A= shift @a
Aresult
11
00
567 0 elsif ( $x =~ /\A-(\d+)\z/ ) { $w = $1 }
568 0 ▶ elsif ( $x =~ /\A-[bs]+\z/ ) { $sp = 1 if $x =~ /s/ }
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /s/ 0 0 0
569 0 else { return (undef) }
570 }
571 0 ▶ return ( "fold: invalid number of columns: '$w'", 0 ) unless $w =~ /\A\d+\z/ && $w > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $w =~ /\A\d+\z/ and $w > 0 0 0 0
Condition0%0/3
$w =~ /\A\d+\z/ and $w > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$w =~ /\A\d+\z/ and $w > 0
$w =~ /\A\d+\z/ $w > 0
Truth table0%0/3
A and B
A= $w =~ /\A\d+\z/B= $w > 0
ABresult
0X0
100
111
572 0 my @o;
573 0 for my $l (@lines) {
574 0 my $r = $l;
575 0 ▶ while ( length $r > $w ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $r > $w) 0 0 0
576 0 my $cut = $w;
577 0 ▶ if ( $sp && substr( $r, 0, $w ) =~ /.*\s/s ) { $cut = $+[0] }
Branch: 1 branch
BranchTrueFalseTotal
if ($sp and substr($r, 0, $w) =~ /.*\s/s) 0 0 0
Condition0%0/3
$sp and substr($r, 0, $w) =~ /.*\s/s
!ll&&!rl&&r
000
MC/DC0%0/2
$sp and substr($r, 0, $w) =~ /.*\s/s
$sp substr($r, 0, $w) =~ /.*\s/s
Truth table0%0/3
A and B
A= $spB= substr($r, 0, $w) =~ /.*\s/s
ABresult
0X0
100
111
578 0 push @o, substr( $r, 0, $cut );
579 0 $r = substr( $r, $cut );
580 }
581 0 push @o, $r;
582 }
583 0 return ( join( "\n", @o ), 1 );
584 }
585 53 ▶ return ( $text, 1 ) if $cmd eq 'cat' && !@a;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "cat" and not @a 0 53 53
Condition33%1/3
$cmd eq "cat" and not @a
!ll&&!rl&&r
5300
MC/DC0%0/2
$cmd eq "cat" and not @a
$cmd eq "cat" not @a
Truth table33%1/3
A and not(B)
A= $cmd eq "cat"B= not @a
ABresult
0X0
100
111
586 53 return (undef);
587 }
588  
589 84 1;
590  
591 __END__
« blib/lib/Langertha/Holmgang/Sim/Linux/Pki.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux.pm »