| 1 | #!/usr/local/bin/perl -w | ||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||
| 3 | # Author : Johan Vromans | ||||||||||||||||||||||||
| 4 | # Created On : Tue Sep 1 15:59:04 2003 | ||||||||||||||||||||||||
| 5 | # Last Modified By: Johan Vromans | ||||||||||||||||||||||||
| 6 | # Last Modified On: Tue Apr 11 12:04:02 2017 | ||||||||||||||||||||||||
| 7 | # Update Count : 48 | ||||||||||||||||||||||||
| 8 | # Status : Unknown, Use with caution! | ||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | ################ Common stuff ################ | ||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||
| 14 | 1 | my $my_name = "csv2lsdb"; | |||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||
| 16 | ################ Command line parameters ################ | ||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||
| 18 | 1 | my $sep = ","; # separator | |||||||||||||||||||||||
| 19 | 1 | my $notesep = 1; # change sep in note to newline | |||||||||||||||||||||||
| 20 | 1 | my $verbose = 0; # more verbosity | |||||||||||||||||||||||
| 21 | 1 | my $pdb = "-"; # output name | |||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||
| 23 | # Development options (not shown with --help). | ||||||||||||||||||||||||
| 24 | 1 | my $debug = 0; # debugging | |||||||||||||||||||||||
| 25 | 1 | my $trace = 0; # trace (show process) | |||||||||||||||||||||||
| 26 | 1 | my $test = 0; # test mode. | |||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||
| 28 | # Process command line options. | ||||||||||||||||||||||||
| 29 | 1 | app_options(); | |||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||
| 31 | # Post-processing. | ||||||||||||||||||||||||
| 32 | 1 | my $sepp = quotemeta($sep); | |||||||||||||||||||||||
| 33 | 1 | ▶ | $trace |= ($debug || $test); | ||||||||||||||||||||||
|
Condition33%1/3
$debug || $test
MC/DC0%0/2
$debug || $test
$debug
$test
Truth table33%1/3
A || B
A= $debugB= $test
| |||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||
| 35 | ################ Presets ################ | ||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||
| 37 | 1 | ▶ | my $TMPDIR = $ENV{TMPDIR} || $ENV{TEMP} || '/usr/tmp'; | ||||||||||||||||||||||
|
Condition40%2/5
$ENV{'TMPDIR'} || $ENV{'TEMP'} || '/usr/tmp'
$ENV{"TMPDIR"} or $ENV{"TEMP"}
MC/DC0%0/2
$ENV{'TMPDIR'} || $ENV{'TEMP'} || '/usr/tmp'
$ENV{"TMPDIR"}
$ENV{"TEMP"}
Truth table33%1/3
A or B
A= $ENV{"TMPDIR"}B= $ENV{"TEMP"}
| |||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||
| 39 | ################ The Process ################ | ||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||
| 41 | 1 | ▶ | use Palm::ListDB::Writer; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||
| 43 | 0 | ▶ | sub wmsg { | ||||||||||||||||||||||
|
Subroutine
wmsg: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||
| 44 | 0 | my $msg = "@_"; | |||||||||||||||||||||||
| 45 | 0 | $msg =~ s/$/, $ARGV line $./; | |||||||||||||||||||||||
| 46 | 0 | print STDERR ($msg); | |||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||
| 48 | 1 | $SIG{__WARN__} = \&wmsg; | |||||||||||||||||||||||
| 49 | 0 | ▶ | $SIG{__DIE__} = sub { &wmsg; exit(-1) }; | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||
| 51 | # First record contains DBname,Label1,Label2,Cat1,Cat2,,,,,, | ||||||||||||||||||||||||
| 52 | 1 | my $a = <>; | |||||||||||||||||||||||
| 53 | 1 | chomp($a); | |||||||||||||||||||||||
| 54 | 1 | $a =~ s/\\$sepp/\n/g; | |||||||||||||||||||||||
| 55 | 1 | my ($db,$l1,$l2,@a) = map { s/\n/$sep/g; $_ } split(/$sepp/, $a); | |||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||
| 57 | 1 | ▶ | die("$my_name: Missing database name, $ARGV line $.\n") unless $db; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 58 | 1 | ▶ | die("$my_name: Missing 1st label, $ARGV line $.\n") unless $l1; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 59 | 1 | ▶ | die("$my_name: Missing 2nd label, $ARGV line $.\n") unless $l2; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 60 | 1 | ▶ | die("$my_name: Missing categories, $ARGV line $.\n") unless @a; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||
| 62 | 1 | my $x = new Palm::ListDB::Writer $db, | |||||||||||||||||||||||
| 63 | label1 => $l1, | ||||||||||||||||||||||||
| 64 | label2 => $l2, | ||||||||||||||||||||||||
| 65 | cat => [ @a ]; | ||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||
| 67 | # Subsequent records contain Cat,Field1,Field2,Note | ||||||||||||||||||||||||
| 68 | 1 | my $tally = 0; | |||||||||||||||||||||||
| 69 | 1 | ▶ | while ( <> ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 70 | 2 | chomp; | |||||||||||||||||||||||
| 71 | 2 | my @a; | |||||||||||||||||||||||
| 72 | 2 | s/\\$sepp/\0/g; | |||||||||||||||||||||||
| 73 | 2 | @a = split(/$sepp/,$_,4); | |||||||||||||||||||||||
| 74 | 2 | ▶ | $a[3] =~ s/$sepp/\n/g if $notesep; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 75 | 2 | for ( @a ) { | |||||||||||||||||||||||
| 76 | 8 | s/\0/$sep/g; | |||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||
| 79 | 2 | ▶ | $a[0] = "Unfiled" if $a[0] eq ""; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 80 | 2 | ▶ | $x->add(@a) && $tally++; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||
| 83 | 1 | $x->write($pdb); | |||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||
| 85 | 1 | ▶ | if ( $verbose ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 86 | 0 | my $ncat = $x->categories; | |||||||||||||||||||||||
| 87 | 0 | ▶ | print STDERR ($my_name, ": Created LSdb $pdb with ", | ||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||
| 88 | $ncat, " categor", ($ncat != 1 ? "ies" : "y"), | ||||||||||||||||||||||||
| 89 | " and $tally record", ($tally != 1 ? "s" : ""), | ||||||||||||||||||||||||
| 90 | "\n"); | ||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||
| 93 | 1 | exit 0; | |||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||
| 95 | ################ Subroutines ################ | ||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||
| 97 | ################ Command Line Options ################ | ||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||
| 99 | 1 | ▶ | use Getopt::Long 2.33; # will enable help/version | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||
| 101 | 1 | ▶ | sub app_options { | ||||||||||||||||||||||
|
Subroutine
app_options: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||
| 103 | GetOptions(ident => \&app_ident, | ||||||||||||||||||||||||
| 104 | 'verbose|v' => \$verbose, | ||||||||||||||||||||||||
| 105 | # application specific options go here | ||||||||||||||||||||||||
| 106 | 0 | ▶ | "tab" => sub { $sep = "\t" }, | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||
| 107 | 1 | ▶ | "pdb=s" => \$pdb, | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 108 | # development options | ||||||||||||||||||||||||
| 109 | test => \$test, | ||||||||||||||||||||||||
| 110 | trace => \$trace, | ||||||||||||||||||||||||
| 111 | debug => \$debug) | ||||||||||||||||||||||||
| 112 | or Getopt::Long::HelpMessage(2); | ||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||
| 115 | 0 | ▶ | sub app_ident { | ||||||||||||||||||||||
|
Subroutine
app_ident: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||
| 116 | 0 | print STDOUT ("This is Palm::ListDB::Writer [$my_name $Palm::ListDB::Writer::VERSION]\n"); | |||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||