| 1 | package Proc::ShellSpawn::Large; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 212 | our $VERSION = '0.13'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # EXPERIMENTAL, awaiting approval: what Proc::ShellSpawn needs to run Proc::ShellSubset::Large trees | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # (doc/large-subset/large-subset-spec.md, sections 4 and 5), as handlers named in Proc::ShellSpawn's tables: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # x_NAME(CONTEXT, NODE, TAIL, K) command nodes { func | export | readonly | local | exec => ... } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # b_NAME(CONTEXT, ARGV, ENV, K, DATA) builtins, and call() for functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Each calls K exactly once, or ends the shell (Proc::ShellSpawn::leave or Proc::ShellSpawn::fail), and never waits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 212 | ▶ | use strict; use warnings; use feature 'current_sub'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 212 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 212 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 212 | ▶ | use Proc::ShellSpawn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # JU3 (post-0.12, the user, 2026-11-15): the shell layer's functions are called through the alias ProcSS (Proc::ShellSpawn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # sets it), not imported; lines longer than 132 columns because of it stay unwrapped (the user's word, an exception to JQ1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 212 | our $UNSUPPORTED = 248; # A4: the status when something outside the subset shows up at run time (250 - 2: sh's syntax error | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # status, moved out of the common range; doc/large-subset/large-subset-spec.md, section 5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | sub unsupported { # A4: something outside the subset, found at run time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unsupported: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | my ($c, $what) = @_; ProcSS::put($c, 2, "Proc::ShellSubset::Large: $what is not supported\n", sub { ProcSS::leave($c, $UNSUPPORTED) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 32 | ▶ | sub parse_text { # TEXT read by the run's own parser (@opt: its options): the tree; or, outside the subset, undef after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_text: called CC=2 SCAR=8.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 32 | my ($c, $text, $what, @opt) = @_; # ending the shell (A4), $what naming the text in the message | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 32 | my $t = $c->{sh}{parse}->($text, @opt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | ref $t eq 'ARRAY' ? $t : do { unsupported($c, $what); undef } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 27 | ▶ | sub aliases { my $al = $_[0]{sh}{alias}; %$al ? (aliases => { %$al }) : () } # the parser's option: the aliases defined so far | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aliases: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 25 | ▶ | sub run_text { # eval, ., trap actions: parse with the large grammar and run in this shell | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_text: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 25 | my ($c, $text, $what, $k) = @_; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 25 | ▶ | my $t = parse_text($c, $text, $what, aliases($c), $what =~ /^the text of '\. / ? () : (nolineno => 1)) # $LINENO in eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
parse_text($c, $text, $what, aliases($c), $what =~ /^the text of '\. / ? () : ("nolineno", 1)) // (return)
MC/DC0%0/1
parse_text($c, $text, $what, aliases($c), $what =~ /^the text of '\. / ? () : ("nolineno", 1)) // (return)
parse_text($c, $text, $what, aliases($c), $what =~ /^the text of '\. / ? () : ("nolineno", 1))
Truth table50%1/2
A
A= parse_text($c, $text, $what, aliases($c), $what =~ /^the text of '\. / ? () : ("nolineno", 1))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | // return; # or trap text: A4 (G8) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 25 | ▶ | return ProcSS::defer($k, 0) unless @$t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 20 | ▶ | $sh->{intext}++; ProcSS::x_list($c, $t, undef, sub { $sh->{intext}--; $k->(@_) }) } # alias in this text: B1, A4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub b_unsupported { my ($c, $argv) = @_; unsupported($c, "'$argv->[0]'") } # a builtin left to sh, named at run time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_unsupported: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | sub x_rest { # P1 (post2-0.04): the rest of the text after a line with an alias definition known only when it ran: parsed now, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_rest: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # with the aliases defined by now, as both shells read a text one complete command at a time; a form outside the subset: A4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | my ($c, $x, $tail, $k) = @_; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | my $t = parse_text($c, $x->{rest}, "a command after an alias definition", aliases($c), lineoff => $x->{lineoff}) // return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
parse_text($c, $x->{"rest"}, "a command after an alias definition", aliases($c), "lineoff", $x->{"lineoff"}) // (return)
MC/DC0%0/1
parse_text($c, $x->{"rest"}, "a command after an alias definition", aliases($c), "lineoff", $x->{"lineoff"}) // (return)
parse_text($c, $x->{"rest"}, "a command after an alias definition", aliases($c), "lineoff", $x->{"lineoff"})
Truth table50%1/2
A
A= parse_text($c, $x->{"rest"}, "a command after an alias definition", aliases($c), "lineoff", $x->{"lineoff"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | return ProcSS::defer($k, $sh->{q}) unless @$t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | ProcSS::x_list($c, $t, $tail, $k) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | sub b_late { # 3A (post-0.04): a command whose name the text also defines as a function, which is not defined (yet): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_late: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # parsed again from its expanded words, quoted, so that the builtin's own checks apply as they would have at parse time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | ▶ | my ($c, $argv, $env, $k) = @_; my $q = sub { (my $w = shift) =~ s/'/'\\''/g; "'$w'" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | my $text = join ' ', (map "$_=" . $q->($env->{$_}), sort keys %$env), map $q->($_), @$argv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | ▶ | my $t = parse_text($c, $text, "'$argv->[0]' in this form") // return; # (no aliases: every word is quoted) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
parse_text($c, $text, "'$argv->[0]' in this form") // (return)
MC/DC0%0/1
parse_text($c, $text, "'$argv->[0]' in this form") // (return)
parse_text($c, $text, "'$argv->[0]' in this form")
Truth table50%1/2
A
A= parse_text($c, $text, "'$argv->[0]' in this form")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | ProcSS::x_list($c, $t, undef, $k) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # ------------------------------------------------------------------ functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 35 | ▶ | sub x_func { my ($c, $x, $tail, $k) = @_; $c->{sh}{cmd}{$x->{func}} = ['Proc::ShellSpawn::Large::call', $x->{body}]; ProcSS::defer($k, 0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_func: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 34 | ▶ | sub call { # NAME ARGS...: the body in this shell, with its own positional parameters and frame | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 34 | my ($c, $argv, $env, $k, $body) = @_; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 34 | my ($old, %saved) = $sh->{args}; # settings before the call: for its duration, exported (dash) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 34 | for (sort keys %$env) { $saved{$_} = [exists $sh->{vars}{$_}, $sh->{vars}{$_}, $sh->{exp}{$_}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | ProcSS::setvar($c, $_, $env->{$_}) or return; $sh->{exp}{$_} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 34 | $sh->{args} = [@$argv[1 .. $#$argv]]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 34 | my $saved = \%saved; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 34 | ▶ | my $ret = sub { my $st = shift; restore($sh, $saved); $sh->{args} = $old; ProcSS::defer($k, $st) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 34 | ProcSS::x_cmd({ %$c, loops => [], held => 0, frame => { saved => $saved, ret => $ret } }, $body, undef, $ret) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 32 | ▶ | sub restore { # put back variables a function changed with local, or settings before its call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restore: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 32 | my ($sh, $saved) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 32 | for my $n (keys %$saved) { my ($had, $v, $exp) = @{delete $saved->{$n}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | if ($had) { $sh->{vars}{$n} = $v } else { delete $sh->{vars}{$n} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ($exp) { $sh->{exp}{$n} = 1 } else { delete $sh->{exp}{$n} } } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 10 | ▶ | sub b_return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_return: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 10 | ▶ | my ($c, $argv, $env, $k) = @_; my $st = $argv->[1] // $c->{sh}{q}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$argv->[1] // $c->{"sh"}{"q"}
MC/DC0%0/2
$argv->[1] // $c->{"sh"}{"q"}
$argv->[1]
$c->{"sh"}{"q"}
Truth table66%2/3
A // B
A= $argv->[1]B= $c->{"sh"}{"q"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 10 | ▶ | return ProcSS::fail($c, 2, "return: Illegal number: $st") # NV1 (X42): known only at run time, as the shells | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $argv->[1] and not Proc::ShellSpawn::ok_num($st, 0)
MC/DC100%2/2
defined $argv->[1] and not Proc::ShellSpawn::ok_num($st, 0)
defined $argv->[1]
not Proc::ShellSpawn::ok_num($st, 0)
Truth table100%3/3
A and not(B)
A= defined $argv->[1]B= not Proc::ShellSpawn::ok_num($st, 0)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | if defined $argv->[1] && !ProcSS::ok_num($st, 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 9 | $st += 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | my $fr = $c->{frame} or return $c->{sh}{intext} ? ProcSS::leave($c, $st) # outside a function, in eval or . text: as exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 9 | ▶ | : $c->{cond} ? ProcSS::msg($c, "return: can only `return' from a function or sourced script", ProcSS::done($k, 2)) # X48: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | : ProcSS::fail($c, 2, "return: can only `return' from a function or sourced script"); # tested (&&, ||, !, if, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # while): status 2, the shell goes on; else the shell ends, status 2: both as bash --posix (rule E) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ProcSS::release_ctx($c); ProcSS::release_all(map $_->{scope}, @{$c->{loops}}); $fr->{ret}->($st) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # ------------------------------------------------------------------ declarations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | ▶ | sub declare { # export, readonly, local: [NAME, Word or undef, ...]; $each->(NAME) after the value is set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
declare: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 8 | ▶ | my ($c, $list, $k, $each, $what) = @_; my @l = @$list; my @pairs; push @pairs, [splice @l, 0, 2] while @l; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 8 | my @log; # NAME or NAME=VALUE as set, for $Proc::ShellSpawn::ONBUILTIN (measurement) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 307 | ▶ | ProcSS::each_async(\@pairs, sub { my ($p, $next) = @_; my ($n, $w) = @$p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 307 | ▶ | my $set = sub { my $m = shift; # the name is known: its value, if one is given, then $each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 307 | ▶ | return push(@log, $m), $each->($m), $next->() unless defined $w; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 307 | ▶ | ProcSS::expand_str($c, $w, sub { my $v = shift; push @log, "$m=$v"; ProcSS::setvar($c, $m, $v) or return; $each->($m); $next->() }) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 307 | ▶ | return $set->($n) unless ref $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | ProcSS::expand_str($c, $n, sub { my $m = shift; # export $v[=value] (parser item P4): the name known only now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | Proc::ShellSubset::settable($m) or return unsupported($c, "the name '$m' in 'export'"); # post-0.04: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # the old test let every name pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $set->($m) }) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 8 | ▶ | sub { $Proc::ShellSpawn::ONBUILTIN->("x_$what", [$what, @log], {}) if $what && $Proc::ShellSpawn::ONBUILTIN; ProcSS::defer($k, 0) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.5
Branch: 1 branch
Condition33%1/3
$what and $Proc::ShellSpawn::ONBUILTIN
MC/DC0%0/2
$what and $Proc::ShellSpawn::ONBUILTIN
$what
$Proc::ShellSpawn::ONBUILTIN
Truth table33%1/3
A and B
A= $whatB= $Proc::ShellSpawn::ONBUILTIN
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 302 | ▶ | sub x_export { my ($c, $x, $tail, $k) = @_; declare($c, $x->{export}, $k, sub { $c->{sh}{exp}{$_[0]} = 1 }, 'export') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
x_export: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | ▶ | sub x_readonly { my ($c, $x, $tail, $k) = @_; declare($c, $x->{readonly}, $k, sub { $c->{sh}{ro}{$_[0]} = 1 }, 'readonly') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
x_readonly: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | sub x_local { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_local: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | my ($c, $x, $tail, $k) = @_; my $fr = $c->{frame}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | return ProcSS::fail($c, 2, "local: not in a function") unless $fr; # A5 (reached only dynamically) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | my $sh = $c->{sh}; my %l = @{$x->{local}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | $fr->{saved}{$_} //= [exists $sh->{vars}{$_}, $sh->{vars}{$_}, $sh->{exp}{$_}] for keys %l; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fr->{"saved"}{$_} //= [exists $sh->{"vars"}{$_}, $sh->{"vars"}{$_}, $sh->{"exp"}{$_}]
MC/DC0%0/1
$fr->{"saved"}{$_} //= [exists $sh->{"vars"}{$_}, $sh->{"vars"}{$_}, $sh->{"exp"}{$_}]
$fr->{"saved"}{$_}
Truth table50%1/2
A
A= $fr->{"saved"}{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | ▶ | declare($c, $x->{local}, $k, sub {}, 'local') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # ------------------------------------------------------------------ exec with redirections only: for the rest of the shell | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | ▶ | sub x_exec { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_exec: called CC=2 SCAR=7.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | my ($c, $x, $tail, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | ▶ | ProcSS::redirect($c, $x->{redir} // [], sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | my ($m, $opened) = @_ or return ProcSS::leave($c, 2); # a special builtin: a failed redirection ends the shell | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | ProcSS::hold($_) for grep defined, values %$m; ProcSS::release($_) for @$opened; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | my $old = $c->{held} && !$c->{released} ? $c->{map} : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$c->{"held"} and not $c->{"released"}
MC/DC0%0/2
$c->{"held"} and not $c->{"released"}
$c->{"held"}
not $c->{"released"}
Truth table33%1/3
A and not(B)
A= $c->{"held"}B= not $c->{"released"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | $c->{map} = $m; ProcSS::release($_) for grep defined, values %$old; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | push @{$c->{shell}{scope}}, $c unless $c->{held}; # released when the shell ends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | ▶ | @$c{qw(held released)} = (1, 0); ProcSS::defer($k, 0) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$x->{"redir"} // []
MC/DC0%0/1
$x->{"redir"} // []
$x->{"redir"}
Truth table50%1/2
A
A= $x->{"redir"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # ------------------------------------------------------------------ builtins | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | ▶ | sub b_shift { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_shift: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | ▶ | my ($c, $argv, $env, $k) = @_; my $n = $argv->[1] // 1; my $a = $c->{sh}{args}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$argv->[1] // 1
MC/DC100%1/1
$argv->[1] // 1
$argv->[1]
Truth table100%2/2
A
A= $argv->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 5 | ▶ | return ProcSS::fail($c, 2, "shift: Illegal number: $n") unless ProcSS::ok_num($n, 0); # NV1 (X46): -1, x1 at run time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | $n += 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | ▶ | return ProcSS::fail($c, 2, "shift: can't shift that many") if $n > @$a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | splice @$a, 0, $n; ProcSS::defer($k, 0) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 212 | my %OPT = (errexit => 'e', nounset => 'u', noglob => 'f', noclobber => 'C', allexport => 'a', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | notify => 'b', ignoreeof => 'ignoreeof', nolog => 'nolog'); # the last three, and +m, do nothing here (P6) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 46 | ▶ | sub b_set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_set: called CC=21 SCAR=31.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 46 | my ($c, $argv, $env, $k) = @_; my @a = @$argv[1 .. $#$argv]; my $o = $c->{sh}{opt}; my $ops; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 46 | ▶ | while (@a) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 46 | my $x = $a[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 46 | ▶ | if ($x eq '--') { shift @a; $ops = 1; last } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 29 | ▶ | last unless $x =~ /^([-+])(.+)/; shift @a; my ($on, $f) = ($1 eq '-', $2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | return ProcSS::fail($c, 2, "set: Illegal option -o history") # B2: as dash, when the caller asked for dash's interactive builtins | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 29 | ▶ | if $f eq 'o' && ($a[0] // '') eq 'history' && $c->{sh}{interactive} eq 'dash'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%4/8
$f eq "o" and ($a[0] // "") eq "history" and $c->{"sh"}{"interactive"} eq "dash"
$f eq "o" and ($a[0] // "") eq "history"
$a[0] // ""
MC/DC0%0/3
$f eq "o" and ($a[0] // "") eq "history" and $c->{"sh"}{"interactive"} eq "dash"
$f eq "o"
$a[0]
$c->{"sh"}{"interactive"} eq "dash"
Truth table25%1/4
A and B and C
A= $f eq "o"B= $a[0]C= $c->{"sh"}{"interactive"} eq "dash"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 29 | ▶ | if ($f eq 'o') { # NV1 (X43): a name known only at run time; none: it lists (A4, as the parser has it) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 9 | ▶ | return unsupported($c, "'set -o' without a name (it lists)") unless @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 9 | my $n = shift @a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 9 | ▶ | exists $OPT{$n} || $n =~ /^(?:vi|emacs|history)\z/ or return ProcSS::fail($c, 2, "set: Illegal option -o $n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $OPT{$n} or $n =~ /^(?:vi|emacs|history)\z/
MC/DC100%2/2
exists $OPT{$n} or $n =~ /^(?:vi|emacs|history)\z/
exists $OPT{$n}
$n =~ /^(?:vi|emacs|history)\z/
Truth table100%3/3
A or B
A= exists $OPT{$n}B= $n =~ /^(?:vi|emacs|history)\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | ▶ | my $l = $OPT{$n} // ''; $on ? ($o->{$l} = 1) : delete $o->{$l}; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$OPT{$n} // ""
MC/DC100%1/1
$OPT{$n} // ""
$OPT{$n}
Truth table100%2/2
A
A= $OPT{$n}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 20 | ▶ | for my $l (split //, $f) { $l =~ /^[eufCab]\z/ || $l eq 'm' && !$on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$l =~ /^[eufCab]\z/ or $l eq "m" and not $on
$l eq "m" and not $on
MC/DC66%2/3
$l =~ /^[eufCab]\z/ or $l eq "m" and not $on
$l =~ /^[eufCab]\z/
$l eq "m"
not $on
Truth table75%3/4
A or B and not(C)
A= $l =~ /^[eufCab]\z/B= $l eq "m"C= not $on
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | or return ProcSS::fail($c, 2, "set: Illegal option $1$l"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 19 | ▶ | $on ? ($o->{$l} = 1) : delete $o->{$l} } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 44 | ▶ | $c->{sh}{args} = [@a] if $ops || @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ops or @a
MC/DC50%1/2
$ops or @a
$ops
@a
Truth table66%2/3
A or B
A= $opsB= @a
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 44 | ProcSS::defer($k, 0) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | ▶ | sub b_eval { my ($c, $argv, $env, $k) = @_; run_text($c, join(' ', @$argv[1 .. $#$argv]), "'eval' text", $k) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_eval: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | ▶ | sub b_dot { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_dot: called CC=8 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 5 | ▶ | my ($c, $argv, $env, $k) = @_; my $f = $argv->[1] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$argv->[1] // ""
MC/DC0%0/1
$argv->[1] // ""
$argv->[1]
Truth table50%1/2
A
A= $argv->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 5 | ▶ | my ($p) = ProcSS::has_dir($f) ? $f : grep -f ProcSS::path_in($c, $_), map +($_ eq '' ? '.' : $_) . "/$f", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | ProcSS::path_list(ProcSS::var($c, 'PATH')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 5 | ▶ | $p = ProcSS::path_in($c, $p) if defined $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | ▶ | open my $fh, '<', $p // '' or return ProcSS::fail($c, 2, ".: cannot open $f: No such file"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$p // ""
MC/DC0%0/1
$p // ""
$p
Truth table50%1/2
A
A= $p
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | ▶ | my $text = do { local $/; <$fh> } // ''; # (X39: in list context an empty file, or a directory, gave no argument at all) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
do {
local $/;
readline $fh
} // ""
MC/DC100%1/1
do {
local $/;
readline $fh
} // ""
do {
local $/;
readline $fh
}
Truth table100%2/2
A
A= do {
local $/;
readline $fh
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | run_text($c, $text, "the text of '. $f'", $k) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 212 | our %SIGNUM; *SIGNUM = \%Proc::Spawner::SIGNUM; # signal names => numbers: Proc::Spawner's table (JH3, part e) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 212 | my %SIGNAME = (%Proc::Spawner::SIGNAME, 0 => 'EXIT'); # numbers => names: its table too, and 0 as the shells have it | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 31 | ▶ | sub b_trap { # names in any case, or numbers (P6); KILL and STOP cannot be caught: nothing to do, status 0, as both shells | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_trap: called CC=15 SCAR=27.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 31 | my ($c, $argv, $env, $k) = @_; my ($act, @sigs) = @$argv[1 .. $#$argv]; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 31 | ▶ | for my $s (map /^[0-9]+\z/ ? $SIGNAME{$_} // $_ : uc, @sigs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$SIGNAME{$_} // $_
MC/DC0%0/2
$SIGNAME{$_} // $_
$SIGNAME{$_}
$_
Truth table33%1/3
A // B
A= $SIGNAME{$_}B= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 32 | ▶ | next if $s eq 'KILL' || $s eq 'STOP'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$s eq "KILL" or $s eq "STOP"
MC/DC100%2/2
$s eq "KILL" or $s eq "STOP"
$s eq "KILL"
$s eq "STOP"
Truth table100%3/3
A or B
A= $s eq "KILL"B= $s eq "STOP"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 30 | ▶ | next if $Proc::ShellSpawn::IGN0{$s}; # X49: ignored on entry: cannot be trapped or reset (POSIX; both shells) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 29 | ▶ | if ($act eq '-') { delete $sh->{trap}{$s} } else { $sh->{trap}{$s} = $act } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 29 | ▶ | next if $s eq 'EXIT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 18 | ▶ | next if $sh->{main}; # X51: a subshell runs in this process; a signal sent to it ($$, the group) is the main shell's, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # as in dash, where the subshell is another process (its trap: recorded, for 'trap' and its programs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 16 | my $w = $c; weaken $w; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 16 | ▶ | my $h = $sh->{tsub}{$s} = sub { return unless $w; push @{$w->{sh}{pend}}, $s }; # X51: run by the list, before its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # next command (X19): after the foreground command, as POSIX and both shells | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 16 | ▶ | next unless exists $SIGNUM{$s}; # a signal Perl does not have here (Windows: USR1, ...): only kill ... $$ sends it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 16 | ▶ | $Proc::ShellSpawn::TRAPSAVE{$s} //= $SIG{$s} // 'DEFAULT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
$Proc::ShellSpawn::TRAPSAVE{$s} //= $SIG{$s} // "DEFAULT"
$SIG{$s} // "DEFAULT"
MC/DC0%0/1
$Proc::ShellSpawn::TRAPSAVE{$s} //= $SIG{$s} // "DEFAULT"
$Proc::ShellSpawn::TRAPSAVE{$s}
Truth table50%1/2
A
A= $Proc::ShellSpawn::TRAPSAVE{$s}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 16 | ▶ | $SIG{$s} = $act eq '-' ? $Proc::ShellSpawn::TRAPSAVE{$s} : $act eq '' ? 'IGNORE' : $h } # queued: the action runs before the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # main shell's next command (X19: as dash, before what follows the command; X51: not while the command still runs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 31 | ProcSS::defer($k, 0) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 8 | ▶ | sub run_pending { # the actions of the signals caught since the last time, in order; then $k (and every other waiter) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_pending: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 8 | my ($c, $k) = @_; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 8 | ▶ | push @{$sh->{twait}}, $k if $k; return if $sh->{tbusy}; $sh->{tbusy} = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 16 | ▶ | sub { my $p = $sh->{pend}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 16 | ▶ | return run_trap($c, shift @$p, __SUB__) if $p && @$p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$p and @$p
MC/DC50%1/2
$p and @$p
$p
@$p
Truth table66%2/3
A and B
A= $pB= @$p
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 8 | ▶ | $sh->{tbusy} = 0; my @w = @{$sh->{twait} // []}; $sh->{twait} = []; $_->() for @w }->() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sh->{"twait"} // []
MC/DC0%0/1
$sh->{"twait"} // []
$sh->{"twait"}
Truth table50%1/2
A
A= $sh->{"twait"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 15 | ▶ | sub run_trap { # a trap's action; $? is kept | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_trap: called CC=4 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 15 | my ($c, $s, $k) = @_; my $a = $c->{sh}{trap}{$s}; my $q = $c->{sh}{q}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 15 | ▶ | return $k && $k->(0) unless defined $a && $a ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
defined $a and $a ne ""
$k && &$k(0)
MC/DC0%0/2
defined $a and $a ne ""
defined $a
$a ne ""
MC/DC0%0/2
$k && &$k(0)
$k
&$k(0)
Truth table33%1/3
A and B
A= defined $aB= $a ne ""
Truth table0%0/3
A && B
A= $kB= &$k(0)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 15 | ▶ | run_text({ %$c, loops => [], held => 0, intrap => 1 }, $a, "the action of 'trap'", sub { $c->{sh}{q} = $q; $k->(0) if $k }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 12 | ▶ | sub b_wait { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_wait: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 12 | my ($c, $argv, $env, $k) = @_; my @pid = @$argv[1 .. $#$argv]; my @j = @{$c->{sh}{jobl}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 12 | ▶ | if (@pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | ▶ | my $p = $pid[-1]; my ($j) = grep +($_->{first} // '') eq $p, @j; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_->{"first"} // ""
MC/DC0%0/1
$_->{"first"} // ""
$_->{"first"}
Truth table50%1/2
A
A= $_->{"first"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | ▶ | return ProcSS::defer($k, 127) unless $j; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | ▶ | return ProcSS::defer($k, $j->{st}) if defined $j->{st}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | ▶ | return push @{$j->{waiters}}, sub { ProcSS::defer($k, $j->{st}) } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 11 | my @left = grep !defined $_->{st}, @j; my $n = @left; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 11 | ▶ | return ProcSS::defer($k, 0) unless $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 9 | ▶ | push @{$_->{waiters}}, sub { ProcSS::defer($k, 0) unless --$n } for @left } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 20 | ▶ | sub b_umask { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_umask: called CC=10 SCAR=23.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 20 | my ($c, $argv, $env, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 20 | ▶ | return ProcSS::put($c, 1, sprintf("%04o\n", $c->{sh}{umask}), ProcSS::done($k, 0)) unless defined(my $m = $argv->[1]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 8 | ▶ | if ($m eq '-S') { # umask -S (parser item P4): u=rwx,g=rx,o=rx | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $u = $c->{sh}{umask}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my @w = map { my $b = 7 & ~($u >> $_); join '', grep $b & {r => 4, w => 2, x => 1}->{$_}, qw(r w x) } 6, 3, 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | return ProcSS::put($c, 1, "u=$w[0],g=$w[1],o=$w[2]\n", ProcSS::done($k, 0)) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 8 | ▶ | if ($m =~ /^[ugoa]*[-+=]/) { # symbolic, as both shells (post4-0.03): on the permissions the mask leaves | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 3 | my $p = ~$c->{sh}{umask} & 0777; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | for (split /,/, $m) { my ($who, $op, $perm) = /^([ugoa]*)([-+=])([rwx]*)\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 4 | ▶ | my $w = 0; $w |= { u => 0700, g => 070, o => 07, a => 0777 }->{$_} for split //, $who || 'a'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$who || 'a'
MC/DC0%0/1
$who || 'a'
$who
Truth table50%1/2
A
A= $who
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | my $b = 0; $b |= { r => 0444, w => 0222, x => 0111 }->{$_} for split //, $perm; $b &= $w; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | ▶ | $p = $op eq '+' ? $p | $b : $op eq '-' ? $p & ~$b : ($p & ~$w) | $b } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | $c->{sh}{umask} = ~$p & 0777; return ProcSS::defer($k, 0) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 5 | $c->{sh}{umask} = oct $m; ProcSS::defer($k, 0) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 212 | our $DEFPATH = '/usr/bin:/bin'; # command -p: bash's (glibc confstr _CS_PATH, in its order); dash adds /usr/sbin:/sbin | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 212 | my %ASPROG = map +($_ => 1), qw(echo printf test [ kill true false pwd cd); # command -v prints the name (spec, section 5) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 22 | ▶ | sub b_pwd { # X23 (the user's choice C, post2-0.03): the program, as '/bin/pwd -L', with PWD set to the shell's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_pwd: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # directory, so that it prints what both shells print (the directory as reached, also through symbolic links); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # operands are dropped, as both shells ignore them (the program would warn); options as given, the last counts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 22 | my ($c, $argv, $env, $k) = @_; my (undef, @a) = @$argv; my @o; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 22 | ▶ | while (@a && $a[0] =~ /^-/) { my $o = shift @a; last if $o eq '--'; push @o, $o } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
@a and $a[0] =~ /^-/
MC/DC100%2/2
@a and $a[0] =~ /^-/
@a
$a[0] =~ /^-/
Truth table100%3/3
A and B
A= @aB= $a[0] =~ /^-/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 22 | ProcSS::spawn($c, $c->{map}, ['pwd', '-L', @o], { %$env, PWD => $c->{sh}{cwd} }, $k) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 43 | ▶ | sub b_test { # rule F (post3-0.04): 's1 < s2', 's1 > s2' (also after '!'), which the program refuses, compared here by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_test: called CC=11 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # bytes, as both shells (POSIX 2024: "collates before/after ... in the current locale"; the same in the C locale); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # every other form: the program, as before (P5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 43 | my ($c, $argv, $env, $k) = @_; my ($n, @a) = @$argv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 43 | ▶ | if ($n eq '[') { return ProcSS::spawn($c, $c->{map}, $argv, $env, $k) unless @a && $a[-1] eq ']'; pop @a } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
@a and $a[-1] eq "]"
MC/DC0%0/2
@a and $a[-1] eq "]"
@a
$a[-1] eq "]"
Truth table33%1/3
A and B
A= @aB= $a[-1] eq "]"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 43 | ▶ | my $not = @a == 4 && $a[0] eq '!' and shift @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@a == 4 && $a[0] eq '!'
MC/DC50%1/2
@a == 4 && $a[0] eq '!'
@a == 4
$a[0] eq '!'
Truth table66%2/3
A && B
A= @a == 4B= $a[0] eq '!'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 43 | ▶ | return ProcSS::spawn($c, $c->{map}, $argv, $env, $k) unless @a == 3 && $a[1] =~ /^[<>]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@a == 3 and $a[1] =~ /^[<>]\z/
MC/DC100%2/2
@a == 3 and $a[1] =~ /^[<>]\z/
@a == 3
$a[1] =~ /^[<>]\z/
Truth table100%3/3
A and B
A= @a == 3B= $a[1] =~ /^[<>]\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | ▶ | my $r = $a[1] eq '<' ? $a[0] lt $a[2] : $a[0] gt $a[2]; $r = !$r if $not; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | ▶ | ProcSS::defer($k, $r ? 0 : 1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 21 | ▶ | sub b_command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_command: called CC=27 SCAR=34.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 21 | my ($c, $argv, $env, $k) = @_; my (undef, @a) = @$argv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 21 | ▶ | if (($a[0] // '') eq '-v') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$a[0] // ""
MC/DC0%0/1
$a[0] // ""
$a[0]
Truth table50%1/2
A
A= $a[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 13 | ▶ | return unsupported($c, "'command -v' with " . (@a - 1) . " names") if @a != 2; # X53: as the parser (one name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 12 | ▶ | my $n = $a[1] // ''; my $sh = $c->{sh}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a[1] // ""
MC/DC0%0/1
$a[1] // ""
$a[1]
Truth table50%1/2
A
A= $a[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | return ProcSS::put($c, 1, "$n\n", ProcSS::done($k, 0)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | if $sh->{cmd}{$n} || (ProcSS::cmd_of($n) // ['unsupported'])->[0] !~ /unsupported/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 12 | ▶ | || $Proc::ShellSpawn::SPECIAL{$n} || $ASPROG{$n} || $Proc::ShellSubset::BI{$n}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition85%12/14
$sh->{"cmd"}{$n} or not +(Proc::ShellSpawn::cmd_of($n) // ["unsupported"])->[0] =~ /unsupported/ or $Proc::ShellSpawn::SPECIAL{$n} or $ASPROG{$n} or $Proc::ShellSubset::BI{$n}
$sh->{"cmd"}{$n} or not +(Proc::ShellSpawn::cmd_of($n) // ["unsupported"])->[0] =~ /unsupported/ or $Proc::ShellSpawn::SPECIAL{$n} or $ASPROG{$n}
$sh->{"cmd"}{$n} or not +(Proc::ShellSpawn::cmd_of($n) // ["unsupported"])->[0] =~ /unsupported/ or $Proc::ShellSpawn::SPECIAL{$n}
$sh->{"cmd"}{$n} or not +(Proc::ShellSpawn::cmd_of($n) // ["unsupported"])->[0] =~ /unsupported/
Proc::ShellSpawn::cmd_of($n) // ["unsupported"]
MC/DC0%0/5
$sh->{"cmd"}{$n} or not +(Proc::ShellSpawn::cmd_of($n) // ["unsupported"])->[0] =~ /unsupported/ or $Proc::ShellSpawn::SPECIAL{$n} or $ASPROG{$n} or $Proc::ShellSubset::BI{$n}
$sh->{"cmd"}{$n}
Proc::ShellSpawn::cmd_of($n)
$Proc::ShellSpawn::SPECIAL{$n}
$ASPROG{$n}
$Proc::ShellSubset::BI{$n}
Truth table16%1/6
A or not(B) or C or D or E
A= $sh->{"cmd"}{$n}B= Proc::ShellSpawn::cmd_of($n)C= $Proc::ShellSpawn::SPECIAL{$n}D= $ASPROG{$n}E= $Proc::ShellSubset::BI{$n}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 5 | my ($p) = ProcSS::find_cmd($c, $n, ProcSS::var($c, 'PATH')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 5 | ▶ | $p //= $n if $Proc::ShellSpawn::INPROC{$n}; # run inside this process, no file (Windows): its name, as for a builtin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p //= $n
MC/DC0%0/2
$p //= $n
$p
$n
Truth table0%0/3
A //= B
A= $pB= $n
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 5 | ▶ | return ProcSS::defer($k, 127) unless defined $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | return ProcSS::put($c, 1, "$p\n", ProcSS::done($k, 0)) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 8 | ▶ | return ProcSS::defer($k, 0) unless @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # X53: the forms the parser refuses (another option, -v with more than one name, -p with an option after it), when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # only expansions make them: outside the subset at run time (A4), not a program named -n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | ▶ | return unsupported($c, "'command " . ($a[0] eq '-p' ? "-p $a[1]" : $a[0]) . "'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition90%10/11
$a[0] =~ /^-/ and $a[0] ne "-p" or $a[0] eq "-p" and ($a[1] // "") =~ /^-/
$a[0] =~ /^-/ and $a[0] ne "-p"
$a[0] eq "-p" and ($a[1] // "") =~ /^-/
$a[1] // ""
MC/DC25%1/4
$a[0] =~ /^-/ and $a[0] ne "-p" or $a[0] eq "-p" and ($a[1] // "") =~ /^-/
$a[0] =~ /^-/
$a[0] ne "-p"
$a[0] eq "-p"
$a[1]
Truth table42%3/7
A and B or C and D
A= $a[0] =~ /^-/B= $a[0] ne "-p"C= $a[0] eq "-p"D= $a[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | if $a[0] =~ /^-/ && $a[0] ne '-p' || $a[0] eq '-p' && ($a[1] // '') =~ /^-/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 6 | ▶ | if ($a[0] eq '-p') { # command -p PROGRAM ... (parser item P4): looked up in a default PATH, run with the PATH it has | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | shift @a; return (ProcSS::cmd_of($a[0]) // [''])->[0] !~ /b_test\z|^\z/ || $c->{sh}{cmd}{$a[0]} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | ? unsupported($c, "'command -p $a[0]'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | ▶ | : ProcSS::spawn($c, $c->{map}, \@a, $env, $k, $DEFPATH) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
not +(Proc::ShellSpawn::cmd_of($a[0]) // [""])->[0] =~ /b_test\z|^\z/ or $c->{"sh"}{"cmd"}{$a[0]}
Proc::ShellSpawn::cmd_of($a[0]) // [""]
MC/DC0%0/2
not +(Proc::ShellSpawn::cmd_of($a[0]) // [""])->[0] =~ /b_test\z|^\z/ or $c->{"sh"}{"cmd"}{$a[0]}
Proc::ShellSpawn::cmd_of($a[0])
$c->{"sh"}{"cmd"}{$a[0]}
Truth table0%0/3
not(A) or B
A= Proc::ShellSpawn::cmd_of($a[0])B= $c->{"sh"}{"cmd"}{$a[0]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 5 | ▶ | return b_late($c, \@a, $env, $k) if $Proc::ShellSubset::REGBI{$a[0]}; # a builtin, not a function: its checks, then it (3A) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | ▶ | if (my $e = ProcSS::cmd_of($a[0])) { return ProcSS::handler($e->[0])->($c, \@a, $env, $k, $e->[1]) } # a builtin, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # not a function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | ProcSS::spawn($c, $c->{map}, \@a, $env, $k) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 24 | ▶ | sub b_getopts { # OPTSTRING NAME [ARGS]: as dash, also OPTIND inside grouped options (A5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_getopts: called CC=19 SCAR=29.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 24 | my ($c, $argv, $env, $k) = @_; my (undef, $os, $name, @a) = @$argv; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 24 | ▶ | @a = @{$sh->{args}} unless @$argv > 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 24 | my $silent = $os =~ s/^://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 24 | ▶ | my $ind = ProcSS::var($c, 'OPTIND'); $ind = 1 if $ind !~ /^[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 24 | ▶ | my $off = ($sh->{optlast} // 0) eq $ind ? $sh->{optoff} // 0 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
$sh->{"optlast"} // 0
$sh->{"optoff"} // 0
MC/DC100%1/1
$sh->{"optlast"} // 0
$sh->{"optlast"}
MC/DC0%0/1
$sh->{"optoff"} // 0
$sh->{"optoff"}
Truth table100%2/2
A
A= $sh->{"optlast"}
Truth table50%1/2
A
A= $sh->{"optoff"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 24 | ▶ | $ind = 1, $off = 0 if $ind > @a + 1; # past the end of these arguments: dash starts over (L7) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 24 | ▶ | my $set = sub { my ($v, $st, @arg) = @_; # @arg undef: OPTARG unset (rule E: POSIX, as bash; dash keeps it, L8) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 24 | ▶ | ProcSS::setvar($c, $name, $v) && ProcSS::setvar($c, OPTIND => $ind) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
Proc::ShellSpawn::setvar($c, $name, $v) and Proc::ShellSpawn::setvar($c, "OPTIND", $ind)
MC/DC0%0/2
Proc::ShellSpawn::setvar($c, $name, $v) and Proc::ShellSpawn::setvar($c, "OPTIND", $ind)
Proc::ShellSpawn::setvar($c, $name, $v)
Proc::ShellSpawn::setvar($c, "OPTIND", $ind)
Truth table33%1/3
A and B
A= Proc::ShellSpawn::setvar($c, $name, $v)B= Proc::ShellSpawn::setvar($c, "OPTIND", $ind)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 24 | ▶ | !@arg ? () : defined $arg[0] ? ProcSS::setvar($c, OPTARG => $arg[0]) || return : delete $sh->{vars}{OPTARG}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
Proc::ShellSpawn::setvar($c, "OPTARG", $arg[0]) or return
MC/DC0%0/1
Proc::ShellSpawn::setvar($c, "OPTARG", $arg[0]) or return
Proc::ShellSpawn::setvar($c, "OPTARG", $arg[0])
Truth table50%1/2
A
A= Proc::ShellSpawn::setvar($c, "OPTARG", $arg[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 24 | @$sh{qw(optlast optoff)} = ($ind, $off); ProcSS::defer($k, $st) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 24 | my $cur; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 24 | ▶ | if ($off) { $cur = $a[$ind - 2] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 23 | $cur = $a[$ind - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 23 | ▶ | return $set->('?', 1, undef) if !defined $cur || $cur !~ /^-./; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cur and $cur =~ /^-./
MC/DC100%2/2
defined $cur and $cur =~ /^-./
defined $cur
$cur =~ /^-./
Truth table100%3/3
A and B
A= defined $curB= $cur =~ /^-./
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 17 | ▶ | $ind++; return $set->('?', 1, undef) if $cur eq '--'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 17 | $off = 1 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 18 | ▶ | my $ch = substr $cur, $off++, 1; my $last = $off >= length $cur; $off = 0 if $last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 18 | my $i = index $os, $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 18 | ▶ | if ($ch eq ':' or $i < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ch eq ":" or $i < 0
MC/DC50%1/2
$ch eq ":" or $i < 0
$ch eq ":"
$i < 0
Truth table66%2/3
A or B
A= $ch eq ":"B= $i < 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 4 | ▶ | return $silent ? $set->('?', 0, $ch) : ProcSS::msg($c, "Illegal option -$ch", sub { $set->('?', 0, undef) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 14 | ▶ | return $set->($ch, 0, undef) unless substr($os, $i + 1, 1) eq ':'; # POSIX: OPTARG unset (rule E; dash: empty) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 8 | ▶ | unless ($last) { my $arg = substr $cur, $off; $off = 0; return $set->($ch, 0, $arg) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 7 | ▶ | return $set->($ch, 0, $a[$ind++ - 1]) if defined $a[$ind - 1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 2 | ▶ | $silent ? $set->(':', 0, $ch) : ProcSS::msg($c, "No arg for -$ch option", sub { $set->('?', 0, undef) }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 12 | ▶ | sub b_unset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_unset: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 12 | my ($c, $argv, $env, $k) = @_; my (undef, @n) = @$argv; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 12 | ▶ | my $f = ($n[0] // '') =~ /^-([vf])\z/ && (shift @n, $1)[1] // 'v'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition57%4/7
($n[0] // "") =~ /^-([vf])\z/ && (shift @n, $1)[1] // "v"
($n[0] // "") =~ /^-([vf])\z/ and (shift @n, $1)[1]
$n[0] // ""
MC/DC0%0/2
($n[0] // "") =~ /^-([vf])\z/ && (shift @n, $1)[1] // "v"
$n[0]
(shift @n, $1)[1]
Truth table33%1/3
A and B
A= $n[0]B= (shift @n, $1)[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 12 | for (@n) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 13 | ▶ | if ($f eq 'f') { delete $sh->{cmd}{$_}; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # X35 (the user, 2026-11-08: as dash): a word that is not a name, from an expansion (a literal one the parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # rejects), stops the shell with status 2, as any error of a special builtin; the names before it are already unset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 9 | ▶ | return ProcSS::fail($c, 2, "unset: $_: bad variable name") unless /^[A-Za-z_][A-Za-z0-9_]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 5 | ▶ | return ProcSS::fail($c, 2, "unset: $_: is read only") if $sh->{ro}{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 4 | delete $sh->{vars}{$_}; delete $sh->{exp}{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 7 | ProcSS::defer($k, 0) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 46 | ▶ | sub b_kill { # kill ... $$: the shell takes the signal itself (F9); every other form goes to the program kill | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
b_kill: called CC=21 SCAR=31.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 46 | my ($c, $argv, $env, $k) = @_; my (undef, @a) = @$argv; my $sh = $c->{sh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # JH4, part c (the user, 2026-11-14: way A, provisionally; X63): the options are read once: -s NAME, or one word of a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # dash with letters and digits that does not start with -l; then a '--'. $s: the signal; @ids: the process IDs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 46 | my ($s, @ids) = ('TERM', @a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 46 | ▶ | if (@ids && $ids[0] eq '-s') { shift @ids; $s = shift @ids } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
@ids and $ids[0] eq "-s"
MC/DC100%2/2
@ids and $ids[0] eq "-s"
@ids
$ids[0] eq "-s"
Truth table100%3/3
A and B
A= @idsB= $ids[0] eq "-s"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 27 | ▶ | elsif (@ids && $ids[0] =~ /^-([0-9A-Za-z]+)\z/ && $ids[0] !~ /^-l/) { $s = $1; shift @ids } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
@ids and $ids[0] =~ /^-([0-9A-Za-z]+)\z/ and not $ids[0] =~ /^-l/
@ids and $ids[0] =~ /^-([0-9A-Za-z]+)\z/
MC/DC100%3/3
@ids and $ids[0] =~ /^-([0-9A-Za-z]+)\z/ and not $ids[0] =~ /^-l/
@ids
$ids[0] =~ /^-([0-9A-Za-z]+)\z/
not $ids[0] =~ /^-l/
Truth table100%4/4
A and B and not(C)
A= @idsB= $ids[0] =~ /^-([0-9A-Za-z]+)\z/C= not $ids[0] =~ /^-l/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 46 | ▶ | my $dd = @ids && $ids[0] eq '--' ? shift @ids : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@ids and $ids[0] eq "--"
MC/DC100%2/2
@ids and $ids[0] eq "--"
@ids
$ids[0] eq "--"
Truth table100%3/3
A and B
A= @idsB= $ids[0] eq "--"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # K0 (the user, 2026-11-05): a signal (-N, -NAME, -s NAME), maybe '--', and no process ID: as both shells, status 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # with dash's text (the program kill: status 1, a long usage text). 'kill -s' alone: the program | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 46 | ▶ | return ProcSS::msg($c, "kill: Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or\nkill -l [exitstatus]", ProcSS::done($k, 2)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not @ids and join($", @a) ne "-s"
MC/DC50%1/2
not @ids and join($", @a) ne "-s"
not @ids
join($", @a) ne "-s"
Truth table66%2/3
not(A) and B
A= not @idsB= join($", @a) ne "-s"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | if !@ids && "@a" ne '-s'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 41 | ▶ | if (defined $s) { $s = $SIGNAME{$s} // $s if $s =~ /^[0-9]+\z/; $s =~ s/^SIG// } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$SIGNAME{$s} // $s
MC/DC0%0/2
$SIGNAME{$s} // $s
$SIGNAME{$s}
$s
Truth table66%2/3
A // B
A= $SIGNAME{$s}B= $s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # The shell takes the signal itself only when the signal is one that exists (0 is EXIT here), every word left is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # number (a process ID, or a group's with '-') and $$ is among them. Every other form goes to the program kill as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # written: it refuses what is no signal or no process ID, and the shell goes on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | return ProcSS::spawn($c, $c->{map}, $argv, $env, $k) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 41 | ▶ | unless defined $s && ($s eq 'EXIT' || $SIGNUM{$s}) && !grep(!/^-?[0-9]+\z/, @ids) && grep $_ eq $sh->{pid}, @ids; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition91%11/12
defined $s and $s eq "EXIT" || $Proc::ShellSpawn::Large::SIGNUM{$s} and not grep((!/^-?[0-9]+\z/), @ids) and grep(($_ eq $sh->{"pid"}), @ids)
defined $s and $s eq "EXIT" || $Proc::ShellSpawn::Large::SIGNUM{$s} and not grep((!/^-?[0-9]+\z/), @ids)
defined $s and $s eq "EXIT" || $Proc::ShellSpawn::Large::SIGNUM{$s}
$s eq "EXIT" or $Proc::ShellSpawn::Large::SIGNUM{$s}
MC/DC80%4/5
defined $s and $s eq "EXIT" || $Proc::ShellSpawn::Large::SIGNUM{$s} and not grep((!/^-?[0-9]+\z/), @ids) and grep(($_ eq $sh->{"pid"}), @ids)
defined $s
$s eq "EXIT"
$Proc::ShellSpawn::Large::SIGNUM{$s}
not grep((!/^-?[0-9]+\z/), @ids)
grep(($_ eq $sh->{"pid"}), @ids)
Truth table62%5/8
A and B or C and not(D) and E
A= defined $sB= $s eq "EXIT"C= $Proc::ShellSpawn::Large::SIGNUM{$s}D= not grep((!/^-?[0-9]+\z/), @ids)E= grep(($_ eq $sh->{"pid"}), @ids)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 25 | my $harmless = $s =~ /^(?:CHLD|CLD|URG|WINCH|CONT)\z/; # post4-0.04: by default these do nothing to the shell (0 is EXIT here) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 25 | my @other = grep $_ ne $sh->{pid}, @ids; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 25 | ▶ | my $m = $sh->{main} // $sh; # $$ is the main shell, also in a subshell: its trap counts (L6) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$sh->{"main"} // $sh
MC/DC0%0/2
$sh->{"main"} // $sh
$sh->{"main"}
$sh
Truth table66%2/3
A // B
A= $sh->{"main"}B= $sh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 25 | ▶ | my $self = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=13 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 25 | my $t = $m->{trap}{$s}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 25 | ▶ | return ProcSS::defer($k, 0) if $s eq 'EXIT' || $harmless && !defined $t; # kill -0 $$ only tests; as both shells, status 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$s eq "EXIT" or $harmless and not defined $t
$harmless and not defined $t
MC/DC66%2/3
$s eq "EXIT" or $harmless and not defined $t
$s eq "EXIT"
$harmless
not defined $t
Truth table75%3/4
A or B and not(C)
A= $s eq "EXIT"B= $harmlessC= not defined $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 19 | ▶ | return ProcSS::defer($k, 0) if defined $t && $t eq ''; # ignored | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $t and $t eq ""
MC/DC100%2/2
defined $t and $t eq ""
defined $t
$t eq ""
Truth table100%3/3
A and B
A= defined $tB= $t eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 17 | ▶ | return ProcSS::defer($k, 0) if $Proc::ShellSpawn::IGN0{$s}; # X49: ignored on entry, so no trap: nothing, as both shells | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 15 | ▶ | return run_trap($c, $s, sub { ProcSS::defer($k, 0) }) if defined $t && $m == $sh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition66%2/3
defined $t and $m == $sh
MC/DC50%1/2
defined $t and $m == $sh
defined $t
$m == $sh
Truth table66%2/3
A and B
A= defined $tB= $m == $sh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 8 | ▶ | if (defined $t) { my $h = $m->{tsub}{$s}; $h->($s) if $h; return ProcSS::defer($k, 0) } # as a real signal: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # the trap runs in the main shell | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | $m->{trap}{EXIT} = '' if exists $m->{trap}{EXIT}; # a death by the signal runs no EXIT trap | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $Proc::ShellSpawn::SIGNALLED = $s; # the caller may die by it too (try.pl does) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | $sh->{die}->(128 + ($SIGNUM{$s} // 15)) }; # the whole string ends, as sh -c would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$Proc::ShellSpawn::Large::SIGNUM{$s} // 15
MC/DC0%0/1
$Proc::ShellSpawn::Large::SIGNUM{$s} // 15
$Proc::ShellSpawn::Large::SIGNUM{$s}
Truth table0%0/2
A
A= $Proc::ShellSpawn::Large::SIGNUM{$s}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 25 | ▶ | return $self->() unless @other; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | ProcSS::spawn($c, $c->{map}, ['kill', "-$s", (defined $dd ? '--' : ()), @other], $env, sub { $self->() }) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 212 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||