- PSDocument *gs = PS_DOCUMENT(data);
- int bytes_written;
- void (*oldsig) (int);
- oldsig = signal(SIGPIPE, catchPipe);
-
- LOG ("Input");
-
- 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((char *) 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;
- }
- }
+ PSDocument *gs = PS_DOCUMENT(data);
+ int bytes_written;
+ void (*oldsig) (int);
+ oldsig = signal(SIGPIPE, catchPipe);
+
+ LOG ("Input");
+
+ 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;
+ }
+ }