| 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
Condition66%2/3
defined $ARGV[$#ARGV] and $ARGV[$#ARGV] eq "-"
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 "-"
| |||||||||||||||||||||||||||||
| 12 | 1 | $stdin = 1; pop @ARGV; | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | my %options; | |||||||||||||||||||||||||||
| 16 | 2 | ▶ | Getopt::Long::GetOptions( \%options, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 23 | 0 | print "This is dbfdump version $XBase::VERSION.\n"; | |||||||||||||||||||||||||||
| 24 | 0 | exit; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | if ($stdin) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 1 | push @ARGV, '-'; | |||||||||||||||||||||||||||
| 29 | 1 | $options{'nomemo'} = 1; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | if (@ARGV == 0 or defined $options{'help'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@ARGV == 0 or defined $options{"help"}
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"}
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $options{"nomemo"} or defined $options{"info"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 67 | 0 | print STDERR XBase->errstr; | |||||||||||||||||||||||||||
| 68 | 0 | next; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 2 | ▶ | if (defined $options{'info'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if (not defined $options{'SQL'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 91 | 0 | print "\t$names[$i] $types[$i]"; | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($types[$i] eq 'blob') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | $lengths[$i] = $decimals[$i] = undef; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($lengths[$i] or $decimals[$i]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$lengths[$i] or $decimals[$i]
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]
| |||||||||||||||||||||||||||||
| 96 | 0 | print "($lengths[$i]"; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | print ", $decimals[$i]" if $decimals[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | print ")"; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if (defined $names[$i+1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 2 | $table->close; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1; | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | __END__ | ||||||||||||||||||||||||||||