comparison src/coding.c @ 90061:48210be97b12

Cancel the change done in HEAD on 2004-11-30. (coding_charset_list): New function.
author Kenichi Handa <handa@m17n.org>
date Sat, 11 Dec 2004 02:12:49 +0000
parents f2ebccfa87d4
children 95879cc1ed20
comparison
equal deleted inserted replaced
90060:637c6bc8a26f 90061:48210be97b12
5083 } 5083 }
5084 5084
5085 return; 5085 return;
5086 } 5086 }
5087 5087
5088 /* Return a list of charsets supported by CODING. */
5089
5090 Lisp_Object
5091 coding_charset_list (coding)
5092 struct coding_system *coding;
5093 {
5094 Lisp_Object attrs, charset_list, coding_type;
5095
5096 CODING_GET_INFO (coding, attrs, charset_list);
5097 if (EQ (CODING_ATTR_TYPE (attrs), Qiso_2022))
5098 {
5099 int flags = XINT (AREF (attrs, coding_attr_iso_flags));
5100
5101 if (flags & CODING_ISO_FLAG_FULL_SUPPORT)
5102 charset_list = Viso_2022_charset_list;
5103 }
5104 else if (EQ (CODING_ATTR_TYPE (attrs), Qemacs_mule))
5105 {
5106 charset_list = Vemacs_mule_charset_list;
5107 }
5108 return charset_list;
5109 }
5110
5111
5088 /* Return raw-text or one of its subsidiaries that has the same 5112 /* Return raw-text or one of its subsidiaries that has the same
5089 eol_type as CODING-SYSTEM. */ 5113 eol_type as CODING-SYSTEM. */
5090 5114
5091 Lisp_Object 5115 Lisp_Object
5092 raw_text_coding_system (coding_system) 5116 raw_text_coding_system (coding_system)
6576 } 6600 }
6577 set_buffer_internal (XBUFFER (current)); 6601 set_buffer_internal (XBUFFER (current));
6578 return Qnil; 6602 return Qnil;
6579 } 6603 }
6580 6604
6581 /* Name (or base name) of work buffer for code conversion. */
6582 static Lisp_Object Vcode_conversion_workbuf_name;
6583
6584 /* Set the current buffer to the working buffer prepared for
6585 code-conversion. MULTIBYTE specifies the multibyteness of the
6586 buffer. */
6587
6588 static struct buffer *
6589 set_conversion_work_buffer (multibyte)
6590 int multibyte;
6591 {
6592 Lisp_Object buffer;
6593 struct buffer *buf;
6594
6595 buffer = Fget_buffer_create (Vcode_conversion_workbuf_name);
6596 buf = XBUFFER (buffer);
6597 delete_all_overlays (buf);
6598 buf->directory = current_buffer->directory;
6599 buf->read_only = Qnil;
6600 buf->filename = Qnil;
6601 buf->undo_list = Qt;
6602 eassert (buf->overlays_before == NULL);
6603 eassert (buf->overlays_after == NULL);
6604 set_buffer_internal (buf);
6605 if (BEG != BEGV || Z != ZV)
6606 Fwiden ();
6607 del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0);
6608 buf->enable_multibyte_characters = multibyte ? Qt : Qnil;
6609 return buf;
6610 }
6611
6612 Lisp_Object 6605 Lisp_Object
6613 code_conversion_save (with_work_buf, multibyte) 6606 code_conversion_save (with_work_buf, multibyte)
6614 int with_work_buf, multibyte; 6607 int with_work_buf, multibyte;
6615 { 6608 {
6616 Lisp_Object workbuf = Qnil; 6609 Lisp_Object workbuf = Qnil;
7021 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes), 7014 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes),
7022 saved_pt_byte + (coding->produced - bytes)); 7015 saved_pt_byte + (coding->produced - bytes));
7023 } 7016 }
7024 7017
7025 unbind_to (count, Qnil); 7018 unbind_to (count, Qnil);
7026 }
7027
7028
7029
7030 /* Run pre-write-conversion function of CODING on NCHARS/NBYTES
7031 text in *STR. *SIZE is the allocated bytes for STR. As it
7032 is intended that this function is called from encode_terminal_code,
7033 the pre-write-conversion function is run by safe_call and thus
7034 "Error during redisplay: ..." is logged when an error occurs.
7035
7036 Store the resulting text in *STR and set CODING->produced_char and
7037 CODING->produced to the number of characters and bytes
7038 respectively. If the size of *STR is too small, enlarge it by
7039 xrealloc and update *STR and *SIZE. */
7040
7041 void
7042 run_pre_write_conversin_on_c_str (str, size, nchars, nbytes, coding)
7043 unsigned char **str;
7044 int *size, nchars, nbytes;
7045 struct coding_system *coding;
7046 {
7047 struct gcpro gcpro1, gcpro2;
7048 struct buffer *cur = current_buffer;
7049 Lisp_Object old_deactivate_mark, old_last_coding_system_used;
7050 Lisp_Object args[3];
7051
7052 /* It is not crucial to specbind this. */
7053 old_deactivate_mark = Vdeactivate_mark;
7054 old_last_coding_system_used = Vlast_coding_system_used;
7055 GCPRO2 (old_deactivate_mark, old_last_coding_system_used);
7056
7057 /* We must insert the contents of STR as is without
7058 unibyte<->multibyte conversion. For that, we adjust the
7059 multibyteness of the working buffer to that of STR. */
7060 set_conversion_work_buffer (coding->src_multibyte);
7061 insert_1_both (*str, nchars, nbytes, 0, 0, 0);
7062 UNGCPRO;
7063 inhibit_pre_post_conversion = 1;
7064 args[0] = coding->pre_write_conversion;
7065 args[1] = make_number (BEG);
7066 args[2] = make_number (Z);
7067 safe_call (3, args);
7068 inhibit_pre_post_conversion = 0;
7069 Vdeactivate_mark = old_deactivate_mark;
7070 Vlast_coding_system_used = old_last_coding_system_used;
7071 coding->produced_char = Z - BEG;
7072 coding->produced = Z_BYTE - BEG_BYTE;
7073 if (coding->produced > *size)
7074 {
7075 *size = coding->produced;
7076 *str = xrealloc (*str, *size);
7077 }
7078 if (BEG < GPT && GPT < Z)
7079 move_gap (BEG);
7080 bcopy (BEG_ADDR, *str, coding->produced);
7081 coding->src_multibyte
7082 = ! NILP (current_buffer->enable_multibyte_characters);
7083 set_buffer_internal (cur);
7084 } 7019 }
7085 7020
7086 7021
7087 Lisp_Object 7022 Lisp_Object
7088 preferred_coding_system () 7023 preferred_coding_system ()