changeset 30950:5682de5cfdac

(decode_coding_string): Set members consumed, consumed_char, produced, produced_char of *coding correctly. If decode_coding doesn't consume any byte, don't try anymore. (encode_coding_string): Likewise.
author Kenichi Handa <handa@m17n.org>
date Fri, 18 Aug 2000 06:41:15 +0000
parents 54e668cd8c0b
children e6acd4b6a8d5
files src/coding.c
diffstat 1 files changed, 27 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/coding.c	Fri Aug 18 06:39:31 2000 +0000
+++ b/src/coding.c	Fri Aug 18 06:41:15 2000 +0000
@@ -5235,7 +5235,7 @@
   int require_decoding;
   int shrinked_bytes = 0;
   Lisp_Object newstr;
-  int consumed, produced, produced_char;
+  int consumed, consumed_char, produced, produced_char;
 
   from = 0;
   to = XSTRING (str)->size;
@@ -5306,16 +5306,19 @@
   len = decoding_buffer_size (coding, to_byte - from);
   allocate_conversion_buffer (buf, len);
 
-  consumed = produced = produced_char = 0;
+  consumed = consumed_char = produced = produced_char = 0;
   while (1)
     {
       result = decode_coding (coding, XSTRING (str)->data + from + consumed,
 			      buf.data + produced, to_byte - from - consumed,
 			      buf.size - produced);
       consumed += coding->consumed;
+      consumed_char += coding->consumed_char;
       produced += coding->produced;
       produced_char += coding->produced_char;
-      if (result == CODING_FINISH_NORMAL)
+      if (result == CODING_FINISH_NORMAL
+	  || (result == CODING_FINISH_INSUFFICIENT_SRC
+	      && coding->consumed == 0))
 	break;
       if (result == CODING_FINISH_INSUFFICIENT_CMP)
 	coding_allocate_composition_data (coding, from + produced_char);
@@ -5351,6 +5354,11 @@
 	}
     }
 
+  coding->consumed = consumed;
+  coding->consumed_char = consumed_char;
+  coding->produced = produced;
+  coding->produced_char = produced_char;
+
   if (coding->dst_multibyte)
     newstr = make_uninit_multibyte_string (produced_char + shrinked_bytes,
 					   produced + shrinked_bytes);
@@ -5390,7 +5398,7 @@
   int result;
   int shrinked_bytes = 0;
   Lisp_Object newstr;
-  int consumed, consumed_char, produced;
+  int consumed, consumed_char, produced, produced_char;
 
   if (SYMBOLP (coding->pre_write_conversion)
       && !NILP (Ffboundp (coding->pre_write_conversion)))
@@ -5403,11 +5411,15 @@
   saved_coding_symbol = Qnil;
   if (! CODING_REQUIRE_ENCODING (coding))
     {
+      coding->consumed = STRING_BYTES (XSTRING (str));
+      coding->consumed_char = XSTRING (str)->size;
       if (STRING_MULTIBYTE (str))
 	{
 	  str = Fstring_as_unibyte (str);
 	  nocopy = 1;
 	}
+      coding->produced = STRING_BYTES (XSTRING (str));
+      coding->produced_char = XSTRING (str)->size;
       return (nocopy ? str : Fcopy_sequence (str));
     }
 
@@ -5432,21 +5444,28 @@
   len = encoding_buffer_size (coding, to_byte - from);
   allocate_conversion_buffer (buf, len);
 
-  consumed = consumed_char = produced = 0;
-
+  consumed = consumed_char = produced = produced_char = 0;
   while (1)
     {
       result = encode_coding (coding, XSTRING (str)->data + from + consumed,
 			      buf.data + produced, to_byte - from - consumed,
 			      buf.size - produced);
       consumed += coding->consumed;
-      produced += coding->produced;
-      if (result == CODING_FINISH_NORMAL)
+      consumed_char += coding->consumed_char;
+      produced_char += coding->produced_char;
+      if (result == CODING_FINISH_NORMAL
+	  || (result == CODING_FINISH_INSUFFICIENT_SRC
+	      && coding->consumed == 0))
 	break;
       /* Now result should be CODING_FINISH_INSUFFICIENT_DST.  */
       extend_conversion_buffer (&buf);
     }
 
+  coding->consumed = consumed;
+  coding->consumed_char = consumed_char;
+  coding->produced = produced;
+  coding->produced_char = produced_char;
+
   newstr = make_uninit_string (produced + shrinked_bytes);
   if (from > 0)
     bcopy (XSTRING (str)->data, XSTRING (newstr)->data, from);