blib/script/makesdb.pl untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 64 CC 2 SCAR 15.4
CC
2
Cov
0%
prompt
6.0
usage
2.0
CRAP 4.7
1 #!/usr/local/bin/perl
2  
3 $dbname = shift (@ARGV) || prompt("Database name");
4 &usage() unless ($dbname =~ /^\w+$/);
5  
6 open (SDB, ">>${dbname}.sdb") || die "Could not open database \"${dbname}.sdb\"!\n";
7  
8 if ($ARGV[0])
9 {
10 $cryptedpswd = crypt($ARGV[1], substr($ARGV[0],0,2));
11 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 {
23 $dbuser = prompt("\nDatabase user");
24 goto DONE unless ($dbuser =~ /^\w+$/);
25 $dbpswd = prompt("User password");
26 goto DONE unless ($dbpswd =~ /^\w+$/);
27 $dbpath = prompt("Database path");
28 $dbpath = '.' unless ($dbpath);
29 $dbpath =~ s#/$##;
30 $dbext = prompt("Table file extension (default .stb)");
31 $dbext = '.stb' unless ($dbext);
32 $rdelim = prompt("Record delimiter (default \\r\\n)");
33 $rdelim = '\r\n' unless ($rdelim);
34 $fdelim = prompt("Field delimiter (default ::)");
35 $fdelim = '::' unless ($fdelim);
36 $cryptedpswd = crypt($dbpswd, substr($dbuser,0,2));
37 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 DONE: ;
49  
50 exit (0);
51  
52 sub prompt
53 {
54 my ($pmpt,$dflt) = @_;
55  
56 my ($t);
57 print "$pmpt: ";
58  
59 $t = <>;
60 chomp($t);
61 $t = $dflt unless ($t =~ /\S/);
62 return $t;
63 }
64  
65 sub usage
66 {
67 print "..usage: $0 [dbname [user password path ext rec_sep field_sep]]\n";
68 print "\nCreates / adds users to a Sprite database.\n\n";
69 exit (1);
70 }