bin/uudecode

filter: Statementstmt 74.5% 41 / 55 Branchbran 63.3% 19 / 30 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod n/a totaltotal 68.7% 66 / 96 CC 1 SCAR 1.5
CC
1
Cov
69%
usage
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« bin/rev ↑ Summary blib/lib/PerlPowerTools.pm »
1 #!/usr/bin/perl
2  
3 =begin metadata
4  
5 Name: uudecode
6 Description: decode a binary file
7 Author: Nick Ing-Simmons, nick@ni-s.u-net.com
8 Author: Tom Christiansen, tchrist@perl.com
9 Author: brian d foy, brian.d.foy@gmail.com
10 License: perl
11  
12 =end metadata
13  
14 =cut
15  
16  
17 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use Getopt::Std qw(getopts);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 4 ▶use constant EX_SUCCESS => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use constant EX_FAILURE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 4 my $Program = basename($0);
26  
27 4 my %opt;
28 4 ▶getopts('io:', \%opt) or usage();
Branch: 1 branch
BranchTrueFalseTotal
&getopts("io:", \%opt) or usage() 4 0 4
29 4 my $output_file = $opt{'o'};
30  
31 FILESPEC :
32 4 ▶while (<>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ARGV)) 4 4 8
33 4 my( $mode, $header_name );
34 4 ▶ next FILESPEC unless ($mode, $header_name) = /^begin\s+(\d+)\s+(\S+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless () = /^begin\s+(\d+)\s+(\S+)/ 0 4 4
35 4 ▶ $output_file = $header_name unless defined $output_file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $output_file 2 2 4
36  
37 4 my $out;
38 4 ▶ if ($output_file eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($output_file eq '-') { } 2 2 4
39 2 $out = *STDOUT;
40 }
41 else {
42 2 ▶ if ($opt{'i'} && -e $output_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"i"} and -e $output_file) 0 2 2
Condition33%1/3
$opt{"i"} and -e $output_file
!ll&&!rl&&r
200
MC/DC0%0/2
$opt{"i"} and -e $output_file
$opt{"i"} -e $output_file
Truth table33%1/3
A and B
A= $opt{"i"}B= -e $output_file
ABresult
0X0
100
111
43 0 warn "$Program: won't clobber file '$output_file'\n";
44 0 exit EX_FAILURE;
45 }
46 2 ▶ unless (open $out, '>', $output_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $out, ">", $output_file) 0 2 2
47 0 warn "$Program: can't create '$output_file': $!\n";
48 0 exit EX_FAILURE;
49 }
50 # Quickly protect file before data is written.
51 # XXX: Does this break on sub-Unix systems, like if
52 # it's a mode 400 or 000 file? If so, then we must
53 # wait until after the close.
54 2 ▶ unless (chmod oct($mode), $output_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chmod oct $mode, $output_file) 0 2 2
55 0 warn "$Program: can't chmod '$output_file' to mode '$mode': $!\n";
56 0 exit EX_FAILURE;
57 }
58 }
59  
60 4 binmode($out); # winsop
61 4 my $ended = 0;
62  
63 LINE:
64 4 ▶ while (<>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ARGV)) 12 0 12
65 12 ▶ if (/^end$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^end$/) 4 8 12
66 4 $ended = 1;
67 4 last LINE;
68 }
69 8 ▶ next LINE if /[a-z]/;
Branch: 1 branch
BranchTrueFalseTotal
if /[a-z]/ 0 8 8
70 8 ▶ next LINE unless int((((ord() - 32) & 077) + 2) / 3)
Branch: 1 branch
BranchTrueFalseTotal
unless int(((ord($_) - 32 & 63) + 2) / 3) == int length($_) / 4 0 8 8
71 == int(length() / 4);
72 8 ▶ unless (print $out unpack("u", $_)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (print $out unpack("u", $_)) 0 8 8
73 0 warn "$Program: can't write '$output_file': $!\n";
74 0 exit EX_FAILURE;
75 }
76 }
77 4 ▶ unless (close $out) {
Branch: 1 branch
BranchTrueFalseTotal
unless (close $out) 0 4 4
78 0 warn "$Program: can't close '$output_file': $!\n";
79 0 exit EX_FAILURE;
80 }
81 4 ▶ unless ($ended) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ended) 0 4 4
82 0 warn "$Program: missing end; '$output_file' may be truncated\n";
83 0 exit EX_FAILURE;
84 }
85 }
86 4 exit EX_SUCCESS;
87  
88 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
89 0 require Pod::Usage;
90 0 Pod::Usage::pod2usage({ -exitval => 1, -verbose => 0 });
91 }
92  
93 __END__
« bin/rev ↑ Summary blib/lib/PerlPowerTools.pm »