1 /* CCL (Code Conversion Language) interpreter.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005,
3 2006 Free Software Foundation, Inc.
4 Copyright (C) 1995, 1997, 1998, 2003, 2004, 2005
5 National Institute of Advanced Industrial Science and Technology (AIST)
6 Registration Number H14PRO021
8 This file is part of GNU Emacs.
10 GNU Emacs is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU Emacs is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU Emacs; see the file COPYING. If not, write to
22 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
34 /* This contains all code conversion map available to CCL. */
35 Lisp_Object Vcode_conversion_map_vector
;
37 /* Alist of fontname patterns vs corresponding CCL program. */
38 Lisp_Object Vfont_ccl_encoder_alist
;
40 /* This symbol is a property which assocates with ccl program vector.
41 Ex: (get 'ccl-big5-encoder 'ccl-program) returns ccl program vector. */
42 Lisp_Object Qccl_program
;
44 /* These symbols are properties which associate with code conversion
45 map and their ID respectively. */
46 Lisp_Object Qcode_conversion_map
;
47 Lisp_Object Qcode_conversion_map_id
;
49 /* Symbols of ccl program have this property, a value of the property
50 is an index for Vccl_protram_table. */
51 Lisp_Object Qccl_program_idx
;
53 /* Table of registered CCL programs. Each element is a vector of
54 NAME, CCL_PROG, RESOLVEDP, and UPDATEDP, where NAME (symbol) is the
55 name of the program, CCL_PROG (vector) is the compiled code of the
56 program, RESOLVEDP (t or nil) is the flag to tell if symbols in
57 CCL_PROG is already resolved to index numbers or not, UPDATEDP (t
58 or nil) is the flat to tell if the CCL program is updated after it
60 Lisp_Object Vccl_program_table
;
62 /* Vector of registered hash tables for translation. */
63 Lisp_Object Vtranslation_hash_table_vector
;
65 /* Return a hash table of id number ID. */
66 #define GET_HASH_TABLE(id) \
67 (XHASH_TABLE (XCDR(XVECTOR(Vtranslation_hash_table_vector)->contents[(id)])))
69 /* CCL (Code Conversion Language) is a simple language which has
70 operations on one input buffer, one output buffer, and 7 registers.
71 The syntax of CCL is described in `ccl.el'. Emacs Lisp function
72 `ccl-compile' compiles a CCL program and produces a CCL code which
73 is a vector of integers. The structure of this vector is as
74 follows: The 1st element: buffer-magnification, a factor for the
75 size of output buffer compared with the size of input buffer. The
76 2nd element: address of CCL code to be executed when encountered
77 with end of input stream. The 3rd and the remaining elements: CCL
80 /* Header of CCL compiled code */
81 #define CCL_HEADER_BUF_MAG 0
82 #define CCL_HEADER_EOF 1
83 #define CCL_HEADER_MAIN 2
85 /* CCL code is a sequence of 28-bit non-negative integers (i.e. the
86 MSB is always 0), each contains CCL command and/or arguments in the
89 |----------------- integer (28-bit) ------------------|
90 |------- 17-bit ------|- 3-bit --|- 3-bit --|- 5-bit -|
91 |--constant argument--|-register-|-register-|-command-|
92 ccccccccccccccccc RRR rrr XXXXX
94 |------- relative address -------|-register-|-command-|
95 cccccccccccccccccccc rrr XXXXX
97 |------------- constant or other args ----------------|
98 cccccccccccccccccccccccccccc
100 where, `cc...c' is a non-negative integer indicating constant value
101 (the left most `c' is always 0) or an absolute jump address, `RRR'
102 and `rrr' are CCL register number, `XXXXX' is one of the following
107 Each comment fields shows one or more lines for command syntax and
108 the following lines for semantics of the command. In semantics, IC
109 stands for Instruction Counter. */
111 #define CCL_SetRegister 0x00 /* Set register a register value:
112 1:00000000000000000RRRrrrXXXXX
113 ------------------------------
117 #define CCL_SetShortConst 0x01 /* Set register a short constant value:
118 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
119 ------------------------------
120 reg[rrr] = CCCCCCCCCCCCCCCCCCC;
123 #define CCL_SetConst 0x02 /* Set register a constant value:
124 1:00000000000000000000rrrXXXXX
126 ------------------------------
131 #define CCL_SetArray 0x03 /* Set register an element of array:
132 1:CCCCCCCCCCCCCCCCCRRRrrrXXXXX
136 ------------------------------
137 if (0 <= reg[RRR] < CC..C)
138 reg[rrr] = ELEMENT[reg[RRR]];
142 #define CCL_Jump 0x04 /* Jump:
143 1:A--D--D--R--E--S--S-000XXXXX
144 ------------------------------
148 /* Note: If CC..C is greater than 0, the second code is omitted. */
150 #define CCL_JumpCond 0x05 /* Jump conditional:
151 1:A--D--D--R--E--S--S-rrrXXXXX
152 ------------------------------
158 #define CCL_WriteRegisterJump 0x06 /* Write register and jump:
159 1:A--D--D--R--E--S--S-rrrXXXXX
160 ------------------------------
165 #define CCL_WriteRegisterReadJump 0x07 /* Write register, read, and jump:
166 1:A--D--D--R--E--S--S-rrrXXXXX
167 2:A--D--D--R--E--S--S-rrrYYYYY
168 -----------------------------
174 /* Note: If read is suspended, the resumed execution starts from the
175 second code (YYYYY == CCL_ReadJump). */
177 #define CCL_WriteConstJump 0x08 /* Write constant and jump:
178 1:A--D--D--R--E--S--S-000XXXXX
180 ------------------------------
185 #define CCL_WriteConstReadJump 0x09 /* Write constant, read, and jump:
186 1:A--D--D--R--E--S--S-rrrXXXXX
188 3:A--D--D--R--E--S--S-rrrYYYYY
189 -----------------------------
195 /* Note: If read is suspended, the resumed execution starts from the
196 second code (YYYYY == CCL_ReadJump). */
198 #define CCL_WriteStringJump 0x0A /* Write string and jump:
199 1:A--D--D--R--E--S--S-000XXXXX
201 3:0000STRIN[0]STRIN[1]STRIN[2]
203 ------------------------------
204 write_string (STRING, LENGTH);
208 #define CCL_WriteArrayReadJump 0x0B /* Write an array element, read, and jump:
209 1:A--D--D--R--E--S--S-rrrXXXXX
214 N:A--D--D--R--E--S--S-rrrYYYYY
215 ------------------------------
216 if (0 <= reg[rrr] < LENGTH)
217 write (ELEMENT[reg[rrr]]);
218 IC += LENGTH + 2; (... pointing at N+1)
222 /* Note: If read is suspended, the resumed execution starts from the
223 Nth code (YYYYY == CCL_ReadJump). */
225 #define CCL_ReadJump 0x0C /* Read and jump:
226 1:A--D--D--R--E--S--S-rrrYYYYY
227 -----------------------------
232 #define CCL_Branch 0x0D /* Jump by branch table:
233 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
234 2:A--D--D--R--E-S-S[0]000XXXXX
235 3:A--D--D--R--E-S-S[1]000XXXXX
237 ------------------------------
238 if (0 <= reg[rrr] < CC..C)
239 IC += ADDRESS[reg[rrr]];
241 IC += ADDRESS[CC..C];
244 #define CCL_ReadRegister 0x0E /* Read bytes into registers:
245 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
246 2:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
248 ------------------------------
253 #define CCL_WriteExprConst 0x0F /* write result of expression:
254 1:00000OPERATION000RRR000XXXXX
256 ------------------------------
257 write (reg[RRR] OPERATION CONSTANT);
261 /* Note: If the Nth read is suspended, the resumed execution starts
262 from the Nth code. */
264 #define CCL_ReadBranch 0x10 /* Read one byte into a register,
265 and jump by branch table:
266 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
267 2:A--D--D--R--E-S-S[0]000XXXXX
268 3:A--D--D--R--E-S-S[1]000XXXXX
270 ------------------------------
272 if (0 <= reg[rrr] < CC..C)
273 IC += ADDRESS[reg[rrr]];
275 IC += ADDRESS[CC..C];
278 #define CCL_WriteRegister 0x11 /* Write registers:
279 1:CCCCCCCCCCCCCCCCCCCrrrXXXXX
280 2:CCCCCCCCCCCCCCCCCCCrrrXXXXX
282 ------------------------------
288 /* Note: If the Nth write is suspended, the resumed execution
289 starts from the Nth code. */
291 #define CCL_WriteExprRegister 0x12 /* Write result of expression
292 1:00000OPERATIONRrrRRR000XXXXX
293 ------------------------------
294 write (reg[RRR] OPERATION reg[Rrr]);
297 #define CCL_Call 0x13 /* Call the CCL program whose ID is
299 1:CCCCCCCCCCCCCCCCCCCCFFFXXXXX
300 [2:00000000cccccccccccccccccccc]
301 ------------------------------
309 #define CCL_WriteConstString 0x14 /* Write a constant or a string:
310 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
311 [2:0000STRIN[0]STRIN[1]STRIN[2]]
313 -----------------------------
317 write_string (STRING, CC..C);
318 IC += (CC..C + 2) / 3;
321 #define CCL_WriteArray 0x15 /* Write an element of array:
322 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
326 ------------------------------
327 if (0 <= reg[rrr] < CC..C)
328 write (ELEMENT[reg[rrr]]);
332 #define CCL_End 0x16 /* Terminate:
333 1:00000000000000000000000XXXXX
334 ------------------------------
338 /* The following two codes execute an assignment arithmetic/logical
339 operation. The form of the operation is like REG OP= OPERAND. */
341 #define CCL_ExprSelfConst 0x17 /* REG OP= constant:
342 1:00000OPERATION000000rrrXXXXX
344 ------------------------------
345 reg[rrr] OPERATION= CONSTANT;
348 #define CCL_ExprSelfReg 0x18 /* REG1 OP= REG2:
349 1:00000OPERATION000RRRrrrXXXXX
350 ------------------------------
351 reg[rrr] OPERATION= reg[RRR];
354 /* The following codes execute an arithmetic/logical operation. The
355 form of the operation is like REG_X = REG_Y OP OPERAND2. */
357 #define CCL_SetExprConst 0x19 /* REG_X = REG_Y OP constant:
358 1:00000OPERATION000RRRrrrXXXXX
360 ------------------------------
361 reg[rrr] = reg[RRR] OPERATION CONSTANT;
365 #define CCL_SetExprReg 0x1A /* REG1 = REG2 OP REG3:
366 1:00000OPERATIONRrrRRRrrrXXXXX
367 ------------------------------
368 reg[rrr] = reg[RRR] OPERATION reg[Rrr];
371 #define CCL_JumpCondExprConst 0x1B /* Jump conditional according to
372 an operation on constant:
373 1:A--D--D--R--E--S--S-rrrXXXXX
376 -----------------------------
377 reg[7] = reg[rrr] OPERATION CONSTANT;
384 #define CCL_JumpCondExprReg 0x1C /* Jump conditional according to
385 an operation on register:
386 1:A--D--D--R--E--S--S-rrrXXXXX
389 -----------------------------
390 reg[7] = reg[rrr] OPERATION reg[RRR];
397 #define CCL_ReadJumpCondExprConst 0x1D /* Read and jump conditional according
398 to an operation on constant:
399 1:A--D--D--R--E--S--S-rrrXXXXX
402 -----------------------------
404 reg[7] = reg[rrr] OPERATION CONSTANT;
411 #define CCL_ReadJumpCondExprReg 0x1E /* Read and jump conditional according
412 to an operation on register:
413 1:A--D--D--R--E--S--S-rrrXXXXX
416 -----------------------------
418 reg[7] = reg[rrr] OPERATION reg[RRR];
425 #define CCL_Extension 0x1F /* Extended CCL code
426 1:ExtendedCOMMNDRrrRRRrrrXXXXX
429 ------------------------------
430 extended_command (rrr,RRR,Rrr,ARGS)
434 Here after, Extended CCL Instructions.
435 Bit length of extended command is 14.
436 Therefore, the instruction code range is 0..16384(0x3fff).
439 /* Read a multibyte characeter.
440 A code point is stored into reg[rrr]. A charset ID is stored into
443 #define CCL_ReadMultibyteChar2 0x00 /* Read Multibyte Character
444 1:ExtendedCOMMNDRrrRRRrrrXXXXX */
446 /* Write a multibyte character.
447 Write a character whose code point is reg[rrr] and the charset ID
450 #define CCL_WriteMultibyteChar2 0x01 /* Write Multibyte Character
451 1:ExtendedCOMMNDRrrRRRrrrXXXXX */
453 /* Translate a character whose code point is reg[rrr] and the charset
454 ID is reg[RRR] by a translation table whose ID is reg[Rrr].
456 A translated character is set in reg[rrr] (code point) and reg[RRR]
459 #define CCL_TranslateCharacter 0x02 /* Translate a multibyte character
460 1:ExtendedCOMMNDRrrRRRrrrXXXXX */
462 /* Translate a character whose code point is reg[rrr] and the charset
463 ID is reg[RRR] by a translation table whose ID is ARGUMENT.
465 A translated character is set in reg[rrr] (code point) and reg[RRR]
468 #define CCL_TranslateCharacterConstTbl 0x03 /* Translate a multibyte character
469 1:ExtendedCOMMNDRrrRRRrrrXXXXX
470 2:ARGUMENT(Translation Table ID)
473 /* Iterate looking up MAPs for reg[rrr] starting from the Nth (N =
474 reg[RRR]) MAP until some value is found.
476 Each MAP is a Lisp vector whose element is number, nil, t, or
478 If the element is nil, ignore the map and proceed to the next map.
479 If the element is t or lambda, finish without changing reg[rrr].
480 If the element is a number, set reg[rrr] to the number and finish.
482 Detail of the map structure is descibed in the comment for
483 CCL_MapMultiple below. */
485 #define CCL_IterateMultipleMap 0x10 /* Iterate multiple maps
486 1:ExtendedCOMMNDXXXRRRrrrXXXXX
493 /* Map the code in reg[rrr] by MAPs starting from the Nth (N =
496 MAPs are supplied in the succeeding CCL codes as follows:
498 When CCL program gives this nested structure of map to this command:
501 (MAP-ID121 MAP-ID122 MAP-ID123)
504 (MAP-ID211 (MAP-ID2111) MAP-ID212)
506 the compiled CCL codes has this sequence:
507 CCL_MapMultiple (CCL code of this command)
508 16 (total number of MAPs and SEPARATORs)
526 A value of each SEPARATOR follows this rule:
527 MAP-SET := SEPARATOR [(MAP-ID | MAP-SET)]+
528 SEPARATOR := -(number of MAP-IDs and SEPARATORs in the MAP-SET)
530 (*)....Nest level of MAP-SET must not be over than MAX_MAP_SET_LEVEL.
532 When some map fails to map (i.e. it doesn't have a value for
533 reg[rrr]), the mapping is treated as identity.
535 The mapping is iterated for all maps in each map set (set of maps
536 separated by SEPARATOR) except in the case that lambda is
537 encountered. More precisely, the mapping proceeds as below:
539 At first, VAL0 is set to reg[rrr], and it is translated by the
540 first map to VAL1. Then, VAL1 is translated by the next map to
541 VAL2. This mapping is iterated until the last map is used. The
542 result of the mapping is the last value of VAL?. When the mapping
543 process reached to the end of the map set, it moves to the next
544 map set. If the next does not exit, the mapping process terminates,
545 and regard the last value as a result.
547 But, when VALm is mapped to VALn and VALn is not a number, the
548 mapping proceed as below:
550 If VALn is nil, the lastest map is ignored and the mapping of VALm
551 proceed to the next map.
553 In VALn is t, VALm is reverted to reg[rrr] and the mapping of VALm
554 proceed to the next map.
556 If VALn is lambda, move to the next map set like reaching to the
557 end of the current map set.
559 If VALn is a symbol, call the CCL program refered by it.
560 Then, use reg[rrr] as a mapped value except for -1, -2 and -3.
561 Such special values are regarded as nil, t, and lambda respectively.
563 Each map is a Lisp vector of the following format (a) or (b):
564 (a)......[STARTPOINT VAL1 VAL2 ...]
565 (b)......[t VAL STARTPOINT ENDPOINT],
567 STARTPOINT is an offset to be used for indexing a map,
568 ENDPOINT is a maximum index number of a map,
569 VAL and VALn is a number, nil, t, or lambda.
571 Valid index range of a map of type (a) is:
572 STARTPOINT <= index < STARTPOINT + map_size - 1
573 Valid index range of a map of type (b) is:
574 STARTPOINT <= index < ENDPOINT */
576 #define CCL_MapMultiple 0x11 /* Mapping by multiple code conversion maps
577 1:ExtendedCOMMNDXXXRRRrrrXXXXX
589 #define MAX_MAP_SET_LEVEL 30
597 static tr_stack mapping_stack
[MAX_MAP_SET_LEVEL
];
598 static tr_stack
*mapping_stack_pointer
;
600 /* If this variable is non-zero, it indicates the stack_idx
601 of immediately called by CCL_MapMultiple. */
602 static int stack_idx_of_map_multiple
;
604 #define PUSH_MAPPING_STACK(restlen, orig) \
607 mapping_stack_pointer->rest_length = (restlen); \
608 mapping_stack_pointer->orig_val = (orig); \
609 mapping_stack_pointer++; \
613 #define POP_MAPPING_STACK(restlen, orig) \
616 mapping_stack_pointer--; \
617 (restlen) = mapping_stack_pointer->rest_length; \
618 (orig) = mapping_stack_pointer->orig_val; \
622 #define CCL_CALL_FOR_MAP_INSTRUCTION(symbol, ret_ic) \
625 struct ccl_program called_ccl; \
626 if (stack_idx >= 256 \
627 || (setup_ccl_program (&called_ccl, (symbol)) != 0)) \
631 ccl_prog = ccl_prog_stack_struct[0].ccl_prog; \
632 ic = ccl_prog_stack_struct[0].ic; \
633 eof_ic = ccl_prog_stack_struct[0].eof_ic; \
637 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog; \
638 ccl_prog_stack_struct[stack_idx].ic = (ret_ic); \
639 ccl_prog_stack_struct[stack_idx].eof_ic = eof_ic; \
641 ccl_prog = called_ccl.prog; \
642 ic = CCL_HEADER_MAIN; \
643 eof_ic = XFASTINT (ccl_prog[CCL_HEADER_EOF]); \
648 #define CCL_MapSingle 0x12 /* Map by single code conversion map
649 1:ExtendedCOMMNDXXXRRRrrrXXXXX
651 ------------------------------
652 Map reg[rrr] by MAP-ID.
653 If some valid mapping is found,
654 set reg[rrr] to the result,
659 #define CCL_LookupIntConstTbl 0x13 /* Lookup multibyte character by
660 integer key. Afterwards R7 set
661 to 1 iff lookup succeeded.
662 1:ExtendedCOMMNDRrrRRRXXXXXXXX
663 2:ARGUMENT(Hash table ID) */
665 #define CCL_LookupCharConstTbl 0x14 /* Lookup integer by multibyte
666 character key. Afterwards R7 set
667 to 1 iff lookup succeeded.
668 1:ExtendedCOMMNDRrrRRRrrrXXXXX
669 2:ARGUMENT(Hash table ID) */
671 /* CCL arithmetic/logical operators. */
672 #define CCL_PLUS 0x00 /* X = Y + Z */
673 #define CCL_MINUS 0x01 /* X = Y - Z */
674 #define CCL_MUL 0x02 /* X = Y * Z */
675 #define CCL_DIV 0x03 /* X = Y / Z */
676 #define CCL_MOD 0x04 /* X = Y % Z */
677 #define CCL_AND 0x05 /* X = Y & Z */
678 #define CCL_OR 0x06 /* X = Y | Z */
679 #define CCL_XOR 0x07 /* X = Y ^ Z */
680 #define CCL_LSH 0x08 /* X = Y << Z */
681 #define CCL_RSH 0x09 /* X = Y >> Z */
682 #define CCL_LSH8 0x0A /* X = (Y << 8) | Z */
683 #define CCL_RSH8 0x0B /* X = Y >> 8, r[7] = Y & 0xFF */
684 #define CCL_DIVMOD 0x0C /* X = Y / Z, r[7] = Y % Z */
685 #define CCL_LS 0x10 /* X = (X < Y) */
686 #define CCL_GT 0x11 /* X = (X > Y) */
687 #define CCL_EQ 0x12 /* X = (X == Y) */
688 #define CCL_LE 0x13 /* X = (X <= Y) */
689 #define CCL_GE 0x14 /* X = (X >= Y) */
690 #define CCL_NE 0x15 /* X = (X != Y) */
692 #define CCL_DECODE_SJIS 0x16 /* X = HIGHER_BYTE (DE-SJIS (Y, Z))
693 r[7] = LOWER_BYTE (DE-SJIS (Y, Z)) */
694 #define CCL_ENCODE_SJIS 0x17 /* X = HIGHER_BYTE (SJIS (Y, Z))
695 r[7] = LOWER_BYTE (SJIS (Y, Z) */
697 /* Terminate CCL program successfully. */
698 #define CCL_SUCCESS \
701 ccl->status = CCL_STAT_SUCCESS; \
706 /* Suspend CCL program because of reading from empty input buffer or
707 writing to full output buffer. When this program is resumed, the
708 same I/O command is executed. */
709 #define CCL_SUSPEND(stat) \
713 ccl->status = stat; \
718 /* Terminate CCL program because of invalid command. Should not occur
719 in the normal case. */
722 #define CCL_INVALID_CMD \
725 ccl->status = CCL_STAT_INVALID_CMD; \
726 goto ccl_error_handler; \
732 #define CCL_INVALID_CMD \
735 ccl_debug_hook (this_ic); \
736 ccl->status = CCL_STAT_INVALID_CMD; \
737 goto ccl_error_handler; \
743 /* Encode one character CH to multibyte form and write to the current
744 output buffer. If CH is less than 256, CH is written as is. */
745 #define CCL_WRITE_CHAR(ch) \
747 int bytes = SINGLE_BYTE_CHAR_P (ch) ? 1: CHAR_BYTES (ch); \
750 else if (dst + bytes + extra_bytes < (dst_bytes ? dst_end : src)) \
755 if (extra_bytes && (ch) >= 0x80 && (ch) < 0xA0) \
756 /* We may have to convert this eight-bit char to \
757 multibyte form later. */ \
760 else if (CHAR_VALID_P (ch, 0)) \
761 dst += CHAR_STRING (ch, dst); \
766 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_DST); \
769 /* Encode one character CH to multibyte form and write to the current
770 output buffer. The output bytes always forms a valid multibyte
772 #define CCL_WRITE_MULTIBYTE_CHAR(ch) \
774 int bytes = CHAR_BYTES (ch); \
777 else if (dst + bytes + extra_bytes < (dst_bytes ? dst_end : src)) \
779 if (CHAR_VALID_P ((ch), 0)) \
780 dst += CHAR_STRING ((ch), dst); \
785 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_DST); \
788 /* Write a string at ccl_prog[IC] of length LEN to the current output
790 #define CCL_WRITE_STRING(len) \
794 else if (dst + len <= (dst_bytes ? dst_end : src)) \
795 for (i = 0; i < len; i++) \
796 *dst++ = ((XFASTINT (ccl_prog[ic + (i / 3)])) \
797 >> ((2 - (i % 3)) * 8)) & 0xFF; \
799 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_DST); \
802 /* Read one byte from the current input buffer into REGth register. */
803 #define CCL_READ_CHAR(REG) \
807 else if (src < src_end) \
811 && ccl->eol_type != CODING_EOL_LF) \
813 /* We are encoding. */ \
814 if (ccl->eol_type == CODING_EOL_CRLF) \
816 if (ccl->cr_consumed) \
817 ccl->cr_consumed = 0; \
820 ccl->cr_consumed = 1; \
828 if (REG == LEADING_CODE_8_BIT_CONTROL \
830 REG = *src++ - 0x20; \
832 else if (ccl->last_block) \
839 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC); \
843 /* Set C to the character code made from CHARSET and CODE. This is
844 like MAKE_CHAR but check the validity of CHARSET and CODE. If they
845 are not valid, set C to (CODE & 0xFF) because that is usually the
846 case that CCL_ReadMultibyteChar2 read an invalid code and it set
847 CODE to that invalid byte. */
849 #define CCL_MAKE_CHAR(charset, code, c) \
851 if (charset == CHARSET_ASCII) \
853 else if (CHARSET_DEFINED_P (charset) \
854 && (code & 0x7F) >= 32 \
855 && (code < 256 || ((code >> 7) & 0x7F) >= 32)) \
857 int c1 = code & 0x7F, c2 = 0; \
860 c2 = c1, c1 = (code >> 7) & 0x7F; \
861 c = MAKE_CHAR (charset, c1, c2); \
868 /* Execute CCL code on SRC_BYTES length text at SOURCE. The resulting
869 text goes to a place pointed by DESTINATION, the length of which
870 should not exceed DST_BYTES. The bytes actually processed is
871 returned as *CONSUMED. The return value is the length of the
872 resulting text. As a side effect, the contents of CCL registers
873 are updated. If SOURCE or DESTINATION is NULL, only operations on
874 registers are permitted. */
877 #define CCL_DEBUG_BACKTRACE_LEN 256
878 int ccl_backtrace_table
[CCL_DEBUG_BACKTRACE_LEN
];
879 int ccl_backtrace_idx
;
882 ccl_debug_hook (int ic
)
889 struct ccl_prog_stack
891 Lisp_Object
*ccl_prog
; /* Pointer to an array of CCL code. */
892 int ic
; /* Instruction Counter. */
893 int eof_ic
; /* Instruction Counter to jump on EOF. */
896 /* For the moment, we only support depth 256 of stack. */
897 static struct ccl_prog_stack ccl_prog_stack_struct
[256];
900 ccl_driver (ccl
, source
, destination
, src_bytes
, dst_bytes
, consumed
)
901 struct ccl_program
*ccl
;
902 unsigned char *source
, *destination
;
903 int src_bytes
, dst_bytes
;
906 register int *reg
= ccl
->reg
;
907 register int ic
= ccl
->ic
;
908 register int code
= 0, field1
, field2
;
909 register Lisp_Object
*ccl_prog
= ccl
->prog
;
910 unsigned char *src
= source
, *src_end
= src
+ src_bytes
;
911 unsigned char *dst
= destination
, *dst_end
= dst
+ dst_bytes
;
914 int stack_idx
= ccl
->stack_idx
;
915 /* Instruction counter of the current CCL code. */
917 /* CCL_WRITE_CHAR will produce 8-bit code of range 0x80..0x9F. But,
918 each of them will be converted to multibyte form of 2-byte
919 sequence. For that conversion, we remember how many more bytes
920 we must keep in DESTINATION in this variable. */
921 int extra_bytes
= ccl
->eight_bit_control
;
922 int eof_ic
= ccl
->eof_ic
;
926 ic
= CCL_HEADER_MAIN
;
928 if (ccl
->buf_magnification
== 0) /* We can't produce any bytes. */
931 /* Set mapping stack pointer. */
932 mapping_stack_pointer
= mapping_stack
;
935 ccl_backtrace_idx
= 0;
942 ccl_backtrace_table
[ccl_backtrace_idx
++] = ic
;
943 if (ccl_backtrace_idx
>= CCL_DEBUG_BACKTRACE_LEN
)
944 ccl_backtrace_idx
= 0;
945 ccl_backtrace_table
[ccl_backtrace_idx
] = 0;
948 if (!NILP (Vquit_flag
) && NILP (Vinhibit_quit
))
950 /* We can't just signal Qquit, instead break the loop as if
951 the whole data is processed. Don't reset Vquit_flag, it
952 must be handled later at a safer place. */
954 src
= source
+ src_bytes
;
955 ccl
->status
= CCL_STAT_QUIT
;
960 code
= XINT (ccl_prog
[ic
]); ic
++;
962 field2
= (code
& 0xFF) >> 5;
965 #define RRR (field1 & 7)
966 #define Rrr ((field1 >> 3) & 7)
968 #define EXCMD (field1 >> 6)
972 case CCL_SetRegister
: /* 00000000000000000RRRrrrXXXXX */
976 case CCL_SetShortConst
: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
980 case CCL_SetConst
: /* 00000000000000000000rrrXXXXX */
981 reg
[rrr
] = XINT (ccl_prog
[ic
]);
985 case CCL_SetArray
: /* CCCCCCCCCCCCCCCCCCCCRRRrrrXXXXX */
988 if ((unsigned int) i
< j
)
989 reg
[rrr
] = XINT (ccl_prog
[ic
+ i
]);
993 case CCL_Jump
: /* A--D--D--R--E--S--S-000XXXXX */
997 case CCL_JumpCond
: /* A--D--D--R--E--S--S-rrrXXXXX */
1002 case CCL_WriteRegisterJump
: /* A--D--D--R--E--S--S-rrrXXXXX */
1008 case CCL_WriteRegisterReadJump
: /* A--D--D--R--E--S--S-rrrXXXXX */
1012 CCL_READ_CHAR (reg
[rrr
]);
1016 case CCL_WriteConstJump
: /* A--D--D--R--E--S--S-000XXXXX */
1017 i
= XINT (ccl_prog
[ic
]);
1022 case CCL_WriteConstReadJump
: /* A--D--D--R--E--S--S-rrrXXXXX */
1023 i
= XINT (ccl_prog
[ic
]);
1026 CCL_READ_CHAR (reg
[rrr
]);
1030 case CCL_WriteStringJump
: /* A--D--D--R--E--S--S-000XXXXX */
1031 j
= XINT (ccl_prog
[ic
]);
1033 CCL_WRITE_STRING (j
);
1037 case CCL_WriteArrayReadJump
: /* A--D--D--R--E--S--S-rrrXXXXX */
1039 j
= XINT (ccl_prog
[ic
]);
1040 if ((unsigned int) i
< j
)
1042 i
= XINT (ccl_prog
[ic
+ 1 + i
]);
1046 CCL_READ_CHAR (reg
[rrr
]);
1047 ic
+= ADDR
- (j
+ 2);
1050 case CCL_ReadJump
: /* A--D--D--R--E--S--S-rrrYYYYY */
1051 CCL_READ_CHAR (reg
[rrr
]);
1055 case CCL_ReadBranch
: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
1056 CCL_READ_CHAR (reg
[rrr
]);
1057 /* fall through ... */
1058 case CCL_Branch
: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
1059 if ((unsigned int) reg
[rrr
] < field1
)
1060 ic
+= XINT (ccl_prog
[ic
+ reg
[rrr
]]);
1062 ic
+= XINT (ccl_prog
[ic
+ field1
]);
1065 case CCL_ReadRegister
: /* CCCCCCCCCCCCCCCCCCCCrrXXXXX */
1068 CCL_READ_CHAR (reg
[rrr
]);
1070 code
= XINT (ccl_prog
[ic
]); ic
++;
1072 field2
= (code
& 0xFF) >> 5;
1076 case CCL_WriteExprConst
: /* 1:00000OPERATION000RRR000XXXXX */
1079 j
= XINT (ccl_prog
[ic
]);
1081 jump_address
= ic
+ 1;
1084 case CCL_WriteRegister
: /* CCCCCCCCCCCCCCCCCCCrrrXXXXX */
1090 code
= XINT (ccl_prog
[ic
]); ic
++;
1092 field2
= (code
& 0xFF) >> 5;
1096 case CCL_WriteExprRegister
: /* 1:00000OPERATIONRrrRRR000XXXXX */
1104 case CCL_Call
: /* 1:CCCCCCCCCCCCCCCCCCCCFFFXXXXX */
1109 /* If FFF is nonzero, the CCL program ID is in the
1113 prog_id
= XINT (ccl_prog
[ic
]);
1119 if (stack_idx
>= 256
1121 || prog_id
>= ASIZE (Vccl_program_table
)
1122 || (slot
= AREF (Vccl_program_table
, prog_id
), !VECTORP (slot
))
1123 || !VECTORP (AREF (slot
, 1)))
1127 ccl_prog
= ccl_prog_stack_struct
[0].ccl_prog
;
1128 ic
= ccl_prog_stack_struct
[0].ic
;
1129 eof_ic
= ccl_prog_stack_struct
[0].eof_ic
;
1134 ccl_prog_stack_struct
[stack_idx
].ccl_prog
= ccl_prog
;
1135 ccl_prog_stack_struct
[stack_idx
].ic
= ic
;
1136 ccl_prog_stack_struct
[stack_idx
].eof_ic
= eof_ic
;
1138 ccl_prog
= XVECTOR (AREF (slot
, 1))->contents
;
1139 ic
= CCL_HEADER_MAIN
;
1140 eof_ic
= XFASTINT (ccl_prog
[CCL_HEADER_EOF
]);
1144 case CCL_WriteConstString
: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
1146 CCL_WRITE_CHAR (field1
);
1149 CCL_WRITE_STRING (field1
);
1150 ic
+= (field1
+ 2) / 3;
1154 case CCL_WriteArray
: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
1156 if ((unsigned int) i
< field1
)
1158 j
= XINT (ccl_prog
[ic
+ i
]);
1164 case CCL_End
: /* 0000000000000000000000XXXXX */
1168 ccl_prog
= ccl_prog_stack_struct
[stack_idx
].ccl_prog
;
1169 ic
= ccl_prog_stack_struct
[stack_idx
].ic
;
1170 eof_ic
= ccl_prog_stack_struct
[stack_idx
].eof_ic
;
1177 /* ccl->ic should points to this command code again to
1178 suppress further processing. */
1182 case CCL_ExprSelfConst
: /* 00000OPERATION000000rrrXXXXX */
1183 i
= XINT (ccl_prog
[ic
]);
1188 case CCL_ExprSelfReg
: /* 00000OPERATION000RRRrrrXXXXX */
1195 case CCL_PLUS
: reg
[rrr
] += i
; break;
1196 case CCL_MINUS
: reg
[rrr
] -= i
; break;
1197 case CCL_MUL
: reg
[rrr
] *= i
; break;
1198 case CCL_DIV
: reg
[rrr
] /= i
; break;
1199 case CCL_MOD
: reg
[rrr
] %= i
; break;
1200 case CCL_AND
: reg
[rrr
] &= i
; break;
1201 case CCL_OR
: reg
[rrr
] |= i
; break;
1202 case CCL_XOR
: reg
[rrr
] ^= i
; break;
1203 case CCL_LSH
: reg
[rrr
] <<= i
; break;
1204 case CCL_RSH
: reg
[rrr
] >>= i
; break;
1205 case CCL_LSH8
: reg
[rrr
] <<= 8; reg
[rrr
] |= i
; break;
1206 case CCL_RSH8
: reg
[7] = reg
[rrr
] & 0xFF; reg
[rrr
] >>= 8; break;
1207 case CCL_DIVMOD
: reg
[7] = reg
[rrr
] % i
; reg
[rrr
] /= i
; break;
1208 case CCL_LS
: reg
[rrr
] = reg
[rrr
] < i
; break;
1209 case CCL_GT
: reg
[rrr
] = reg
[rrr
] > i
; break;
1210 case CCL_EQ
: reg
[rrr
] = reg
[rrr
] == i
; break;
1211 case CCL_LE
: reg
[rrr
] = reg
[rrr
] <= i
; break;
1212 case CCL_GE
: reg
[rrr
] = reg
[rrr
] >= i
; break;
1213 case CCL_NE
: reg
[rrr
] = reg
[rrr
] != i
; break;
1214 default: CCL_INVALID_CMD
;
1218 case CCL_SetExprConst
: /* 00000OPERATION000RRRrrrXXXXX */
1220 j
= XINT (ccl_prog
[ic
]);
1222 jump_address
= ++ic
;
1225 case CCL_SetExprReg
: /* 00000OPERATIONRrrRRRrrrXXXXX */
1232 case CCL_ReadJumpCondExprConst
: /* A--D--D--R--E--S--S-rrrXXXXX */
1233 CCL_READ_CHAR (reg
[rrr
]);
1234 case CCL_JumpCondExprConst
: /* A--D--D--R--E--S--S-rrrXXXXX */
1236 op
= XINT (ccl_prog
[ic
]);
1237 jump_address
= ic
++ + ADDR
;
1238 j
= XINT (ccl_prog
[ic
]);
1243 case CCL_ReadJumpCondExprReg
: /* A--D--D--R--E--S--S-rrrXXXXX */
1244 CCL_READ_CHAR (reg
[rrr
]);
1245 case CCL_JumpCondExprReg
:
1247 op
= XINT (ccl_prog
[ic
]);
1248 jump_address
= ic
++ + ADDR
;
1249 j
= reg
[XINT (ccl_prog
[ic
])];
1256 case CCL_PLUS
: reg
[rrr
] = i
+ j
; break;
1257 case CCL_MINUS
: reg
[rrr
] = i
- j
; break;
1258 case CCL_MUL
: reg
[rrr
] = i
* j
; break;
1259 case CCL_DIV
: reg
[rrr
] = i
/ j
; break;
1260 case CCL_MOD
: reg
[rrr
] = i
% j
; break;
1261 case CCL_AND
: reg
[rrr
] = i
& j
; break;
1262 case CCL_OR
: reg
[rrr
] = i
| j
; break;
1263 case CCL_XOR
: reg
[rrr
] = i
^ j
;; break;
1264 case CCL_LSH
: reg
[rrr
] = i
<< j
; break;
1265 case CCL_RSH
: reg
[rrr
] = i
>> j
; break;
1266 case CCL_LSH8
: reg
[rrr
] = (i
<< 8) | j
; break;
1267 case CCL_RSH8
: reg
[rrr
] = i
>> 8; reg
[7] = i
& 0xFF; break;
1268 case CCL_DIVMOD
: reg
[rrr
] = i
/ j
; reg
[7] = i
% j
; break;
1269 case CCL_LS
: reg
[rrr
] = i
< j
; break;
1270 case CCL_GT
: reg
[rrr
] = i
> j
; break;
1271 case CCL_EQ
: reg
[rrr
] = i
== j
; break;
1272 case CCL_LE
: reg
[rrr
] = i
<= j
; break;
1273 case CCL_GE
: reg
[rrr
] = i
>= j
; break;
1274 case CCL_NE
: reg
[rrr
] = i
!= j
; break;
1275 case CCL_DECODE_SJIS
: DECODE_SJIS (i
, j
, reg
[rrr
], reg
[7]); break;
1276 case CCL_ENCODE_SJIS
: ENCODE_SJIS (i
, j
, reg
[rrr
], reg
[7]); break;
1277 default: CCL_INVALID_CMD
;
1280 if (code
== CCL_WriteExprConst
|| code
== CCL_WriteExprRegister
)
1293 case CCL_ReadMultibyteChar2
:
1300 goto ccl_read_multibyte_character_suspend
;
1303 if (!ccl
->multibyte
)
1306 if (!UNIBYTE_STR_AS_MULTIBYTE_P (src
, src_end
- src
, bytes
))
1308 reg
[RRR
] = CHARSET_8_BIT_CONTROL
;
1314 if (i
== '\n' && ccl
->eol_type
!= CODING_EOL_LF
)
1316 /* We are encoding. */
1317 if (ccl
->eol_type
== CODING_EOL_CRLF
)
1319 if (ccl
->cr_consumed
)
1320 ccl
->cr_consumed
= 0;
1323 ccl
->cr_consumed
= 1;
1331 reg
[RRR
] = CHARSET_ASCII
;
1337 reg
[RRR
] = CHARSET_ASCII
;
1339 else if (i
<= MAX_CHARSET_OFFICIAL_DIMENSION2
)
1341 int dimension
= BYTES_BY_CHAR_HEAD (i
) - 1;
1345 /* `i' is a leading code for an undefined charset. */
1346 reg
[RRR
] = CHARSET_8_BIT_GRAPHIC
;
1349 else if (src
+ dimension
> src_end
)
1350 goto ccl_read_multibyte_character_suspend
;
1354 i
= (*src
++ & 0x7F);
1358 reg
[rrr
] = ((i
<< 7) | (*src
++ & 0x7F));
1361 else if ((i
== LEADING_CODE_PRIVATE_11
)
1362 || (i
== LEADING_CODE_PRIVATE_12
))
1364 if ((src
+ 1) >= src_end
)
1365 goto ccl_read_multibyte_character_suspend
;
1367 reg
[rrr
] = (*src
++ & 0x7F);
1369 else if ((i
== LEADING_CODE_PRIVATE_21
)
1370 || (i
== LEADING_CODE_PRIVATE_22
))
1372 if ((src
+ 2) >= src_end
)
1373 goto ccl_read_multibyte_character_suspend
;
1375 i
= (*src
++ & 0x7F);
1376 reg
[rrr
] = ((i
<< 7) | (*src
& 0x7F));
1379 else if (i
== LEADING_CODE_8_BIT_CONTROL
)
1382 goto ccl_read_multibyte_character_suspend
;
1383 reg
[RRR
] = CHARSET_8_BIT_CONTROL
;
1384 reg
[rrr
] = (*src
++ - 0x20);
1388 reg
[RRR
] = CHARSET_8_BIT_GRAPHIC
;
1393 /* INVALID CODE. Return a single byte character. */
1394 reg
[RRR
] = CHARSET_ASCII
;
1399 ccl_read_multibyte_character_suspend
:
1400 if (src
<= src_end
&& !ccl
->multibyte
&& ccl
->last_block
)
1402 reg
[RRR
] = CHARSET_8_BIT_CONTROL
;
1407 if (ccl
->last_block
)
1414 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC
);
1418 case CCL_WriteMultibyteChar2
:
1419 i
= reg
[RRR
]; /* charset */
1420 if (i
== CHARSET_ASCII
1421 || i
== CHARSET_8_BIT_CONTROL
1422 || i
== CHARSET_8_BIT_GRAPHIC
)
1423 i
= reg
[rrr
] & 0xFF;
1424 else if (CHARSET_DIMENSION (i
) == 1)
1425 i
= ((i
- 0x70) << 7) | (reg
[rrr
] & 0x7F);
1426 else if (i
< MIN_CHARSET_PRIVATE_DIMENSION2
)
1427 i
= ((i
- 0x8F) << 14) | reg
[rrr
];
1429 i
= ((i
- 0xE0) << 14) | reg
[rrr
];
1431 CCL_WRITE_MULTIBYTE_CHAR (i
);
1435 case CCL_TranslateCharacter
:
1436 CCL_MAKE_CHAR (reg
[RRR
], reg
[rrr
], i
);
1437 op
= translate_char (GET_TRANSLATION_TABLE (reg
[Rrr
]),
1439 SPLIT_CHAR (op
, reg
[RRR
], i
, j
);
1446 case CCL_TranslateCharacterConstTbl
:
1447 op
= XINT (ccl_prog
[ic
]); /* table */
1449 CCL_MAKE_CHAR (reg
[RRR
], reg
[rrr
], i
);
1450 op
= translate_char (GET_TRANSLATION_TABLE (op
), i
, -1, 0, 0);
1451 SPLIT_CHAR (op
, reg
[RRR
], i
, j
);
1458 case CCL_LookupIntConstTbl
:
1459 op
= XINT (ccl_prog
[ic
]); /* table */
1462 struct Lisp_Hash_Table
*h
= GET_HASH_TABLE (op
);
1464 op
= hash_lookup (h
, make_number (reg
[RRR
]), NULL
);
1468 opl
= HASH_VALUE (h
, op
);
1469 if (!CHAR_VALID_P (XINT (opl
), 0))
1471 SPLIT_CHAR (XINT (opl
), reg
[RRR
], i
, j
);
1475 reg
[7] = 1; /* r7 true for success */
1482 case CCL_LookupCharConstTbl
:
1483 op
= XINT (ccl_prog
[ic
]); /* table */
1485 CCL_MAKE_CHAR (reg
[RRR
], reg
[rrr
], i
);
1487 struct Lisp_Hash_Table
*h
= GET_HASH_TABLE (op
);
1489 op
= hash_lookup (h
, make_number (i
), NULL
);
1493 opl
= HASH_VALUE (h
, op
);
1494 if (!INTEGERP (opl
))
1496 reg
[RRR
] = XINT (opl
);
1497 reg
[7] = 1; /* r7 true for success */
1504 case CCL_IterateMultipleMap
:
1506 Lisp_Object map
, content
, attrib
, value
;
1507 int point
, size
, fin_ic
;
1509 j
= XINT (ccl_prog
[ic
++]); /* number of maps. */
1512 if ((j
> reg
[RRR
]) && (j
>= 0))
1527 size
= ASIZE (Vcode_conversion_map_vector
);
1528 point
= XINT (ccl_prog
[ic
++]);
1529 if (point
>= size
) continue;
1530 map
= AREF (Vcode_conversion_map_vector
, point
);
1532 /* Check map varidity. */
1533 if (!CONSP (map
)) continue;
1535 if (!VECTORP (map
)) continue;
1537 if (size
<= 1) continue;
1539 content
= AREF (map
, 0);
1542 [STARTPOINT VAL1 VAL2 ...] or
1543 [t ELELMENT STARTPOINT ENDPOINT] */
1544 if (NUMBERP (content
))
1546 point
= XUINT (content
);
1547 point
= op
- point
+ 1;
1548 if (!((point
>= 1) && (point
< size
))) continue;
1549 content
= AREF (map
, point
);
1551 else if (EQ (content
, Qt
))
1553 if (size
!= 4) continue;
1554 if ((op
>= XUINT (AREF (map
, 2)))
1555 && (op
< XUINT (AREF (map
, 3))))
1556 content
= AREF (map
, 1);
1565 else if (NUMBERP (content
))
1568 reg
[rrr
] = XINT(content
);
1571 else if (EQ (content
, Qt
) || EQ (content
, Qlambda
))
1576 else if (CONSP (content
))
1578 attrib
= XCAR (content
);
1579 value
= XCDR (content
);
1580 if (!NUMBERP (attrib
) || !NUMBERP (value
))
1583 reg
[rrr
] = XUINT (value
);
1586 else if (SYMBOLP (content
))
1587 CCL_CALL_FOR_MAP_INSTRUCTION (content
, fin_ic
);
1597 case CCL_MapMultiple
:
1599 Lisp_Object map
, content
, attrib
, value
;
1600 int point
, size
, map_vector_size
;
1601 int map_set_rest_length
, fin_ic
;
1602 int current_ic
= this_ic
;
1604 /* inhibit recursive call on MapMultiple. */
1605 if (stack_idx_of_map_multiple
> 0)
1607 if (stack_idx_of_map_multiple
<= stack_idx
)
1609 stack_idx_of_map_multiple
= 0;
1610 mapping_stack_pointer
= mapping_stack
;
1615 mapping_stack_pointer
= mapping_stack
;
1616 stack_idx_of_map_multiple
= 0;
1618 map_set_rest_length
=
1619 XINT (ccl_prog
[ic
++]); /* number of maps and separators. */
1620 fin_ic
= ic
+ map_set_rest_length
;
1623 if ((map_set_rest_length
> reg
[RRR
]) && (reg
[RRR
] >= 0))
1627 map_set_rest_length
-= i
;
1633 mapping_stack_pointer
= mapping_stack
;
1637 if (mapping_stack_pointer
<= (mapping_stack
+ 1))
1639 /* Set up initial state. */
1640 mapping_stack_pointer
= mapping_stack
;
1641 PUSH_MAPPING_STACK (0, op
);
1646 /* Recover after calling other ccl program. */
1649 POP_MAPPING_STACK (map_set_rest_length
, orig_op
);
1650 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1654 /* Regard it as Qnil. */
1658 map_set_rest_length
--;
1661 /* Regard it as Qt. */
1665 map_set_rest_length
--;
1668 /* Regard it as Qlambda. */
1670 i
+= map_set_rest_length
;
1671 ic
+= map_set_rest_length
;
1672 map_set_rest_length
= 0;
1675 /* Regard it as normal mapping. */
1676 i
+= map_set_rest_length
;
1677 ic
+= map_set_rest_length
;
1678 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1682 map_vector_size
= ASIZE (Vcode_conversion_map_vector
);
1685 for (;map_set_rest_length
> 0;i
++, ic
++, map_set_rest_length
--)
1687 point
= XINT(ccl_prog
[ic
]);
1690 /* +1 is for including separator. */
1692 if (mapping_stack_pointer
1693 >= &mapping_stack
[MAX_MAP_SET_LEVEL
])
1695 PUSH_MAPPING_STACK (map_set_rest_length
- point
,
1697 map_set_rest_length
= point
;
1702 if (point
>= map_vector_size
) continue;
1703 map
= AREF (Vcode_conversion_map_vector
, point
);
1705 /* Check map varidity. */
1706 if (!CONSP (map
)) continue;
1708 if (!VECTORP (map
)) continue;
1710 if (size
<= 1) continue;
1712 content
= AREF (map
, 0);
1715 [STARTPOINT VAL1 VAL2 ...] or
1716 [t ELEMENT STARTPOINT ENDPOINT] */
1717 if (NUMBERP (content
))
1719 point
= XUINT (content
);
1720 point
= op
- point
+ 1;
1721 if (!((point
>= 1) && (point
< size
))) continue;
1722 content
= AREF (map
, point
);
1724 else if (EQ (content
, Qt
))
1726 if (size
!= 4) continue;
1727 if ((op
>= XUINT (AREF (map
, 2))) &&
1728 (op
< XUINT (AREF (map
, 3))))
1729 content
= AREF (map
, 1);
1740 if (NUMBERP (content
))
1742 op
= XINT (content
);
1743 i
+= map_set_rest_length
- 1;
1744 ic
+= map_set_rest_length
- 1;
1745 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1746 map_set_rest_length
++;
1748 else if (CONSP (content
))
1750 attrib
= XCAR (content
);
1751 value
= XCDR (content
);
1752 if (!NUMBERP (attrib
) || !NUMBERP (value
))
1755 i
+= map_set_rest_length
- 1;
1756 ic
+= map_set_rest_length
- 1;
1757 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1758 map_set_rest_length
++;
1760 else if (EQ (content
, Qt
))
1764 else if (EQ (content
, Qlambda
))
1766 i
+= map_set_rest_length
;
1767 ic
+= map_set_rest_length
;
1770 else if (SYMBOLP (content
))
1772 if (mapping_stack_pointer
1773 >= &mapping_stack
[MAX_MAP_SET_LEVEL
])
1775 PUSH_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1776 PUSH_MAPPING_STACK (map_set_rest_length
, op
);
1777 stack_idx_of_map_multiple
= stack_idx
+ 1;
1778 CCL_CALL_FOR_MAP_INSTRUCTION (content
, current_ic
);
1783 if (mapping_stack_pointer
<= (mapping_stack
+ 1))
1785 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1786 i
+= map_set_rest_length
;
1787 ic
+= map_set_rest_length
;
1788 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1798 Lisp_Object map
, attrib
, value
, content
;
1800 j
= XINT (ccl_prog
[ic
++]); /* map_id */
1802 if (j
>= ASIZE (Vcode_conversion_map_vector
))
1807 map
= AREF (Vcode_conversion_map_vector
, j
);
1820 point
= XUINT (AREF (map
, 0));
1821 point
= op
- point
+ 1;
1824 (!((point
>= 1) && (point
< size
))))
1829 content
= AREF (map
, point
);
1832 else if (NUMBERP (content
))
1833 reg
[rrr
] = XINT (content
);
1834 else if (EQ (content
, Qt
));
1835 else if (CONSP (content
))
1837 attrib
= XCAR (content
);
1838 value
= XCDR (content
);
1839 if (!NUMBERP (attrib
) || !NUMBERP (value
))
1841 reg
[rrr
] = XUINT(value
);
1844 else if (SYMBOLP (content
))
1845 CCL_CALL_FOR_MAP_INSTRUCTION (content
, ic
);
1863 /* The suppress_error member is set when e.g. a CCL-based coding
1864 system is used for terminal output. */
1865 if (!ccl
->suppress_error
&& destination
)
1867 /* We can insert an error message only if DESTINATION is
1868 specified and we still have a room to store the message
1876 switch (ccl
->status
)
1878 case CCL_STAT_INVALID_CMD
:
1879 sprintf(msg
, "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
1880 code
& 0x1F, code
, this_ic
);
1883 int i
= ccl_backtrace_idx
- 1;
1886 msglen
= strlen (msg
);
1887 if (dst
+ msglen
<= (dst_bytes
? dst_end
: src
))
1889 bcopy (msg
, dst
, msglen
);
1893 for (j
= 0; j
< CCL_DEBUG_BACKTRACE_LEN
; j
++, i
--)
1895 if (i
< 0) i
= CCL_DEBUG_BACKTRACE_LEN
- 1;
1896 if (ccl_backtrace_table
[i
] == 0)
1898 sprintf(msg
, " %d", ccl_backtrace_table
[i
]);
1899 msglen
= strlen (msg
);
1900 if (dst
+ msglen
> (dst_bytes
? dst_end
: src
))
1902 bcopy (msg
, dst
, msglen
);
1911 sprintf(msg
, "\nCCL: Quited.");
1915 sprintf(msg
, "\nCCL: Unknown error type (%d)", ccl
->status
);
1918 msglen
= strlen (msg
);
1919 if (dst
+ msglen
<= (dst_bytes
? dst_end
: src
))
1921 bcopy (msg
, dst
, msglen
);
1925 if (ccl
->status
== CCL_STAT_INVALID_CMD
)
1927 #if 0 /* If the remaining bytes contain 0x80..0x9F, copying them
1928 results in an invalid multibyte sequence. */
1930 /* Copy the remaining source data. */
1931 int i
= src_end
- src
;
1932 if (dst_bytes
&& (dst_end
- dst
) < i
)
1934 bcopy (src
, dst
, i
);
1938 /* Signal that we've consumed everything. */
1946 ccl
->stack_idx
= stack_idx
;
1947 ccl
->prog
= ccl_prog
;
1948 ccl
->eight_bit_control
= (extra_bytes
> 1);
1950 *consumed
= src
- source
;
1951 return (dst
? dst
- destination
: 0);
1954 /* Resolve symbols in the specified CCL code (Lisp vector). This
1955 function converts symbols of code conversion maps and character
1956 translation tables embeded in the CCL code into their ID numbers.
1958 The return value is a vector (CCL itself or a new vector in which
1959 all symbols are resolved), Qt if resolving of some symbol failed,
1960 or nil if CCL contains invalid data. */
1963 resolve_symbol_ccl_program (ccl
)
1966 int i
, veclen
, unresolved
= 0;
1967 Lisp_Object result
, contents
, val
;
1970 veclen
= ASIZE (result
);
1972 for (i
= 0; i
< veclen
; i
++)
1974 contents
= AREF (result
, i
);
1975 if (INTEGERP (contents
))
1977 else if (CONSP (contents
)
1978 && SYMBOLP (XCAR (contents
))
1979 && SYMBOLP (XCDR (contents
)))
1981 /* This is the new style for embedding symbols. The form is
1982 (SYMBOL . PROPERTY). (get SYMBOL PROPERTY) should give
1985 if (EQ (result
, ccl
))
1986 result
= Fcopy_sequence (ccl
);
1988 val
= Fget (XCAR (contents
), XCDR (contents
));
1990 AREF (result
, i
) = val
;
1995 else if (SYMBOLP (contents
))
1997 /* This is the old style for embedding symbols. This style
1998 may lead to a bug if, for instance, a translation table
1999 and a code conversion map have the same name. */
2000 if (EQ (result
, ccl
))
2001 result
= Fcopy_sequence (ccl
);
2003 val
= Fget (contents
, Qtranslation_table_id
);
2005 AREF (result
, i
) = val
;
2008 val
= Fget (contents
, Qcode_conversion_map_id
);
2010 AREF (result
, i
) = val
;
2013 val
= Fget (contents
, Qccl_program_idx
);
2015 AREF (result
, i
) = val
;
2025 return (unresolved
? Qt
: result
);
2028 /* Return the compiled code (vector) of CCL program CCL_PROG.
2029 CCL_PROG is a name (symbol) of the program or already compiled
2030 code. If necessary, resolve symbols in the compiled code to index
2031 numbers. If we failed to get the compiled code or to resolve
2032 symbols, return Qnil. */
2035 ccl_get_compiled_code (ccl_prog
, idx
)
2036 Lisp_Object ccl_prog
;
2039 Lisp_Object val
, slot
;
2041 if (VECTORP (ccl_prog
))
2043 val
= resolve_symbol_ccl_program (ccl_prog
);
2045 return (VECTORP (val
) ? val
: Qnil
);
2047 if (!SYMBOLP (ccl_prog
))
2050 val
= Fget (ccl_prog
, Qccl_program_idx
);
2052 || XINT (val
) >= ASIZE (Vccl_program_table
))
2054 slot
= AREF (Vccl_program_table
, XINT (val
));
2055 if (! VECTORP (slot
)
2056 || ASIZE (slot
) != 4
2057 || ! VECTORP (AREF (slot
, 1)))
2060 if (NILP (AREF (slot
, 2)))
2062 val
= resolve_symbol_ccl_program (AREF (slot
, 1));
2063 if (! VECTORP (val
))
2065 AREF (slot
, 1) = val
;
2066 AREF (slot
, 2) = Qt
;
2068 return AREF (slot
, 1);
2071 /* Setup fields of the structure pointed by CCL appropriately for the
2072 execution of CCL program CCL_PROG. CCL_PROG is the name (symbol)
2073 of the CCL program or the already compiled code (vector).
2074 Return 0 if we succeed this setup, else return -1.
2076 If CCL_PROG is nil, we just reset the structure pointed by CCL. */
2078 setup_ccl_program (ccl
, ccl_prog
)
2079 struct ccl_program
*ccl
;
2080 Lisp_Object ccl_prog
;
2084 if (! NILP (ccl_prog
))
2086 struct Lisp_Vector
*vp
;
2088 ccl_prog
= ccl_get_compiled_code (ccl_prog
, &ccl
->idx
);
2089 if (! VECTORP (ccl_prog
))
2091 vp
= XVECTOR (ccl_prog
);
2092 ccl
->size
= vp
->size
;
2093 ccl
->prog
= vp
->contents
;
2094 ccl
->eof_ic
= XINT (vp
->contents
[CCL_HEADER_EOF
]);
2095 ccl
->buf_magnification
= XINT (vp
->contents
[CCL_HEADER_BUF_MAG
]);
2100 slot
= AREF (Vccl_program_table
, ccl
->idx
);
2101 ASET (slot
, 3, Qnil
);
2104 ccl
->ic
= CCL_HEADER_MAIN
;
2105 for (i
= 0; i
< 8; i
++)
2107 ccl
->last_block
= 0;
2108 ccl
->private_state
= 0;
2111 ccl
->eol_type
= CODING_EOL_LF
;
2112 ccl
->suppress_error
= 0;
2113 ccl
->eight_bit_control
= 0;
2118 /* Check if CCL is updated or not. If not, re-setup members of CCL. */
2121 check_ccl_update (ccl
)
2122 struct ccl_program
*ccl
;
2124 Lisp_Object slot
, ccl_prog
;
2128 slot
= AREF (Vccl_program_table
, ccl
->idx
);
2129 if (NILP (AREF (slot
, 3)))
2131 ccl_prog
= ccl_get_compiled_code (AREF (slot
, 0), &ccl
->idx
);
2132 if (! VECTORP (ccl_prog
))
2134 ccl
->size
= ASIZE (ccl_prog
);
2135 ccl
->prog
= XVECTOR (ccl_prog
)->contents
;
2136 ccl
->eof_ic
= XINT (AREF (ccl_prog
, CCL_HEADER_EOF
));
2137 ccl
->buf_magnification
= XINT (AREF (ccl_prog
, CCL_HEADER_BUF_MAG
));
2138 ASET (slot
, 3, Qnil
);
2143 DEFUN ("ccl-program-p", Fccl_program_p
, Sccl_program_p
, 1, 1, 0,
2144 doc
: /* Return t if OBJECT is a CCL program name or a compiled CCL program code.
2145 See the documentation of `define-ccl-program' for the detail of CCL program. */)
2151 if (VECTORP (object
))
2153 val
= resolve_symbol_ccl_program (object
);
2154 return (VECTORP (val
) ? Qt
: Qnil
);
2156 if (!SYMBOLP (object
))
2159 val
= Fget (object
, Qccl_program_idx
);
2160 return ((! NATNUMP (val
)
2161 || XINT (val
) >= ASIZE (Vccl_program_table
))
2165 DEFUN ("ccl-execute", Fccl_execute
, Sccl_execute
, 2, 2, 0,
2166 doc
: /* Execute CCL-PROGRAM with registers initialized by REGISTERS.
2168 CCL-PROGRAM is a CCL program name (symbol)
2169 or compiled code generated by `ccl-compile' (for backward compatibility.
2170 In the latter case, the execution overhead is bigger than in the former).
2171 No I/O commands should appear in CCL-PROGRAM.
2173 REGISTERS is a vector of [R0 R1 ... R7] where RN is an initial value
2174 for the Nth register.
2176 As side effect, each element of REGISTERS holds the value of
2177 the corresponding register after the execution.
2179 See the documentation of `define-ccl-program' for a definition of CCL
2182 Lisp_Object ccl_prog
, reg
;
2184 struct ccl_program ccl
;
2187 if (setup_ccl_program (&ccl
, ccl_prog
) < 0)
2188 error ("Invalid CCL program");
2191 if (ASIZE (reg
) != 8)
2192 error ("Length of vector REGISTERS is not 8");
2194 for (i
= 0; i
< 8; i
++)
2195 ccl
.reg
[i
] = (INTEGERP (AREF (reg
, i
))
2196 ? XINT (AREF (reg
, i
))
2199 ccl_driver (&ccl
, (unsigned char *)0, (unsigned char *)0, 0, 0, (int *)0);
2201 if (ccl
.status
!= CCL_STAT_SUCCESS
)
2202 error ("Error in CCL program at %dth code", ccl
.ic
);
2204 for (i
= 0; i
< 8; i
++)
2205 XSETINT (AREF (reg
, i
), ccl
.reg
[i
]);
2209 DEFUN ("ccl-execute-on-string", Fccl_execute_on_string
, Sccl_execute_on_string
,
2211 doc
: /* Execute CCL-PROGRAM with initial STATUS on STRING.
2213 CCL-PROGRAM is a symbol registered by `register-ccl-program',
2214 or a compiled code generated by `ccl-compile' (for backward compatibility,
2215 in this case, the execution is slower).
2217 Read buffer is set to STRING, and write buffer is allocated automatically.
2219 STATUS is a vector of [R0 R1 ... R7 IC], where
2220 R0..R7 are initial values of corresponding registers,
2221 IC is the instruction counter specifying from where to start the program.
2222 If R0..R7 are nil, they are initialized to 0.
2223 If IC is nil, it is initialized to head of the CCL program.
2225 If optional 4th arg CONTINUE is non-nil, keep IC on read operation
2226 when read buffer is exausted, else, IC is always set to the end of
2227 CCL-PROGRAM on exit.
2229 It returns the contents of write buffer as a string,
2230 and as side effect, STATUS is updated.
2231 If the optional 5th arg UNIBYTE-P is non-nil, the returned string
2232 is a unibyte string. By default it is a multibyte string.
2234 See the documentation of `define-ccl-program' for the detail of CCL program.
2235 usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBYTE-P) */)
2236 (ccl_prog
, status
, str
, contin
, unibyte_p
)
2237 Lisp_Object ccl_prog
, status
, str
, contin
, unibyte_p
;
2240 struct ccl_program ccl
;
2244 struct gcpro gcpro1
, gcpro2
;
2246 if (setup_ccl_program (&ccl
, ccl_prog
) < 0)
2247 error ("Invalid CCL program");
2249 CHECK_VECTOR (status
);
2250 if (ASIZE (status
) != 9)
2251 error ("Length of vector STATUS is not 9");
2254 GCPRO2 (status
, str
);
2256 for (i
= 0; i
< 8; i
++)
2258 if (NILP (AREF (status
, i
)))
2259 XSETINT (AREF (status
, i
), 0);
2260 if (INTEGERP (AREF (status
, i
)))
2261 ccl
.reg
[i
] = XINT (AREF (status
, i
));
2263 if (INTEGERP (AREF (status
, i
)))
2265 i
= XFASTINT (AREF (status
, 8));
2266 if (ccl
.ic
< i
&& i
< ccl
.size
)
2269 outbufsize
= SBYTES (str
) * ccl
.buf_magnification
+ 256;
2270 outbuf
= (char *) xmalloc (outbufsize
);
2271 ccl
.last_block
= NILP (contin
);
2272 ccl
.multibyte
= STRING_MULTIBYTE (str
);
2273 produced
= ccl_driver (&ccl
, SDATA (str
), outbuf
,
2274 SBYTES (str
), outbufsize
, (int *) 0);
2275 for (i
= 0; i
< 8; i
++)
2276 ASET (status
, i
, make_number (ccl
.reg
[i
]));
2277 ASET (status
, 8, make_number (ccl
.ic
));
2280 if (NILP (unibyte_p
))
2284 produced
= str_as_multibyte (outbuf
, outbufsize
, produced
, &nchars
);
2285 val
= make_multibyte_string (outbuf
, nchars
, produced
);
2288 val
= make_unibyte_string (outbuf
, produced
);
2291 if (ccl
.status
== CCL_STAT_SUSPEND_BY_DST
)
2292 error ("Output buffer for the CCL programs overflow");
2293 if (ccl
.status
!= CCL_STAT_SUCCESS
2294 && ccl
.status
!= CCL_STAT_SUSPEND_BY_SRC
)
2295 error ("Error in CCL program at %dth code", ccl
.ic
);
2300 DEFUN ("register-ccl-program", Fregister_ccl_program
, Sregister_ccl_program
,
2302 doc
: /* Register CCL program CCL-PROG as NAME in `ccl-program-table'.
2303 CCL-PROG should be a compiled CCL program (vector), or nil.
2304 If it is nil, just reserve NAME as a CCL program name.
2305 Return index number of the registered CCL program. */)
2307 Lisp_Object name
, ccl_prog
;
2309 int len
= ASIZE (Vccl_program_table
);
2311 Lisp_Object resolved
;
2313 CHECK_SYMBOL (name
);
2315 if (!NILP (ccl_prog
))
2317 CHECK_VECTOR (ccl_prog
);
2318 resolved
= resolve_symbol_ccl_program (ccl_prog
);
2319 if (NILP (resolved
))
2320 error ("Error in CCL program");
2321 if (VECTORP (resolved
))
2323 ccl_prog
= resolved
;
2330 for (idx
= 0; idx
< len
; idx
++)
2334 slot
= AREF (Vccl_program_table
, idx
);
2335 if (!VECTORP (slot
))
2336 /* This is the first unsed slot. Register NAME here. */
2339 if (EQ (name
, AREF (slot
, 0)))
2341 /* Update this slot. */
2342 ASET (slot
, 1, ccl_prog
);
2343 ASET (slot
, 2, resolved
);
2345 return make_number (idx
);
2351 /* Extend the table. */
2352 Lisp_Object new_table
;
2355 new_table
= Fmake_vector (make_number (len
* 2), Qnil
);
2356 for (j
= 0; j
< len
; j
++)
2357 ASET (new_table
, j
, AREF (Vccl_program_table
, j
));
2358 Vccl_program_table
= new_table
;
2364 elt
= Fmake_vector (make_number (4), Qnil
);
2365 ASET (elt
, 0, name
);
2366 ASET (elt
, 1, ccl_prog
);
2367 ASET (elt
, 2, resolved
);
2369 ASET (Vccl_program_table
, idx
, elt
);
2372 Fput (name
, Qccl_program_idx
, make_number (idx
));
2373 return make_number (idx
);
2376 /* Register code conversion map.
2377 A code conversion map consists of numbers, Qt, Qnil, and Qlambda.
2378 The first element is the start code point.
2379 The other elements are mapped numbers.
2380 Symbol t means to map to an original number before mapping.
2381 Symbol nil means that the corresponding element is empty.
2382 Symbol lambda means to terminate mapping here.
2385 DEFUN ("register-code-conversion-map", Fregister_code_conversion_map
,
2386 Sregister_code_conversion_map
,
2388 doc
: /* Register SYMBOL as code conversion map MAP.
2389 Return index number of the registered map. */)
2391 Lisp_Object symbol
, map
;
2393 int len
= ASIZE (Vcode_conversion_map_vector
);
2397 CHECK_SYMBOL (symbol
);
2400 for (i
= 0; i
< len
; i
++)
2402 Lisp_Object slot
= AREF (Vcode_conversion_map_vector
, i
);
2407 if (EQ (symbol
, XCAR (slot
)))
2409 index
= make_number (i
);
2410 XSETCDR (slot
, map
);
2411 Fput (symbol
, Qcode_conversion_map
, map
);
2412 Fput (symbol
, Qcode_conversion_map_id
, index
);
2419 Lisp_Object new_vector
= Fmake_vector (make_number (len
* 2), Qnil
);
2422 for (j
= 0; j
< len
; j
++)
2423 AREF (new_vector
, j
)
2424 = AREF (Vcode_conversion_map_vector
, j
);
2425 Vcode_conversion_map_vector
= new_vector
;
2428 index
= make_number (i
);
2429 Fput (symbol
, Qcode_conversion_map
, map
);
2430 Fput (symbol
, Qcode_conversion_map_id
, index
);
2431 AREF (Vcode_conversion_map_vector
, i
) = Fcons (symbol
, map
);
2439 staticpro (&Vccl_program_table
);
2440 Vccl_program_table
= Fmake_vector (make_number (32), Qnil
);
2442 Qccl_program
= intern ("ccl-program");
2443 staticpro (&Qccl_program
);
2445 Qccl_program_idx
= intern ("ccl-program-idx");
2446 staticpro (&Qccl_program_idx
);
2448 Qcode_conversion_map
= intern ("code-conversion-map");
2449 staticpro (&Qcode_conversion_map
);
2451 Qcode_conversion_map_id
= intern ("code-conversion-map-id");
2452 staticpro (&Qcode_conversion_map_id
);
2454 DEFVAR_LISP ("code-conversion-map-vector", &Vcode_conversion_map_vector
,
2455 doc
: /* Vector of code conversion maps. */);
2456 Vcode_conversion_map_vector
= Fmake_vector (make_number (16), Qnil
);
2458 DEFVAR_LISP ("font-ccl-encoder-alist", &Vfont_ccl_encoder_alist
,
2459 doc
: /* Alist of fontname patterns vs corresponding CCL program.
2460 Each element looks like (REGEXP . CCL-CODE),
2461 where CCL-CODE is a compiled CCL program.
2462 When a font whose name matches REGEXP is used for displaying a character,
2463 CCL-CODE is executed to calculate the code point in the font
2464 from the charset number and position code(s) of the character which are set
2465 in CCL registers R0, R1, and R2 before the execution.
2466 The code point in the font is set in CCL registers R1 and R2
2467 when the execution terminated.
2468 If the font is single-byte font, the register R2 is not used. */);
2469 Vfont_ccl_encoder_alist
= Qnil
;
2471 DEFVAR_LISP ("translation-hash-table-vector", &Vtranslation_hash_table_vector
,
2472 doc
: /* Vector containing all translation hash tables ever defined.
2473 Comprises pairs (SYMBOL . TABLE) where SYMBOL and TABLE were set up by calls
2474 to `define-translation-hash-table'. The vector is indexed by the table id
2476 Vtranslation_hash_table_vector
= Qnil
;
2478 defsubr (&Sccl_program_p
);
2479 defsubr (&Sccl_execute
);
2480 defsubr (&Sccl_execute_on_string
);
2481 defsubr (&Sregister_ccl_program
);
2482 defsubr (&Sregister_code_conversion_map
);
2485 /* arch-tag: bb9a37be-68ce-4576-8d3d-15d750e4a860
2486 (do not change this comment) */