9 #include "interlacemodes.h"
13 int pipe_sigpipe_received;
15 void pipe_handle_sigpipe(int signum) {
16 printf("Received sigpipe\n");
17 pipe_sigpipe_received++;
21 Pipe::Pipe(char *command, char *sub_str, char sub_char) {
22 this->command = command;
23 this->sub_str = sub_str;
24 this->sub_char = sub_char;
30 // FUTURE: could probably set to SIG_IGN once things work
31 signal(SIGPIPE, pipe_handle_sigpipe);
38 int Pipe::substitute() {
39 if (command == NULL) {
44 if (sub_str == NULL || sub_char == '\0') {
45 strcpy(complete, command);
53 // directly copy anything substitution char
59 // move over the substitution character
62 // two substitution characters in a row is literal
68 // insert the file string at the substitution point
69 if (f + strlen(sub_str) - complete > sizeof(complete)) {
70 printf("Pipe::substitute(): max length exceeded\n");
83 int Pipe::open(char *mode) {
87 printf("Pipe::open(): no mode given\n");
91 if (substitute() < 0) {
95 if (complete == NULL || strlen(complete) == 0) {
96 printf("Pipe::open(): no pipe to open\n");
100 printf("trying popen(%s)\n", complete);
101 file = popen(complete, mode);
107 // NOTE: popen() fails only if fork/exec fails
108 // there is no immediate way to see if command failed
109 // As such, one must expect to raise SIGPIPE on failure
110 printf("Pipe::open(%s,%s) failed: %s\n",
111 complete, mode, strerror(errno));
115 int Pipe::open_read() {
119 int Pipe::open_write() {
130 PipeConfig::PipeConfig(BC_WindowBase *window, BC_Hash *defaults, Asset *asset)
132 this->window = window;
133 this->defaults = defaults;
137 // NOTE: Default destructor should destroy all subwindows
139 int PipeConfig::create_objects(int x, int y, int textbox_width, int format) {
142 // NOTE: out of order so pipe_textbox is available to pipe_checkbox
143 textbox = new BC_TextBox(x + 120, y, textbox_width, 1, asset->pipe);
144 window->add_subwindow(textbox);
145 if (! asset->use_pipe) textbox->disable();
147 window->add_subwindow(new BC_Title(x, y, _("Use Pipe:")));
148 checkbox = new PipeCheckBox(85, y - 5, asset->use_pipe, textbox);
149 window->add_subwindow(checkbox);
154 recent = new BC_RecentList("PIPE", defaults, textbox,
156 window->add_subwindow(recent);
157 recent->load_items(FILE_FORMAT_PREFIX(format));
161 window->add_subwindow(titlew = new BC_Title(x, y, _("Stream Header:"), MEDIUMFONT, RED));
165 window->add_subwindow(new BC_Title(x, y, _("Interlacing:")));
166 char string[BCTEXTLEN];
167 ilacemode_to_text(string,asset->interlace_mode);
168 window->add_subwindow(new BC_Title(x + titlew->get_w() + 5, y, string, MEDIUMFONT, YELLOW));
171 PipeCheckBox::PipeCheckBox(int x, int y, int value, BC_TextBox *textbox)
172 : BC_CheckBox(x, y, value)
174 this->textbox = textbox;
176 int PipeCheckBox::handle_event() {
177 if (get_value()) textbox->enable();
178 else textbox->disable();
181 PipeStatus::PipeStatus(int x, int y, char *default_string)
182 : BC_Title(x, y, default_string)
184 this->default_string = default_string;
186 int PipeStatus::set_status(Asset *asset) {
187 if (! asset->use_pipe || ! asset->pipe || ! *(asset->pipe)) {
189 sprintf(status, default_string);
193 sprintf(status, "| %s", asset->pipe);
201 PipePreset::PipePreset(int x, int y, char *title, PipeConfig *config)
202 : BC_PopupMenu(x, y, 150, title)
204 this->config = config;
208 int PipePreset::handle_event() {
209 char *text = get_text();
210 // NOTE: preset items must have a '|' before the actual command
211 char *pipe = strchr(text, '|');
212 // pipe + 1 to skip over the '|'
213 if (pipe) config->textbox->update(pipe + 1);
215 config->textbox->enable();
216 config->checkbox->set_value(1, 1);
218 // menuitem sets the title after selection but we reset it