changeset 29009:85822da9ece9

(Finsert_file_contents): Setup src_multibyte and dst_multibyte members of coding. On handling REPLACE on unibyte buffer, convert the result of decode_coding to unibyte. On inserting into a mutibyte buffer, always call code_convert_region. (e_write): Setup cdoing->src_multibyte according to the multibyteness of the source (buffer or string).
author Kenichi Handa <handa@m17n.org>
date Fri, 19 May 2000 23:59:27 +0000
parents 939760ef7379
children f62cfa81b0c4
files src/fileio.c
diffstat 1 files changed, 27 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/fileio.c	Fri May 19 23:59:04 2000 +0000
+++ b/src/fileio.c	Fri May 19 23:59:27 2000 +0000
@@ -3650,6 +3650,9 @@
 	   end-of-line conversion.  */
 	setup_raw_text_coding_system (&coding);
 
+      coding.src_multibyte = 0;
+      coding.dst_multibyte
+	= !NILP (current_buffer->enable_multibyte_characters);
       coding_system_decided = 1;
     }
 
@@ -3672,9 +3675,7 @@
      and let the following if-statement handle the replace job.  */
   if (!NILP (replace)
       && BEGV < ZV
-      && ! CODING_REQUIRE_DECODING (&coding)
-      && (coding.eol_type == CODING_EOL_UNDECIDED
-	  || coding.eol_type == CODING_EOL_LF))
+      && !(coding.common_flags & CODING_REQUIRE_DECODING_MASK))
     {
       /* same_at_start and same_at_end count bytes,
 	 because file access counts bytes
@@ -3711,7 +3712,7 @@
 
 	  if (coding.type == coding_type_undecided)
 	    detect_coding (&coding, buffer, nread);
-	  if (CODING_REQUIRE_DECODING (&coding))
+	  if (coding.common_flags & CODING_REQUIRE_DECODING_MASK)
 	    /* We found that the file should be decoded somehow.
                Let's give up here.  */
 	    {
@@ -3929,7 +3930,11 @@
 	      /* Save for next iteration whatever we didn't convert.  */
 	      unprocessed = this - coding.consumed;
 	      bcopy (read_buf + coding.consumed, read_buf, unprocessed);
-	      this = coding.produced;
+	      if (!NILP (current_buffer->enable_multibyte_characters))
+		this = coding.produced;
+	      else
+		this = str_as_unibyte (conversion_buffer + inserted,
+				       coding.produced);
 	    }
 
 	  inserted += this;
@@ -4198,34 +4203,27 @@
 	setup_raw_text_coding_system (&coding);
     }
 
+  if (!NILP (visit)
+      && (coding.type == coding_type_no_conversion
+	  || coding.type == coding_type_raw_text))
+    {
+      /* Visiting a file with these coding system always make the buffer
+	 unibyte. */
+      current_buffer->enable_multibyte_characters = Qnil;
+      coding.dst_multibyte = 0;
+    }
+
   if (inserted > 0 || coding.type == coding_type_ccl)
     {
       if (CODING_MAY_REQUIRE_DECODING (&coding))
 	{
-	  /* Here, we don't have to consider byte combining (see the
-             comment below) because code_convert_region takes care of
-             it.  */
 	  code_convert_region (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted,
 			       &coding, 0, 0);
-	  inserted = (NILP (current_buffer->enable_multibyte_characters)
-		      ? coding.produced : coding.produced_char);
-	}
-      else if (!NILP (current_buffer->enable_multibyte_characters))
-	{
-	  int inserted_byte = inserted;
-
-	  /* There's a possibility that we must combine bytes at the
-	     head (resp. the tail) of the just inserted text with the
-	     bytes before (resp. after) the gap to form a single
-	     character.  */
-	  inserted = multibyte_chars_in_text (GPT_ADDR - inserted, inserted);
-	  adjust_after_insert (PT, PT_BYTE,
-			       PT + inserted_byte, PT_BYTE + inserted_byte,
-			       inserted);
+	  inserted = coding.produced_char;
 	}
       else
 	adjust_after_insert (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted,
-			     inserted);
+ 			     inserted);
     }
 
 #ifdef DOS_NT
@@ -5020,6 +5018,7 @@
   register int nbytes;
   char buf[WRITE_BUF_SIZE];
   int return_val = 0;
+  int require_encoding_p;
 
   if (start >= end)
     coding->composing = COMPOSITION_DISABLED;
@@ -5030,17 +5029,21 @@
     {
       addr = XSTRING (string)->data;
       nbytes = STRING_BYTES (XSTRING (string));
+      coding->src_multibyte = STRING_MULTIBYTE (string);
     }
   else if (start < end)
     {
       /* It is assured that the gap is not in the range START and END-1.  */
       addr = CHAR_POS_ADDR (start);
       nbytes = CHAR_TO_BYTE (end) - CHAR_TO_BYTE (start);
+      coding->src_multibyte
+	= !NILP (current_buffer->enable_multibyte_characters);
     }
   else
     {
       addr = "";
       nbytes = 0;
+      coding->src_multibyte = 1;
     }
 
   /* We used to have a code for handling selective display here.  But,