comparison src/coding.c @ 89442:7349f4473e7f

(detected_mask): Delete unused variable. (decode_coding_iso_2022): Pay attention to the byte sequence of CTEXT extended segment, and retain those bytes as is. (decode_coding_ccl): Delete unused variable `valids'. (setup_coding_system): Delete unused variable `category'. (consume_chars): Delete unused variable `category'. Make it work for non-multibyte case. (make_conversion_work_buffer): Argument changed. (saved_coding): Delete unused variable. (code_conversion_restore): Don't check saved_coding->destination. (code_conversion_save): New function. (decode_coding_gap, encode_coding_gap): Call code_conversion_save instead of record_unwind_protect. (decode_coding_object, encode_coding_object): Likewise. Recover PT. (detect_coding_system): Delete unused variable `mask'. (Fdefine_coding_system_internal): Delete unsed vaiable id;
author Kenichi Handa <handa@m17n.org>
date Wed, 28 May 2003 11:36:37 +0000
parents 3c978149859b
children 1c88b057b9d3
comparison
equal deleted inserted replaced
89441:e8f4dff2bfc1 89442:7349f4473e7f
698 static enum coding_category coding_priorities[coding_category_max]; 698 static enum coding_category coding_priorities[coding_category_max];
699 699
700 /* Nth element is a coding context for the coding system bound to the 700 /* Nth element is a coding context for the coding system bound to the
701 Nth coding category. */ 701 Nth coding category. */
702 static struct coding_system coding_categories[coding_category_max]; 702 static struct coding_system coding_categories[coding_category_max];
703
704 static int detected_mask[coding_category_raw_text] =
705 { CATEGORY_MASK_ISO,
706 CATEGORY_MASK_ISO,
707 CATEGORY_MASK_ISO,
708 CATEGORY_MASK_ISO,
709 CATEGORY_MASK_ISO,
710 CATEGORY_MASK_ISO,
711 CATEGORY_MASK_UTF_8,
712 CATEGORY_MASK_UTF_16,
713 CATEGORY_MASK_UTF_16,
714 CATEGORY_MASK_UTF_16,
715 CATEGORY_MASK_UTF_16,
716 CATEGORY_MASK_UTF_16,
717 CATEGORY_MASK_CHARSET,
718 CATEGORY_MASK_SJIS,
719 CATEGORY_MASK_BIG5,
720 CATEGORY_MASK_CCL,
721 CATEGORY_MASK_EMACS_MULE
722 };
723 703
724 /*** Commonly used macros and functions ***/ 704 /*** Commonly used macros and functions ***/
725 705
726 #ifndef min 706 #ifndef min
727 #define min(a, b) ((a) < (b) ? (a) : (b)) 707 #define min(a, b) ((a) < (b) ? (a) : (b))
3078 default: 3058 default:
3079 goto invalid_code; 3059 goto invalid_code;
3080 } 3060 }
3081 continue; 3061 continue;
3082 3062
3063 case '%':
3064 ONE_MORE_BYTE (c1);
3065 if (c1 == '/')
3066 {
3067 /* CTEXT extended segment:
3068 ESC % / [0-4] M L --ENCODING-NAME-- \002 --BYTES--
3069 We keep these bytes as is for the moment.
3070 They may be decoded by post-read-conversion. */
3071 int dim, M, L;
3072 int size;
3073
3074 ONE_MORE_BYTE (dim);
3075 ONE_MORE_BYTE (M);
3076 ONE_MORE_BYTE (L);
3077 size = ((M - 128) * 128) + (L - 128);
3078 if (charbuf + 8 + size > charbuf_end)
3079 goto break_loop;
3080 *charbuf++ = ISO_CODE_ESC;
3081 *charbuf++ = '%';
3082 *charbuf++ = '/';
3083 *charbuf++ = dim;
3084 *charbuf++ = BYTE8_TO_CHAR (M);
3085 *charbuf++ = BYTE8_TO_CHAR (L);
3086 while (size-- > 0)
3087 {
3088 ONE_MORE_BYTE (c1);
3089 *charbuf++ = ASCII_BYTE_P (c1) ? c1 : BYTE8_TO_CHAR (c1);
3090 }
3091 }
3092 else if (c1 == 'G')
3093 {
3094 /* XFree86 extension for embedding UTF-8 in CTEXT:
3095 ESC % G --UTF-8-BYTES-- ESC % @
3096 We keep these bytes as is for the moment.
3097 They may be decoded by post-read-conversion. */
3098 int *p = charbuf;
3099
3100 if (p + 6 > charbuf_end)
3101 goto break_loop;
3102 *p++ = ISO_CODE_ESC;
3103 *p++ = '%';
3104 *p++ = 'G';
3105 while (p < charbuf_end)
3106 {
3107 ONE_MORE_BYTE (c1);
3108 if (c1 == ISO_CODE_ESC
3109 && src + 1 < src_end
3110 && src[0] == '%'
3111 && src[1] == '@')
3112 break;
3113 *p++ = ASCII_BYTE_P (c1) ? c1 : BYTE8_TO_CHAR (c1);
3114 }
3115 if (p + 3 > charbuf_end)
3116 goto break_loop;
3117 *p++ = ISO_CODE_ESC;
3118 *p++ = '%';
3119 *p++ = '@';
3120 charbuf = p;
3121 }
3122 else
3123 goto invalid_code;
3124 continue;
3125 break;
3126
3083 default: 3127 default:
3084 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) 3128 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION))
3085 goto invalid_code; 3129 goto invalid_code;
3086 if (c1 >= 0x28 && c1 <= 0x2B) 3130 if (c1 >= 0x28 && c1 <= 0x2B)
3087 { /* designation of DIMENSION1_CHARS94 character set */ 3131 { /* designation of DIMENSION1_CHARS94 character set */
3166 consumed_chars = consumed_chars_base; 3210 consumed_chars = consumed_chars_base;
3167 ONE_MORE_BYTE (c); 3211 ONE_MORE_BYTE (c);
3168 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); 3212 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c);
3169 char_offset++; 3213 char_offset++;
3170 coding->errors++; 3214 coding->errors++;
3215 continue;
3216
3217 break_loop:
3218 break;
3171 } 3219 }
3172 3220
3173 no_more_source: 3221 no_more_source:
3174 if (last_id != charset_ascii) 3222 if (last_id != charset_ascii)
3175 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); 3223 ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id);
4285 int consumed_chars = 0; 4333 int consumed_chars = 0;
4286 int multibytep = coding->src_multibyte; 4334 int multibytep = coding->src_multibyte;
4287 struct ccl_program ccl; 4335 struct ccl_program ccl;
4288 int source_charbuf[1024]; 4336 int source_charbuf[1024];
4289 int source_byteidx[1024]; 4337 int source_byteidx[1024];
4290 Lisp_Object attrs, eol_type, charset_list, valids; 4338 Lisp_Object attrs, eol_type, charset_list;
4291 4339
4292 CODING_GET_INFO (coding, attrs, eol_type, charset_list); 4340 CODING_GET_INFO (coding, attrs, eol_type, charset_list);
4293 setup_ccl_program (&ccl, CODING_CCL_DECODER (coding)); 4341 setup_ccl_program (&ccl, CODING_CCL_DECODER (coding));
4294 4342
4295 while (src < src_end) 4343 while (src < src_end)
4791 } 4839 }
4792 else if (EQ (coding_type, Qiso_2022)) 4840 else if (EQ (coding_type, Qiso_2022))
4793 { 4841 {
4794 int i; 4842 int i;
4795 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); 4843 int flags = XINT (AREF (attrs, coding_attr_iso_flags));
4796 enum coding_category category = XINT (CODING_ATTR_CATEGORY (attrs));
4797 4844
4798 /* Invoke graphic register 0 to plane 0. */ 4845 /* Invoke graphic register 0 to plane 0. */
4799 CODING_ISO_INVOCATION (coding, 0) = 0; 4846 CODING_ISO_INVOCATION (coding, 0) = 0;
4800 /* Invoke graphic register 1 to plane 1 if we can use 8-bit. */ 4847 /* Invoke graphic register 1 to plane 1 if we can use 8-bit. */
4801 CODING_ISO_INVOCATION (coding, 1) 4848 CODING_ISO_INVOCATION (coding, 1)
5946 struct coding_system *coding; 5993 struct coding_system *coding;
5947 { 5994 {
5948 int *buf = coding->charbuf; 5995 int *buf = coding->charbuf;
5949 int *buf_end = coding->charbuf + coding->charbuf_size; 5996 int *buf_end = coding->charbuf + coding->charbuf_size;
5950 const unsigned char *src = coding->source + coding->consumed; 5997 const unsigned char *src = coding->source + coding->consumed;
5998 const unsigned char *src_end = coding->source + coding->src_bytes;
5951 EMACS_INT pos = coding->src_pos + coding->consumed_char; 5999 EMACS_INT pos = coding->src_pos + coding->consumed_char;
5952 EMACS_INT end_pos = coding->src_pos + coding->src_chars; 6000 EMACS_INT end_pos = coding->src_pos + coding->src_chars;
5953 int multibytep = coding->src_multibyte; 6001 int multibytep = coding->src_multibyte;
5954 Lisp_Object eol_type; 6002 Lisp_Object eol_type;
5955 int c; 6003 int c;
5956 EMACS_INT stop, stop_composition, stop_charset; 6004 EMACS_INT stop, stop_composition, stop_charset;
5957 int id;
5958 6005
5959 eol_type = CODING_ID_EOL_TYPE (coding->id); 6006 eol_type = CODING_ID_EOL_TYPE (coding->id);
5960 if (VECTORP (eol_type)) 6007 if (VECTORP (eol_type))
5961 eol_type = Qunix; 6008 eol_type = Qunix;
5962 6009
5976 buf_end -= 1 + MAX_ANNOTATION_LENGTH; 6023 buf_end -= 1 + MAX_ANNOTATION_LENGTH;
5977 while (buf < buf_end) 6024 while (buf < buf_end)
5978 { 6025 {
5979 if (pos == stop) 6026 if (pos == stop)
5980 { 6027 {
5981 int *p;
5982
5983 if (pos == end_pos) 6028 if (pos == end_pos)
5984 break; 6029 break;
5985 if (pos == stop_composition) 6030 if (pos == stop_composition)
5986 buf = handle_composition_annotation (pos, end_pos, coding, 6031 buf = handle_composition_annotation (pos, end_pos, coding,
5987 buf, &stop_composition); 6032 buf, &stop_composition);
5991 stop = (stop_composition < stop_charset 6036 stop = (stop_composition < stop_charset
5992 ? stop_composition : stop_charset); 6037 ? stop_composition : stop_charset);
5993 } 6038 }
5994 6039
5995 if (! multibytep) 6040 if (! multibytep)
5996 c = *src++; 6041 {
6042 EMACS_INT bytes = MULTIBYTE_LENGTH (src, src_end);
6043
6044 if (bytes > 0)
6045 c = STRING_CHAR_ADVANCE (src), pos += bytes;
6046 else
6047 c = *src++, pos++;
6048 }
5997 else 6049 else
5998 c = STRING_CHAR_ADVANCE (src); 6050 c = STRING_CHAR_ADVANCE (src), pos++;
5999 if ((c == '\r') && (coding->mode & CODING_MODE_SELECTIVE_DISPLAY)) 6051 if ((c == '\r') && (coding->mode & CODING_MODE_SELECTIVE_DISPLAY))
6000 c = '\n'; 6052 c = '\n';
6001 if (! EQ (eol_type, Qunix)) 6053 if (! EQ (eol_type, Qunix))
6002 { 6054 {
6003 if (c == '\n') 6055 if (c == '\n')
6007 else 6059 else
6008 c = '\r'; 6060 c = '\r';
6009 } 6061 }
6010 } 6062 }
6011 *buf++ = c; 6063 *buf++ = c;
6012 pos++;
6013 } 6064 }
6014 6065
6015 coding->consumed = src - coding->source; 6066 coding->consumed = src - coding->source;
6016 coding->consumed_char = pos - coding->src_pos; 6067 coding->consumed_char = pos - coding->src_pos;
6017 coding->charbuf_used = buf - coding->charbuf; 6068 coding->charbuf_used = buf - coding->charbuf;
6079 insert_from_gap (coding->produced_char, coding->produced); 6130 insert_from_gap (coding->produced_char, coding->produced);
6080 6131
6081 return (coding->result); 6132 return (coding->result);
6082 } 6133 }
6083 6134
6084 /* Work buffer */ 6135
6085 6136 /* Stack of working buffers used in code conversion. An nil element
6086 /* List of currently used working buffer. */ 6137 means that the code conversion of that level is not using a working
6138 buffer. */
6087 Lisp_Object Vcode_conversion_work_buf_list; 6139 Lisp_Object Vcode_conversion_work_buf_list;
6088 6140
6089 /* A working buffer used by the top level conversion. */ 6141 /* A working buffer used by the top level conversion. */
6090 Lisp_Object Vcode_conversion_reused_work_buf; 6142 Lisp_Object Vcode_conversion_reused_work_buf;
6091 6143
6093 /* Return a working buffer that can be freely used by the following 6145 /* Return a working buffer that can be freely used by the following
6094 code conversion. MULTIBYTEP specifies the multibyteness of the 6146 code conversion. MULTIBYTEP specifies the multibyteness of the
6095 buffer. */ 6147 buffer. */
6096 6148
6097 Lisp_Object 6149 Lisp_Object
6098 make_conversion_work_buffer (multibytep) 6150 make_conversion_work_buffer (multibytep, depth)
6099 int multibytep; 6151 int multibytep, depth;
6100 { 6152 {
6101 struct buffer *current = current_buffer; 6153 struct buffer *current = current_buffer;
6102 Lisp_Object buf; 6154 Lisp_Object buf, name;
6103 6155
6104 if (NILP (Vcode_conversion_work_buf_list)) 6156 if (depth == 0)
6105 { 6157 {
6106 if (NILP (Vcode_conversion_reused_work_buf)) 6158 if (NILP (Vcode_conversion_reused_work_buf))
6107 Vcode_conversion_reused_work_buf 6159 Vcode_conversion_reused_work_buf
6108 = Fget_buffer_create (build_string (" *code-conversion-work*")); 6160 = Fget_buffer_create (build_string (" *code-conversion-work<0>*"));
6109 Vcode_conversion_work_buf_list 6161 buf = Vcode_conversion_reused_work_buf;
6110 = Fcons (Vcode_conversion_reused_work_buf, Qnil);
6111 } 6162 }
6112 else 6163 else
6113 { 6164 {
6114 int depth = XINT (Flength (Vcode_conversion_work_buf_list)); 6165 if (depth < 0)
6115 char str[128]; 6166 {
6116 6167 name = build_string (" *code-conversion-work*");
6117 sprintf (str, " *code-conversion-work*<%d>", depth); 6168 name = Fgenerate_new_buffer_name (name, Qnil);
6118 Vcode_conversion_work_buf_list 6169 }
6119 = Fcons (Fget_buffer_create (build_string (str)), 6170 else
6120 Vcode_conversion_work_buf_list); 6171 {
6121 } 6172 char str[128];
6122 6173
6123 buf = XCAR (Vcode_conversion_work_buf_list); 6174 sprintf (str, " *code-conversion-work*<%d>", depth);
6175 name = build_string (str);
6176 }
6177 buf = Fget_buffer_create (name);
6178 }
6124 set_buffer_internal (XBUFFER (buf)); 6179 set_buffer_internal (XBUFFER (buf));
6125 current_buffer->undo_list = Qt; 6180 current_buffer->undo_list = Qt;
6126 Ferase_buffer (); 6181 Ferase_buffer ();
6127 Fset_buffer_multibyte (multibytep ? Qt : Qnil, Qnil); 6182 Fset_buffer_multibyte (multibytep ? Qt : Qnil, Qnil);
6128 set_buffer_internal (current); 6183 set_buffer_internal (current);
6129 return buf; 6184 return buf;
6130 } 6185 }
6131 6186
6132 static struct coding_system *saved_coding; 6187 static Lisp_Object
6133 6188 code_conversion_restore (buffer)
6134 Lisp_Object 6189 Lisp_Object buffer;
6135 code_conversion_restore (info) 6190 {
6136 Lisp_Object info; 6191 Lisp_Object workbuf;
6137 { 6192
6138 int depth = XINT (Flength (Vcode_conversion_work_buf_list)); 6193 workbuf = XCAR (Vcode_conversion_work_buf_list);
6139 Lisp_Object buf; 6194 if (! NILP (workbuf)
6140 6195 && ! EQ (workbuf, Vcode_conversion_reused_work_buf)
6141 if (depth > 0) 6196 && ! NILP (Fbuffer_live_p (workbuf)))
6142 { 6197 Fkill_buffer (workbuf);
6143 buf = XCAR (Vcode_conversion_work_buf_list); 6198 Vcode_conversion_work_buf_list = XCDR (Vcode_conversion_work_buf_list);
6144 Vcode_conversion_work_buf_list = XCDR (Vcode_conversion_work_buf_list); 6199 set_buffer_internal (XBUFFER (buffer));
6145 if (depth > 1 && !NILP (Fbuffer_live_p (buf))) 6200 return Qnil;
6146 Fkill_buffer (buf); 6201 }
6147 } 6202
6148 6203 static Lisp_Object
6149 if (EQ (saved_coding->dst_object, Qt) 6204 code_conversion_save (buffer, with_work_buf, multibyte)
6150 && saved_coding->destination) 6205 Lisp_Object buffer;
6151 xfree (saved_coding->destination); 6206 int with_work_buf, multibyte;
6152 6207 {
6153 return save_excursion_restore (info); 6208 Lisp_Object workbuf;
6154 } 6209
6155 6210 if (with_work_buf)
6211 {
6212 int depth = XINT (Flength (Vcode_conversion_work_buf_list));
6213
6214 workbuf = make_conversion_work_buffer (multibyte, depth);
6215 }
6216 else
6217 workbuf = Qnil;
6218 Vcode_conversion_work_buf_list
6219 = Fcons (workbuf, Vcode_conversion_work_buf_list);
6220 record_unwind_protect (code_conversion_restore, buffer);
6221 return workbuf;
6222 }
6156 6223
6157 int 6224 int
6158 decode_coding_gap (coding, chars, bytes) 6225 decode_coding_gap (coding, chars, bytes)
6159 struct coding_system *coding; 6226 struct coding_system *coding;
6160 EMACS_INT chars, bytes; 6227 EMACS_INT chars, bytes;
6161 { 6228 {
6162 int count = specpdl_ptr - specpdl; 6229 int count = specpdl_ptr - specpdl;
6163 6230 Lisp_Object buffer;
6164 saved_coding = coding; 6231
6165 record_unwind_protect (code_conversion_restore, save_excursion_save ()); 6232 buffer = Fcurrent_buffer ();
6166 6233 code_conversion_save (buffer, 0, 0);
6167 coding->src_object = Fcurrent_buffer (); 6234
6235 coding->src_object = buffer;
6168 coding->src_chars = chars; 6236 coding->src_chars = chars;
6169 coding->src_bytes = bytes; 6237 coding->src_bytes = bytes;
6170 coding->src_pos = -chars; 6238 coding->src_pos = -chars;
6171 coding->src_pos_byte = -bytes; 6239 coding->src_pos_byte = -bytes;
6172 coding->src_multibyte = chars < bytes; 6240 coding->src_multibyte = chars < bytes;
6191 EMACS_INT chars, bytes; 6259 EMACS_INT chars, bytes;
6192 { 6260 {
6193 int count = specpdl_ptr - specpdl; 6261 int count = specpdl_ptr - specpdl;
6194 Lisp_Object buffer; 6262 Lisp_Object buffer;
6195 6263
6196 saved_coding = coding;
6197 record_unwind_protect (code_conversion_restore, save_excursion_save ());
6198
6199 buffer = Fcurrent_buffer (); 6264 buffer = Fcurrent_buffer ();
6265 code_conversion_save (buffer, 0, 0);
6266
6200 coding->src_object = buffer; 6267 coding->src_object = buffer;
6201 coding->src_chars = chars; 6268 coding->src_chars = chars;
6202 coding->src_bytes = bytes; 6269 coding->src_bytes = bytes;
6203 coding->src_pos = -chars; 6270 coding->src_pos = -chars;
6204 coding->src_pos_byte = -bytes; 6271 coding->src_pos_byte = -bytes;
6255 unsigned char *destination; 6322 unsigned char *destination;
6256 EMACS_INT dst_bytes; 6323 EMACS_INT dst_bytes;
6257 EMACS_INT chars = to - from; 6324 EMACS_INT chars = to - from;
6258 EMACS_INT bytes = to_byte - from_byte; 6325 EMACS_INT bytes = to_byte - from_byte;
6259 Lisp_Object attrs; 6326 Lisp_Object attrs;
6260 6327 Lisp_Object buffer;
6261 saved_coding = coding; 6328 int saved_pt = -1, saved_pt_byte;
6262 record_unwind_protect (code_conversion_restore, save_excursion_save ()); 6329
6330 buffer = Fcurrent_buffer ();
6263 6331
6264 if (NILP (dst_object)) 6332 if (NILP (dst_object))
6265 { 6333 {
6266 destination = coding->destination; 6334 destination = coding->destination;
6267 dst_bytes = coding->dst_bytes; 6335 dst_bytes = coding->dst_bytes;
6282 set_buffer_internal (XBUFFER (src_object)); 6350 set_buffer_internal (XBUFFER (src_object));
6283 if (from != GPT) 6351 if (from != GPT)
6284 move_gap_both (from, from_byte); 6352 move_gap_both (from, from_byte);
6285 if (EQ (src_object, dst_object)) 6353 if (EQ (src_object, dst_object))
6286 { 6354 {
6355 saved_pt = PT, saved_pt_byte = PT_BYTE;
6287 TEMP_SET_PT_BOTH (from, from_byte); 6356 TEMP_SET_PT_BOTH (from, from_byte);
6288 del_range_both (from, from_byte, to, to_byte, 1); 6357 del_range_both (from, from_byte, to, to_byte, 1);
6289 coding->src_pos = -chars; 6358 coding->src_pos = -chars;
6290 coding->src_pos_byte = -bytes; 6359 coding->src_pos_byte = -bytes;
6291 } 6360 }
6302 6371
6303 if (EQ (dst_object, Qt) 6372 if (EQ (dst_object, Qt)
6304 || (! NILP (CODING_ATTR_POST_READ (attrs)) 6373 || (! NILP (CODING_ATTR_POST_READ (attrs))
6305 && NILP (dst_object))) 6374 && NILP (dst_object)))
6306 { 6375 {
6307 coding->dst_object = make_conversion_work_buffer (1); 6376 coding->dst_object = code_conversion_save (buffer, 1, 1);
6308 coding->dst_pos = BEG; 6377 coding->dst_pos = BEG;
6309 coding->dst_pos_byte = BEG_BYTE; 6378 coding->dst_pos_byte = BEG_BYTE;
6310 coding->dst_multibyte = 1; 6379 coding->dst_multibyte = 1;
6311 } 6380 }
6312 else if (BUFFERP (dst_object)) 6381 else if (BUFFERP (dst_object))
6313 { 6382 {
6383 code_conversion_save (buffer, 0, 0);
6314 coding->dst_object = dst_object; 6384 coding->dst_object = dst_object;
6315 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); 6385 coding->dst_pos = BUF_PT (XBUFFER (dst_object));
6316 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); 6386 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object));
6317 coding->dst_multibyte 6387 coding->dst_multibyte
6318 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters); 6388 = ! NILP (XBUFFER (dst_object)->enable_multibyte_characters);
6319 } 6389 }
6320 else 6390 else
6321 { 6391 {
6392 code_conversion_save (buffer, 0, 0);
6322 coding->dst_object = Qnil; 6393 coding->dst_object = Qnil;
6323 coding->dst_multibyte = 1; 6394 coding->dst_multibyte = 1;
6324 } 6395 }
6325 6396
6326 decode_coding (coding); 6397 decode_coding (coding);
6366 bcopy (BEGV_ADDR, destination, coding->produced); 6437 bcopy (BEGV_ADDR, destination, coding->produced);
6367 coding->destination = destination; 6438 coding->destination = destination;
6368 } 6439 }
6369 } 6440 }
6370 6441
6442 if (saved_pt >= 0)
6443 {
6444 /* This is the case of:
6445 (BUFFERP (src_object) && EQ (src_object, dst_object))
6446 As we have moved PT while replacing the original buffer
6447 contents, we must recover it now. */
6448 set_buffer_internal (XBUFFER (src_object));
6449 if (saved_pt < from)
6450 TEMP_SET_PT_BOTH (saved_pt, saved_pt_byte);
6451 else if (saved_pt < from + chars)
6452 TEMP_SET_PT_BOTH (from, from_byte);
6453 else if (! NILP (current_buffer->enable_multibyte_characters))
6454 TEMP_SET_PT_BOTH (saved_pt + (coding->produced_char - chars),
6455 saved_pt_byte + (coding->produced - bytes));
6456 else
6457 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes),
6458 saved_pt_byte + (coding->produced - bytes));
6459 }
6460
6371 unbind_to (count, Qnil); 6461 unbind_to (count, Qnil);
6372 } 6462 }
6373 6463
6374 6464
6375 void 6465 void
6382 { 6472 {
6383 int count = specpdl_ptr - specpdl; 6473 int count = specpdl_ptr - specpdl;
6384 EMACS_INT chars = to - from; 6474 EMACS_INT chars = to - from;
6385 EMACS_INT bytes = to_byte - from_byte; 6475 EMACS_INT bytes = to_byte - from_byte;
6386 Lisp_Object attrs; 6476 Lisp_Object attrs;
6387 6477 Lisp_Object buffer;
6388 saved_coding = coding; 6478 int saved_pt = -1, saved_pt_byte;
6389 record_unwind_protect (code_conversion_restore, save_excursion_save ()); 6479
6480 buffer = Fcurrent_buffer ();
6390 6481
6391 coding->src_object = src_object; 6482 coding->src_object = src_object;
6392 coding->src_chars = chars; 6483 coding->src_chars = chars;
6393 coding->src_bytes = bytes; 6484 coding->src_bytes = bytes;
6394 coding->src_multibyte = chars < bytes; 6485 coding->src_multibyte = chars < bytes;
6395 6486
6396 attrs = CODING_ID_ATTRS (coding->id); 6487 attrs = CODING_ID_ATTRS (coding->id);
6397 6488
6398 if (! NILP (CODING_ATTR_PRE_WRITE (attrs))) 6489 if (! NILP (CODING_ATTR_PRE_WRITE (attrs)))
6399 { 6490 {
6400 coding->src_object = make_conversion_work_buffer (coding->src_multibyte); 6491 coding->src_object = code_conversion_save (buffer, 1,
6492 coding->src_multibyte);
6401 set_buffer_internal (XBUFFER (coding->src_object)); 6493 set_buffer_internal (XBUFFER (coding->src_object));
6402 if (STRINGP (src_object)) 6494 if (STRINGP (src_object))
6403 insert_from_string (src_object, from, from_byte, chars, bytes, 0); 6495 insert_from_string (src_object, from, from_byte, chars, bytes, 0);
6404 else if (BUFFERP (src_object)) 6496 else if (BUFFERP (src_object))
6405 insert_from_buffer (XBUFFER (src_object), from, chars, 0); 6497 insert_from_buffer (XBUFFER (src_object), from, chars, 0);
6407 insert_1_both (coding->source + from, chars, bytes, 0, 0, 0); 6499 insert_1_both (coding->source + from, chars, bytes, 0, 0, 0);
6408 6500
6409 if (EQ (src_object, dst_object)) 6501 if (EQ (src_object, dst_object))
6410 { 6502 {
6411 set_buffer_internal (XBUFFER (src_object)); 6503 set_buffer_internal (XBUFFER (src_object));
6504 saved_pt = PT, saved_pt_byte = PT_BYTE;
6412 del_range_both (from, from_byte, to, to_byte, 1); 6505 del_range_both (from, from_byte, to, to_byte, 1);
6413 set_buffer_internal (XBUFFER (coding->src_object)); 6506 set_buffer_internal (XBUFFER (coding->src_object));
6414 } 6507 }
6415 6508
6416 call2 (CODING_ATTR_PRE_WRITE (attrs), 6509 call2 (CODING_ATTR_PRE_WRITE (attrs),
6424 coding->src_pos_byte = BEG_BYTE; 6517 coding->src_pos_byte = BEG_BYTE;
6425 coding->src_multibyte = Z < Z_BYTE; 6518 coding->src_multibyte = Z < Z_BYTE;
6426 } 6519 }
6427 else if (STRINGP (src_object)) 6520 else if (STRINGP (src_object))
6428 { 6521 {
6522 code_conversion_save (buffer, 0, 0);
6429 coding->src_pos = from; 6523 coding->src_pos = from;
6430 coding->src_pos_byte = from_byte; 6524 coding->src_pos_byte = from_byte;
6431 } 6525 }
6432 else if (BUFFERP (src_object)) 6526 else if (BUFFERP (src_object))
6433 { 6527 {
6528 code_conversion_save (buffer, 0, 0);
6434 set_buffer_internal (XBUFFER (src_object)); 6529 set_buffer_internal (XBUFFER (src_object));
6435 if (EQ (src_object, dst_object)) 6530 if (EQ (src_object, dst_object))
6436 { 6531 {
6532 saved_pt = PT, saved_pt_byte = PT_BYTE;
6437 coding->src_object = del_range_1 (from, to, 1, 1); 6533 coding->src_object = del_range_1 (from, to, 1, 1);
6438 coding->src_pos = 0; 6534 coding->src_pos = 0;
6439 coding->src_pos_byte = 0; 6535 coding->src_pos_byte = 0;
6440 } 6536 }
6441 else 6537 else
6444 move_gap_both (from, from_byte); 6540 move_gap_both (from, from_byte);
6445 coding->src_pos = from; 6541 coding->src_pos = from;
6446 coding->src_pos_byte = from_byte; 6542 coding->src_pos_byte = from_byte;
6447 } 6543 }
6448 } 6544 }
6545 else
6546 code_conversion_save (buffer, 0, 0);
6449 6547
6450 if (BUFFERP (dst_object)) 6548 if (BUFFERP (dst_object))
6451 { 6549 {
6452 coding->dst_object = dst_object; 6550 coding->dst_object = dst_object;
6453 if (EQ (src_object, dst_object)) 6551 if (EQ (src_object, dst_object))
6489 coding->dst_object 6587 coding->dst_object
6490 = make_unibyte_string ((char *) coding->destination, 6588 = make_unibyte_string ((char *) coding->destination,
6491 coding->produced); 6589 coding->produced);
6492 xfree (coding->destination); 6590 xfree (coding->destination);
6493 } 6591 }
6592 }
6593
6594 if (saved_pt >= 0)
6595 {
6596 /* This is the case of:
6597 (BUFFERP (src_object) && EQ (src_object, dst_object))
6598 As we have moved PT while replacing the original buffer
6599 contents, we must recover it now. */
6600 set_buffer_internal (XBUFFER (src_object));
6601 if (saved_pt < from)
6602 TEMP_SET_PT_BOTH (saved_pt, saved_pt_byte);
6603 else if (saved_pt < from + chars)
6604 TEMP_SET_PT_BOTH (from, from_byte);
6605 else if (! NILP (current_buffer->enable_multibyte_characters))
6606 TEMP_SET_PT_BOTH (saved_pt + (coding->produced_char - chars),
6607 saved_pt_byte + (coding->produced - bytes));
6608 else
6609 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes),
6610 saved_pt_byte + (coding->produced - bytes));
6494 } 6611 }
6495 6612
6496 unbind_to (count, Qnil); 6613 unbind_to (count, Qnil);
6497 } 6614 }
6498 6615
6587 int src_bytes, highest; 6704 int src_bytes, highest;
6588 int multibytep; 6705 int multibytep;
6589 Lisp_Object coding_system; 6706 Lisp_Object coding_system;
6590 { 6707 {
6591 unsigned char *src_end = src + src_bytes; 6708 unsigned char *src_end = src + src_bytes;
6592 int mask = CATEGORY_MASK_ANY;
6593 Lisp_Object attrs, eol_type; 6709 Lisp_Object attrs, eol_type;
6594 Lisp_Object val; 6710 Lisp_Object val;
6595 struct coding_system coding; 6711 struct coding_system coding;
6596 int id; 6712 int id;
6597 struct coding_detection_info detect_info; 6713 struct coding_detection_info detect_info;
8003 : coding_category_utf_16_le)); 8119 : coding_category_utf_16_le));
8004 } 8120 }
8005 else if (EQ (coding_type, Qiso_2022)) 8121 else if (EQ (coding_type, Qiso_2022))
8006 { 8122 {
8007 Lisp_Object initial, reg_usage, request, flags; 8123 Lisp_Object initial, reg_usage, request, flags;
8008 int i, id; 8124 int i;
8009 8125
8010 if (nargs < coding_arg_iso2022_max) 8126 if (nargs < coding_arg_iso2022_max)
8011 goto short_args; 8127 goto short_args;
8012 8128
8013 initial = Fcopy_sequence (args[coding_arg_iso2022_initial]); 8129 initial = Fcopy_sequence (args[coding_arg_iso2022_initial]);