comparison src/coding.c @ 83353:532e0a9335a9

Merged in changes from CVS trunk. Plus added lisp/term tweaks. Patches applied: * lorentey@elte.hu--2004/emacs--cvs-trunk--0--base-0 tag of miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-474 * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-1 Add CVS metadata files. * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-2 Update from CVS. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-393
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 04 Sep 2005 03:48:17 +0000
parents 9216636c02fc a0d1312ede66
children d84f940244dc
comparison
equal deleted inserted replaced
83352:b258b3492423 83353:532e0a9335a9
1 /* Coding system handler (conversion, detection, and etc). 1 /* Coding system handler (conversion, detection, and etc).
2 Copyright (C) 1995,97,1998,2002,2003 Electrotechnical Laboratory, JAPAN. 2 Copyright (C) 1995,97,1998,2002,2003 Electrotechnical Laboratory, JAPAN.
3 Licensed to the Free Software Foundation. 3 Licensed to the Free Software Foundation.
4 Copyright (C) 2001,2002,2003 Free Software Foundation, Inc. 4 Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 5
6 This file is part of GNU Emacs. 6 This file is part of GNU Emacs.
7 7
8 GNU Emacs is free software; you can redistribute it and/or modify 8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
363 Lisp_Object Qcoding_system_history; 363 Lisp_Object Qcoding_system_history;
364 Lisp_Object Qsafe_chars; 364 Lisp_Object Qsafe_chars;
365 Lisp_Object Qvalid_codes; 365 Lisp_Object Qvalid_codes;
366 366
367 extern Lisp_Object Qinsert_file_contents, Qwrite_region; 367 extern Lisp_Object Qinsert_file_contents, Qwrite_region;
368 Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument; 368 Lisp_Object Qcall_process, Qcall_process_region;
369 Lisp_Object Qstart_process, Qopen_network_stream; 369 Lisp_Object Qstart_process, Qopen_network_stream;
370 Lisp_Object Qtarget_idx; 370 Lisp_Object Qtarget_idx;
371 371
372 /* If a symbol has this property, evaluate the value to define the 372 /* If a symbol has this property, evaluate the value to define the
373 symbol as a coding system. */ 373 symbol as a coding system. */
5347 if (encodep) shrink_encoding_region (beg, end, coding, str); \ 5347 if (encodep) shrink_encoding_region (beg, end, coding, str); \
5348 else shrink_decoding_region (beg, end, coding, str); \ 5348 else shrink_decoding_region (beg, end, coding, str); \
5349 } \ 5349 } \
5350 } while (0) 5350 } while (0)
5351 5351
5352 /* ARG is (CODING . BUFFER) where CODING is what to be set in
5353 Vlast_coding_system_used and BUFFER if non-nil is a buffer to
5354 kill. */
5352 static Lisp_Object 5355 static Lisp_Object
5353 code_convert_region_unwind (arg) 5356 code_convert_region_unwind (arg)
5354 Lisp_Object arg; 5357 Lisp_Object arg;
5355 { 5358 {
5356 inhibit_pre_post_conversion = 0; 5359 inhibit_pre_post_conversion = 0;
5357 Vlast_coding_system_used = arg; 5360 Vlast_coding_system_used = XCAR (arg);
5361 if (! NILP (XCDR (arg)))
5362 Fkill_buffer (XCDR (arg));
5358 return Qnil; 5363 return Qnil;
5359 } 5364 }
5360 5365
5361 /* Store information about all compositions in the range FROM and TO 5366 /* Store information about all compositions in the range FROM and TO
5362 of OBJ in memory blocks pointed by CODING->cmp_data. OBJ is a 5367 of OBJ in memory blocks pointed by CODING->cmp_data. OBJ is a
5605 new buffer. */ 5610 new buffer. */
5606 struct buffer *prev = current_buffer; 5611 struct buffer *prev = current_buffer;
5607 Lisp_Object new; 5612 Lisp_Object new;
5608 5613
5609 record_unwind_protect (code_convert_region_unwind, 5614 record_unwind_protect (code_convert_region_unwind,
5610 Vlast_coding_system_used); 5615 Fcons (Vlast_coding_system_used, Qnil));
5611 /* We should not call any more pre-write/post-read-conversion 5616 /* We should not call any more pre-write/post-read-conversion
5612 functions while this pre-write-conversion is running. */ 5617 functions while this pre-write-conversion is running. */
5613 inhibit_pre_post_conversion = 1; 5618 inhibit_pre_post_conversion = 1;
5614 call2 (coding->pre_write_conversion, 5619 call2 (coding->pre_write_conversion,
5615 make_number (from), make_number (to)); 5620 make_number (from), make_number (to));
5973 5978
5974 if (from != PT) 5979 if (from != PT)
5975 TEMP_SET_PT_BOTH (from, from_byte); 5980 TEMP_SET_PT_BOTH (from, from_byte);
5976 prev_Z = Z; 5981 prev_Z = Z;
5977 record_unwind_protect (code_convert_region_unwind, 5982 record_unwind_protect (code_convert_region_unwind,
5978 Vlast_coding_system_used); 5983 Fcons (Vlast_coding_system_used, Qnil));
5979 saved_coding_system = Vlast_coding_system_used; 5984 saved_coding_system = Vlast_coding_system_used;
5980 Vlast_coding_system_used = coding->symbol; 5985 Vlast_coding_system_used = coding->symbol;
5981 /* We should not call any more pre-write/post-read-conversion 5986 /* We should not call any more pre-write/post-read-conversion
5982 functions while this post-read-conversion is running. */ 5987 functions while this post-read-conversion is running. */
5983 inhibit_pre_post_conversion = 1; 5988 inhibit_pre_post_conversion = 1;
6019 /* Name (or base name) of work buffer for code conversion. */ 6024 /* Name (or base name) of work buffer for code conversion. */
6020 static Lisp_Object Vcode_conversion_workbuf_name; 6025 static Lisp_Object Vcode_conversion_workbuf_name;
6021 6026
6022 /* Set the current buffer to the working buffer prepared for 6027 /* Set the current buffer to the working buffer prepared for
6023 code-conversion. MULTIBYTE specifies the multibyteness of the 6028 code-conversion. MULTIBYTE specifies the multibyteness of the
6024 buffer. */ 6029 buffer. Return the buffer we set if it must be killed after use.
6025 6030 Otherwise return Qnil. */
6026 static struct buffer * 6031
6032 static Lisp_Object
6027 set_conversion_work_buffer (multibyte) 6033 set_conversion_work_buffer (multibyte)
6028 int multibyte; 6034 int multibyte;
6029 { 6035 {
6030 Lisp_Object buffer; 6036 Lisp_Object buffer, buffer_to_kill;
6031 struct buffer *buf; 6037 struct buffer *buf;
6032 6038
6033 buffer = Fget_buffer_create (Vcode_conversion_workbuf_name); 6039 buffer = Fget_buffer_create (Vcode_conversion_workbuf_name);
6034 buf = XBUFFER (buffer); 6040 buf = XBUFFER (buffer);
6041 if (buf == current_buffer)
6042 {
6043 /* As we are already in the work buffer, we must generate a new
6044 buffer for the work. */
6045 Lisp_Object name;
6046
6047 name = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil);
6048 buffer = buffer_to_kill = Fget_buffer_create (name);
6049 buf = XBUFFER (buffer);
6050 }
6051 else
6052 buffer_to_kill = Qnil;
6053
6035 delete_all_overlays (buf); 6054 delete_all_overlays (buf);
6036 buf->directory = current_buffer->directory; 6055 buf->directory = current_buffer->directory;
6037 buf->read_only = Qnil; 6056 buf->read_only = Qnil;
6038 buf->filename = Qnil; 6057 buf->filename = Qnil;
6039 buf->undo_list = Qt; 6058 buf->undo_list = Qt;
6042 set_buffer_internal (buf); 6061 set_buffer_internal (buf);
6043 if (BEG != BEGV || Z != ZV) 6062 if (BEG != BEGV || Z != ZV)
6044 Fwiden (); 6063 Fwiden ();
6045 del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0); 6064 del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0);
6046 buf->enable_multibyte_characters = multibyte ? Qt : Qnil; 6065 buf->enable_multibyte_characters = multibyte ? Qt : Qnil;
6047 return buf; 6066 return buffer_to_kill;
6048 } 6067 }
6049 6068
6050 Lisp_Object 6069 Lisp_Object
6051 run_pre_post_conversion_on_str (str, coding, encodep) 6070 run_pre_post_conversion_on_str (str, coding, encodep)
6052 Lisp_Object str; 6071 Lisp_Object str;
6055 { 6074 {
6056 int count = SPECPDL_INDEX (); 6075 int count = SPECPDL_INDEX ();
6057 struct gcpro gcpro1, gcpro2; 6076 struct gcpro gcpro1, gcpro2;
6058 int multibyte = STRING_MULTIBYTE (str); 6077 int multibyte = STRING_MULTIBYTE (str);
6059 Lisp_Object old_deactivate_mark; 6078 Lisp_Object old_deactivate_mark;
6079 Lisp_Object buffer_to_kill;
6060 6080
6061 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 6081 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
6062 record_unwind_protect (code_convert_region_unwind,
6063 Vlast_coding_system_used);
6064 /* It is not crucial to specbind this. */ 6082 /* It is not crucial to specbind this. */
6065 old_deactivate_mark = Vdeactivate_mark; 6083 old_deactivate_mark = Vdeactivate_mark;
6066 GCPRO2 (str, old_deactivate_mark); 6084 GCPRO2 (str, old_deactivate_mark);
6067 6085
6068 /* We must insert the contents of STR as is without 6086 /* We must insert the contents of STR as is without
6069 unibyte<->multibyte conversion. For that, we adjust the 6087 unibyte<->multibyte conversion. For that, we adjust the
6070 multibyteness of the working buffer to that of STR. */ 6088 multibyteness of the working buffer to that of STR. */
6071 set_conversion_work_buffer (multibyte); 6089 buffer_to_kill = set_conversion_work_buffer (multibyte);
6090 record_unwind_protect (code_convert_region_unwind,
6091 Fcons (Vlast_coding_system_used, buffer_to_kill));
6072 6092
6073 insert_from_string (str, 0, 0, 6093 insert_from_string (str, 0, 0,
6074 SCHARS (str), SBYTES (str), 0); 6094 SCHARS (str), SBYTES (str), 0);
6075 UNGCPRO; 6095 UNGCPRO;
6076 inhibit_pre_post_conversion = 1; 6096 inhibit_pre_post_conversion = 1;
6109 { 6129 {
6110 struct gcpro gcpro1, gcpro2; 6130 struct gcpro gcpro1, gcpro2;
6111 struct buffer *cur = current_buffer; 6131 struct buffer *cur = current_buffer;
6112 Lisp_Object old_deactivate_mark, old_last_coding_system_used; 6132 Lisp_Object old_deactivate_mark, old_last_coding_system_used;
6113 Lisp_Object args[3]; 6133 Lisp_Object args[3];
6134 Lisp_Object buffer_to_kill;
6114 6135
6115 /* It is not crucial to specbind this. */ 6136 /* It is not crucial to specbind this. */
6116 old_deactivate_mark = Vdeactivate_mark; 6137 old_deactivate_mark = Vdeactivate_mark;
6117 old_last_coding_system_used = Vlast_coding_system_used; 6138 old_last_coding_system_used = Vlast_coding_system_used;
6118 GCPRO2 (old_deactivate_mark, old_last_coding_system_used); 6139 GCPRO2 (old_deactivate_mark, old_last_coding_system_used);
6119 6140
6120 /* We must insert the contents of STR as is without 6141 /* We must insert the contents of STR as is without
6121 unibyte<->multibyte conversion. For that, we adjust the 6142 unibyte<->multibyte conversion. For that, we adjust the
6122 multibyteness of the working buffer to that of STR. */ 6143 multibyteness of the working buffer to that of STR. */
6123 set_conversion_work_buffer (coding->src_multibyte); 6144 buffer_to_kill = set_conversion_work_buffer (coding->src_multibyte);
6124 insert_1_both (*str, nchars, nbytes, 0, 0, 0); 6145 insert_1_both (*str, nchars, nbytes, 0, 0, 0);
6125 UNGCPRO; 6146 UNGCPRO;
6126 inhibit_pre_post_conversion = 1; 6147 inhibit_pre_post_conversion = 1;
6127 args[0] = coding->pre_write_conversion; 6148 args[0] = coding->pre_write_conversion;
6128 args[1] = make_number (BEG); 6149 args[1] = make_number (BEG);
6142 move_gap (BEG); 6163 move_gap (BEG);
6143 bcopy (BEG_ADDR, *str, coding->produced); 6164 bcopy (BEG_ADDR, *str, coding->produced);
6144 coding->src_multibyte 6165 coding->src_multibyte
6145 = ! NILP (current_buffer->enable_multibyte_characters); 6166 = ! NILP (current_buffer->enable_multibyte_characters);
6146 set_buffer_internal (cur); 6167 set_buffer_internal (cur);
6168 if (! NILP (buffer_to_kill))
6169 Fkill_buffer (buffer_to_kill);
6147 } 6170 }
6148 6171
6149 6172
6150 Lisp_Object 6173 Lisp_Object
6151 decode_coding_string (str, coding, nocopy) 6174 decode_coding_string (str, coding, nocopy)