comparison src/callproc.c @ 21966:10183730b250

(Fcall_process): If we must display received data on the fly, don't wait until a buffer is filled.
author Kenichi Handa <handa@m17n.org>
date Thu, 07 May 1998 01:05:36 +0000
parents 5f8f1b124f45
children 8320a731c121
comparison
equal deleted inserted replaced
21965:3681d61e4ed8 21966:10183730b250
631 { 631 {
632 register int nread; 632 register int nread;
633 int first = 1; 633 int first = 1;
634 int total_read = 0; 634 int total_read = 0;
635 int carryover = 0; 635 int carryover = 0;
636 int display_on_the_fly = !NILP (display) && INTERACTIVE;
637 struct coding_system saved_coding = process_coding;
636 638
637 while (1) 639 while (1)
638 { 640 {
639 /* Repeatedly read until we've filled as much as possible 641 /* Repeatedly read until we've filled as much as possible
640 of the buffer size we have. But don't read 642 of the buffer size we have. But don't read
641 less than 1024--save that for the next bufferful. */ 643 less than 1024--save that for the next bufferful. */
642
643 nread = carryover; 644 nread = carryover;
644 while (nread < bufsize - 1024) 645 while (nread < bufsize - 1024)
645 { 646 {
646 int this_read = read (fd[0], bufptr + nread, bufsize - nread); 647 int this_read = read (fd[0], bufptr + nread, bufsize - nread);
647 648
648 if (this_read < 0) 649 if (this_read < 0)
649 goto give_up; 650 goto give_up;
650 651
651 if (this_read == 0) 652 if (this_read == 0)
652 goto give_up_1; 653 {
654 process_coding.mode |= CODING_MODE_LAST_BLOCK;
655 break;
656 }
653 657
654 nread += this_read; 658 nread += this_read;
659 total_read += this_read;
660
661 if (display_on_the_fly)
662 break;
655 } 663 }
656 664
657 give_up_1:
658
659 /* Now NREAD is the total amount of data in the buffer. */ 665 /* Now NREAD is the total amount of data in the buffer. */
660 if (nread == carryover)
661 /* Here, just tell decode_coding that we are processing the
662 last block. We break the loop after decoding. */
663 process_coding.mode |= CODING_MODE_LAST_BLOCK;
664
665 immediate_quit = 0; 666 immediate_quit = 0;
666 total_read += nread - carryover;
667 667
668 if (!NILP (buffer)) 668 if (!NILP (buffer))
669 { 669 {
670 if (process_coding.type == coding_type_no_conversion) 670 if (process_coding.type == coding_type_no_conversion)
671 insert (bufptr, nread); 671 insert (bufptr, nread);
674 int size = decoding_buffer_size (&process_coding, nread); 674 int size = decoding_buffer_size (&process_coding, nread);
675 char *decoding_buf = get_conversion_buffer (size); 675 char *decoding_buf = get_conversion_buffer (size);
676 676
677 decode_coding (&process_coding, bufptr, decoding_buf, 677 decode_coding (&process_coding, bufptr, decoding_buf,
678 nread, size); 678 nread, size);
679 if (display_on_the_fly
680 && saved_coding.type == coding_type_undecided
681 && process_coding.type != coding_type_undecided)
682 {
683 /* We have detected some coding system. But,
684 there's a possibility that the detection was
685 done by insufficient data. So, we give up
686 displaying on the fly. */
687 display_on_the_fly = 0;
688 process_coding = saved_coding;
689 carryover = nread;
690 continue;
691 }
679 if (process_coding.produced > 0) 692 if (process_coding.produced > 0)
680 insert (decoding_buf, process_coding.produced); 693 insert (decoding_buf, process_coding.produced);
681 carryover = nread - process_coding.consumed; 694 carryover = nread - process_coding.consumed;
682 if (carryover > 0) 695 if (carryover > 0)
683 { 696 {