aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa2004-03-11 07:07:41 +0000
committerKenichi Handa2004-03-11 07:07:41 +0000
commit09ee6fdda7f7d3eb36f1598606df4e3ff7bf2e2a (patch)
tree78996690192888295b1bde811f3520b99eeb5782
parente6a54062d36cd81aa26fe64c54173b62b1517c32 (diff)
downloademacs-09ee6fdda7f7d3eb36f1598606df4e3ff7bf2e2a.tar.gz
emacs-09ee6fdda7f7d3eb36f1598606df4e3ff7bf2e2a.zip
(get_translation_table): New arg max_lookup. Caller changed.
(LOOKUP_TRANSLATION_TABLE): Pay attention that table may be a list.
-rw-r--r--src/coding.c128
1 files changed, 77 insertions, 51 deletions
diff --git a/src/coding.c b/src/coding.c
index ef66395b843..2c12e6b0b5a 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -5508,9 +5508,12 @@ decode_eol (coding)
5508 decoding (ENCODEP is zero). */ 5508 decoding (ENCODEP is zero). */
5509 5509
5510static Lisp_Object 5510static Lisp_Object
5511get_translation_table (attrs, encodep) 5511get_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),
@@ -5519,50 +5522,75 @@ get_translation_table (attrs, encodep)
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);
5525 else if (CONSP (translation_table))
5526 { 5527 {
5527 Lisp_Object val; 5528 if (SYMBOLP (translation_table))
5528 5529 translation_table = Fget (translation_table, Qtranslation_table);
5529 translation_table = Fcopy_sequence (translation_table); 5530 else if (CONSP (translation_table))
5530 for (val = translation_table; CONSP (val); val = XCDR (val)) 5531 {
5531 if (SYMBOLP (XCAR (val))) 5532 translation_table = Fcopy_sequence (translation_table);
5532 XSETCAR (val, Fget (XCAR (val), Qtranslation_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 }
5533 } 5546 }
5534 if (! NILP (standard)) 5547 *max_lookup = 1;
5548 if (CHAR_TABLE_P (translation_table)
5549 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (translation_table)) > 1)
5535 { 5550 {
5536 if (CONSP (translation_table)) 5551 val = XCHAR_TABLE (translation_table)->extras[1];
5537 translation_table = nconc2 (translation_table, Fcons (standard, Qnil)); 5552 if (NATNUMP (val) && *max_lookup < XFASTINT (val))
5538 else 5553 *max_lookup = XFASTINT (val);
5539 translation_table = Fcons (translation_table, Fcons (standard, Qnil)); 5554 }
5555 else if (CONSP (translation_table))
5556 {
5557 Lisp_Object tail, val;
5558
5559 for (tail = translation_table; CONSP (tail); tail = XCDR (tail))
5560 if (CHAR_TABLE_P (XCAR (tail))
5561 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (XCAR (tail))) > 1)
5562 {
5563 val = XCHAR_TABLE (XCAR (tail))->extras[1];
5564 if (NATNUMP (val) && *max_lookup < XFASTINT (val))
5565 *max_lookup = XFASTINT (val);
5566 }
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
@@ -5645,8 +5673,7 @@ produce_chars (coding, translation_table, last_block)
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,
@@ -5975,6 +6002,7 @@ decode_coding (coding)
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)
@@ -6003,7 +6031,7 @@ decode_coding (coding)
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
@@ -6201,9 +6229,10 @@ handle_charset_annotation (pos, limit, coding, buf, stop)
6201 6229
6202 6230
6203static void 6231static void
6204consume_chars (coding, translation_table) 6232consume_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;
@@ -6215,13 +6244,10 @@ consume_chars (coding, translation_table)
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))
@@ -6290,8 +6316,7 @@ consume_chars (coding, translation_table)
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
@@ -6352,9 +6377,10 @@ encode_coding (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 {
@@ -6372,7 +6398,7 @@ encode_coding (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);