| 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
| |||||||||||||||||||||||||||||
| 29 | 4 | my $output_file = $opt{'o'}; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | FILESPEC : | ||||||||||||||||||||||||||||
| 32 | 4 | ▶ | while (<>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 4 | my( $mode, $header_name ); | |||||||||||||||||||||||||||
| 34 | 4 | ▶ | next FILESPEC unless ($mode, $header_name) = /^begin\s+(\d+)\s+(\S+)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 4 | ▶ | $output_file = $header_name unless defined $output_file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 4 | my $out; | |||||||||||||||||||||||||||
| 38 | 4 | ▶ | if ($output_file eq '-') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 2 | $out = *STDOUT; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | else { | ||||||||||||||||||||||||||||
| 42 | 2 | ▶ | if ($opt{'i'} && -e $output_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt{"i"} and -e $output_file
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 65 | 12 | ▶ | if (/^end$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 4 | $ended = 1; | |||||||||||||||||||||||||||
| 67 | 4 | last LINE; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 8 | ▶ | next LINE if /[a-z]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 8 | ▶ | next LINE unless int((((ord() - 32) & 077) + 2) / 3) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | == int(length() / 4); | ||||||||||||||||||||||||||||
| 72 | 8 | ▶ | unless (print $out unpack("u", $_)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 78 | 0 | warn "$Program: can't close '$output_file': $!\n"; | |||||||||||||||||||||||||||
| 79 | 0 | exit EX_FAILURE; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 4 | ▶ | unless ($ended) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||