-static void
-output (gpointer data, gint source, GdkInputCondition condition)
-{
- char buf[MAX_BUFSIZE + 1];
- guint bytes = 0;
- PSDocument *gs = PS_DOCUMENT(data);
-
- if (source == gs->interpreter_output) {
- bytes = read(gs->interpreter_output, buf, MAX_BUFSIZE);
- if (bytes == 0) { /* EOF occurred */
- close (gs->interpreter_output);
- gs->interpreter_output = -1;
- gdk_input_remove (gs->interpreter_output_id);
- return;
- } else if (bytes == -1) {
- /* trouble... */
- interpreter_failed (gs, NULL);
- return;
- }
- if (gs->interpreter_err == -1) {
- interpreter_failed (gs, NULL);
- }
- } else if (source == gs->interpreter_err) {
- bytes = read (gs->interpreter_err, buf, MAX_BUFSIZE);
- if (bytes == 0) { /* EOF occurred */
- close (gs->interpreter_err);
- gs->interpreter_err = -1;
- gdk_input_remove (gs->interpreter_error_id);
- return;
- } else if (bytes == -1) {
- /* trouble... */
- interpreter_failed (gs, NULL);
- return;
- }
- if (gs->interpreter_output == -1) {
- interpreter_failed(gs, NULL);
- }
- }
-
- if (bytes > 0) {
- buf[bytes] = '\0';
- printf ("%s", buf);
- }
-}
-
-static void
-catchPipe (int i)
-{
- broken_pipe = True;
-}
-
-static void
-input(gpointer data, gint source, GdkInputCondition condition)
-{
- PSDocument *gs = PS_DOCUMENT(data);
- int bytes_written;
- void (*oldsig) (int);
- oldsig = signal(SIGPIPE, catchPipe);
-
- do {
- if (gs->buffer_bytes_left == 0) {
- /* Get a new section if required */
- if (gs->ps_input && gs->bytes_left == 0) {
- struct record_list *ps_old = gs->ps_input;
- gs->ps_input = ps_old->next;
- if (ps_old->close && NULL != ps_old->fp)
- fclose (ps_old->fp);
- g_free (ps_old);
- }
-
- /* Have to seek at the beginning of each section */
- if (gs->ps_input && gs->ps_input->seek_needed) {
- fseek (gs->ps_input->fp, gs->ps_input->begin, SEEK_SET);
- gs->ps_input->seek_needed = FALSE;
- gs->bytes_left = gs->ps_input->len;
- }
-
- if (gs->bytes_left > MAX_BUFSIZE) {
- gs->buffer_bytes_left = fread (gs->input_buffer, sizeof(char),
- MAX_BUFSIZE, gs->ps_input->fp);
- } else if (gs->bytes_left > 0) {
- gs->buffer_bytes_left = fread (gs->input_buffer, sizeof(char),
- gs->bytes_left, gs->ps_input->fp);
- } else {
- gs->buffer_bytes_left = 0;
- }
- if (gs->bytes_left > 0 && gs->buffer_bytes_left == 0) {
- interpreter_failed (gs, NULL); /* Error occurred */
- }
- gs->input_buffer_ptr = gs->input_buffer;
- gs->bytes_left -= gs->buffer_bytes_left;
- }
-
- if (gs->buffer_bytes_left > 0) {
- bytes_written = write (gs->interpreter_input,
- gs->input_buffer_ptr, gs->buffer_bytes_left);
-
- if (broken_pipe) {
- interpreter_failed (gs, g_strdup(_("Broken pipe.")));
- broken_pipe = FALSE;
- interpreter_failed (gs, NULL);
- } else if (bytes_written == -1) {
- if ((errno != EWOULDBLOCK) && (errno != EAGAIN)) {
- interpreter_failed (gs, NULL); /* Something bad happened */
- }
- } else {
- gs->buffer_bytes_left -= bytes_written;
- gs->input_buffer_ptr += bytes_written;
- }
- }
- } while (gs->ps_input && gs->buffer_bytes_left == 0);
-
- signal (SIGPIPE, oldsig);
-
- if (gs->ps_input == NULL && gs->buffer_bytes_left == 0) {
- if (gs->interpreter_input_id != 0) {
- gdk_input_remove (gs->interpreter_input_id);
- gs->interpreter_input_id = 0;
- }