comparison src/coding.c @ 89859:b706c5ee6492

(get_translation_table): New arg max_lookup. Caller changed. (LOOKUP_TRANSLATION_TABLE): Pay attention that table may be a list.
author Kenichi Handa <handa@m17n.org>
date Thu, 11 Mar 2004 07:07:41 +0000
parents 23cb9ed79225
children 7160ded23e55
comparison
equal deleted inserted replaced
89858:23cb9ed79225 89859:b706c5ee6492
5506 /* Return a translation table (or list of them) from coding system 5506 /* Return a translation table (or list of them) from coding system
5507 attribute vector ATTRS for encoding (ENCODEP is nonzero) or 5507 attribute vector ATTRS for encoding (ENCODEP is nonzero) or
5508 decoding (ENCODEP is zero). */ 5508 decoding (ENCODEP is zero). */
5509 5509
5510 static Lisp_Object 5510 static Lisp_Object
5511 get_translation_table (attrs, encodep) 5511 get_translation_table (attrs, encodep, max_lookup)
5512 Lisp_Object attrs;
5513 int encodep, *max_lookup;
5512 { 5514 {
5513 Lisp_Object standard, translation_table; 5515 Lisp_Object standard, translation_table;
5516 Lisp_Object val;
5514 5517
5515 if (encodep) 5518 if (encodep)
5516 translation_table = CODING_ATTR_ENCODE_TBL (attrs), 5519 translation_table = CODING_ATTR_ENCODE_TBL (attrs),
5517 standard = Vstandard_translation_table_for_encode; 5520 standard = Vstandard_translation_table_for_encode;
5518 else 5521 else
5519 translation_table = CODING_ATTR_DECODE_TBL (attrs), 5522 translation_table = CODING_ATTR_DECODE_TBL (attrs),
5520 standard = Vstandard_translation_table_for_decode; 5523 standard = Vstandard_translation_table_for_decode;
5521 if (NILP (translation_table)) 5524 if (NILP (translation_table))
5522 return standard; 5525 translation_table = standard;
5523 if (SYMBOLP (translation_table)) 5526 else
5524 translation_table = Fget (translation_table, Qtranslation_table); 5527 {
5528 if (SYMBOLP (translation_table))
5529 translation_table = Fget (translation_table, Qtranslation_table);
5530 else if (CONSP (translation_table))
5531 {
5532 translation_table = Fcopy_sequence (translation_table);
5533 for (val = translation_table; CONSP (val); val = XCDR (val))
5534 if (SYMBOLP (XCAR (val)))
5535 XSETCAR (val, Fget (XCAR (val), Qtranslation_table));
5536 }
5537 if (CHAR_TABLE_P (standard))
5538 {
5539 if (CONSP (translation_table))
5540 translation_table = nconc2 (translation_table,
5541 Fcons (standard, Qnil));
5542 else
5543 translation_table = Fcons (translation_table,
5544 Fcons (standard, Qnil));
5545 }
5546 }
5547 *max_lookup = 1;
5548 if (CHAR_TABLE_P (translation_table)
5549 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (translation_table)) > 1)
5550 {
5551 val = XCHAR_TABLE (translation_table)->extras[1];
5552 if (NATNUMP (val) && *max_lookup < XFASTINT (val))
5553 *max_lookup = XFASTINT (val);
5554 }
5525 else if (CONSP (translation_table)) 5555 else if (CONSP (translation_table))
5526 { 5556 {
5527 Lisp_Object val; 5557 Lisp_Object tail, val;
5528 5558
5529 translation_table = Fcopy_sequence (translation_table); 5559 for (tail = translation_table; CONSP (tail); tail = XCDR (tail))
5530 for (val = translation_table; CONSP (val); val = XCDR (val)) 5560 if (CHAR_TABLE_P (XCAR (tail))
5531 if (SYMBOLP (XCAR (val))) 5561 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (XCAR (tail))) > 1)
5532 XSETCAR (val, Fget (XCAR (val), Qtranslation_table)); 5562 {
5533 } 5563 val = XCHAR_TABLE (XCAR (tail))->extras[1];
5534 if (! NILP (standard)) 5564 if (NATNUMP (val) && *max_lookup < XFASTINT (val))
5535 { 5565 *max_lookup = XFASTINT (val);
5536 if (CONSP (translation_table)) 5566 }
5537 translation_table = nconc2 (translation_table, Fcons (standard, Qnil));
5538 else
5539 translation_table = Fcons (translation_table, Fcons (standard, Qnil));
5540 } 5567 }
5541 return translation_table; 5568 return translation_table;
5542 } 5569 }
5543 5570
5544 #define LOOKUP_TRANSLATION_TABLE(table, c, trans) \ 5571 #define LOOKUP_TRANSLATION_TABLE(table, c, trans) \
5545 do { \ 5572 do { \
5546 if (CHAR_TABLE_P (table)) \ 5573 trans = Qnil; \
5547 { \ 5574 if (CHAR_TABLE_P (table)) \
5548 trans = CHAR_TABLE_REF (table, c); \ 5575 { \
5549 if (CHARACTERP (trans)) \ 5576 trans = CHAR_TABLE_REF (table, c); \
5550 c = XFASTINT (trans), trans = Qnil; \ 5577 if (CHARACTERP (trans)) \
5551 } \ 5578 c = XFASTINT (trans), trans = Qnil; \
5552 else \ 5579 } \
5553 { \ 5580 else if (CONSP (table)) \
5554 Lisp_Object tail = table; \ 5581 { \
5555 \ 5582 Lisp_Object tail; \
5556 for (; CONSP (tail); tail = XCDR (tail)) \ 5583 \
5557 if (CHAR_TABLE_P (XCAR (tail))) \ 5584 for (tail = table; CONSP (tail); tail = XCDR (tail)) \
5558 { \ 5585 if (CHAR_TABLE_P (XCAR (tail))) \
5559 trans = CHAR_TABLE_REF (table, c); \ 5586 { \
5560 if (CHARACTERP (trans)) \ 5587 trans = CHAR_TABLE_REF (XCAR (tail), c); \
5561 c = XFASTINT (trans), trans = Qnil; \ 5588 if (CHARACTERP (trans)) \
5562 else if (! NILP (trans)) \ 5589 c = XFASTINT (trans), trans = Qnil; \
5563 break; \ 5590 else if (! NILP (trans)) \
5564 } \ 5591 break; \
5565 } \ 5592 } \
5593 } \
5566 } while (0) 5594 } while (0)
5567 5595
5568 5596
5569 static Lisp_Object 5597 static Lisp_Object
5570 get_translation (val, buf, buf_end, last_block, from_nchars, to_nchars) 5598 get_translation (val, buf, buf_end, last_block, from_nchars, to_nchars)
5643 if (c >= 0) 5671 if (c >= 0)
5644 { 5672 {
5645 int from_nchars = 1, to_nchars = 1; 5673 int from_nchars = 1, to_nchars = 1;
5646 Lisp_Object trans = Qnil; 5674 Lisp_Object trans = Qnil;
5647 5675
5648 if (! NILP (translation_table)) 5676 LOOKUP_TRANSLATION_TABLE (translation_table, c, trans);
5649 LOOKUP_TRANSLATION_TABLE (translation_table, c, trans);
5650 if (! NILP (trans)) 5677 if (! NILP (trans))
5651 { 5678 {
5652 trans = get_translation (trans, buf, buf_end, last_block, 5679 trans = get_translation (trans, buf, buf_end, last_block,
5653 &from_nchars, &to_nchars); 5680 &from_nchars, &to_nchars);
5654 if (EQ (trans, Qt)) 5681 if (EQ (trans, Qt))
5973 { 6000 {
5974 Lisp_Object attrs; 6001 Lisp_Object attrs;
5975 Lisp_Object undo_list; 6002 Lisp_Object undo_list;
5976 Lisp_Object translation_table; 6003 Lisp_Object translation_table;
5977 int carryover; 6004 int carryover;
6005 int max_lookup;
5978 int i; 6006 int i;
5979 6007
5980 if (BUFFERP (coding->src_object) 6008 if (BUFFERP (coding->src_object)
5981 && coding->src_pos > 0 6009 && coding->src_pos > 0
5982 && coding->src_pos < GPT 6010 && coding->src_pos < GPT
6001 coding->errors = 0; 6029 coding->errors = 0;
6002 6030
6003 ALLOC_CONVERSION_WORK_AREA (coding); 6031 ALLOC_CONVERSION_WORK_AREA (coding);
6004 6032
6005 attrs = CODING_ID_ATTRS (coding->id); 6033 attrs = CODING_ID_ATTRS (coding->id);
6006 translation_table = get_translation_table (attrs, 0); 6034 translation_table = get_translation_table (attrs, 0, &max_lookup);
6007 6035
6008 carryover = 0; 6036 carryover = 0;
6009 do 6037 do
6010 { 6038 {
6011 EMACS_INT pos = coding->dst_pos + coding->produced_char; 6039 EMACS_INT pos = coding->dst_pos + coding->produced_char;
6199 return buf; 6227 return buf;
6200 } 6228 }
6201 6229
6202 6230
6203 static void 6231 static void
6204 consume_chars (coding, translation_table) 6232 consume_chars (coding, translation_table, max_lookup)
6205 struct coding_system *coding; 6233 struct coding_system *coding;
6206 Lisp_Object translation_table; 6234 Lisp_Object translation_table;
6235 int max_lookup;
6207 { 6236 {
6208 int *buf = coding->charbuf; 6237 int *buf = coding->charbuf;
6209 int *buf_end = coding->charbuf + coding->charbuf_size; 6238 int *buf_end = coding->charbuf + coding->charbuf_size;
6210 const unsigned char *src = coding->source + coding->consumed; 6239 const unsigned char *src = coding->source + coding->consumed;
6211 const unsigned char *src_end = coding->source + coding->src_bytes; 6240 const unsigned char *src_end = coding->source + coding->src_bytes;
6213 EMACS_INT end_pos = coding->src_pos + coding->src_chars; 6242 EMACS_INT end_pos = coding->src_pos + coding->src_chars;
6214 int multibytep = coding->src_multibyte; 6243 int multibytep = coding->src_multibyte;
6215 Lisp_Object eol_type; 6244 Lisp_Object eol_type;
6216 int c; 6245 int c;
6217 EMACS_INT stop, stop_composition, stop_charset; 6246 EMACS_INT stop, stop_composition, stop_charset;
6218 int max_lookup = 0, *lookup_buf = NULL; 6247 int *lookup_buf = NULL;
6219 6248
6220 if (! NILP (translation_table)) 6249 if (! NILP (translation_table))
6221 { 6250 lookup_buf = alloca (sizeof (int) * max_lookup);
6222 max_lookup = XINT (XCHAR_TABLE (translation_table)->extras[1]);
6223 lookup_buf = alloca (sizeof (int) * max_lookup);
6224 }
6225 6251
6226 eol_type = CODING_ID_EOL_TYPE (coding->id); 6252 eol_type = CODING_ID_EOL_TYPE (coding->id);
6227 if (VECTORP (eol_type)) 6253 if (VECTORP (eol_type))
6228 eol_type = Qunix; 6254 eol_type = Qunix;
6229 6255
6288 c = '\r'; 6314 c = '\r';
6289 } 6315 }
6290 } 6316 }
6291 6317
6292 trans = Qnil; 6318 trans = Qnil;
6293 if (! NILP (translation_table)) 6319 LOOKUP_TRANSLATION_TABLE (translation_table, c, trans);
6294 LOOKUP_TRANSLATION_TABLE (translation_table, c, trans);
6295 if (NILP (trans)) 6320 if (NILP (trans))
6296 *buf++ = c; 6321 *buf++ = c;
6297 else 6322 else
6298 { 6323 {
6299 int from_nchars = 1, to_nchars = 1; 6324 int from_nchars = 1, to_nchars = 1;
6350 encode_coding (coding) 6375 encode_coding (coding)
6351 struct coding_system *coding; 6376 struct coding_system *coding;
6352 { 6377 {
6353 Lisp_Object attrs; 6378 Lisp_Object attrs;
6354 Lisp_Object translation_table; 6379 Lisp_Object translation_table;
6380 int max_lookup;
6355 6381
6356 attrs = CODING_ID_ATTRS (coding->id); 6382 attrs = CODING_ID_ATTRS (coding->id);
6357 translation_table = get_translation_table (attrs, 1); 6383 translation_table = get_translation_table (attrs, 1, &max_lookup);
6358 6384
6359 if (BUFFERP (coding->dst_object)) 6385 if (BUFFERP (coding->dst_object))
6360 { 6386 {
6361 set_buffer_internal (XBUFFER (coding->dst_object)); 6387 set_buffer_internal (XBUFFER (coding->dst_object));
6362 coding->dst_multibyte 6388 coding->dst_multibyte
6370 6396
6371 ALLOC_CONVERSION_WORK_AREA (coding); 6397 ALLOC_CONVERSION_WORK_AREA (coding);
6372 6398
6373 do { 6399 do {
6374 coding_set_source (coding); 6400 coding_set_source (coding);
6375 consume_chars (coding, translation_table); 6401 consume_chars (coding, translation_table, max_lookup);
6376 coding_set_destination (coding); 6402 coding_set_destination (coding);
6377 (*(coding->encoder)) (coding); 6403 (*(coding->encoder)) (coding);
6378 } while (coding->consumed_char < coding->src_chars); 6404 } while (coding->consumed_char < coding->src_chars);
6379 6405
6380 if (BUFFERP (coding->dst_object)) 6406 if (BUFFERP (coding->dst_object))