comparison src/coding.c @ 83231:549734260e34

Merged in changes from CVS trunk. Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-714 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-271
author Karoly Lorentey <lorentey@elte.hu>
date Wed, 08 Dec 2004 22:20:27 +0000
parents f70dc61a797f ff8a37b5299b
children 223c12363c0c
comparison
equal deleted inserted replaced
83230:d8738586aaec 83231:549734260e34
6002 } 6002 }
6003 6003
6004 return 0; 6004 return 0;
6005 } 6005 }
6006 6006
6007 Lisp_Object 6007 /* Name (or base name) of work buffer for code conversion. */
6008 run_pre_post_conversion_on_str (str, coding, encodep) 6008 static Lisp_Object Vcode_conversion_workbuf_name;
6009 Lisp_Object str; 6009
6010 struct coding_system *coding; 6010 /* Set the current buffer to the working buffer prepared for
6011 int encodep; 6011 code-conversion. MULTIBYTE specifies the multibyteness of the
6012 { 6012 buffer. */
6013 int count = SPECPDL_INDEX (); 6013
6014 struct gcpro gcpro1, gcpro2; 6014 static struct buffer *
6015 int multibyte = STRING_MULTIBYTE (str); 6015 set_conversion_work_buffer (multibyte)
6016 int multibyte;
6017 {
6016 Lisp_Object buffer; 6018 Lisp_Object buffer;
6017 struct buffer *buf; 6019 struct buffer *buf;
6018 Lisp_Object old_deactivate_mark; 6020
6019 6021 buffer = Fget_buffer_create (Vcode_conversion_workbuf_name);
6020 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
6021 record_unwind_protect (code_convert_region_unwind,
6022 Vlast_coding_system_used);
6023 /* It is not crucial to specbind this. */
6024 old_deactivate_mark = Vdeactivate_mark;
6025 GCPRO2 (str, old_deactivate_mark);
6026
6027 buffer = Fget_buffer_create (build_string (" *code-converting-work*"));
6028 buf = XBUFFER (buffer); 6022 buf = XBUFFER (buffer);
6029
6030 delete_all_overlays (buf); 6023 delete_all_overlays (buf);
6031 buf->directory = current_buffer->directory; 6024 buf->directory = current_buffer->directory;
6032 buf->read_only = Qnil; 6025 buf->read_only = Qnil;
6033 buf->filename = Qnil; 6026 buf->filename = Qnil;
6034 buf->undo_list = Qt; 6027 buf->undo_list = Qt;
6035 eassert (buf->overlays_before == NULL); 6028 eassert (buf->overlays_before == NULL);
6036 eassert (buf->overlays_after == NULL); 6029 eassert (buf->overlays_after == NULL);
6037
6038 set_buffer_internal (buf); 6030 set_buffer_internal (buf);
6031 if (BEG != BEGV || Z != ZV)
6032 Fwiden ();
6033 del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0);
6034 buf->enable_multibyte_characters = multibyte ? Qt : Qnil;
6035 return buf;
6036 }
6037
6038 Lisp_Object
6039 run_pre_post_conversion_on_str (str, coding, encodep)
6040 Lisp_Object str;
6041 struct coding_system *coding;
6042 int encodep;
6043 {
6044 int count = SPECPDL_INDEX ();
6045 struct gcpro gcpro1, gcpro2;
6046 int multibyte = STRING_MULTIBYTE (str);
6047 struct buffer *buf;
6048 Lisp_Object old_deactivate_mark;
6049
6050 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
6051 record_unwind_protect (code_convert_region_unwind,
6052 Vlast_coding_system_used);
6053 /* It is not crucial to specbind this. */
6054 old_deactivate_mark = Vdeactivate_mark;
6055 GCPRO2 (str, old_deactivate_mark);
6056
6039 /* We must insert the contents of STR as is without 6057 /* We must insert the contents of STR as is without
6040 unibyte<->multibyte conversion. For that, we adjust the 6058 unibyte<->multibyte conversion. For that, we adjust the
6041 multibyteness of the working buffer to that of STR. */ 6059 multibyteness of the working buffer to that of STR. */
6042 Ferase_buffer (); 6060 set_conversion_work_buffer (multibyte);
6043 buf->enable_multibyte_characters = multibyte ? Qt : Qnil;
6044 6061
6045 insert_from_string (str, 0, 0, 6062 insert_from_string (str, 0, 0,
6046 SCHARS (str), SBYTES (str), 0); 6063 SCHARS (str), SBYTES (str), 0);
6047 UNGCPRO; 6064 UNGCPRO;
6048 inhibit_pre_post_conversion = 1; 6065 inhibit_pre_post_conversion = 1;
6058 inhibit_pre_post_conversion = 0; 6075 inhibit_pre_post_conversion = 0;
6059 Vdeactivate_mark = old_deactivate_mark; 6076 Vdeactivate_mark = old_deactivate_mark;
6060 str = make_buffer_string (BEG, Z, 1); 6077 str = make_buffer_string (BEG, Z, 1);
6061 return unbind_to (count, str); 6078 return unbind_to (count, str);
6062 } 6079 }
6080
6081
6082 /* Run pre-write-conversion function of CODING on NCHARS/NBYTES
6083 text in *STR. *SIZE is the allocated bytes for STR. As it
6084 is intended that this function is called from encode_terminal_code,
6085 the pre-write-conversion function is run by safe_call and thus
6086 "Error during redisplay: ..." is logged when an error occurs.
6087
6088 Store the resulting text in *STR and set CODING->produced_char and
6089 CODING->produced to the number of characters and bytes
6090 respectively. If the size of *STR is too small, enlarge it by
6091 xrealloc and update *STR and *SIZE. */
6092
6093 void
6094 run_pre_write_conversin_on_c_str (str, size, nchars, nbytes, coding)
6095 unsigned char **str;
6096 int *size, nchars, nbytes;
6097 struct coding_system *coding;
6098 {
6099 struct gcpro gcpro1, gcpro2;
6100 struct buffer *cur = current_buffer;
6101 Lisp_Object old_deactivate_mark, old_last_coding_system_used;
6102 Lisp_Object args[3];
6103
6104 /* It is not crucial to specbind this. */
6105 old_deactivate_mark = Vdeactivate_mark;
6106 old_last_coding_system_used = Vlast_coding_system_used;
6107 GCPRO2 (old_deactivate_mark, old_last_coding_system_used);
6108
6109 /* We must insert the contents of STR as is without
6110 unibyte<->multibyte conversion. For that, we adjust the
6111 multibyteness of the working buffer to that of STR. */
6112 set_conversion_work_buffer (coding->src_multibyte);
6113 insert_1_both (*str, nchars, nbytes, 0, 0, 0);
6114 UNGCPRO;
6115 inhibit_pre_post_conversion = 1;
6116 args[0] = coding->pre_write_conversion;
6117 args[1] = make_number (BEG);
6118 args[2] = make_number (Z);
6119 safe_call (3, args);
6120 inhibit_pre_post_conversion = 0;
6121 Vdeactivate_mark = old_deactivate_mark;
6122 Vlast_coding_system_used = old_last_coding_system_used;
6123 coding->produced_char = Z - BEG;
6124 coding->produced = Z_BYTE - BEG_BYTE;
6125 if (coding->produced > *size)
6126 {
6127 *size = coding->produced;
6128 *str = xrealloc (*str, *size);
6129 }
6130 if (BEG < GPT && GPT < Z)
6131 move_gap (BEG);
6132 bcopy (BEG_ADDR, *str, coding->produced);
6133 coding->src_multibyte
6134 = ! NILP (current_buffer->enable_multibyte_characters);
6135 set_buffer_internal (cur);
6136 }
6137
6063 6138
6064 Lisp_Object 6139 Lisp_Object
6065 decode_coding_string (str, coding, nocopy) 6140 decode_coding_string (str, coding, nocopy)
6066 Lisp_Object str; 6141 Lisp_Object str;
6067 struct coding_system *coding; 6142 struct coding_system *coding;
7537 #ifdef emacs 7612 #ifdef emacs
7538 7613
7539 void 7614 void
7540 syms_of_coding () 7615 syms_of_coding ()
7541 { 7616 {
7617 staticpro (&Vcode_conversion_workbuf_name);
7618 Vcode_conversion_workbuf_name = build_string (" *code-conversion-work*");
7619
7542 Qtarget_idx = intern ("target-idx"); 7620 Qtarget_idx = intern ("target-idx");
7543 staticpro (&Qtarget_idx); 7621 staticpro (&Qtarget_idx);
7544 7622
7545 Qcoding_system_history = intern ("coding-system-history"); 7623 Qcoding_system_history = intern ("coding-system-history");
7546 staticpro (&Qcoding_system_history); 7624 staticpro (&Qcoding_system_history);