comparison src/coding.c @ 89856:18b52da60a76

(get_translation): Fix previous change. (encode_coding): Don't call translate_chars. (consume_chars): New arg translation_table. Caller changed. (translate_chars): Deleted. (syms_of_coding): Make translation-table's number of extra slots 2.
author Kenichi Handa <handa@m17n.org>
date Thu, 11 Mar 2004 02:18:12 +0000
parents b636ae1109c6
children 23cb9ed79225
comparison
equal deleted inserted replaced
89855:182d3c31dea9 89856:18b52da60a76
5540 } 5540 }
5541 return translation_table; 5541 return translation_table;
5542 } 5542 }
5543 5543
5544 5544
5545 static void
5546 translate_chars (coding, table)
5547 struct coding_system *coding;
5548 Lisp_Object table;
5549 {
5550 int *charbuf = coding->charbuf;
5551 int *charbuf_end = charbuf + coding->charbuf_used;
5552 int c;
5553
5554 if (coding->chars_at_source)
5555 return;
5556
5557 while (charbuf < charbuf_end)
5558 {
5559 c = *charbuf;
5560 if (c < 0)
5561 charbuf += -c;
5562 else
5563 *charbuf++ = translate_char (table, c);
5564 }
5565 }
5566
5567 static Lisp_Object 5545 static Lisp_Object
5568 get_translation (val, buf, buf_end, last_block, from_nchars, to_nchars) 5546 get_translation (val, buf, buf_end, last_block, from_nchars, to_nchars)
5569 Lisp_Object val; 5547 Lisp_Object val;
5570 int *buf, *buf_end; 5548 int *buf, *buf_end;
5571 int last_block; 5549 int last_block;
5572 int *from_nchars, *to_nchars; 5550 int *from_nchars, *to_nchars;
5573 { 5551 {
5574 /* VAL is TO-CHAR, [TO-CHAR ...], ([FROM-CHAR ...] . TO-CHAR), or 5552 /* VAL is TO or (([FROM-CHAR ...] . TO) ...) where TO is TO-CHAR or
5575 ([FROM-CHAR ...] . [TO-CHAR ...]). */ 5553 [TO-CHAR ...]. */
5576 if (CONSP (val)) 5554 if (CONSP (val))
5577 { 5555 {
5578 Lisp_Object from; 5556 Lisp_Object from, tail;
5579 int i, len; 5557 int i, len;
5580 5558
5581 from = XCAR (val); 5559 for (tail = val; CONSP (tail); tail = XCDR (tail))
5582 val = XCDR (val); 5560 {
5583 len = ASIZE (from); 5561 val = XCAR (tail);
5584 for (i = 0; i < len; i++) 5562 from = XCAR (val);
5585 { 5563 len = ASIZE (from);
5586 if (buf + i == buf_end) 5564 for (i = 0; i < len; i++)
5587 return (last_block ? Qnil : Qt); 5565 {
5588 if (XINT (AREF (from, i)) != buf[i]) 5566 if (buf + i == buf_end)
5589 return Qnil; 5567 {
5590 } 5568 if (! last_block)
5591 *from_nchars = len; 5569 return Qt;
5570 break;
5571 }
5572 if (XINT (AREF (from, i)) != buf[i])
5573 break;
5574 }
5575 if (i == len)
5576 {
5577 val = XCDR (val);
5578 *from_nchars = len;
5579 break;
5580 }
5581 }
5582 if (! CONSP (tail))
5583 return Qnil;
5592 } 5584 }
5593 if (VECTORP (val)) 5585 if (VECTORP (val))
5594 *buf = XINT (AREF (val, 0)), *to_nchars = ASIZE (val); 5586 *buf = XINT (AREF (val, 0)), *to_nchars = ASIZE (val);
5595 else 5587 else
5596 *buf = XINT (val); 5588 *buf = XINT (val);
5646 + MAX_MULTIBYTE_LENGTH * to_nchars, 5638 + MAX_MULTIBYTE_LENGTH * to_nchars,
5647 dst); 5639 dst);
5648 dst_end = coding->destination + coding->dst_bytes; 5640 dst_end = coding->destination + coding->dst_bytes;
5649 } 5641 }
5650 5642
5651 for (i = 0; i < to_nchars; i++, c = XINT (AREF (trans, i))) 5643 for (i = 0; i < to_nchars; i++)
5652 { 5644 {
5645 if (i > 0)
5646 c = XINT (AREF (trans, i));
5653 if (coding->dst_multibyte 5647 if (coding->dst_multibyte
5654 || ! CHAR_BYTE8_P (c)) 5648 || ! CHAR_BYTE8_P (c))
5655 CHAR_STRING_ADVANCE (c, dst); 5649 CHAR_STRING_ADVANCE (c, dst);
5656 else 5650 else
5657 *dst++ = CHAR_TO_BYTE8 (c); 5651 *dst++ = CHAR_TO_BYTE8 (c);
6180 return buf; 6174 return buf;
6181 } 6175 }
6182 6176
6183 6177
6184 static void 6178 static void
6185 consume_chars (coding) 6179 consume_chars (coding, translation_table)
6186 struct coding_system *coding; 6180 struct coding_system *coding;
6181 Lisp_Object translation_table;
6187 { 6182 {
6188 int *buf = coding->charbuf; 6183 int *buf = coding->charbuf;
6189 int *buf_end = coding->charbuf + coding->charbuf_size; 6184 int *buf_end = coding->charbuf + coding->charbuf_size;
6190 const unsigned char *src = coding->source + coding->consumed; 6185 const unsigned char *src = coding->source + coding->consumed;
6191 const unsigned char *src_end = coding->source + coding->src_bytes; 6186 const unsigned char *src_end = coding->source + coding->src_bytes;
6193 EMACS_INT end_pos = coding->src_pos + coding->src_chars; 6188 EMACS_INT end_pos = coding->src_pos + coding->src_chars;
6194 int multibytep = coding->src_multibyte; 6189 int multibytep = coding->src_multibyte;
6195 Lisp_Object eol_type; 6190 Lisp_Object eol_type;
6196 int c; 6191 int c;
6197 EMACS_INT stop, stop_composition, stop_charset; 6192 EMACS_INT stop, stop_composition, stop_charset;
6193 int max_lookup = 0, *lookup_buf = NULL;
6194
6195 if (! NILP (translation_table))
6196 {
6197 max_lookup = XINT (XCHAR_TABLE (translation_table)->extras[1]);
6198 lookup_buf = alloca (sizeof (int) * max_lookup);
6199 }
6198 6200
6199 eol_type = CODING_ID_EOL_TYPE (coding->id); 6201 eol_type = CODING_ID_EOL_TYPE (coding->id);
6200 if (VECTORP (eol_type)) 6202 if (VECTORP (eol_type))
6201 eol_type = Qunix; 6203 eol_type = Qunix;
6202 6204
6219 6221
6220 /* Compensate for CRLF and conversion. */ 6222 /* Compensate for CRLF and conversion. */
6221 buf_end -= 1 + MAX_ANNOTATION_LENGTH; 6223 buf_end -= 1 + MAX_ANNOTATION_LENGTH;
6222 while (buf < buf_end) 6224 while (buf < buf_end)
6223 { 6225 {
6226 Lisp_Object trans;
6227
6224 if (pos == stop) 6228 if (pos == stop)
6225 { 6229 {
6226 if (pos == end_pos) 6230 if (pos == end_pos)
6227 break; 6231 break;
6228 if (pos == stop_composition) 6232 if (pos == stop_composition)
6257 *buf++ = '\r'; 6261 *buf++ = '\r';
6258 else 6262 else
6259 c = '\r'; 6263 c = '\r';
6260 } 6264 }
6261 } 6265 }
6262 *buf++ = c; 6266
6267 if (NILP (translation_table)
6268 || NILP (trans = CHAR_TABLE_REF (translation_table, c)))
6269 *buf++ = c;
6270 else
6271 {
6272 int from_nchars = 1, to_nchars = 1;
6273 int *lookup_buf_end;
6274 const unsigned char *p = src;
6275 int i;
6276
6277 lookup_buf[0] = c;
6278 for (i = 1; i < max_lookup && p < src_end; i++)
6279 lookup_buf[i] = STRING_CHAR_ADVANCE (p);
6280 lookup_buf_end = lookup_buf + i;
6281 trans = get_translation (trans, lookup_buf, lookup_buf_end, 1,
6282 &from_nchars, &to_nchars);
6283 if (EQ (trans, Qt)
6284 || buf + to_nchars > buf_end)
6285 break;
6286 *buf++ = *lookup_buf;
6287 for (i = 1; i < to_nchars; i++)
6288 *buf++ = XINT (AREF (trans, i));
6289 for (i = 1; i < from_nchars; i++, pos++)
6290 src += MULTIBYTE_LENGTH_NO_CHECK (src);
6291 }
6263 } 6292 }
6264 6293
6265 coding->consumed = src - coding->source; 6294 coding->consumed = src - coding->source;
6266 coding->consumed_char = pos - coding->src_pos; 6295 coding->consumed_char = pos - coding->src_pos;
6267 coding->charbuf_used = buf - coding->charbuf; 6296 coding->charbuf_used = buf - coding->charbuf;
6314 6343
6315 ALLOC_CONVERSION_WORK_AREA (coding); 6344 ALLOC_CONVERSION_WORK_AREA (coding);
6316 6345
6317 do { 6346 do {
6318 coding_set_source (coding); 6347 coding_set_source (coding);
6319 consume_chars (coding); 6348 consume_chars (coding, translation_table);
6320
6321 if (!NILP (translation_table))
6322 translate_chars (coding, translation_table);
6323
6324 coding_set_destination (coding); 6349 coding_set_destination (coding);
6325 (*(coding->encoder)) (coding); 6350 (*(coding->encoder)) (coding);
6326 } while (coding->consumed_char < coding->src_chars); 6351 } while (coding->consumed_char < coding->src_chars);
6327 6352
6328 if (BUFFERP (coding->dst_object)) 6353 if (BUFFERP (coding->dst_object))
8987 Setting this variable twice is harmless. 9012 Setting this variable twice is harmless.
8988 But don't staticpro it here--that is done in alloc.c. */ 9013 But don't staticpro it here--that is done in alloc.c. */
8989 Qchar_table_extra_slots = intern ("char-table-extra-slots"); 9014 Qchar_table_extra_slots = intern ("char-table-extra-slots");
8990 9015
8991 DEFSYM (Qtranslation_table, "translation-table"); 9016 DEFSYM (Qtranslation_table, "translation-table");
8992 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (1)); 9017 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (2));
8993 DEFSYM (Qtranslation_table_id, "translation-table-id"); 9018 DEFSYM (Qtranslation_table_id, "translation-table-id");
8994 DEFSYM (Qtranslation_table_for_decode, "translation-table-for-decode"); 9019 DEFSYM (Qtranslation_table_for_decode, "translation-table-for-decode");
8995 DEFSYM (Qtranslation_table_for_encode, "translation-table-for-encode"); 9020 DEFSYM (Qtranslation_table_for_encode, "translation-table-for-encode");
8996 9021
8997 DEFSYM (Qvalid_codes, "valid-codes"); 9022 DEFSYM (Qvalid_codes, "valid-codes");