File Coverage

script/pdl.c
Criterion Covered Total %
statement 0 37 0.0
branch 0 24 0.0
condition n/a
subroutine n/a
pod n/a
total 0 61 0.0


line stmt bran cond sub pod time code
1             /******************************
2             * pdl.c - perldl spawner
3             * Works around a problem with many unices that you can't use an interpreter
4             * to run an interpreter -- so "#!/usr/bin/perldl" won't work.
5             * This is a compiled piece of code that launches perldl "directly",
6             * so that the poor kernel's mind isn't blown.
7             *
8             * If you feed in a single non-switch argument it gets prepended with a
9             * "-" to let perldl know that it's an input file. That way you can be lazy
10             * and say "#!/usr/bin/pdl" at the top of your script.
11             *
12             * CED 21-Jul-2004
13             */
14              
15             #include
16             #include
17             #include
18             #include
19             #include
20              
21 0           int main(int argc, char **argv) {
22             char perldl[BUFSIZ];
23             int pipes[2];
24             int pid,i;
25             int status;
26              
27 0 0         if(pipe(pipes)) {perror("pdl (perldl spawn wrapper)"); exit(1);}
28 0           pid = fork();
29 0 0         if(pid==0) {
30 0           dup2(pipes[1],1);
31 0           dup2(pipes[1],2);
32 0           exit(system("which perldl"));
33             }
34 0           pid = wait(&status);
35 0 0         if(! WIFEXITED(status) ) {
36 0           fprintf(stderr,"Hmmm... couldn't seem to find perldl anywhere. Quitting.\n");
37 0           goto exit;
38             }
39 0 0         if( read(pipes[0],perldl,BUFSIZ) <= 0 ) {
40 0           fprintf(stderr, "Read error - quitting.\n");
41 0           goto exit;
42             }
43              
44             /* Remove trailing newline */
45 0 0         for(i=0;i
    0          
46 0 0         if(perldl[i]=='\n' || perldl[i]=='\r')
    0          
47 0           perldl[i]='\0';
48              
49 0 0         if(argc==2) {
50 0 0         if(argv[1][0]!='-') {
51 0           char **argv2 = malloc((argc+2)*sizeof(char *));
52             int i;
53              
54 0 0         if(!argv2)
55 0           goto exit;
56              
57 0 0         for(i=0;i
58 0           argv2[i+1]=argv[i];
59              
60 0           argv2[1]="-";
61 0           argv2[0]="perldl";
62 0           argv2[argc+1]=0;
63              
64 0           execv(perldl,argv2);
65 0           fprintf(stderr,"couldn't execv %s\n",perldl);
66 0           goto exit;
67             }
68             }
69              
70 0           argv[0]="perldl";
71 0           execv(perldl,argv);
72 0           fprintf(stderr,"couldn't execv %s (%d args)\n",perldl,argc);
73 0           goto exit;
74              
75 0           exit:
76 0           perror("pdl (perldl trampoline)");
77 0           exit(-1);
78             }