bin/perl5i.c

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 59 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/perl5i/latest.pm ↑ Summary
1 /* THIS FILE IS GENERATED BY bin/perl5i.c.PL
2 * Any changes here will be wiped out. Edit it there instead.
3 */
4  
5 #define DEBUG 0
6  
7 #include <unistd.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11  
12 /*
13 * Meant to mimic the shell command
14 * exec perl -Mperl5i::latest "$@"
15 *
16 * This is a C program so it works in a #! line.
17 */
18  
19 0 int main (int argc, char* argv[]) {
20 int i;
21 int j;
22 0 const char* perl_cmd = "/usr/local/bin/perl";
23 0 char* perl_args[argc+1];
24 0 char* dash_m = (char *)malloc(sizeof(char) * (strlen(argv[0]) + 20));
25 0 char* program = "";
26 0 int saw_dash_e = 0;
27  
28 0 strcpy(dash_m, "-Mperl5i::cmd=");
29 0 strcat(dash_m, argv[0]);
30  
31 0 perl_args[0] = (char *)perl_cmd;
32 0 perl_args[1] = dash_m;
33  
34 0 ▶ for( i = 1, j = 2; i < argc; i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
for( i = 1, j = 2; i < argc; i++ ) { 0 0 0
35 0 char *dash_e = strchr(argv[i], 'e');
36  
37 /* Its a one liner */
38 0 ▶ if( dash_e
Branch: 1 branch
BranchTrueFalseTotal
if( dash_e 0 0 0
39 0 ▶ && dash_e > argv[i]
Branch: 1 branch
BranchTrueFalseTotal
&& dash_e > argv[i] 0 0 0
40 0 ▶ && *(dash_e-1) == '-'
Branch: 1 branch
BranchTrueFalseTotal
&& *(dash_e-1) == '-' 0 0 0
41 0 ▶ && (strchr(argv[i], '-') == argv[i])
Branch: 1 branch
BranchTrueFalseTotal
&& (strchr(argv[i], '-') == argv[i]) 0 0 0
42 0 ▶ && i+1 < argc
Branch: 1 branch
BranchTrueFalseTotal
&& i+1 < argc 0 0 0
43 )
44 {
45 0 saw_dash_e = 1;
46  
47 /* Chop out the -e */
48 0 dash_e[0] = '\0';
49  
50 /* If all that's left is a dash, ignore it */
51 0 ▶ if( strcmp(argv[i], "-") != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if( strcmp(argv[i], "-") != 0 ) { 0 0 0
52 0 perl_args[j] = argv[i];
53 0 j++;
54 }
55  
56 /* Skip the next argument, its the program */
57 0 i++;
58 0 program = argv[i];
59 0 continue;
60 }
61  
62 0 perl_args[j] = argv[i];
63 0 j++;
64 }
65  
66 /* Turn one liners into real programs to work around
67 a Devel::Declare bug */
68 0 ▶ if( saw_dash_e ) {
Branch: 1 branch
BranchTrueFalseTotal
if( saw_dash_e ) { 0 0 0
69 0 char tempfile[] = "/tmp/perl5i.XXXXXX";
70 0 int fd = mkstemp(tempfile);
71 0 ▶ if( fd == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if( fd == -1 ) { 0 0 0
72 0 perror("Could not open temporary file 'tempfile'");
73 0 exit(1);
74 }
75 0 FILE *fh = fdopen(fd, "w");
76 0 fprintf( fh, "$0 = '-e';\n" );
77 0 fprintf( fh, "#line 1 \"-e\"\n" );
78 0 fprintf( fh, "%s", program );
79 0 fclose(fh);
80  
81 0 perl_args[j++] = tempfile;
82 }
83  
84 /* Argument array must be terminated by a null */
85 0 perl_args[j] = (char *)NULL;
86  
87 #if DEBUG
88 for( i = 0; i <= j; i++ ) {
89 printf("perl_args[%d]: %s\n", i, perl_args[i]);
90 }
91  
92 if( saw_dash_e )
93 printf("program: %s\n", program);
94 #endif
95  
96 0 return execv( perl_cmd, perl_args );
97 }
« blib/lib/perl5i/latest.pm ↑ Summary