makesdb.pl

filter: Statementstmt 23.5% 8 / 34 Branchbran 15.0% 3 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 2 Podpod n/a totaltotal 19.6% 12 / 61 CC 2 SCAR 15.4
CC
2
Cov
21%
prompt
6.0
usage
2.0
CRAP 4.7
« blib/script/makesdb.pl ↑ Summary
1 #!/usr/bin/perl
2  
3 1 ▶$dbname = shift (@ARGV) || prompt("Database name");
Condition33%1/3
shift @ARGV || prompt('Database name')
l!l&&r!l&&!r
100
MC/DC0%0/2
shift @ARGV || prompt('Database name')
shift @ARGV prompt('Database name')
Truth table33%1/3
A || B
A= shift @ARGVB= prompt('Database name')
ABresult
1X1
011
000
4 1 ▶&usage() unless ($dbname =~ /^\w+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $dbname =~ /^\w+$/ 0 1 1
5  
6 1 ▶open (SDB, ">>${dbname}.sdb") || die "Could not open database \"${dbname}.sdb\"!\n";
Branch: 1 branch
BranchTrueFalseTotal
open SDB, ">>$dbname.sdb" or die qq[Could not open database "$dbname.sdb"!\n] 1 0 1
7  
8 1 ▶if ($ARGV[0])
Branch: 1 branch
BranchTrueFalseTotal
if ($ARGV[0]) { } 1 0 1
9 {
10 1 $cryptedpswd = crypt($ARGV[1], substr($ARGV[0],0,2));
11 1 print SDB <<END_REC;
12 $ARGV[2]/*$ARGV[3]
13 $ARGV[0]
14 $cryptedpswd
15 $ARGV[5]
16 $ARGV[4]
17 END_REC
18 }
19 else
20 {
21 do
22 0 {
23 0 $dbuser = prompt("\nDatabase user");
24 0 ▶ goto DONE unless ($dbuser =~ /^\w+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $dbuser =~ /^\w+$/ 0 0 0
25 0 $dbpswd = prompt("User password");
26 0 ▶ goto DONE unless ($dbpswd =~ /^\w+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $dbpswd =~ /^\w+$/ 0 0 0
27 0 $dbpath = prompt("Database path");
28 0 ▶ $dbpath = '.' unless ($dbpath);
Branch: 1 branch
BranchTrueFalseTotal
unless $dbpath 0 0 0
29 0 $dbpath =~ s#/$##;
30 0 $dbext = prompt("Table file extension (default .stb)");
31 0 ▶ $dbext = '.stb' unless ($dbext);
Branch: 1 branch
BranchTrueFalseTotal
unless $dbext 0 0 0
32 0 $rdelim = prompt("Record delimiter (default \\r\\n)");
33 0 ▶ $rdelim = '\r\n' unless ($rdelim);
Branch: 1 branch
BranchTrueFalseTotal
unless $rdelim 0 0 0
34 0 $fdelim = prompt("Field delimiter (default ::)");
35 0 ▶ $fdelim = '::' unless ($fdelim);
Branch: 1 branch
BranchTrueFalseTotal
unless $fdelim 0 0 0
36 0 $cryptedpswd = crypt($dbpswd, substr($dbuser,0,2));
37 0 print SDB <<END_REC;
38 $dbpath/*$dbext
39 $dbuser
40 $cryptedpswd
41 $fdelim
42 $rdelim
43 END_REC
44 }
45 while (1);
46 }
47  
48 1 DONE: ;
49  
50 1 exit (0);
51  
52 sub prompt
53 0 ▶{
Subroutine prompt: not called CC=2 SCAR=17.9
54 0 my ($pmpt,$dflt) = @_;
55  
56 0 my ($t);
57 0 print "$pmpt: ";
58  
59 0 $t = <>;
60 0 chomp($t);
61 0 ▶ $t = $dflt unless ($t =~ /\S/);
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ /\S/ 0 0 0
62 0 return $t;
63 }
64  
65 sub usage
66 0 ▶{
Subroutine usage: not called CC=1 SCAR=6.9
67 0 print "..usage: $0 [dbname [user password path ext rec_sep field_sep]]\n";
68 0 print "\nCreates / adds users to a Sprite database.\n\n";
69 0 exit (1);
70 }
« blib/script/makesdb.pl ↑ Summary