9 #include "interlacemodes.h"
14 int pipe_sigpipe_received;
16 void pipe_handle_sigpipe(int signum)
18 printf("Received sigpipe\n");
19 pipe_sigpipe_received++;
23 Pipe::Pipe(char *command, char *sub_str, char sub_char)
25 this->command = command;
26 this->sub_str = sub_str;
27 this->sub_char = sub_char;
33 // FUTURE: could probably set to SIG_IGN once things work
34 signal(SIGPIPE, pipe_handle_sigpipe);
42 int Pipe::substitute()
50 if (sub_str == NULL || sub_char == '\0')
52 strcpy(complete, command);
61 // directly copy anything substitution char
68 // move over the substitution character
71 // two substitution characters in a row is literal
77 // insert the file string at the substitution point
78 if (f + strlen(sub_str) - complete > sizeof(complete))
80 printf("Pipe::substitute(): max length exceeded\n");
93 int Pipe::open(char *mode)
99 printf("Pipe::open(): no mode given\n");
103 if (substitute() < 0)
106 if (complete == NULL || strlen(complete) == 0)
108 printf("Pipe::open(): no pipe to open\n");
112 printf("trying popen(%s)\n", complete);
113 file = popen(complete, mode);
120 // NOTE: popen() fails only if fork/exec fails
121 // there is no immediate way to see if command failed
122 // As such, one must expect to raise SIGPIPE on failure
123 printf("Pipe::open(%s,%s) failed: %s\n",
124 complete, mode, strerror(errno));
128 int Pipe::open_read()
133 int Pipe::open_write()