changeset 88456:a7b309f72920

(coding_alloc_by_making_gap): Check the case that the source and destination are the same correctly. (decode_coding_raw_text): Set coding->consumed_char and coding->consumed to 0. (produce_chars): If coding->chars_at_source is nonzero, update coding->consumed_char and coding->consumed before calling alloc_destination. (Fdefine_coding_system_alias): Register ALIAS in Vcoding_system_alist. (syms_of_coding): Define `no-convesion' coding system at the tail.
author Kenichi Handa <handa@m17n.org>
date Tue, 07 May 2002 04:50:48 +0000
parents bae0bd953f61
children 478d6f47e263
files src/coding.c
diffstat 1 files changed, 70 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/src/coding.c	Tue May 07 04:50:29 2002 +0000
+++ b/src/coding.c	Tue May 07 04:50:48 2002 +0000
@@ -928,7 +928,6 @@
       coding->destination = (BUF_BEG_ADDR (XBUFFER (coding->dst_object))
 			     + coding->dst_pos_byte - 1);
       if (coding->src_pos < 0)
-	/* The source and destination is in the same buffer.  */
 	coding->dst_bytes = (GAP_END_ADDR
 			     - (coding->src_bytes - coding->consumed)
 			     - coding->destination);
@@ -958,10 +957,8 @@
      struct coding_system *coding;
      EMACS_INT bytes;
 {
-  Lisp_Object this_buffer;
-
-  this_buffer = Fcurrent_buffer ();
-  if (EQ (this_buffer, coding->dst_object))
+  if (BUFFERP (coding->dst_object)
+      && EQ (coding->src_object, coding->dst_object))
     {
       EMACS_INT add = coding->src_bytes - coding->consumed;
 
@@ -971,6 +968,9 @@
     }
   else
     {
+      Lisp_Object this_buffer;
+
+      this_buffer = Fcurrent_buffer ();
       set_buffer_internal (XBUFFER (coding->dst_object));
       make_gap (bytes);
       set_buffer_internal (XBUFFER (this_buffer));
@@ -4130,8 +4130,8 @@
      struct coding_system *coding;
 {
   coding->chars_at_source = 1;
-  coding->consumed_char = coding->src_chars;
-  coding->consumed = coding->src_bytes;
+  coding->consumed_char = 0;
+  coding->consumed = 0;
   coding->result = CODING_RESULT_SUCCESS;
 }
 
@@ -5124,13 +5124,19 @@
 		    }
 		  if (dst == dst_end)
 		    {
-		      EMACS_INT offset = src - coding->source;
-
-		      dst = alloc_destination (coding, src_end - src + 1, dst);
-		      dst_end = coding->destination + coding->dst_bytes;
-		      coding_set_source (coding);
-		      src = coding->source + offset;
-		      src_end = coding->source + coding->src_bytes;
+		      coding->consumed = src - coding->source;
+
+		    if (EQ (coding->src_object, coding->dst_object))
+		      dst_end = src;
+		    if (dst == dst_end)
+		      {
+			dst = alloc_destination (coding, src_end - src + 1,
+						 dst);
+			dst_end = coding->destination + coding->dst_bytes;
+			coding_set_source (coding);
+			src = coding->source + coding->consumed;
+			src_end = coding->source + coding->src_bytes;
+		      }
 		    }
 		  *dst++ = c;
 		  produced_chars++;
@@ -5157,13 +5163,19 @@
 		  }
 		if (dst >= dst_end - 1)
 		  {
-		    EMACS_INT offset = src - coding->source;
-
-		    dst = alloc_destination (coding, src_end - src + 2, dst);
-		    dst_end = coding->destination + coding->dst_bytes;
-		    coding_set_source (coding);
-		    src = coding->source + offset;
-		    src_end = coding->source + coding->src_bytes;
+		    coding->consumed = src - coding->source;
+
+		    if (EQ (coding->src_object, coding->dst_object))
+		      dst_end = src;
+		    if (dst >= dst_end - 1)
+		      {
+			dst = alloc_destination (coding, src_end - src + 2,
+						 dst);
+			dst_end = coding->destination + coding->dst_bytes;
+			coding_set_source (coding);
+			src = coding->source + coding->consumed;
+			src_end = coding->source + coding->src_bytes;
+		      }
 		  }
 		EMIT_ONE_BYTE (c);
 	      }
@@ -5204,6 +5216,8 @@
 	      *dst++ = c;
 	    }
 	}
+      coding->consumed = coding->src_bytes;
+      coding->consumed_char = coding->src_chars;
     }
 
   produced = dst - (coding->destination + coding->produced);
@@ -7574,6 +7588,7 @@
     }
 
   Fputhash (alias, spec, Vcoding_system_hash_table);
+  Vcoding_system_alist = Fcons (Fcons (alias, Qnil), Vcoding_system_alist);
 
   return Qnil;
 }
@@ -7847,40 +7862,6 @@
   ASET (Vcoding_category_table, coding_category_undecided,
 	intern ("coding-category-undecided"));
 
-  {
-    Lisp_Object args[coding_arg_max];
-    Lisp_Object plist[14];
-    int i;
-
-    for (i = 0; i < coding_arg_max; i++)
-      args[i] = Qnil;
-
-    plist[0] = intern (":name");
-    plist[1] = args[coding_arg_name] = Qno_conversion;
-    plist[2] = intern (":mnemonic");
-    plist[3] = args[coding_arg_mnemonic] = make_number ('=');
-    plist[4] = intern (":coding-type");
-    plist[5] = args[coding_arg_coding_type] = Qraw_text;
-    plist[6] = intern (":ascii-compatible-p");
-    plist[7] = args[coding_arg_ascii_compatible_p] = Qt;
-    plist[8] = intern (":default-char");
-    plist[9] = args[coding_arg_default_char] = make_number (0);
-    plist[10] = intern (":docstring");
-    plist[11] = build_string ("Do no conversion.\n\
-\n\
-When you visit a file with this coding, the file is read into a\n\
-unibyte buffer as is, thus each byte of a file is treated as a\n\
-character.");
-    plist[12] = intern (":eol-type");
-    plist[13] = args[coding_arg_eol_type] = Qunix;
-    args[coding_arg_plist] = Flist (14, plist);
-    Fdefine_coding_system_internal (coding_arg_max, args);
-  }
-
-  setup_coding_system (Qno_conversion, &keyboard_coding);
-  setup_coding_system (Qno_conversion, &terminal_coding);
-  setup_coding_system (Qno_conversion, &safe_terminal_coding);
-
   defsubr (&Scoding_system_p);
   defsubr (&Sread_coding_system);
   defsubr (&Sread_non_nil_coding_system);
@@ -8153,6 +8134,40 @@
 to explicitly specify some coding system that doesn't use ISO2022's
 escape sequence (e.g `latin-1') on reading by \\[universal-coding-system-argument].  */);
   inhibit_iso_escape_detection = 0;
+
+  {
+    Lisp_Object args[coding_arg_max];
+    Lisp_Object plist[14];
+    int i;
+
+    for (i = 0; i < coding_arg_max; i++)
+      args[i] = Qnil;
+
+    plist[0] = intern (":name");
+    plist[1] = args[coding_arg_name] = Qno_conversion;
+    plist[2] = intern (":mnemonic");
+    plist[3] = args[coding_arg_mnemonic] = make_number ('=');
+    plist[4] = intern (":coding-type");
+    plist[5] = args[coding_arg_coding_type] = Qraw_text;
+    plist[6] = intern (":ascii-compatible-p");
+    plist[7] = args[coding_arg_ascii_compatible_p] = Qt;
+    plist[8] = intern (":default-char");
+    plist[9] = args[coding_arg_default_char] = make_number (0);
+    plist[10] = intern (":docstring");
+    plist[11] = build_string ("Do no conversion.\n\
+\n\
+When you visit a file with this coding, the file is read into a\n\
+unibyte buffer as is, thus each byte of a file is treated as a\n\
+character.");
+    plist[12] = intern (":eol-type");
+    plist[13] = args[coding_arg_eol_type] = Qunix;
+    args[coding_arg_plist] = Flist (14, plist);
+    Fdefine_coding_system_internal (coding_arg_max, args);
+  }
+
+  setup_coding_system (Qno_conversion, &keyboard_coding);
+  setup_coding_system (Qno_conversion, &terminal_coding);
+  setup_coding_system (Qno_conversion, &safe_terminal_coding);
 }
 
 char *