diff 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
line wrap: on
line diff
--- a/src/callproc.c	Wed May 06 21:28:42 1998 +0000
+++ b/src/callproc.c	Thu May 07 01:05:36 1998 +0000
@@ -633,13 +633,14 @@
     int first = 1;
     int total_read = 0;
     int carryover = 0;
+    int display_on_the_fly = !NILP (display) && INTERACTIVE;
+    struct coding_system saved_coding = process_coding;
 
     while (1)
       {
 	/* Repeatedly read until we've filled as much as possible
 	   of the buffer size we have.  But don't read
 	   less than 1024--save that for the next bufferful.  */
-
 	nread = carryover;
 	while (nread < bufsize - 1024)
 	  {
@@ -649,21 +650,20 @@
 	      goto give_up;
 
 	    if (this_read == 0)
-	      goto give_up_1;
+	      {
+		process_coding.mode |= CODING_MODE_LAST_BLOCK;
+		break;
+	      }
 
 	    nread += this_read;
-	  }
+	    total_read += this_read;
 
-      give_up_1:
+	    if (display_on_the_fly)
+	      break;
+	  }
 
 	/* Now NREAD is the total amount of data in the buffer.  */
-	if (nread == carryover)
-	  /* Here, just tell decode_coding that we are processing the
-             last block.  We break the loop after decoding.  */
-	  process_coding.mode |= CODING_MODE_LAST_BLOCK;
-
 	immediate_quit = 0;
-	total_read += nread - carryover;
 	
 	if (!NILP (buffer))
 	  {
@@ -676,6 +676,19 @@
 
 		decode_coding (&process_coding, bufptr, decoding_buf,
 			       nread, size);
+		if (display_on_the_fly
+		    && saved_coding.type == coding_type_undecided
+		    && process_coding.type != coding_type_undecided)
+		  {
+		    /* We have detected some coding system.  But,
+		       there's a possibility that the detection was
+		       done by insufficient data.  So, we give up
+		       displaying on the fly.  */
+		    display_on_the_fly = 0;
+		    process_coding = saved_coding;
+		    carryover = nread;
+		    continue;
+		  }
 		if (process_coding.produced > 0)
 		  insert (decoding_buf, process_coding.produced);
 		carryover = nread - process_coding.consumed;