script/dbfdump

filter: Statementstmt 53.9% 34 / 63 Branchbran 40.6% 13 / 32 Conditioncond 41.6% 5 / 12 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 48.3% 57 / 118 CC 1 SCAR 0.0
CC
1
Cov
49%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/XBase/Base.pm ↑ Summary
1 #!/usr/local/bin/perl -w
2  
3  
4 2 ▶use XBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $^W = 1;
8  
9 2 my $stdin = 0;
10  
11 2 ▶if (defined $ARGV[$#ARGV] and $ARGV[$#ARGV] eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ARGV[$#ARGV] and $ARGV[$#ARGV] eq "-") 1 1 2
Condition66%2/3
defined $ARGV[$#ARGV] and $ARGV[$#ARGV] eq "-"
!ll&&!rl&&r
011
MC/DC50%1/2
defined $ARGV[$#ARGV] and $ARGV[$#ARGV] eq "-"
defined $ARGV[$#ARGV] $ARGV[$#ARGV] eq "-"
Truth table66%2/3
A and B
A= defined $ARGV[$#ARGV]B= $ARGV[$#ARGV] eq "-"
ABresult
0X0
100
111
12 1 $stdin = 1; pop @ARGV;
13 }
14  
15 2 my %options;
16 2 ▶Getopt::Long::GetOptions( \%options,
Branch: 1 branch
BranchTrueFalseTotal
&Getopt::Long::GetOptions(\%options, "help", "version", "info", "rs=s", "fs=s", "undef=s", "fields=s", "nomemo", "memofile=s", "memosep=s", "table", "SQL") or exit 0 2 2
17 'help', 'version', 'info', 'rs=s', 'fs=s', 'undef=s', 'fields=s',
18 'nomemo', 'memofile=s', 'memosep=s', 'table',
19 'SQL',
20 ) or exit;
21  
22 2 ▶if (defined $options{'version'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{"version"}) 0 2 2
23 0 print "This is dbfdump version $XBase::VERSION.\n";
24 0 exit;
25 }
26  
27 2 ▶if ($stdin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stdin) 1 1 2
28 1 push @ARGV, '-';
29 1 $options{'nomemo'} = 1;
30 }
31  
32 2 ▶if (@ARGV == 0 or defined $options{'help'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV == 0 or defined $options{"help"}) 0 2 2
Condition33%1/3
@ARGV == 0 or defined $options{"help"}
l!l&&r!l&&!r
002
MC/DC0%0/2
@ARGV == 0 or defined $options{"help"}
@ARGV == 0 defined $options{"help"}
Truth table33%1/3
A or B
A= @ARGV == 0B= defined $options{"help"}
ABresult
1X1
011
000
33 0 die <<'EOF';
34 Usage: dbfdump [ options ] files
35 where the options specify
36 --rs output record separator (default newline)
37 --fs output field separator (default colon)
38 --fields comma separated list of fields to print (default all)
39 --undef what to print for NULL values (default empty string)
40 --memofile specifies unstandard name of attached memo file
41 --memosep separator for dBase III dbt's (default \x1a\x1a)
42 --table output in nice table format (needs Data::ShowTable)
43 all having as parameter a string; and also
44 --nomemo do not try to read the memo (dbt/fpt) file
45 --info only print info about the file and fields
46 --version print version of the XBase library
47 EOF
48 }
49  
50 2 my %addopts = ();
51 2 ▶if (defined $options{'nomemo'} or defined $options{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{"nomemo"} or defined $options{"info"}) 1 1 2
Condition66%2/3
defined $options{"nomemo"} or defined $options{"info"}
l!l&&r!l&&!r
101
MC/DC50%1/2
defined $options{"nomemo"} or defined $options{"info"}
defined $options{"nomemo"} defined $options{"info"}
Truth table66%2/3
A or B
A= defined $options{"nomemo"}B= defined $options{"info"}
ABresult
1X1
011
000
52 1 $addopts{'ignorememo'} = 1;
53 }
54  
55 2 $addopts{'memosep'} = $options{'memosep'};
56 2 $addopts{'memofile'} = $options{'memofile'};
57  
58 2 ▶if (defined $options{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{"info"}) 0 2 2
59 0 $addopts{'ignorebadheader'} = 1;
60 }
61  
62 2 my $file;
63 2 for $file (@ARGV) {
64 2 my $table = new XBase 'name' => $file, %addopts;
65  
66 2 ▶ if (not defined $table) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $table) 0 2 2
67 0 print STDERR XBase->errstr;
68 0 next;
69 }
70 2 ▶ if (defined $options{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options{'info'}) { } 0 2 2
71 0 ▶ if (not defined $options{'SQL'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $options{'SQL'}) { } 0 0 0
72 0 print $table->header_info;
73 } else {
74 0 my $name = $file;
75 0 $name =~ s!^.*/|\.dbf$!!ig;
76 0 print "create table $name (\n";
77 0 my @names = $table->field_names;
78 0 my %conv = qw!
79 C varchar
80 N numeric
81 F numeric
82 L boolean
83 M blob
84 D date
85 T time
86 !;
87 0 my @types = map { $conv{$_} } $table->field_types;
88 0 my @lengths = $table->field_lengths;
89 0 my @decimals = $table->field_decimals;
90 0 ▶ for (my $i = 0; $i < @names; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @names) 0 0 0
91 0 print "\t$names[$i] $types[$i]";
92 0 ▶ if ($types[$i] eq 'blob') {
Branch: 1 branch
BranchTrueFalseTotal
if ($types[$i] eq "blob") 0 0 0
93 0 $lengths[$i] = $decimals[$i] = undef;
94 }
95 0 ▶ if ($lengths[$i] or $decimals[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lengths[$i] or $decimals[$i]) 0 0 0
Condition0%0/3
$lengths[$i] or $decimals[$i]
l!l&&r!l&&!r
000
MC/DC0%0/2
$lengths[$i] or $decimals[$i]
$lengths[$i] $decimals[$i]
Truth table0%0/3
A or B
A= $lengths[$i]B= $decimals[$i]
ABresult
1X1
011
000
96 0 print "($lengths[$i]";
97 0 ▶ print ", $decimals[$i]" if $decimals[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $decimals[$i] 0 0 0
98 0 print ")";
99 }
100 0 ▶ if (defined $names[$i+1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $names[$i + 1]) 0 0 0
101 0 print ',';
102 }
103 0 print "\n";
104 }
105 0 print ")\n";
106 }
107 } else {
108 2 ▶ $table->dump_records(%options) or print STDERR $table->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$table->dump_records(%options) or print STDERR $table->errstr 0 2 2
109 }
110 2 $table->close;
111 }
112  
113 1;
114  
115 __END__
« lib/XBase/Base.pm ↑ Summary