Commit 69a80ea3 authored by Kenichi Handa's avatar Kenichi Handa

(MAX_ANNOTATION_LENGTH): Adjusted for the change of

annotation data format.
(ADD_ANNOTATION_DATA, ADD_COMPOSITION_DATA, ADD_CHARSET_DATA):
Change arguments FROM and TO to single argument NCHARS.  Caller
changed.
(decode_coding_utf_8): Pay attention to coding->charbuf_used.
(decode_coding_utf_16, decode_coding_emacs_mule)
(decode_coding_iso_2022, decode_coding_sjis, decode_coding_big5)
(decode_coding_ccl, decode_coding_charset): Likewise.
(get_translation): New function.
(produce_chars): New arguments translation_table and last_block.
Translate characters here.  Return number of carryover chars.
Caller changed.
(produce_composition): New argument pos.  Caller changed.
Adjusted for the change of annotation data format.
(produce_charset, produce_annotation): Likewise.
(decode_coding): Don't call translate_chars.
parent 6e76ae91
...@@ -212,8 +212,8 @@ decode_coding_XXXX (coding) ...@@ -212,8 +212,8 @@ decode_coding_XXXX (coding)
when there's no room in CHARBUF for a decoded character. */ when there's no room in CHARBUF for a decoded character. */
unsigned char *src_base; unsigned char *src_base;
/* A buffer to produce decoded characters. */ /* A buffer to produce decoded characters. */
int *charbuf = coding->charbuf; int *charbuf = coding->charbuf + coding->charbuf_used;
int *charbuf_end = charbuf + coding->charbuf_size; int *charbuf_end = coding->charbuf + coding->charbuf_size;
int multibytep = coding->src_multibyte; int multibytep = coding->src_multibyte;
while (1) while (1)
...@@ -1025,15 +1025,14 @@ alloc_destination (coding, nbytes, dst) ...@@ -1025,15 +1025,14 @@ alloc_destination (coding, nbytes, dst)
/* Maximum length of annotation data (sum of annotations for /* Maximum length of annotation data (sum of annotations for
composition and charset). */ composition and charset). */
#define MAX_ANNOTATION_LENGTH (5 + (MAX_COMPOSITION_COMPONENTS * 2) - 1 + 5) #define MAX_ANNOTATION_LENGTH (4 + (MAX_COMPOSITION_COMPONENTS * 2) - 1 + 4)
/* An annotation data is stored in the array coding->charbuf in this /* An annotation data is stored in the array coding->charbuf in this
format: format:
[ -LENGTH ANNOTATION_MASK FROM TO ... ] [ -LENGTH ANNOTATION_MASK NCHARS ... ]
LENGTH is the number of elements in the annotation. LENGTH is the number of elements in the annotation.
ANNOTATION_MASK is one of CODING_ANNOTATE_XXX_MASK. ANNOTATION_MASK is one of CODING_ANNOTATE_XXX_MASK.
FROM and TO specify the range of text annotated. They are relative NCHARS is the number of characters in the text annotated.
to coding->src_pos (on encoding) or coding->dst_pos (on decoding).
The format of the following elements depend on ANNOTATION_MASK. The format of the following elements depend on ANNOTATION_MASK.
...@@ -1047,26 +1046,25 @@ alloc_destination (coding, nbytes, dst) ...@@ -1047,26 +1046,25 @@ alloc_destination (coding, nbytes, dst)
In the case of CODING_ANNOTATE_CHARSET_MASK, one element CHARSET-ID In the case of CODING_ANNOTATE_CHARSET_MASK, one element CHARSET-ID
follows. */ follows. */
#define ADD_ANNOTATION_DATA(buf, len, mask, from, to) \ #define ADD_ANNOTATION_DATA(buf, len, mask, nchars) \
do { \ do { \
*(buf)++ = -(len); \ *(buf)++ = -(len); \
*(buf)++ = (mask); \ *(buf)++ = (mask); \
*(buf)++ = (from); \ *(buf)++ = (nchars); \
*(buf)++ = (to); \
coding->annotated = 1; \ coding->annotated = 1; \
} while (0); } while (0);
#define ADD_COMPOSITION_DATA(buf, from, to, method) \ #define ADD_COMPOSITION_DATA(buf, nchars, method) \
do { \ do { \
ADD_ANNOTATION_DATA (buf, 5, CODING_ANNOTATE_COMPOSITION_MASK, from, to); \ ADD_ANNOTATION_DATA (buf, 4, CODING_ANNOTATE_COMPOSITION_MASK, nchars); \
*buf++ = method; \ *buf++ = method; \
} while (0) } while (0)
#define ADD_CHARSET_DATA(buf, from, to, id) \ #define ADD_CHARSET_DATA(buf, nchars, id) \
do { \ do { \
ADD_ANNOTATION_DATA (buf, 5, CODING_ANNOTATE_CHARSET_MASK, from, to); \ ADD_ANNOTATION_DATA (buf, 4, CODING_ANNOTATE_CHARSET_MASK, nchars); \
*buf++ = id; \ *buf++ = id; \
} while (0) } while (0)
...@@ -1166,8 +1164,8 @@ decode_coding_utf_8 (coding) ...@@ -1166,8 +1164,8 @@ decode_coding_utf_8 (coding)
const unsigned char *src = coding->source + coding->consumed; const unsigned char *src = coding->source + coding->consumed;
const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_end = coding->source + coding->src_bytes;
const unsigned char *src_base; const unsigned char *src_base;
int *charbuf = coding->charbuf; int *charbuf = coding->charbuf + coding->charbuf_used;
int *charbuf_end = charbuf + coding->charbuf_size; int *charbuf_end = coding->charbuf + coding->charbuf_size;
int consumed_chars = 0, consumed_chars_base; int consumed_chars = 0, consumed_chars_base;
int multibytep = coding->src_multibyte; int multibytep = coding->src_multibyte;
Lisp_Object attr, charset_list; Lisp_Object attr, charset_list;
...@@ -1413,8 +1411,8 @@ decode_coding_utf_16 (coding) ...@@ -1413,8 +1411,8 @@ decode_coding_utf_16 (coding)
const unsigned char *src = coding->source + coding->consumed; const unsigned char *src = coding->source + coding->consumed;
const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_end = coding->source + coding->src_bytes;
const unsigned char *src_base; const unsigned char *src_base;
int *charbuf = coding->charbuf; int *charbuf = coding->charbuf + coding->charbuf_used;
int *charbuf_end = charbuf + coding->charbuf_size; int *charbuf_end = coding->charbuf + coding->charbuf_size;
int consumed_chars = 0, consumed_chars_base; int consumed_chars = 0, consumed_chars_base;
int multibytep = coding->src_multibyte; int multibytep = coding->src_multibyte;
enum utf_16_bom_type bom = CODING_UTF_16_BOM (coding); enum utf_16_bom_type bom = CODING_UTF_16_BOM (coding);
...@@ -1921,7 +1919,6 @@ detect_coding_emacs_mule (coding, detect_info) ...@@ -1921,7 +1919,6 @@ detect_coding_emacs_mule (coding, detect_info)
number of characters composed by this composition. */ \ number of characters composed by this composition. */ \
enum composition_method method = c - 0xF2; \ enum composition_method method = c - 0xF2; \
int *charbuf_base = charbuf; \ int *charbuf_base = charbuf; \
int from, to; \
int consumed_chars_limit; \ int consumed_chars_limit; \
int nbytes, nchars; \ int nbytes, nchars; \
\ \
...@@ -1935,9 +1932,7 @@ detect_coding_emacs_mule (coding, detect_info) ...@@ -1935,9 +1932,7 @@ detect_coding_emacs_mule (coding, detect_info)
if (c < 0) \ if (c < 0) \
goto invalid_code; \ goto invalid_code; \
nchars = c - 0xA0; \ nchars = c - 0xA0; \
from = coding->produced + char_offset; \ ADD_COMPOSITION_DATA (charbuf, nchars, method); \
to = from + nchars; \
ADD_COMPOSITION_DATA (charbuf, from, to, method); \
consumed_chars_limit = consumed_chars_base + nbytes; \ consumed_chars_limit = consumed_chars_base + nbytes; \
if (method != COMPOSITION_RELATIVE) \ if (method != COMPOSITION_RELATIVE) \
{ \ { \
...@@ -1965,7 +1960,6 @@ detect_coding_emacs_mule (coding, detect_info) ...@@ -1965,7 +1960,6 @@ detect_coding_emacs_mule (coding, detect_info)
int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \ int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \
int *buf = components; \ int *buf = components; \
int i, j; \ int i, j; \
int from, to; \
\ \
src = src_base; \ src = src_base; \
ONE_MORE_BYTE (c); /* skip 0x80 */ \ ONE_MORE_BYTE (c); /* skip 0x80 */ \
...@@ -1973,9 +1967,7 @@ detect_coding_emacs_mule (coding, detect_info) ...@@ -1973,9 +1967,7 @@ detect_coding_emacs_mule (coding, detect_info)
DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \
if (i < 2) \ if (i < 2) \
goto invalid_code; \ goto invalid_code; \
from = coding->produced_char + char_offset; \ ADD_COMPOSITION_DATA (charbuf, i, method); \
to = from + i; \
ADD_COMPOSITION_DATA (charbuf, from, to, method); \
for (j = 0; j < i; j++) \ for (j = 0; j < i; j++) \
*charbuf++ = components[j]; \ *charbuf++ = components[j]; \
} while (0) } while (0)
...@@ -1989,7 +1981,6 @@ detect_coding_emacs_mule (coding, detect_info) ...@@ -1989,7 +1981,6 @@ detect_coding_emacs_mule (coding, detect_info)
int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \ int components[MAX_COMPOSITION_COMPONENTS * 2 - 1]; \
int *buf = components; \ int *buf = components; \
int i, j; \ int i, j; \
int from, to; \
\ \
DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \ DECODE_EMACS_MULE_COMPOSITION_CHAR (buf); \
for (i = 0; i < MAX_COMPOSITION_COMPONENTS; i++) \ for (i = 0; i < MAX_COMPOSITION_COMPONENTS; i++) \
...@@ -2001,9 +1992,7 @@ detect_coding_emacs_mule (coding, detect_info) ...@@ -2001,9 +1992,7 @@ detect_coding_emacs_mule (coding, detect_info)
goto invalid_code; \ goto invalid_code; \
if (charbuf + i + (i / 2) + 1 < charbuf_end) \ if (charbuf + i + (i / 2) + 1 < charbuf_end) \
goto no_more_source; \ goto no_more_source; \
from = coding->produced_char + char_offset; \ ADD_COMPOSITION_DATA (buf, i, method); \
to = from + i; \
ADD_COMPOSITION_DATA (buf, from, to, method); \
for (j = 0; j < i; j++) \ for (j = 0; j < i; j++) \
*charbuf++ = components[j]; \ *charbuf++ = components[j]; \
for (j = 0; j < i; j += 2) \ for (j = 0; j < i; j += 2) \
...@@ -2018,8 +2007,9 @@ decode_coding_emacs_mule (coding) ...@@ -2018,8 +2007,9 @@ decode_coding_emacs_mule (coding)
const unsigned char *src = coding->source + coding->consumed; const unsigned char *src = coding->source + coding->consumed;
const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_end = coding->source + coding->src_bytes;
const unsigned char *src_base; const unsigned char *src_base;
int *charbuf = coding->charbuf; int *charbuf = coding->charbuf + coding->charbuf_used;
int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; int *charbuf_end
= coding->charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH;
int consumed_chars = 0, consumed_chars_base; int consumed_chars = 0, consumed_chars_base;
int multibytep = coding->src_multibyte; int multibytep = coding->src_multibyte;
Lisp_Object attrs, charset_list; Lisp_Object attrs, charset_list;
...@@ -2082,7 +2072,7 @@ decode_coding_emacs_mule (coding) ...@@ -2082,7 +2072,7 @@ decode_coding_emacs_mule (coding)
if (last_id != id) if (last_id != id)
{ {
if (last_id != charset_ascii) if (last_id != charset_ascii)
ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id);
last_id = id; last_id = id;
last_offset = char_offset; last_offset = char_offset;
} }
...@@ -2104,7 +2094,7 @@ decode_coding_emacs_mule (coding) ...@@ -2104,7 +2094,7 @@ decode_coding_emacs_mule (coding)
no_more_source: no_more_source:
if (last_id != charset_ascii) if (last_id != charset_ascii)
ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id);
coding->consumed_char += consumed_chars_base; coding->consumed_char += consumed_chars_base;
coding->consumed = src_base - coding->source; coding->consumed = src_base - coding->source;
coding->charbuf_used = charbuf - coding->charbuf; coding->charbuf_used = charbuf - coding->charbuf;
...@@ -2810,10 +2800,8 @@ detect_coding_iso_2022 (coding, detect_info) ...@@ -2810,10 +2800,8 @@ detect_coding_iso_2022 (coding, detect_info)
: (component_idx + 1) / 2); \ : (component_idx + 1) / 2); \
int i; \ int i; \
int *saved_charbuf = charbuf; \ int *saved_charbuf = charbuf; \
int from = char_offset; \
int to = from + nchars; \
\ \
ADD_COMPOSITION_DATA (charbuf, from, to, method); \ ADD_COMPOSITION_DATA (charbuf, nchars, method); \
if (method != COMPOSITION_RELATIVE) \ if (method != COMPOSITION_RELATIVE) \
{ \ { \
if (component_len == 0) \ if (component_len == 0) \
...@@ -2869,9 +2857,9 @@ decode_coding_iso_2022 (coding) ...@@ -2869,9 +2857,9 @@ decode_coding_iso_2022 (coding)
const unsigned char *src = coding->source + coding->consumed; const unsigned char *src = coding->source + coding->consumed;
const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_end = coding->source + coding->src_bytes;
const unsigned char *src_base; const unsigned char *src_base;
int *charbuf = coding->charbuf; int *charbuf = coding->charbuf + coding->charbuf_used;
int *charbuf_end int *charbuf_end
= charbuf + coding->charbuf_size - 4 - MAX_ANNOTATION_LENGTH; = coding->charbuf + coding->charbuf_size - 4 - MAX_ANNOTATION_LENGTH;
int consumed_chars = 0, consumed_chars_base; int consumed_chars = 0, consumed_chars_base;
int multibytep = coding->src_multibyte; int multibytep = coding->src_multibyte;
/* Charsets invoked to graphic plane 0 and 1 respectively. */ /* Charsets invoked to graphic plane 0 and 1 respectively. */
...@@ -3224,7 +3212,7 @@ decode_coding_iso_2022 (coding) ...@@ -3224,7 +3212,7 @@ decode_coding_iso_2022 (coding)
&& last_id != charset->id) && last_id != charset->id)
{ {
if (last_id != charset_ascii) if (last_id != charset_ascii)
ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id);
last_id = charset->id; last_id = charset->id;
last_offset = char_offset; last_offset = char_offset;
} }
...@@ -3293,7 +3281,7 @@ decode_coding_iso_2022 (coding) ...@@ -3293,7 +3281,7 @@ decode_coding_iso_2022 (coding)
no_more_source: no_more_source:
if (last_id != charset_ascii) if (last_id != charset_ascii)
ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id);
coding->consumed_char += consumed_chars_base; coding->consumed_char += consumed_chars_base;
coding->consumed = src_base - coding->source; coding->consumed = src_base - coding->source;
coding->charbuf_used = charbuf - coding->charbuf; coding->charbuf_used = charbuf - coding->charbuf;
...@@ -3995,8 +3983,9 @@ decode_coding_sjis (coding) ...@@ -3995,8 +3983,9 @@ decode_coding_sjis (coding)
const unsigned char *src = coding->source + coding->consumed; const unsigned char *src = coding->source + coding->consumed;
const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_end = coding->source + coding->src_bytes;
const unsigned char *src_base; const unsigned char *src_base;
int *charbuf = coding->charbuf; int *charbuf = coding->charbuf + coding->charbuf_used;
int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; int *charbuf_end
= coding->charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH;
int consumed_chars = 0, consumed_chars_base; int consumed_chars = 0, consumed_chars_base;
int multibytep = coding->src_multibyte; int multibytep = coding->src_multibyte;
struct charset *charset_roman, *charset_kanji, *charset_kana; struct charset *charset_roman, *charset_kanji, *charset_kana;
...@@ -4064,7 +4053,7 @@ decode_coding_sjis (coding) ...@@ -4064,7 +4053,7 @@ decode_coding_sjis (coding)
&& last_id != charset->id) && last_id != charset->id)
{ {
if (last_id != charset_ascii) if (last_id != charset_ascii)
ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id);
last_id = charset->id; last_id = charset->id;
last_offset = char_offset; last_offset = char_offset;
} }
...@@ -4084,7 +4073,7 @@ decode_coding_sjis (coding) ...@@ -4084,7 +4073,7 @@ decode_coding_sjis (coding)
no_more_source: no_more_source:
if (last_id != charset_ascii) if (last_id != charset_ascii)
ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id);
coding->consumed_char += consumed_chars_base; coding->consumed_char += consumed_chars_base;
coding->consumed = src_base - coding->source; coding->consumed = src_base - coding->source;
coding->charbuf_used = charbuf - coding->charbuf; coding->charbuf_used = charbuf - coding->charbuf;
...@@ -4097,8 +4086,9 @@ decode_coding_big5 (coding) ...@@ -4097,8 +4086,9 @@ decode_coding_big5 (coding)
const unsigned char *src = coding->source + coding->consumed; const unsigned char *src = coding->source + coding->consumed;
const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_end = coding->source + coding->src_bytes;
const unsigned char *src_base; const unsigned char *src_base;
int *charbuf = coding->charbuf; int *charbuf = coding->charbuf + coding->charbuf_used;
int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; int *charbuf_end
= coding->charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH;
int consumed_chars = 0, consumed_chars_base; int consumed_chars = 0, consumed_chars_base;
int multibytep = coding->src_multibyte; int multibytep = coding->src_multibyte;
struct charset *charset_roman, *charset_big5; struct charset *charset_roman, *charset_big5;
...@@ -4144,7 +4134,7 @@ decode_coding_big5 (coding) ...@@ -4144,7 +4134,7 @@ decode_coding_big5 (coding)
&& last_id != charset->id) && last_id != charset->id)
{ {
if (last_id != charset_ascii) if (last_id != charset_ascii)
ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id);
last_id = charset->id; last_id = charset->id;
last_offset = char_offset; last_offset = char_offset;
} }
...@@ -4164,7 +4154,7 @@ decode_coding_big5 (coding) ...@@ -4164,7 +4154,7 @@ decode_coding_big5 (coding)
no_more_source: no_more_source:
if (last_id != charset_ascii) if (last_id != charset_ascii)
ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id);
coding->consumed_char += consumed_chars_base; coding->consumed_char += consumed_chars_base;
coding->consumed = src_base - coding->source; coding->consumed = src_base - coding->source;
coding->charbuf_used = charbuf - coding->charbuf; coding->charbuf_used = charbuf - coding->charbuf;
...@@ -4396,8 +4386,8 @@ decode_coding_ccl (coding) ...@@ -4396,8 +4386,8 @@ decode_coding_ccl (coding)
{ {
const unsigned char *src = coding->source + coding->consumed; const unsigned char *src = coding->source + coding->consumed;
const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_end = coding->source + coding->src_bytes;
int *charbuf = coding->charbuf; int *charbuf = coding->charbuf + coding->charbuf_used;
int *charbuf_end = charbuf + coding->charbuf_size; int *charbuf_end = coding->charbuf + coding->charbuf_size;
int consumed_chars = 0; int consumed_chars = 0;
int multibytep = coding->src_multibyte; int multibytep = coding->src_multibyte;
struct ccl_program ccl; struct ccl_program ccl;
...@@ -4683,8 +4673,9 @@ decode_coding_charset (coding) ...@@ -4683,8 +4673,9 @@ decode_coding_charset (coding)
const unsigned char *src = coding->source + coding->consumed; const unsigned char *src = coding->source + coding->consumed;
const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_end = coding->source + coding->src_bytes;
const unsigned char *src_base; const unsigned char *src_base;
int *charbuf = coding->charbuf; int *charbuf = coding->charbuf + coding->charbuf_used;
int *charbuf_end = charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; int *charbuf_end
= coding->charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH;
int consumed_chars = 0, consumed_chars_base; int consumed_chars = 0, consumed_chars_base;
int multibytep = coding->src_multibyte; int multibytep = coding->src_multibyte;
Lisp_Object attrs, charset_list, valids; Lisp_Object attrs, charset_list, valids;
...@@ -4759,7 +4750,7 @@ decode_coding_charset (coding) ...@@ -4759,7 +4750,7 @@ decode_coding_charset (coding)
&& last_id != charset->id) && last_id != charset->id)
{ {
if (last_id != charset_ascii) if (last_id != charset_ascii)
ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id);
last_id = charset->id; last_id = charset->id;
last_offset = char_offset; last_offset = char_offset;
} }
...@@ -4779,7 +4770,7 @@ decode_coding_charset (coding) ...@@ -4779,7 +4770,7 @@ decode_coding_charset (coding)
no_more_source: no_more_source:
if (last_id != charset_ascii) if (last_id != charset_ascii)
ADD_CHARSET_DATA (charbuf, last_offset, char_offset, last_id); ADD_CHARSET_DATA (charbuf, char_offset - last_offset, last_id);
coding->consumed_char += consumed_chars_base; coding->consumed_char += consumed_chars_base;
coding->consumed = src_base - coding->source; coding->consumed = src_base - coding->source;
coding->charbuf_used = charbuf - coding->charbuf; coding->charbuf_used = charbuf - coding->charbuf;
...@@ -5573,53 +5564,108 @@ translate_chars (coding, table) ...@@ -5573,53 +5564,108 @@ translate_chars (coding, table)
} }
} }
static Lisp_Object
get_translation (val, buf, buf_end, last_block, from_nchars, to_nchars)
Lisp_Object val;
int *buf, *buf_end;
int last_block;
int *from_nchars, *to_nchars;
{
/* VAL is TO-CHAR, [TO-CHAR ...], ([FROM-CHAR ...] . TO-CHAR), or
([FROM-CHAR ...] . [TO-CHAR ...]). */
if (CONSP (val))
{
Lisp_Object from;
int i, len;
from = XCAR (val);
val = XCDR (val);
len = ASIZE (from);
for (i = 0; i < len; i++)
{
if (buf + i == buf_end)
return (last_block ? Qnil : Qt);
if (XINT (AREF (from, i)) != buf[i])
return Qnil;
}
*from_nchars = len;
}
if (VECTORP (val))
*buf = XINT (AREF (val, 0)), *to_nchars = ASIZE (val);
else
*buf = XINT (val);
return val;
}
static int static int
produce_chars (coding) produce_chars (coding, translation_table, last_block)
struct coding_system *coding; struct coding_system *coding;
Lisp_Object translation_table;
int last_block;
{ {
unsigned char *dst = coding->destination + coding->produced; unsigned char *dst = coding->destination + coding->produced;
unsigned char *dst_end = coding->destination + coding->dst_bytes; unsigned char *dst_end = coding->destination + coding->dst_bytes;
int produced; int produced;
int produced_chars = 0; int produced_chars = 0;
int carryover = 0;
if (! coding->chars_at_source) if (! coding->chars_at_source)
{ {
/* Characters are in coding->charbuf. */ /* Characters are in coding->charbuf. */
int *buf = coding->charbuf; int *buf = coding->charbuf;
int *buf_end = buf + coding->charbuf_used; int *buf_end = buf + coding->charbuf_used;
unsigned char *adjusted_dst_end;
if (BUFFERP (coding->src_object) if (BUFFERP (coding->src_object)
&& EQ (coding->src_object, coding->dst_object)) && EQ (coding->src_object, coding->dst_object))
dst_end = ((unsigned char *) coding->source) + coding->consumed; dst_end = ((unsigned char *) coding->source) + coding->consumed;
adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH;
while (buf < buf_end) while (buf < buf_end)
{ {
int c = *buf++; int c = *buf, i;
if (dst >= adjusted_dst_end)
{
dst = alloc_destination (coding,
buf_end - buf + MAX_MULTIBYTE_LENGTH,
dst);
dst_end = coding->destination + coding->dst_bytes;
adjusted_dst_end = dst_end - MAX_MULTIBYTE_LENGTH;
}
if (c >= 0) if (c >= 0)
{ {
if (coding->dst_multibyte int from_nchars = 1, to_nchars = 1;
|| ! CHAR_BYTE8_P (c)) Lisp_Object trans = Qnil;
CHAR_STRING_ADVANCE (c, dst);
else if (! NILP (translation_table)
*dst++ = CHAR_TO_BYTE8 (c); && ! NILP (trans = CHAR_TABLE_REF (translation_table, c)))
produced_chars++; {
trans = get_translation (trans, buf, buf_end, last_block,
&from_nchars, &to_nchars);
if (EQ (trans, Qt))
break;
c = *buf;
}
if (dst + MAX_MULTIBYTE_LENGTH * to_nchars > dst_end)
{
dst = alloc_destination (coding,
buf_end - buf
+ MAX_MULTIBYTE_LENGTH * to_nchars,
dst);
dst_end = coding->destination + coding->dst_bytes;
}
for (i = 0; i < to_nchars; i++, c = XINT (AREF (trans, i)))
{
if (coding->dst_multibyte
|| ! CHAR_BYTE8_P (c))
CHAR_STRING_ADVANCE (c, dst);
else
*dst++ = CHAR_TO_BYTE8 (c);
}
produced_chars += to_nchars;
*buf++ = to_nchars;
while (--from_nchars > 0)
*buf++ = 0;
} }
else else
/* This is an annotation datum. (-C) is the length of /* This is an annotation datum. (-C) is the length. */
it. */ buf += -c;
buf += -c - 1;
} }
carryover = buf_end - buf;
} }
else else
{ {
...@@ -5761,7 +5807,7 @@ produce_chars (coding) ...@@ -5761,7 +5807,7 @@ produce_chars (coding)
insert_from_gap (produced_chars, produced); insert_from_gap (produced_chars, produced);
coding->produced += produced; coding->produced += produced;
coding->produced_char += produced_chars; coding->produced_char += produced_chars;
return produced_chars; return carryover;
} }
/* Compose text in CODING->object according to the annotation data at /* Compose text in CODING->object according to the annotation data at
...@@ -5770,19 +5816,19 @@ produce_chars (coding) ...@@ -5770,19 +5816,19 @@ produce_chars (coding)
*/ */
static INLINE void static INLINE void
produce_composition (coding, charbuf) produce_composition (coding, charbuf, pos)
struct coding_system *coding; struct coding_system *coding;
int *charbuf; int *charbuf;
EMACS_INT pos;
{ {
int len; int len;
EMACS_INT from, to; EMACS_INT to;
enum composition_method method; enum composition_method method;
Lisp_Object components; Lisp_Object components;
len = -charbuf[0]; len = -charbuf[0];
from = coding->dst_pos + charbuf[2]; to = pos + charbuf[2];
to = coding->dst_pos + charbuf[3]; method = (enum composition_method) (charbuf[3]);
method = (enum composition_method) (charbuf[4]);
if (method == COMPOSITION_RELATIVE) if (method == COMPOSITION_RELATIVE)
components = Qnil; components = Qnil;
...@@ -5791,32 +5837,32 @@ produce_composition (coding, charbuf) ...@@ -5791,32 +5837,32 @@ produce_composition (coding, charbuf)
Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1]; Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1];
int i; int i;
len -= 5; len -= 4;
charbuf += 5; charbuf += 4;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
args[i] = make_number (charbuf[i]); args[i] = make_number (charbuf[i]);
components = (method == COMPOSITION_WITH_ALTCHARS components = (method == COMPOSITION_WITH_ALTCHARS
? Fstring (len, args) : Fvector (len, args)); ? Fstring (len, args) : Fvector (len, args));
} }
compose_text (from, to, components, Qnil, coding->dst_object); compose_text (pos, to, components, Qnil, coding->dst_object);
} }
/* Put `charset' property on text in CODING->object according to /* Put `charset' property on text in CODING->object according to
the annotation data at CHARBUF. CHARBUF is an array: the annotation data at CHARBUF. CHARBUF is an array:
[ -LENGTH ANNOTATION_MASK FROM TO CHARSET-ID ] [ -LENGTH ANNOTATION_MASK NCHARS CHARSET-ID ]
*/ */
static INLINE void static INLINE void
produce_charset (coding, charbuf) produce_charset (coding, charbuf, pos)
struct coding_system *coding; struct coding_system *coding;
int *charbuf; int *charbuf;
EMACS_INT pos;
{ {
EMACS_INT from = coding->dst_pos + charbuf[2]; EMACS_INT from = pos - charbuf[2];
EMACS_INT to = coding->dst_pos + charbuf[3]; struct charset *charset = CHARSET_FROM_ID (charbuf[3]);
struct charset *charset = CHARSET_FROM_ID (charbuf[4]);
Fput_text_property (make_number (from), make_number (to), Fput_text_property (make_number (from), make_number (pos),
Qcharset, CHARSET_NAME (charset),