lists.PL

filter: Statementstmt 100% 84 / 84 Branchbran 70.0% 14 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 91.3% 106 / 116 CC 9 SCAR 13.0
CC
9
Cov
93%
from_listing
5.0
dump_table
5.0
BEGIN
1.0
CRAP 3.7
« blib/lib/POSIX/1003/Properties.pm ↑ Summary blib/lib/POSIX/1003/FdIO.pm »
1 #!/usr/bin/env perl
2 #
3 # This script builds .c files with constants, to be included in the XS
4  
5 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use blib;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub dump_table($$$);
14 sub from_listing($$);
15  
16 # Maybe someone uses cross-compilation
17 1 ▶my $system = lc ($ENV{OSNAME} || $^O);
Condition33%1/3
$ENV{'OSNAME'} || $^O
l!l&&r!l&&!r
010
MC/DC0%0/2
$ENV{'OSNAME'} || $^O
$ENV{'OSNAME'} $^O
Truth table33%1/3
A || B
A= $ENV{'OSNAME'}B= $^O
ABresult
1X1
011
000
18  
19 1 my %float_as_string = map +($_ => 1),
20 qw/DBL_MAX FLT_MAX HUGE_VAL LDBL_MAX/;
21  
22 1 my ( %sc, %cs, %posix, %math, %pc, %ul, %rl, %events, %sig
23 , %fdio, %fsys, %errno, %fcntl, %socket, %locale, %osconsts
24 , %proc, %time, %user);
25  
26 1 from_listing \%cs, 'confstr.txt';
27 1 from_listing \%errno, 'errno.txt';
28 1 from_listing \%fcntl, 'fcntl.txt';
29 1 from_listing \%fdio, 'fdio.txt';
30 1 from_listing \%fsys, 'fsys.txt';
31 1 from_listing \%locale,'locale.txt';
32 1 from_listing \%math, 'math.txt';
33 1 from_listing \%osconsts,'osconsts.txt';
34 1 from_listing \%pc, 'pathconf.txt';
35 1 from_listing \%events,'events.txt';
36 1 from_listing \%posix, 'posix.txt';
37 1 from_listing \%proc, 'proc.txt';
38 1 from_listing \%rl, 'rlimit.txt';
39 1 from_listing \%sc, 'sysconf.txt';
40 1 from_listing \%sig, 'signals.txt';
41 1 from_listing \%time, 'time.txt';
42 1 from_listing \%ul, 'ulimit.txt';
43 1 from_listing \%user, 'user.txt';
44 1 from_listing \%socket,'socket.txt';
45  
46 #use Data::Dumper;
47 #warn Dumper \%sc, \%cs, \%posix, \%pc;
48  
49 1 dump_table(\%cs, 'cs_table', 'confstr.c' );
50 1 dump_table(\%errno, 'errno_table', 'errno.c' );
51 1 dump_table(\%fcntl, 'fcntl_table', 'fcntl.c' );
52 1 dump_table(\%fdio, 'fdio_table', 'fdio.c' );
53 1 dump_table(\%fsys, 'fsys_table', 'fsys.c' );
54 1 dump_table(\%locale,'locale_table','locale.c' );
55 1 dump_table(\%math, 'math_table', 'math.c' );
56 1 dump_table(\%osconsts,'os_table', 'osconsts.c' );
57 1 dump_table(\%pc, 'pc_table', 'pathconf.c' );
58 1 dump_table(\%events,'events_table','events.c' );
59 1 dump_table(\%posix, 'pr_table', 'properties.c');
60 1 dump_table(\%proc, 'proc_table', 'proc.c' );
61 1 dump_table(\%rl, 'rl_table', 'rlimit.c' );
62 1 dump_table(\%sc, 'sc_table', 'sysconf.c' );
63 1 dump_table(\%sig, 'sig_table', 'signals.c' );
64 1 dump_table(\%time, 'time_table', 'time.c' );
65 1 dump_table(\%ul, 'ul_table', 'ulimit.c' );
66 1 dump_table(\%user, 'user_table', 'user.c' );
67 1 dump_table(\%socket,'socket_table','socket.c' );
68  
69 # System specific compilation helpers
70 1 ▶open SYSTEM, '>', 'system.c'
Branch: 1 branch
BranchTrueFalseTotal
open SYSTEM, ">", "system.c" or die "cannot write to system.c: $!" 0 1 1
71 or die "cannot write to system.c: $!";
72  
73 1 my $incl = File::Spec->catfile('system', $system.'.c');
74 1 ▶if(-f $incl)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $incl) 1 0 1
75 1 { print SYSTEM qq{#include "$incl"\n};
76 }
77  
78 1 ▶close SYSTEM
Branch: 1 branch
BranchTrueFalseTotal
close SYSTEM or die "write errors to system.c: $!" 0 1 1
79 or die "write errors to system.c: $!";
80  
81 1 exit 0;
82  
83 sub dump_table($$$)
84 19 ▶{ my ($consts, $table, $filename) = @_;
Subroutine dump_table: called CC=5 SCAR=16.1
85 19 local *TABLE;
86 19 ▶ open TABLE, '>', $filename
Branch: 1 branch
BranchTrueFalseTotal
open TABLE, ">", $filename or die "cannot write to ${filename}: $!\n" 0 19 19
87 or die "cannot write to $filename: $!\n";
88  
89 19 print TABLE "/* Generated */\n\n"
90 , "missing_is_sorted = 0;\n\n";
91  
92 19 foreach my $const (sort keys %$consts)
93 1610 { my $klen = length $const;
94  
95 1610 my $store;
96 1610 ▶ if($float_as_string{$const})
Branch: 1 branch
BranchTrueFalseTotal
if ($float_as_string{$const}) { } 4 1606 1610
97 4 { $store = <<_FLOAT;
98 sprintf(float_string, "%g", $const);
99 (void)hv_store($table, "$const", $klen, newSVpv(float_string, 0), 0);
100 _FLOAT
101 }
102 else
103 1606 ▶ { my $cast = $const =~ m/^SIG_/ ? '(long)' : '';
Branch: 1 branch
BranchTrueFalseTotal
$const =~ /^SIG_/ ? : 7 1599 1606
104 1606 $store = <<_INT;
105 (void)hv_store($table, "$const", $klen, newSViv($cast$const), 0);
106 _INT
107 }
108  
109 1610 print TABLE <<_CONST
110 #ifdef $const
111 $store#else
112 missing[nr_missing++] = "$const";
113 #endif
114 _CONST
115 }
116  
117 19 close TABLE;
118 }
119  
120 sub from_listing($$)
121 19 ▶{ my ($table, $filename) = @_;
Subroutine from_listing: called CC=5 SCAR=16.2
122 19 my $path = File::Spec->catfile('lists', $filename);
123 19 local *IN;
124 19 ▶ open IN, '<', $path
Branch: 1 branch
BranchTrueFalseTotal
open IN, "<", $path or die "cannot read from ${path}: $!" 0 19 19
125 or die "cannot read from $path: $!";
126 19 ▶ while(<IN>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline IN)) 1699 19 1718
127 1699 ▶ { next if m/^#|^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^#|^\s*$/ 85 1614 1699
128 1614 chomp;
129 1614 $table->{$_}++;
130 }
131 19 ▶ close IN
Branch: 1 branch
BranchTrueFalseTotal
close IN or die "errors while reading ${path}: $!" 0 19 19
132 or die "errors while reading $path: $!";
133 }
« blib/lib/POSIX/1003/Properties.pm ↑ Summary blib/lib/POSIX/1003/FdIO.pm »