(encode_coding_object): If a pre-write-conversion
[bpt/emacs.git] / src / coding.c
index 6643055..15130b9 100644 (file)
@@ -1,7 +1,7 @@
 /* Coding system handler (conversion, detection, etc).
    Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN.
      Licensed to the Free Software Foundation.
 /* Coding system handler (conversion, detection, etc).
    Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN.
      Licensed to the Free Software Foundation.
-   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    Copyright (C) 2003
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H13PRO009
    Copyright (C) 2003
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H13PRO009
@@ -20,8 +20,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 /*** TABLE OF CONTENTS ***
 
 
 /*** TABLE OF CONTENTS ***
 
@@ -314,9 +314,10 @@ Lisp_Object Qvalid_codes;
 Lisp_Object QCcategory, QCmnemonic, QCdefalut_char;
 Lisp_Object QCdecode_translation_table, QCencode_translation_table;
 Lisp_Object QCpost_read_conversion, QCpre_write_conversion;
 Lisp_Object QCcategory, QCmnemonic, QCdefalut_char;
 Lisp_Object QCdecode_translation_table, QCencode_translation_table;
 Lisp_Object QCpost_read_conversion, QCpre_write_conversion;
+Lisp_Object QCascii_compatible_p;
 
 extern Lisp_Object Qinsert_file_contents, Qwrite_region;
 
 extern Lisp_Object Qinsert_file_contents, Qwrite_region;
-Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument;
+Lisp_Object Qcall_process, Qcall_process_region;
 Lisp_Object Qstart_process, Qopen_network_stream;
 Lisp_Object Qtarget_idx;
 
 Lisp_Object Qstart_process, Qopen_network_stream;
 Lisp_Object Qtarget_idx;
 
@@ -706,7 +707,8 @@ static struct coding_system coding_categories[coding_category_max];
          c = ((c & 1) << 6) | *src++;                  \
        else                                            \
          {                                             \
          c = ((c & 1) << 6) | *src++;                  \
        else                                            \
          {                                             \
-           c = - string_char (--src, &src, NULL);      \
+           src--;                                      \
+           c = - string_char (src, &src, NULL);        \
            record_conversion_result                    \
              (coding, CODING_RESULT_INVALID_SRC);      \
          }                                             \
            record_conversion_result                    \
              (coding, CODING_RESULT_INVALID_SRC);      \
          }                                             \
@@ -724,7 +726,8 @@ static struct coding_system coding_categories[coding_category_max];
          c = ((c & 1) << 6) | *src++;                  \
        else                                            \
          {                                             \
          c = ((c & 1) << 6) | *src++;                  \
        else                                            \
          {                                             \
-           c = - string_char (--src, &src, NULL);      \
+           src--;                                      \
+           c = - string_char (src, &src, NULL);        \
            record_conversion_result                    \
              (coding, CODING_RESULT_INVALID_SRC);      \
          }                                             \
            record_conversion_result                    \
              (coding, CODING_RESULT_INVALID_SRC);      \
          }                                             \
@@ -918,6 +921,8 @@ record_conversion_result (struct coding_system *coding,
     case CODING_RESULT_INSUFFICIENT_MEM:
       Vlast_code_conversion_error = Qinsufficient_memory;
       break;
     case CODING_RESULT_INSUFFICIENT_MEM:
       Vlast_code_conversion_error = Qinsufficient_memory;
       break;
+    default:
+      Vlast_code_conversion_error = intern ("Unknown error");
     }
 }
 
     }
 }
 
@@ -5091,7 +5096,7 @@ Lisp_Object
 coding_charset_list (coding)
      struct coding_system *coding;
 {
 coding_charset_list (coding)
      struct coding_system *coding;
 {
-  Lisp_Object attrs, charset_list, coding_type;
+  Lisp_Object attrs, charset_list;
 
   CODING_GET_INFO (coding, attrs, charset_list);
   if (EQ (CODING_ATTR_TYPE (attrs), Qiso_2022))
 
   CODING_GET_INFO (coding, attrs, charset_list);
   if (EQ (CODING_ATTR_TYPE (attrs), Qiso_2022))
@@ -6882,6 +6887,7 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
   Lisp_Object attrs;
   Lisp_Object buffer;
   int saved_pt = -1, saved_pt_byte;
   Lisp_Object attrs;
   Lisp_Object buffer;
   int saved_pt = -1, saved_pt_byte;
+  int kill_src_buffer = 0;
 
   buffer = Fcurrent_buffer ();
 
 
   buffer = Fcurrent_buffer ();
 
@@ -6919,6 +6925,8 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
        args[2] = make_number (Z);
        safe_call (3, args);
       }
        args[2] = make_number (Z);
        safe_call (3, args);
       }
+      if (XBUFFER (coding->src_object) != current_buffer)
+       kill_src_buffer = 1;
       coding->src_object = Fcurrent_buffer ();
       if (BEG != GPT)
        move_gap_both (BEG, BEG_BYTE);
       coding->src_object = Fcurrent_buffer ();
       if (BEG != GPT)
        move_gap_both (BEG, BEG_BYTE);
@@ -7021,6 +7029,8 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
                          saved_pt_byte + (coding->produced - bytes));
     }
 
                          saved_pt_byte + (coding->produced - bytes));
     }
 
+  if (kill_src_buffer)
+    Fkill_buffer (coding->src_object);
   unbind_to (count, Qnil);
 }
 
   unbind_to (count, Qnil);
 }
 
@@ -8871,6 +8881,10 @@ usage: (define-coding-system-internal ...)  */)
   CODING_ATTR_PLIST (attrs)
     = Fcons (QCcategory, Fcons (AREF (Vcoding_category_table, category),
                                CODING_ATTR_PLIST (attrs)));
   CODING_ATTR_PLIST (attrs)
     = Fcons (QCcategory, Fcons (AREF (Vcoding_category_table, category),
                                CODING_ATTR_PLIST (attrs)));
+  CODING_ATTR_PLIST (attrs)
+    = Fcons (QCascii_compatible_p, 
+            Fcons (CODING_ATTR_ASCII_COMPAT (attrs),
+                   CODING_ATTR_PLIST (attrs)));
 
   eol_type = args[coding_arg_eol_type];
   if (! NILP (eol_type)
 
   eol_type = args[coding_arg_eol_type];
   if (! NILP (eol_type)
@@ -8972,6 +8986,10 @@ DEFUN ("coding-system-put", Fcoding_system_put, Scoding_system_put,
       CHECK_SYMBOL (val);
       CODING_ATTR_PRE_WRITE (attrs) = val;
     }
       CHECK_SYMBOL (val);
       CODING_ATTR_PRE_WRITE (attrs) = val;
     }
+  else if (EQ (prop, QCascii_compatible_p))
+    {
+      CODING_ATTR_ASCII_COMPAT (attrs) = val;
+    }
 
   CODING_ATTR_PLIST (attrs)
     = Fplist_put (CODING_ATTR_PLIST (attrs), prop, val);
 
   CODING_ATTR_PLIST (attrs)
     = Fplist_put (CODING_ATTR_PLIST (attrs), prop, val);
@@ -9247,6 +9265,7 @@ syms_of_coding ()
   DEFSYM (QCencode_translation_table, ":encode-translation-table");
   DEFSYM (QCpost_read_conversion, ":post-read-conversion");
   DEFSYM (QCpre_write_conversion, ":pre-write-conversion");
   DEFSYM (QCencode_translation_table, ":encode-translation-table");
   DEFSYM (QCpost_read_conversion, ":post-read-conversion");
   DEFSYM (QCpre_write_conversion, ":pre-write-conversion");
+  DEFSYM (QCascii_compatible_p, ":ascii-compatible-p");
 
   Vcoding_category_table
     = Fmake_vector (make_number (coding_category_max), Qnil);
 
   Vcoding_category_table
     = Fmake_vector (make_number (coding_category_max), Qnil);
@@ -9635,7 +9654,7 @@ character.");
     plist[3] = args[coding_arg_mnemonic] = make_number ('-');
     plist[5] = args[coding_arg_coding_type] = Qundecided;
     /* This is already set.
     plist[3] = args[coding_arg_mnemonic] = make_number ('-');
     plist[5] = args[coding_arg_coding_type] = Qundecided;
     /* This is already set.
-    /*plist[7] = args[coding_arg_ascii_compatible_p] = Qt;*/
+       plist[7] = args[coding_arg_ascii_compatible_p] = Qt; */
     plist[8] = intern (":charset-list");
     plist[9] = args[coding_arg_charset_list] = Fcons (Qascii, Qnil);
     plist[11] = args[coding_arg_for_unibyte] = Qnil;
     plist[8] = intern (":charset-list");
     plist[9] = args[coding_arg_charset_list] = Fcons (Qascii, Qnil);
     plist[11] = args[coding_arg_for_unibyte] = Qnil;