int m_fork(void) { pid_t r; r= fork(); if (r == -1) { onerr_abort++; ohshite(_("fork failed")); } if (r > 0) return r; push_cleanup(cu_m_fork,~0, NULL,0, 0); set_error_display(print_error_forked,NULL); return r; }
void commandfd(const char *const *argv) { jmp_buf ejbuf; struct varbuf linevb = VARBUF_INIT; const char * pipein; const char **newargs = NULL; char *ptr, *endptr; FILE *in; unsigned long infd; int c, lno, i; bool skipchar; void (*actionfunction)(const char *const *argv); pipein = *argv++; if (pipein == NULL) badusage(_("--command-fd takes one argument, not zero")); if (*argv) badusage(_("--command-fd only takes one argument")); errno = 0; infd = strtoul(pipein, &endptr, 10); if (pipein == endptr || *endptr || infd > INT_MAX) ohshite(_("invalid integer for --%s: `%.250s'"), "command-fd", pipein); if ((in= fdopen(infd, "r")) == NULL) ohshite(_("couldn't open `%i' for stream"), (int) infd); if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */ error_unwind(ehflag_bombout); exit(2); } for (;;) { bool mode = false; int argc= 1; lno= 0; push_error_handler(&ejbuf, print_error_fatal, NULL); do { c= getc(in); if (c == '\n') lno++; } while (c != EOF && isspace(c)); if (c == EOF) break; if (c == '#') { do { c= getc(in); if (c == '\n') lno++; } while (c != EOF && c != '\n'); continue; } varbufreset(&linevb); do { varbufaddc(&linevb,c); c= getc(in); if (c == '\n') lno++; if (isspace(c)) argc++; /* This isn't fully accurate, but overestimating can't hurt. */ } while (c != EOF && c != '\n'); if (c == EOF) ohshit(_("unexpected eof before end of line %d"),lno); if (!argc) continue; varbufaddc(&linevb,0); newargs = m_realloc(newargs, sizeof(const char *) * (argc + 1)); argc= 1; ptr= linevb.buf; endptr= ptr + linevb.used; skipchar = false; while(ptr < endptr) { if (skipchar) { skipchar = false; } else if (*ptr == '\\') { memmove(ptr, (ptr+1), (linevb.used-(linevb.buf - ptr)-1)); endptr--; skipchar = true; continue; } else if (isspace(*ptr)) { if (mode == true) { *ptr = '\0'; mode = false; } } else { if (mode == false) { newargs[argc]= ptr; argc++; mode = true; } } ptr++; } *ptr = '\0'; newargs[argc++] = NULL; /* We strdup each argument, but never free it, because the error messages * contain references back to these strings. Freeing them, and reusing * the memory, would make those error messages confusing, to say the * least. */ for(i=1;i<argc;i++) if (newargs[i]) newargs[i] = m_strdup(newargs[i]); cipaction= NULL; myopt((const char *const**)&newargs,cmdinfos); if (!cipaction) badusage(_("need an action option")); actionfunction= (void (*)(const char* const*))cipaction->farg; actionfunction(newargs); set_error_display(NULL, NULL); error_unwind(ehflag_normaltidy); } }
GtkWidget *snd_as_widget(int argc, char **argv, GtkWidget *parent, void (*error_func)(const char *msg)) { #else void snd_doit(int argc, char **argv) { #endif GtkWidget *shell; int i; #ifdef SND_AS_WIDGET set_error_display(error_func); ss = snd_main(argc, argv); #else gtk_init(&argc, &argv); #if (!HAVE_GTK_3) #ifndef HAVE_OSX gdk_set_locale(); #endif #endif #endif ss->channel_min_height = CHANNEL_MIN_HEIGHT; ss->Graph_Cursor = DEFAULT_GRAPH_CURSOR; #ifndef SND_AS_WIDGET shell = gtk_window_new(GTK_WINDOW_TOPLEVEL); sg_make_resizable(shell); #endif auto_open_files = argc-1; if (argc > 1) auto_open_file_names = (char **)(argv + 1); ss->startup_title = mus_strdup("snd"); set_sound_style(SOUNDS_VERTICAL); for (i = 1; i < argc; i++) if ((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "-horizontal") == 0) || (strcmp(argv[i], "--horizontal") == 0)) set_sound_style(SOUNDS_HORIZONTAL); else if ((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "-vertical") == 0) || (strcmp(argv[i], "--vertical") == 0)) set_sound_style(SOUNDS_VERTICAL); else if ((strcmp(argv[i], "-notebook") == 0) || (strcmp(argv[i], "--notebook") == 0)) set_sound_style(SOUNDS_IN_NOTEBOOK); else if ((strcmp(argv[i], "-separate") == 0) || (strcmp(argv[i], "--separate") == 0)) set_sound_style(SOUNDS_IN_SEPARATE_WINDOWS); else if (strcmp(argv[i], "-noglob") == 0) noglob = true; else if (strcmp(argv[i], "-noinit") == 0) noinit = true; else if (strcmp(argv[i], "-nostdin") == 0) nostdin = true; else if ((strcmp(argv[i], "-b") == 0) || (strcmp(argv[i], "-batch") == 0) || (strcmp(argv[i], "--batch") == 0)) batch = true; else if (strcmp(argv[i], "--features") == 0) /* testing (compsnd) */ check_features_list(argv[i + 1]); ss->batch_mode = batch; set_auto_resize(AUTO_RESIZE_DEFAULT); ss->zoom_slider_width = ZOOM_SLIDER_WIDTH; ss->position_slider_width = POSITION_SLIDER_WIDTH; ss->channel_sash_indent = CHANNEL_SASH_INDENT; /* not currently used */ ss->channel_sash_size = CHANNEL_SASH_SIZE; ss->sash_size = SASH_SIZE; ss->sash_indent = SASH_INDENT; ss->toggle_size = TOGGLE_SIZE; ss->graph_is_active = false; ss->bg_gradient = 0.05; ss->white = WHITE_COLOR; ss->black = BLACK_COLOR; ss->light_blue = LIGHT_BLUE_COLOR; ss->lighter_blue = LIGHTER_BLUE_COLOR; ss->red = RED_COLOR; ss->green = GREEN_COLOR; ss->blue = BLUE_COLOR; ss->yellow = YELLOW_COLOR; ss->highlight_color = HIGHLIGHT_COLOR; ss->basic_color = BASIC_COLOR; ss->position_color = POSITION_COLOR; ss->zoom_color = ZOOM_COLOR; ss->cursor_color = CURSOR_COLOR; ss->selection_color = SELECTION_COLOR; ss->mix_color = MIX_COLOR; ss->enved_waveform_color = ENVED_WAVEFORM_COLOR; ss->filter_control_waveform_color = FILTER_CONTROL_WAVEFORM_COLOR; ss->listener_color = LISTENER_COLOR; ss->listener_text_color = LISTENER_TEXT_COLOR; ss->graph_color = GRAPH_COLOR; ss->selected_graph_color = SELECTED_GRAPH_COLOR; ss->data_color = DATA_COLOR; ss->selected_data_color = SELECTED_DATA_COLOR; ss->mark_color = MARK_COLOR; ss->sash_color = SASH_COLOR; ss->text_focus_color = TEXT_FOCUS_COLOR; ss->grid_color = get_in_between_color(ss->data_color, ss->graph_color); ss->selected_grid_color = get_in_between_color(ss->selected_data_color, ss->selected_graph_color); ss->axis_color_set = false; ss->orig_data_color = ss->data_color; ss->orig_selected_data_color = ss->selected_data_color; ss->orig_mark_color = ss->mark_color; ss->orig_mix_color = ss->mix_color; ss->orig_graph_color = ss->graph_color; ss->orig_selected_graph_color = ss->selected_graph_color; ss->orig_listener_color = ss->listener_color; ss->orig_listener_text_color = ss->listener_text_color; ss->orig_cursor_color = ss->cursor_color; ss->orig_basic_color = ss->basic_color; ss->orig_selection_color = ss->selection_color; ss->orig_zoom_color = ss->zoom_color; ss->orig_position_color = ss->position_color; ss->orig_highlight_color = ss->highlight_color; if ((!(set_tiny_font(DEFAULT_TINY_FONT))) && (!(set_tiny_font(FALLBACK_FONT)))) fprintf(stderr, "can't find tiny font: %s", DEFAULT_TINY_FONT); if ((!(set_axis_label_font(DEFAULT_AXIS_LABEL_FONT))) && (!(set_axis_label_font(FALLBACK_FONT)))) fprintf(stderr, "can't find axis label font: %s", DEFAULT_AXIS_LABEL_FONT); if ((!(set_axis_numbers_font(DEFAULT_AXIS_NUMBERS_FONT))) && (!(set_axis_numbers_font(FALLBACK_FONT)))) fprintf(stderr, "can't find axis numbers font: %s", DEFAULT_AXIS_NUMBERS_FONT); if ((!(set_peaks_font(DEFAULT_PEAKS_FONT))) && (!(set_peaks_font(FALLBACK_FONT)))) fprintf(stderr, "can't find peaks font: %s", DEFAULT_PEAKS_FONT); if ((!(set_bold_peaks_font(DEFAULT_BOLD_PEAKS_FONT))) && (!(set_bold_peaks_font(FALLBACK_FONT)))) fprintf(stderr, "can't find bold peaks font: %s", DEFAULT_BOLD_PEAKS_FONT); if (!(set_listener_font(FALLBACK_FONT))) fprintf(stderr, "can't find listener font: %s", FALLBACK_FONT); ss->orig_axis_label_font = mus_strdup(axis_label_font(ss)); ss->orig_axis_numbers_font = mus_strdup(axis_numbers_font(ss)); ss->orig_peaks_font = mus_strdup(peaks_font(ss)); ss->orig_bold_peaks_font = mus_strdup(bold_peaks_font(ss)); ss->orig_listener_font = mus_strdup(listener_font(ss)); ss->orig_tiny_font = mus_strdup(tiny_font(ss)); #if (!HAVE_GTK_3) init_gtk(); #endif MAIN_PANE(ss) = gtk_vbox_new(false, 0); /* not homogenous, spacing 0 */ #if (HAVE_GTK_3) init_gtk(); #endif #ifdef SND_AS_WIDGET MAIN_SHELL(ss) = parent; shell = MAIN_PANE(ss); #else MAIN_SHELL(ss) = shell; gtk_container_add(GTK_CONTAINER(MAIN_SHELL(ss)), MAIN_PANE(ss)); #endif add_menu(); /* adds menubar to MAIN_PANE (via box_pack_start) */ if (with_toolbar(ss)) show_toolbar(); if (sound_style(ss) != SOUNDS_IN_SEPARATE_WINDOWS) { SOUND_PANE(ss) = gtk_vpaned_new(); gtk_container_set_border_width(GTK_CONTAINER(SOUND_PANE(ss)), 0); gtk_container_add(GTK_CONTAINER(MAIN_PANE(ss)), SOUND_PANE(ss)); if (sound_style(ss) == SOUNDS_IN_NOTEBOOK) { SOUND_PANE_BOX(ss) = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(SOUND_PANE_BOX(ss)), GTK_POS_TOP); SG_SIGNAL_CONNECT(SOUND_PANE_BOX(ss), "switch_page", notebook_switch_page, NULL); } else { if (sound_style(ss) == SOUNDS_HORIZONTAL) SOUND_PANE_BOX(ss) = gtk_hbox_new(false, 0); else SOUND_PANE_BOX(ss) = gtk_vbox_new(false, 0); } gtk_paned_add1(GTK_PANED(SOUND_PANE(ss)), SOUND_PANE_BOX(ss)); gtk_widget_show(SOUND_PANE_BOX(ss)); gtk_widget_show(SOUND_PANE(ss)); } gtk_widget_show(MAIN_PANE(ss)); gtk_widget_show(MAIN_SHELL(ss)); #ifndef SND_AS_WIDGET #if HAVE_GTK_ADJUSTMENT_GET_UPPER MAIN_WINDOW(ss) = gtk_widget_get_window(MAIN_SHELL(ss)); #else MAIN_WINDOW(ss) = MAIN_SHELL(ss)->window; #endif #else MAIN_WINDOW(ss) = gtk_widget_get_parent_window(MAIN_SHELL(ss)); #endif setup_gcs(); if (batch) gtk_widget_hide(MAIN_SHELL(ss)); else gdk_window_resize(WIDGET_TO_WINDOW(MAIN_SHELL(ss)), INITIAL_WINDOW_WIDTH, INITIAL_WINDOW_HEIGHT); startup_funcs(); #if HAVE_SETJMP_H #if MUS_TRAP_SEGFAULT if (sigsetjmp(envHandleEventsLoop, 1)) { if (!(ss->exiting)) snd_error_without_format("Caught seg fault (will try to continue):\n"); else { snd_error_without_format("Caught seg fault while trying to exit.\n"); exit(0); } } #endif if (setjmp(top_level_jump)) { if (!(ss->jump_ok)) snd_error_without_format("Caught top level error (will try to continue):\n"); else ss->jump_ok = false; } #endif if (ss->startup_errors) { post_it("Error in initialization", ss->startup_errors); free(ss->startup_errors); ss->startup_errors = NULL; } #if HAVE_GTK_3 set_basic_color(ss->basic_color); color_listener(ss->listener_color); color_chan_components(ss->zoom_color, COLOR_ZOOM); color_chan_components(ss->position_color, COLOR_POSITION); #endif #ifndef SND_AS_WIDGET set_up_icon(); gtk_main(); #else return(shell); #endif }