1 /* CCL (Code Conversion Language) interpreter.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 Free Software Foundation, Inc.
4 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 National Institute of Advanced Industrial Science and Technology (AIST)
7 Registration Number H14PRO021
9 This file is part of GNU Emacs.
11 GNU Emacs is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3, or (at your option)
16 GNU Emacs is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GNU Emacs; see the file COPYING. If not, write to
23 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA. */
35 /* This contains all code conversion map available to CCL. */
36 Lisp_Object Vcode_conversion_map_vector
;
38 /* Alist of fontname patterns vs corresponding CCL program. */
39 Lisp_Object Vfont_ccl_encoder_alist
;
41 /* This symbol is a property which assocates with ccl program vector.
42 Ex: (get 'ccl-big5-encoder 'ccl-program) returns ccl program vector. */
43 Lisp_Object Qccl_program
;
45 /* These symbols are properties which associate with code conversion
46 map and their ID respectively. */
47 Lisp_Object Qcode_conversion_map
;
48 Lisp_Object Qcode_conversion_map_id
;
50 /* Symbols of ccl program have this property, a value of the property
51 is an index for Vccl_protram_table. */
52 Lisp_Object Qccl_program_idx
;
54 /* Table of registered CCL programs. Each element is a vector of
55 NAME, CCL_PROG, RESOLVEDP, and UPDATEDP, where NAME (symbol) is the
56 name of the program, CCL_PROG (vector) is the compiled code of the
57 program, RESOLVEDP (t or nil) is the flag to tell if symbols in
58 CCL_PROG is already resolved to index numbers or not, UPDATEDP (t
59 or nil) is the flat to tell if the CCL program is updated after it
61 Lisp_Object Vccl_program_table
;
63 /* Vector of registered hash tables for translation. */
64 Lisp_Object Vtranslation_hash_table_vector
;
66 /* Return a hash table of id number ID. */
67 #define GET_HASH_TABLE(id) \
68 (XHASH_TABLE (XCDR(XVECTOR(Vtranslation_hash_table_vector)->contents[(id)])))
70 /* CCL (Code Conversion Language) is a simple language which has
71 operations on one input buffer, one output buffer, and 7 registers.
72 The syntax of CCL is described in `ccl.el'. Emacs Lisp function
73 `ccl-compile' compiles a CCL program and produces a CCL code which
74 is a vector of integers. The structure of this vector is as
75 follows: The 1st element: buffer-magnification, a factor for the
76 size of output buffer compared with the size of input buffer. The
77 2nd element: address of CCL code to be executed when encountered
78 with end of input stream. The 3rd and the remaining elements: CCL
81 /* Header of CCL compiled code */
82 #define CCL_HEADER_BUF_MAG 0
83 #define CCL_HEADER_EOF 1
84 #define CCL_HEADER_MAIN 2
86 /* CCL code is a sequence of 28-bit non-negative integers (i.e. the
87 MSB is always 0), each contains CCL command and/or arguments in the
90 |----------------- integer (28-bit) ------------------|
91 |------- 17-bit ------|- 3-bit --|- 3-bit --|- 5-bit -|
92 |--constant argument--|-register-|-register-|-command-|
93 ccccccccccccccccc RRR rrr XXXXX
95 |------- relative address -------|-register-|-command-|
96 cccccccccccccccccccc rrr XXXXX
98 |------------- constant or other args ----------------|
99 cccccccccccccccccccccccccccc
101 where, `cc...c' is a non-negative integer indicating constant value
102 (the left most `c' is always 0) or an absolute jump address, `RRR'
103 and `rrr' are CCL register number, `XXXXX' is one of the following
108 Each comment fields shows one or more lines for command syntax and
109 the following lines for semantics of the command. In semantics, IC
110 stands for Instruction Counter. */
112 #define CCL_SetRegister 0x00 /* Set register a register value:
113 1:00000000000000000RRRrrrXXXXX
114 ------------------------------
118 #define CCL_SetShortConst 0x01 /* Set register a short constant value:
119 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
120 ------------------------------
121 reg[rrr] = CCCCCCCCCCCCCCCCCCC;
124 #define CCL_SetConst 0x02 /* Set register a constant value:
125 1:00000000000000000000rrrXXXXX
127 ------------------------------
132 #define CCL_SetArray 0x03 /* Set register an element of array:
133 1:CCCCCCCCCCCCCCCCCRRRrrrXXXXX
137 ------------------------------
138 if (0 <= reg[RRR] < CC..C)
139 reg[rrr] = ELEMENT[reg[RRR]];
143 #define CCL_Jump 0x04 /* Jump:
144 1:A--D--D--R--E--S--S-000XXXXX
145 ------------------------------
149 /* Note: If CC..C is greater than 0, the second code is omitted. */
151 #define CCL_JumpCond 0x05 /* Jump conditional:
152 1:A--D--D--R--E--S--S-rrrXXXXX
153 ------------------------------
159 #define CCL_WriteRegisterJump 0x06 /* Write register and jump:
160 1:A--D--D--R--E--S--S-rrrXXXXX
161 ------------------------------
166 #define CCL_WriteRegisterReadJump 0x07 /* Write register, read, and jump:
167 1:A--D--D--R--E--S--S-rrrXXXXX
168 2:A--D--D--R--E--S--S-rrrYYYYY
169 -----------------------------
175 /* Note: If read is suspended, the resumed execution starts from the
176 second code (YYYYY == CCL_ReadJump). */
178 #define CCL_WriteConstJump 0x08 /* Write constant and jump:
179 1:A--D--D--R--E--S--S-000XXXXX
181 ------------------------------
186 #define CCL_WriteConstReadJump 0x09 /* Write constant, read, and jump:
187 1:A--D--D--R--E--S--S-rrrXXXXX
189 3:A--D--D--R--E--S--S-rrrYYYYY
190 -----------------------------
196 /* Note: If read is suspended, the resumed execution starts from the
197 second code (YYYYY == CCL_ReadJump). */
199 #define CCL_WriteStringJump 0x0A /* Write string and jump:
200 1:A--D--D--R--E--S--S-000XXXXX
202 3:0000STRIN[0]STRIN[1]STRIN[2]
204 ------------------------------
205 write_string (STRING, LENGTH);
209 #define CCL_WriteArrayReadJump 0x0B /* Write an array element, read, and jump:
210 1:A--D--D--R--E--S--S-rrrXXXXX
215 N:A--D--D--R--E--S--S-rrrYYYYY
216 ------------------------------
217 if (0 <= reg[rrr] < LENGTH)
218 write (ELEMENT[reg[rrr]]);
219 IC += LENGTH + 2; (... pointing at N+1)
223 /* Note: If read is suspended, the resumed execution starts from the
224 Nth code (YYYYY == CCL_ReadJump). */
226 #define CCL_ReadJump 0x0C /* Read and jump:
227 1:A--D--D--R--E--S--S-rrrYYYYY
228 -----------------------------
233 #define CCL_Branch 0x0D /* Jump by branch table:
234 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
235 2:A--D--D--R--E-S-S[0]000XXXXX
236 3:A--D--D--R--E-S-S[1]000XXXXX
238 ------------------------------
239 if (0 <= reg[rrr] < CC..C)
240 IC += ADDRESS[reg[rrr]];
242 IC += ADDRESS[CC..C];
245 #define CCL_ReadRegister 0x0E /* Read bytes into registers:
246 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
247 2:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
249 ------------------------------
254 #define CCL_WriteExprConst 0x0F /* write result of expression:
255 1:00000OPERATION000RRR000XXXXX
257 ------------------------------
258 write (reg[RRR] OPERATION CONSTANT);
262 /* Note: If the Nth read is suspended, the resumed execution starts
263 from the Nth code. */
265 #define CCL_ReadBranch 0x10 /* Read one byte into a register,
266 and jump by branch table:
267 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
268 2:A--D--D--R--E-S-S[0]000XXXXX
269 3:A--D--D--R--E-S-S[1]000XXXXX
271 ------------------------------
273 if (0 <= reg[rrr] < CC..C)
274 IC += ADDRESS[reg[rrr]];
276 IC += ADDRESS[CC..C];
279 #define CCL_WriteRegister 0x11 /* Write registers:
280 1:CCCCCCCCCCCCCCCCCCCrrrXXXXX
281 2:CCCCCCCCCCCCCCCCCCCrrrXXXXX
283 ------------------------------
289 /* Note: If the Nth write is suspended, the resumed execution
290 starts from the Nth code. */
292 #define CCL_WriteExprRegister 0x12 /* Write result of expression
293 1:00000OPERATIONRrrRRR000XXXXX
294 ------------------------------
295 write (reg[RRR] OPERATION reg[Rrr]);
298 #define CCL_Call 0x13 /* Call the CCL program whose ID is
300 1:CCCCCCCCCCCCCCCCCCCCFFFXXXXX
301 [2:00000000cccccccccccccccccccc]
302 ------------------------------
310 #define CCL_WriteConstString 0x14 /* Write a constant or a string:
311 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
312 [2:0000STRIN[0]STRIN[1]STRIN[2]]
314 -----------------------------
318 write_string (STRING, CC..C);
319 IC += (CC..C + 2) / 3;
322 #define CCL_WriteArray 0x15 /* Write an element of array:
323 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
327 ------------------------------
328 if (0 <= reg[rrr] < CC..C)
329 write (ELEMENT[reg[rrr]]);
333 #define CCL_End 0x16 /* Terminate:
334 1:00000000000000000000000XXXXX
335 ------------------------------
339 /* The following two codes execute an assignment arithmetic/logical
340 operation. The form of the operation is like REG OP= OPERAND. */
342 #define CCL_ExprSelfConst 0x17 /* REG OP= constant:
343 1:00000OPERATION000000rrrXXXXX
345 ------------------------------
346 reg[rrr] OPERATION= CONSTANT;
349 #define CCL_ExprSelfReg 0x18 /* REG1 OP= REG2:
350 1:00000OPERATION000RRRrrrXXXXX
351 ------------------------------
352 reg[rrr] OPERATION= reg[RRR];
355 /* The following codes execute an arithmetic/logical operation. The
356 form of the operation is like REG_X = REG_Y OP OPERAND2. */
358 #define CCL_SetExprConst 0x19 /* REG_X = REG_Y OP constant:
359 1:00000OPERATION000RRRrrrXXXXX
361 ------------------------------
362 reg[rrr] = reg[RRR] OPERATION CONSTANT;
366 #define CCL_SetExprReg 0x1A /* REG1 = REG2 OP REG3:
367 1:00000OPERATIONRrrRRRrrrXXXXX
368 ------------------------------
369 reg[rrr] = reg[RRR] OPERATION reg[Rrr];
372 #define CCL_JumpCondExprConst 0x1B /* Jump conditional according to
373 an operation on constant:
374 1:A--D--D--R--E--S--S-rrrXXXXX
377 -----------------------------
378 reg[7] = reg[rrr] OPERATION CONSTANT;
385 #define CCL_JumpCondExprReg 0x1C /* Jump conditional according to
386 an operation on register:
387 1:A--D--D--R--E--S--S-rrrXXXXX
390 -----------------------------
391 reg[7] = reg[rrr] OPERATION reg[RRR];
398 #define CCL_ReadJumpCondExprConst 0x1D /* Read and jump conditional according
399 to an operation on constant:
400 1:A--D--D--R--E--S--S-rrrXXXXX
403 -----------------------------
405 reg[7] = reg[rrr] OPERATION CONSTANT;
412 #define CCL_ReadJumpCondExprReg 0x1E /* Read and jump conditional according
413 to an operation on register:
414 1:A--D--D--R--E--S--S-rrrXXXXX
417 -----------------------------
419 reg[7] = reg[rrr] OPERATION reg[RRR];
426 #define CCL_Extension 0x1F /* Extended CCL code
427 1:ExtendedCOMMNDRrrRRRrrrXXXXX
430 ------------------------------
431 extended_command (rrr,RRR,Rrr,ARGS)
435 Here after, Extended CCL Instructions.
436 Bit length of extended command is 14.
437 Therefore, the instruction code range is 0..16384(0x3fff).
440 /* Read a multibyte characeter.
441 A code point is stored into reg[rrr]. A charset ID is stored into
444 #define CCL_ReadMultibyteChar2 0x00 /* Read Multibyte Character
445 1:ExtendedCOMMNDRrrRRRrrrXXXXX */
447 /* Write a multibyte character.
448 Write a character whose code point is reg[rrr] and the charset ID
451 #define CCL_WriteMultibyteChar2 0x01 /* Write Multibyte Character
452 1:ExtendedCOMMNDRrrRRRrrrXXXXX */
454 /* Translate a character whose code point is reg[rrr] and the charset
455 ID is reg[RRR] by a translation table whose ID is reg[Rrr].
457 A translated character is set in reg[rrr] (code point) and reg[RRR]
460 #define CCL_TranslateCharacter 0x02 /* Translate a multibyte character
461 1:ExtendedCOMMNDRrrRRRrrrXXXXX */
463 /* Translate a character whose code point is reg[rrr] and the charset
464 ID is reg[RRR] by a translation table whose ID is ARGUMENT.
466 A translated character is set in reg[rrr] (code point) and reg[RRR]
469 #define CCL_TranslateCharacterConstTbl 0x03 /* Translate a multibyte character
470 1:ExtendedCOMMNDRrrRRRrrrXXXXX
471 2:ARGUMENT(Translation Table ID)
474 /* Iterate looking up MAPs for reg[rrr] starting from the Nth (N =
475 reg[RRR]) MAP until some value is found.
477 Each MAP is a Lisp vector whose element is number, nil, t, or
479 If the element is nil, ignore the map and proceed to the next map.
480 If the element is t or lambda, finish without changing reg[rrr].
481 If the element is a number, set reg[rrr] to the number and finish.
483 Detail of the map structure is descibed in the comment for
484 CCL_MapMultiple below. */
486 #define CCL_IterateMultipleMap 0x10 /* Iterate multiple maps
487 1:ExtendedCOMMNDXXXRRRrrrXXXXX
494 /* Map the code in reg[rrr] by MAPs starting from the Nth (N =
497 MAPs are supplied in the succeeding CCL codes as follows:
499 When CCL program gives this nested structure of map to this command:
502 (MAP-ID121 MAP-ID122 MAP-ID123)
505 (MAP-ID211 (MAP-ID2111) MAP-ID212)
507 the compiled CCL codes has this sequence:
508 CCL_MapMultiple (CCL code of this command)
509 16 (total number of MAPs and SEPARATORs)
527 A value of each SEPARATOR follows this rule:
528 MAP-SET := SEPARATOR [(MAP-ID | MAP-SET)]+
529 SEPARATOR := -(number of MAP-IDs and SEPARATORs in the MAP-SET)
531 (*)....Nest level of MAP-SET must not be over than MAX_MAP_SET_LEVEL.
533 When some map fails to map (i.e. it doesn't have a value for
534 reg[rrr]), the mapping is treated as identity.
536 The mapping is iterated for all maps in each map set (set of maps
537 separated by SEPARATOR) except in the case that lambda is
538 encountered. More precisely, the mapping proceeds as below:
540 At first, VAL0 is set to reg[rrr], and it is translated by the
541 first map to VAL1. Then, VAL1 is translated by the next map to
542 VAL2. This mapping is iterated until the last map is used. The
543 result of the mapping is the last value of VAL?. When the mapping
544 process reached to the end of the map set, it moves to the next
545 map set. If the next does not exit, the mapping process terminates,
546 and regard the last value as a result.
548 But, when VALm is mapped to VALn and VALn is not a number, the
549 mapping proceed as below:
551 If VALn is nil, the lastest map is ignored and the mapping of VALm
552 proceed to the next map.
554 In VALn is t, VALm is reverted to reg[rrr] and the mapping of VALm
555 proceed to the next map.
557 If VALn is lambda, move to the next map set like reaching to the
558 end of the current map set.
560 If VALn is a symbol, call the CCL program refered by it.
561 Then, use reg[rrr] as a mapped value except for -1, -2 and -3.
562 Such special values are regarded as nil, t, and lambda respectively.
564 Each map is a Lisp vector of the following format (a) or (b):
565 (a)......[STARTPOINT VAL1 VAL2 ...]
566 (b)......[t VAL STARTPOINT ENDPOINT],
568 STARTPOINT is an offset to be used for indexing a map,
569 ENDPOINT is a maximum index number of a map,
570 VAL and VALn is a number, nil, t, or lambda.
572 Valid index range of a map of type (a) is:
573 STARTPOINT <= index < STARTPOINT + map_size - 1
574 Valid index range of a map of type (b) is:
575 STARTPOINT <= index < ENDPOINT */
577 #define CCL_MapMultiple 0x11 /* Mapping by multiple code conversion maps
578 1:ExtendedCOMMNDXXXRRRrrrXXXXX
590 #define MAX_MAP_SET_LEVEL 30
598 static tr_stack mapping_stack
[MAX_MAP_SET_LEVEL
];
599 static tr_stack
*mapping_stack_pointer
;
601 /* If this variable is non-zero, it indicates the stack_idx
602 of immediately called by CCL_MapMultiple. */
603 static int stack_idx_of_map_multiple
;
605 #define PUSH_MAPPING_STACK(restlen, orig) \
608 mapping_stack_pointer->rest_length = (restlen); \
609 mapping_stack_pointer->orig_val = (orig); \
610 mapping_stack_pointer++; \
614 #define POP_MAPPING_STACK(restlen, orig) \
617 mapping_stack_pointer--; \
618 (restlen) = mapping_stack_pointer->rest_length; \
619 (orig) = mapping_stack_pointer->orig_val; \
623 #define CCL_CALL_FOR_MAP_INSTRUCTION(symbol, ret_ic) \
626 struct ccl_program called_ccl; \
627 if (stack_idx >= 256 \
628 || (setup_ccl_program (&called_ccl, (symbol)) != 0)) \
632 ccl_prog = ccl_prog_stack_struct[0].ccl_prog; \
633 ic = ccl_prog_stack_struct[0].ic; \
634 eof_ic = ccl_prog_stack_struct[0].eof_ic; \
638 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog; \
639 ccl_prog_stack_struct[stack_idx].ic = (ret_ic); \
640 ccl_prog_stack_struct[stack_idx].eof_ic = eof_ic; \
642 ccl_prog = called_ccl.prog; \
643 ic = CCL_HEADER_MAIN; \
644 eof_ic = XFASTINT (ccl_prog[CCL_HEADER_EOF]); \
649 #define CCL_MapSingle 0x12 /* Map by single code conversion map
650 1:ExtendedCOMMNDXXXRRRrrrXXXXX
652 ------------------------------
653 Map reg[rrr] by MAP-ID.
654 If some valid mapping is found,
655 set reg[rrr] to the result,
660 #define CCL_LookupIntConstTbl 0x13 /* Lookup multibyte character by
661 integer key. Afterwards R7 set
662 to 1 if lookup succeeded.
663 1:ExtendedCOMMNDRrrRRRXXXXXXXX
664 2:ARGUMENT(Hash table ID) */
666 #define CCL_LookupCharConstTbl 0x14 /* Lookup integer by multibyte
667 character key. Afterwards R7 set
668 to 1 if lookup succeeded.
669 1:ExtendedCOMMNDRrrRRRrrrXXXXX
670 2:ARGUMENT(Hash table ID) */
672 /* CCL arithmetic/logical operators. */
673 #define CCL_PLUS 0x00 /* X = Y + Z */
674 #define CCL_MINUS 0x01 /* X = Y - Z */
675 #define CCL_MUL 0x02 /* X = Y * Z */
676 #define CCL_DIV 0x03 /* X = Y / Z */
677 #define CCL_MOD 0x04 /* X = Y % Z */
678 #define CCL_AND 0x05 /* X = Y & Z */
679 #define CCL_OR 0x06 /* X = Y | Z */
680 #define CCL_XOR 0x07 /* X = Y ^ Z */
681 #define CCL_LSH 0x08 /* X = Y << Z */
682 #define CCL_RSH 0x09 /* X = Y >> Z */
683 #define CCL_LSH8 0x0A /* X = (Y << 8) | Z */
684 #define CCL_RSH8 0x0B /* X = Y >> 8, r[7] = Y & 0xFF */
685 #define CCL_DIVMOD 0x0C /* X = Y / Z, r[7] = Y % Z */
686 #define CCL_LS 0x10 /* X = (X < Y) */
687 #define CCL_GT 0x11 /* X = (X > Y) */
688 #define CCL_EQ 0x12 /* X = (X == Y) */
689 #define CCL_LE 0x13 /* X = (X <= Y) */
690 #define CCL_GE 0x14 /* X = (X >= Y) */
691 #define CCL_NE 0x15 /* X = (X != Y) */
693 #define CCL_DECODE_SJIS 0x16 /* X = HIGHER_BYTE (DE-SJIS (Y, Z))
694 r[7] = LOWER_BYTE (DE-SJIS (Y, Z)) */
695 #define CCL_ENCODE_SJIS 0x17 /* X = HIGHER_BYTE (SJIS (Y, Z))
696 r[7] = LOWER_BYTE (SJIS (Y, Z) */
698 /* Terminate CCL program successfully. */
699 #define CCL_SUCCESS \
702 ccl->status = CCL_STAT_SUCCESS; \
707 /* Suspend CCL program because of reading from empty input buffer or
708 writing to full output buffer. When this program is resumed, the
709 same I/O command is executed. */
710 #define CCL_SUSPEND(stat) \
714 ccl->status = stat; \
719 /* Terminate CCL program because of invalid command. Should not occur
720 in the normal case. */
723 #define CCL_INVALID_CMD \
726 ccl->status = CCL_STAT_INVALID_CMD; \
727 goto ccl_error_handler; \
733 #define CCL_INVALID_CMD \
736 ccl_debug_hook (this_ic); \
737 ccl->status = CCL_STAT_INVALID_CMD; \
738 goto ccl_error_handler; \
744 /* Encode one character CH to multibyte form and write to the current
745 output buffer. If CH is less than 256, CH is written as is. */
746 #define CCL_WRITE_CHAR(ch) \
748 int bytes = SINGLE_BYTE_CHAR_P (ch) ? 1: CHAR_BYTES (ch); \
751 else if (dst + bytes + extra_bytes < (dst_bytes ? dst_end : src)) \
756 if (extra_bytes && (ch) >= 0x80 && (ch) < 0xA0) \
757 /* We may have to convert this eight-bit char to \
758 multibyte form later. */ \
761 else if (CHAR_VALID_P (ch, 0)) \
762 dst += CHAR_STRING (ch, dst); \
767 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_DST); \
770 /* Encode one character CH to multibyte form and write to the current
771 output buffer. The output bytes always forms a valid multibyte
773 #define CCL_WRITE_MULTIBYTE_CHAR(ch) \
775 int bytes = CHAR_BYTES (ch); \
778 else if (dst + bytes + extra_bytes < (dst_bytes ? dst_end : src)) \
780 if (CHAR_VALID_P ((ch), 0)) \
781 dst += CHAR_STRING ((ch), dst); \
786 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_DST); \
789 /* Write a string at ccl_prog[IC] of length LEN to the current output
791 #define CCL_WRITE_STRING(len) \
795 else if (dst + len <= (dst_bytes ? dst_end : src)) \
796 for (i = 0; i < len; i++) \
797 *dst++ = ((XFASTINT (ccl_prog[ic + (i / 3)])) \
798 >> ((2 - (i % 3)) * 8)) & 0xFF; \
800 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_DST); \
803 /* Read one byte from the current input buffer into REGth register. */
804 #define CCL_READ_CHAR(REG) \
808 else if (src < src_end) \
812 && ccl->eol_type != CODING_EOL_LF) \
814 /* We are encoding. */ \
815 if (ccl->eol_type == CODING_EOL_CRLF) \
817 if (ccl->cr_consumed) \
818 ccl->cr_consumed = 0; \
821 ccl->cr_consumed = 1; \
829 if (REG == LEADING_CODE_8_BIT_CONTROL \
831 REG = *src++ - 0x20; \
833 else if (ccl->last_block) \
840 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC); \
844 /* Set C to the character code made from CHARSET and CODE. This is
845 like MAKE_CHAR but check the validity of CHARSET and CODE. If they
846 are not valid, set C to (CODE & 0xFF) because that is usually the
847 case that CCL_ReadMultibyteChar2 read an invalid code and it set
848 CODE to that invalid byte. */
850 #define CCL_MAKE_CHAR(charset, code, c) \
852 if (charset == CHARSET_ASCII) \
854 else if (CHARSET_DEFINED_P (charset) \
855 && (code & 0x7F) >= 32 \
856 && (code < 256 || ((code >> 7) & 0x7F) >= 32)) \
858 int c1 = code & 0x7F, c2 = 0; \
861 c2 = c1, c1 = (code >> 7) & 0x7F; \
862 c = MAKE_CHAR (charset, c1, c2); \
869 /* Execute CCL code on SRC_BYTES length text at SOURCE. The resulting
870 text goes to a place pointed by DESTINATION, the length of which
871 should not exceed DST_BYTES. The bytes actually processed is
872 returned as *CONSUMED. The return value is the length of the
873 resulting text. As a side effect, the contents of CCL registers
874 are updated. If SOURCE or DESTINATION is NULL, only operations on
875 registers are permitted. */
878 #define CCL_DEBUG_BACKTRACE_LEN 256
879 int ccl_backtrace_table
[CCL_DEBUG_BACKTRACE_LEN
];
880 int ccl_backtrace_idx
;
883 ccl_debug_hook (int ic
)
890 struct ccl_prog_stack
892 Lisp_Object
*ccl_prog
; /* Pointer to an array of CCL code. */
893 int ic
; /* Instruction Counter. */
894 int eof_ic
; /* Instruction Counter to jump on EOF. */
897 /* For the moment, we only support depth 256 of stack. */
898 static struct ccl_prog_stack ccl_prog_stack_struct
[256];
901 ccl_driver (ccl
, source
, destination
, src_bytes
, dst_bytes
, consumed
)
902 struct ccl_program
*ccl
;
903 unsigned char *source
, *destination
;
904 int src_bytes
, dst_bytes
;
907 register int *reg
= ccl
->reg
;
908 register int ic
= ccl
->ic
;
909 register int code
= 0, field1
, field2
;
910 register Lisp_Object
*ccl_prog
= ccl
->prog
;
911 unsigned char *src
= source
, *src_end
= src
+ src_bytes
;
912 unsigned char *dst
= destination
, *dst_end
= dst
+ dst_bytes
;
915 int stack_idx
= ccl
->stack_idx
;
916 /* Instruction counter of the current CCL code. */
918 /* CCL_WRITE_CHAR will produce 8-bit code of range 0x80..0x9F. But,
919 each of them will be converted to multibyte form of 2-byte
920 sequence. For that conversion, we remember how many more bytes
921 we must keep in DESTINATION in this variable. */
922 int extra_bytes
= ccl
->eight_bit_control
;
923 int eof_ic
= ccl
->eof_ic
;
927 ic
= CCL_HEADER_MAIN
;
929 if (ccl
->buf_magnification
== 0) /* We can't produce any bytes. */
932 /* Set mapping stack pointer. */
933 mapping_stack_pointer
= mapping_stack
;
936 ccl_backtrace_idx
= 0;
943 ccl_backtrace_table
[ccl_backtrace_idx
++] = ic
;
944 if (ccl_backtrace_idx
>= CCL_DEBUG_BACKTRACE_LEN
)
945 ccl_backtrace_idx
= 0;
946 ccl_backtrace_table
[ccl_backtrace_idx
] = 0;
949 if (!NILP (Vquit_flag
) && NILP (Vinhibit_quit
))
951 /* We can't just signal Qquit, instead break the loop as if
952 the whole data is processed. Don't reset Vquit_flag, it
953 must be handled later at a safer place. */
955 src
= source
+ src_bytes
;
956 ccl
->status
= CCL_STAT_QUIT
;
961 code
= XINT (ccl_prog
[ic
]); ic
++;
963 field2
= (code
& 0xFF) >> 5;
966 #define RRR (field1 & 7)
967 #define Rrr ((field1 >> 3) & 7)
969 #define EXCMD (field1 >> 6)
973 case CCL_SetRegister
: /* 00000000000000000RRRrrrXXXXX */
977 case CCL_SetShortConst
: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
981 case CCL_SetConst
: /* 00000000000000000000rrrXXXXX */
982 reg
[rrr
] = XINT (ccl_prog
[ic
]);
986 case CCL_SetArray
: /* CCCCCCCCCCCCCCCCCCCCRRRrrrXXXXX */
989 if ((unsigned int) i
< j
)
990 reg
[rrr
] = XINT (ccl_prog
[ic
+ i
]);
994 case CCL_Jump
: /* A--D--D--R--E--S--S-000XXXXX */
998 case CCL_JumpCond
: /* A--D--D--R--E--S--S-rrrXXXXX */
1003 case CCL_WriteRegisterJump
: /* A--D--D--R--E--S--S-rrrXXXXX */
1009 case CCL_WriteRegisterReadJump
: /* A--D--D--R--E--S--S-rrrXXXXX */
1013 CCL_READ_CHAR (reg
[rrr
]);
1017 case CCL_WriteConstJump
: /* A--D--D--R--E--S--S-000XXXXX */
1018 i
= XINT (ccl_prog
[ic
]);
1023 case CCL_WriteConstReadJump
: /* A--D--D--R--E--S--S-rrrXXXXX */
1024 i
= XINT (ccl_prog
[ic
]);
1027 CCL_READ_CHAR (reg
[rrr
]);
1031 case CCL_WriteStringJump
: /* A--D--D--R--E--S--S-000XXXXX */
1032 j
= XINT (ccl_prog
[ic
]);
1034 CCL_WRITE_STRING (j
);
1038 case CCL_WriteArrayReadJump
: /* A--D--D--R--E--S--S-rrrXXXXX */
1040 j
= XINT (ccl_prog
[ic
]);
1041 if ((unsigned int) i
< j
)
1043 i
= XINT (ccl_prog
[ic
+ 1 + i
]);
1047 CCL_READ_CHAR (reg
[rrr
]);
1048 ic
+= ADDR
- (j
+ 2);
1051 case CCL_ReadJump
: /* A--D--D--R--E--S--S-rrrYYYYY */
1052 CCL_READ_CHAR (reg
[rrr
]);
1056 case CCL_ReadBranch
: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
1057 CCL_READ_CHAR (reg
[rrr
]);
1058 /* fall through ... */
1059 case CCL_Branch
: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
1060 if ((unsigned int) reg
[rrr
] < field1
)
1061 ic
+= XINT (ccl_prog
[ic
+ reg
[rrr
]]);
1063 ic
+= XINT (ccl_prog
[ic
+ field1
]);
1066 case CCL_ReadRegister
: /* CCCCCCCCCCCCCCCCCCCCrrXXXXX */
1069 CCL_READ_CHAR (reg
[rrr
]);
1071 code
= XINT (ccl_prog
[ic
]); ic
++;
1073 field2
= (code
& 0xFF) >> 5;
1077 case CCL_WriteExprConst
: /* 1:00000OPERATION000RRR000XXXXX */
1080 j
= XINT (ccl_prog
[ic
]);
1082 jump_address
= ic
+ 1;
1085 case CCL_WriteRegister
: /* CCCCCCCCCCCCCCCCCCCrrrXXXXX */
1091 code
= XINT (ccl_prog
[ic
]); ic
++;
1093 field2
= (code
& 0xFF) >> 5;
1097 case CCL_WriteExprRegister
: /* 1:00000OPERATIONRrrRRR000XXXXX */
1105 case CCL_Call
: /* 1:CCCCCCCCCCCCCCCCCCCCFFFXXXXX */
1110 /* If FFF is nonzero, the CCL program ID is in the
1114 prog_id
= XINT (ccl_prog
[ic
]);
1120 if (stack_idx
>= 256
1122 || prog_id
>= ASIZE (Vccl_program_table
)
1123 || (slot
= AREF (Vccl_program_table
, prog_id
), !VECTORP (slot
))
1124 || !VECTORP (AREF (slot
, 1)))
1128 ccl_prog
= ccl_prog_stack_struct
[0].ccl_prog
;
1129 ic
= ccl_prog_stack_struct
[0].ic
;
1130 eof_ic
= ccl_prog_stack_struct
[0].eof_ic
;
1135 ccl_prog_stack_struct
[stack_idx
].ccl_prog
= ccl_prog
;
1136 ccl_prog_stack_struct
[stack_idx
].ic
= ic
;
1137 ccl_prog_stack_struct
[stack_idx
].eof_ic
= eof_ic
;
1139 ccl_prog
= XVECTOR (AREF (slot
, 1))->contents
;
1140 ic
= CCL_HEADER_MAIN
;
1141 eof_ic
= XFASTINT (ccl_prog
[CCL_HEADER_EOF
]);
1145 case CCL_WriteConstString
: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
1147 CCL_WRITE_CHAR (field1
);
1150 CCL_WRITE_STRING (field1
);
1151 ic
+= (field1
+ 2) / 3;
1155 case CCL_WriteArray
: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
1157 if ((unsigned int) i
< field1
)
1159 j
= XINT (ccl_prog
[ic
+ i
]);
1165 case CCL_End
: /* 0000000000000000000000XXXXX */
1169 ccl_prog
= ccl_prog_stack_struct
[stack_idx
].ccl_prog
;
1170 ic
= ccl_prog_stack_struct
[stack_idx
].ic
;
1171 eof_ic
= ccl_prog_stack_struct
[stack_idx
].eof_ic
;
1178 /* ccl->ic should points to this command code again to
1179 suppress further processing. */
1183 case CCL_ExprSelfConst
: /* 00000OPERATION000000rrrXXXXX */
1184 i
= XINT (ccl_prog
[ic
]);
1189 case CCL_ExprSelfReg
: /* 00000OPERATION000RRRrrrXXXXX */
1196 case CCL_PLUS
: reg
[rrr
] += i
; break;
1197 case CCL_MINUS
: reg
[rrr
] -= i
; break;
1198 case CCL_MUL
: reg
[rrr
] *= i
; break;
1199 case CCL_DIV
: reg
[rrr
] /= i
; break;
1200 case CCL_MOD
: reg
[rrr
] %= i
; break;
1201 case CCL_AND
: reg
[rrr
] &= i
; break;
1202 case CCL_OR
: reg
[rrr
] |= i
; break;
1203 case CCL_XOR
: reg
[rrr
] ^= i
; break;
1204 case CCL_LSH
: reg
[rrr
] <<= i
; break;
1205 case CCL_RSH
: reg
[rrr
] >>= i
; break;
1206 case CCL_LSH8
: reg
[rrr
] <<= 8; reg
[rrr
] |= i
; break;
1207 case CCL_RSH8
: reg
[7] = reg
[rrr
] & 0xFF; reg
[rrr
] >>= 8; break;
1208 case CCL_DIVMOD
: reg
[7] = reg
[rrr
] % i
; reg
[rrr
] /= i
; break;
1209 case CCL_LS
: reg
[rrr
] = reg
[rrr
] < i
; break;
1210 case CCL_GT
: reg
[rrr
] = reg
[rrr
] > i
; break;
1211 case CCL_EQ
: reg
[rrr
] = reg
[rrr
] == i
; break;
1212 case CCL_LE
: reg
[rrr
] = reg
[rrr
] <= i
; break;
1213 case CCL_GE
: reg
[rrr
] = reg
[rrr
] >= i
; break;
1214 case CCL_NE
: reg
[rrr
] = reg
[rrr
] != i
; break;
1215 default: CCL_INVALID_CMD
;
1219 case CCL_SetExprConst
: /* 00000OPERATION000RRRrrrXXXXX */
1221 j
= XINT (ccl_prog
[ic
]);
1223 jump_address
= ++ic
;
1226 case CCL_SetExprReg
: /* 00000OPERATIONRrrRRRrrrXXXXX */
1233 case CCL_ReadJumpCondExprConst
: /* A--D--D--R--E--S--S-rrrXXXXX */
1234 CCL_READ_CHAR (reg
[rrr
]);
1235 case CCL_JumpCondExprConst
: /* A--D--D--R--E--S--S-rrrXXXXX */
1237 op
= XINT (ccl_prog
[ic
]);
1238 jump_address
= ic
++ + ADDR
;
1239 j
= XINT (ccl_prog
[ic
]);
1244 case CCL_ReadJumpCondExprReg
: /* A--D--D--R--E--S--S-rrrXXXXX */
1245 CCL_READ_CHAR (reg
[rrr
]);
1246 case CCL_JumpCondExprReg
:
1248 op
= XINT (ccl_prog
[ic
]);
1249 jump_address
= ic
++ + ADDR
;
1250 j
= reg
[XINT (ccl_prog
[ic
])];
1257 case CCL_PLUS
: reg
[rrr
] = i
+ j
; break;
1258 case CCL_MINUS
: reg
[rrr
] = i
- j
; break;
1259 case CCL_MUL
: reg
[rrr
] = i
* j
; break;
1260 case CCL_DIV
: reg
[rrr
] = i
/ j
; break;
1261 case CCL_MOD
: reg
[rrr
] = i
% j
; break;
1262 case CCL_AND
: reg
[rrr
] = i
& j
; break;
1263 case CCL_OR
: reg
[rrr
] = i
| j
; break;
1264 case CCL_XOR
: reg
[rrr
] = i
^ j
; break;
1265 case CCL_LSH
: reg
[rrr
] = i
<< j
; break;
1266 case CCL_RSH
: reg
[rrr
] = i
>> j
; break;
1267 case CCL_LSH8
: reg
[rrr
] = (i
<< 8) | j
; break;
1268 case CCL_RSH8
: reg
[rrr
] = i
>> 8; reg
[7] = i
& 0xFF; break;
1269 case CCL_DIVMOD
: reg
[rrr
] = i
/ j
; reg
[7] = i
% j
; break;
1270 case CCL_LS
: reg
[rrr
] = i
< j
; break;
1271 case CCL_GT
: reg
[rrr
] = i
> j
; break;
1272 case CCL_EQ
: reg
[rrr
] = i
== j
; break;
1273 case CCL_LE
: reg
[rrr
] = i
<= j
; break;
1274 case CCL_GE
: reg
[rrr
] = i
>= j
; break;
1275 case CCL_NE
: reg
[rrr
] = i
!= j
; break;
1276 case CCL_DECODE_SJIS
: DECODE_SJIS (i
, j
, reg
[rrr
], reg
[7]); break;
1277 case CCL_ENCODE_SJIS
: ENCODE_SJIS (i
, j
, reg
[rrr
], reg
[7]); break;
1278 default: CCL_INVALID_CMD
;
1281 if (code
== CCL_WriteExprConst
|| code
== CCL_WriteExprRegister
)
1294 case CCL_ReadMultibyteChar2
:
1301 goto ccl_read_multibyte_character_suspend
;
1304 if (!ccl
->multibyte
)
1307 if (!UNIBYTE_STR_AS_MULTIBYTE_P (src
, src_end
- src
, bytes
))
1309 reg
[RRR
] = CHARSET_8_BIT_CONTROL
;
1315 if (i
== '\n' && ccl
->eol_type
!= CODING_EOL_LF
)
1317 /* We are encoding. */
1318 if (ccl
->eol_type
== CODING_EOL_CRLF
)
1320 if (ccl
->cr_consumed
)
1321 ccl
->cr_consumed
= 0;
1324 ccl
->cr_consumed
= 1;
1332 reg
[RRR
] = CHARSET_ASCII
;
1338 reg
[RRR
] = CHARSET_ASCII
;
1340 else if (i
<= MAX_CHARSET_OFFICIAL_DIMENSION2
)
1342 int dimension
= BYTES_BY_CHAR_HEAD (i
) - 1;
1346 /* `i' is a leading code for an undefined charset. */
1347 reg
[RRR
] = CHARSET_8_BIT_GRAPHIC
;
1350 else if (src
+ dimension
> src_end
)
1351 goto ccl_read_multibyte_character_suspend
;
1355 i
= (*src
++ & 0x7F);
1359 reg
[rrr
] = ((i
<< 7) | (*src
++ & 0x7F));
1362 else if ((i
== LEADING_CODE_PRIVATE_11
)
1363 || (i
== LEADING_CODE_PRIVATE_12
))
1365 if ((src
+ 1) >= src_end
)
1366 goto ccl_read_multibyte_character_suspend
;
1368 reg
[rrr
] = (*src
++ & 0x7F);
1370 else if ((i
== LEADING_CODE_PRIVATE_21
)
1371 || (i
== LEADING_CODE_PRIVATE_22
))
1373 if ((src
+ 2) >= src_end
)
1374 goto ccl_read_multibyte_character_suspend
;
1376 i
= (*src
++ & 0x7F);
1377 reg
[rrr
] = ((i
<< 7) | (*src
& 0x7F));
1380 else if (i
== LEADING_CODE_8_BIT_CONTROL
)
1383 goto ccl_read_multibyte_character_suspend
;
1384 reg
[RRR
] = CHARSET_8_BIT_CONTROL
;
1385 reg
[rrr
] = (*src
++ - 0x20);
1389 reg
[RRR
] = CHARSET_8_BIT_GRAPHIC
;
1394 /* INVALID CODE. Return a single byte character. */
1395 reg
[RRR
] = CHARSET_ASCII
;
1400 ccl_read_multibyte_character_suspend
:
1401 if (src
<= src_end
&& !ccl
->multibyte
&& ccl
->last_block
)
1403 reg
[RRR
] = CHARSET_8_BIT_CONTROL
;
1408 if (ccl
->last_block
)
1415 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC
);
1419 case CCL_WriteMultibyteChar2
:
1420 i
= reg
[RRR
]; /* charset */
1421 if (i
== CHARSET_ASCII
1422 || i
== CHARSET_8_BIT_CONTROL
1423 || i
== CHARSET_8_BIT_GRAPHIC
)
1424 i
= reg
[rrr
] & 0xFF;
1425 else if (CHARSET_DIMENSION (i
) == 1)
1426 i
= ((i
- 0x70) << 7) | (reg
[rrr
] & 0x7F);
1427 else if (i
< MIN_CHARSET_PRIVATE_DIMENSION2
)
1428 i
= ((i
- 0x8F) << 14) | reg
[rrr
];
1430 i
= ((i
- 0xE0) << 14) | reg
[rrr
];
1432 CCL_WRITE_MULTIBYTE_CHAR (i
);
1436 case CCL_TranslateCharacter
:
1437 CCL_MAKE_CHAR (reg
[RRR
], reg
[rrr
], i
);
1438 op
= translate_char (GET_TRANSLATION_TABLE (reg
[Rrr
]),
1440 SPLIT_CHAR (op
, reg
[RRR
], i
, j
);
1447 case CCL_TranslateCharacterConstTbl
:
1448 op
= XINT (ccl_prog
[ic
]); /* table */
1450 CCL_MAKE_CHAR (reg
[RRR
], reg
[rrr
], i
);
1451 op
= translate_char (GET_TRANSLATION_TABLE (op
), i
, -1, 0, 0);
1452 SPLIT_CHAR (op
, reg
[RRR
], i
, j
);
1459 case CCL_LookupIntConstTbl
:
1460 op
= XINT (ccl_prog
[ic
]); /* table */
1463 struct Lisp_Hash_Table
*h
= GET_HASH_TABLE (op
);
1465 op
= hash_lookup (h
, make_number (reg
[RRR
]), NULL
);
1469 opl
= HASH_VALUE (h
, op
);
1470 if (!CHAR_VALID_P (XINT (opl
), 0))
1472 SPLIT_CHAR (XINT (opl
), reg
[RRR
], i
, j
);
1476 reg
[7] = 1; /* r7 true for success */
1483 case CCL_LookupCharConstTbl
:
1484 op
= XINT (ccl_prog
[ic
]); /* table */
1486 CCL_MAKE_CHAR (reg
[RRR
], reg
[rrr
], i
);
1488 struct Lisp_Hash_Table
*h
= GET_HASH_TABLE (op
);
1490 op
= hash_lookup (h
, make_number (i
), NULL
);
1494 opl
= HASH_VALUE (h
, op
);
1495 if (!INTEGERP (opl
))
1497 reg
[RRR
] = XINT (opl
);
1498 reg
[7] = 1; /* r7 true for success */
1505 case CCL_IterateMultipleMap
:
1507 Lisp_Object map
, content
, attrib
, value
;
1508 int point
, size
, fin_ic
;
1510 j
= XINT (ccl_prog
[ic
++]); /* number of maps. */
1513 if ((j
> reg
[RRR
]) && (j
>= 0))
1528 size
= ASIZE (Vcode_conversion_map_vector
);
1529 point
= XINT (ccl_prog
[ic
++]);
1530 if (point
>= size
) continue;
1531 map
= AREF (Vcode_conversion_map_vector
, point
);
1533 /* Check map varidity. */
1534 if (!CONSP (map
)) continue;
1536 if (!VECTORP (map
)) continue;
1538 if (size
<= 1) continue;
1540 content
= AREF (map
, 0);
1543 [STARTPOINT VAL1 VAL2 ...] or
1544 [t ELELMENT STARTPOINT ENDPOINT] */
1545 if (NUMBERP (content
))
1547 point
= XUINT (content
);
1548 point
= op
- point
+ 1;
1549 if (!((point
>= 1) && (point
< size
))) continue;
1550 content
= AREF (map
, point
);
1552 else if (EQ (content
, Qt
))
1554 if (size
!= 4) continue;
1555 if ((op
>= XUINT (AREF (map
, 2)))
1556 && (op
< XUINT (AREF (map
, 3))))
1557 content
= AREF (map
, 1);
1566 else if (NUMBERP (content
))
1569 reg
[rrr
] = XINT(content
);
1572 else if (EQ (content
, Qt
) || EQ (content
, Qlambda
))
1577 else if (CONSP (content
))
1579 attrib
= XCAR (content
);
1580 value
= XCDR (content
);
1581 if (!NUMBERP (attrib
) || !NUMBERP (value
))
1584 reg
[rrr
] = XUINT (value
);
1587 else if (SYMBOLP (content
))
1588 CCL_CALL_FOR_MAP_INSTRUCTION (content
, fin_ic
);
1598 case CCL_MapMultiple
:
1600 Lisp_Object map
, content
, attrib
, value
;
1601 int point
, size
, map_vector_size
;
1602 int map_set_rest_length
, fin_ic
;
1603 int current_ic
= this_ic
;
1605 /* inhibit recursive call on MapMultiple. */
1606 if (stack_idx_of_map_multiple
> 0)
1608 if (stack_idx_of_map_multiple
<= stack_idx
)
1610 stack_idx_of_map_multiple
= 0;
1611 mapping_stack_pointer
= mapping_stack
;
1616 mapping_stack_pointer
= mapping_stack
;
1617 stack_idx_of_map_multiple
= 0;
1619 map_set_rest_length
=
1620 XINT (ccl_prog
[ic
++]); /* number of maps and separators. */
1621 fin_ic
= ic
+ map_set_rest_length
;
1624 if ((map_set_rest_length
> reg
[RRR
]) && (reg
[RRR
] >= 0))
1628 map_set_rest_length
-= i
;
1634 mapping_stack_pointer
= mapping_stack
;
1638 if (mapping_stack_pointer
<= (mapping_stack
+ 1))
1640 /* Set up initial state. */
1641 mapping_stack_pointer
= mapping_stack
;
1642 PUSH_MAPPING_STACK (0, op
);
1647 /* Recover after calling other ccl program. */
1650 POP_MAPPING_STACK (map_set_rest_length
, orig_op
);
1651 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1655 /* Regard it as Qnil. */
1659 map_set_rest_length
--;
1662 /* Regard it as Qt. */
1666 map_set_rest_length
--;
1669 /* Regard it as Qlambda. */
1671 i
+= map_set_rest_length
;
1672 ic
+= map_set_rest_length
;
1673 map_set_rest_length
= 0;
1676 /* Regard it as normal mapping. */
1677 i
+= map_set_rest_length
;
1678 ic
+= map_set_rest_length
;
1679 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1683 map_vector_size
= ASIZE (Vcode_conversion_map_vector
);
1686 for (;map_set_rest_length
> 0;i
++, ic
++, map_set_rest_length
--)
1688 point
= XINT(ccl_prog
[ic
]);
1691 /* +1 is for including separator. */
1693 if (mapping_stack_pointer
1694 >= &mapping_stack
[MAX_MAP_SET_LEVEL
])
1696 PUSH_MAPPING_STACK (map_set_rest_length
- point
,
1698 map_set_rest_length
= point
;
1703 if (point
>= map_vector_size
) continue;
1704 map
= AREF (Vcode_conversion_map_vector
, point
);
1706 /* Check map varidity. */
1707 if (!CONSP (map
)) continue;
1709 if (!VECTORP (map
)) continue;
1711 if (size
<= 1) continue;
1713 content
= AREF (map
, 0);
1716 [STARTPOINT VAL1 VAL2 ...] or
1717 [t ELEMENT STARTPOINT ENDPOINT] */
1718 if (NUMBERP (content
))
1720 point
= XUINT (content
);
1721 point
= op
- point
+ 1;
1722 if (!((point
>= 1) && (point
< size
))) continue;
1723 content
= AREF (map
, point
);
1725 else if (EQ (content
, Qt
))
1727 if (size
!= 4) continue;
1728 if ((op
>= XUINT (AREF (map
, 2))) &&
1729 (op
< XUINT (AREF (map
, 3))))
1730 content
= AREF (map
, 1);
1741 if (NUMBERP (content
))
1743 op
= XINT (content
);
1744 i
+= map_set_rest_length
- 1;
1745 ic
+= map_set_rest_length
- 1;
1746 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1747 map_set_rest_length
++;
1749 else if (CONSP (content
))
1751 attrib
= XCAR (content
);
1752 value
= XCDR (content
);
1753 if (!NUMBERP (attrib
) || !NUMBERP (value
))
1756 i
+= map_set_rest_length
- 1;
1757 ic
+= map_set_rest_length
- 1;
1758 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1759 map_set_rest_length
++;
1761 else if (EQ (content
, Qt
))
1765 else if (EQ (content
, Qlambda
))
1767 i
+= map_set_rest_length
;
1768 ic
+= map_set_rest_length
;
1771 else if (SYMBOLP (content
))
1773 if (mapping_stack_pointer
1774 >= &mapping_stack
[MAX_MAP_SET_LEVEL
])
1776 PUSH_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1777 PUSH_MAPPING_STACK (map_set_rest_length
, op
);
1778 stack_idx_of_map_multiple
= stack_idx
+ 1;
1779 CCL_CALL_FOR_MAP_INSTRUCTION (content
, current_ic
);
1784 if (mapping_stack_pointer
<= (mapping_stack
+ 1))
1786 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1787 i
+= map_set_rest_length
;
1788 ic
+= map_set_rest_length
;
1789 POP_MAPPING_STACK (map_set_rest_length
, reg
[rrr
]);
1799 Lisp_Object map
, attrib
, value
, content
;
1801 j
= XINT (ccl_prog
[ic
++]); /* map_id */
1803 if (j
>= ASIZE (Vcode_conversion_map_vector
))
1808 map
= AREF (Vcode_conversion_map_vector
, j
);
1821 point
= XUINT (AREF (map
, 0));
1822 point
= op
- point
+ 1;
1825 (!((point
>= 1) && (point
< size
))))
1830 content
= AREF (map
, point
);
1833 else if (NUMBERP (content
))
1834 reg
[rrr
] = XINT (content
);
1835 else if (EQ (content
, Qt
));
1836 else if (CONSP (content
))
1838 attrib
= XCAR (content
);
1839 value
= XCDR (content
);
1840 if (!NUMBERP (attrib
) || !NUMBERP (value
))
1842 reg
[rrr
] = XUINT(value
);
1845 else if (SYMBOLP (content
))
1846 CCL_CALL_FOR_MAP_INSTRUCTION (content
, ic
);
1864 /* The suppress_error member is set when e.g. a CCL-based coding
1865 system is used for terminal output. */
1866 if (!ccl
->suppress_error
&& destination
)
1868 /* We can insert an error message only if DESTINATION is
1869 specified and we still have a room to store the message
1877 switch (ccl
->status
)
1879 case CCL_STAT_INVALID_CMD
:
1880 sprintf(msg
, "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
1881 code
& 0x1F, code
, this_ic
);
1884 int i
= ccl_backtrace_idx
- 1;
1887 msglen
= strlen (msg
);
1888 if (dst
+ msglen
<= (dst_bytes
? dst_end
: src
))
1890 bcopy (msg
, dst
, msglen
);
1894 for (j
= 0; j
< CCL_DEBUG_BACKTRACE_LEN
; j
++, i
--)
1896 if (i
< 0) i
= CCL_DEBUG_BACKTRACE_LEN
- 1;
1897 if (ccl_backtrace_table
[i
] == 0)
1899 sprintf(msg
, " %d", ccl_backtrace_table
[i
]);
1900 msglen
= strlen (msg
);
1901 if (dst
+ msglen
> (dst_bytes
? dst_end
: src
))
1903 bcopy (msg
, dst
, msglen
);
1912 sprintf(msg
, "\nCCL: Quited.");
1916 sprintf(msg
, "\nCCL: Unknown error type (%d)", ccl
->status
);
1919 msglen
= strlen (msg
);
1920 if (dst
+ msglen
<= (dst_bytes
? dst_end
: src
))
1922 bcopy (msg
, dst
, msglen
);
1926 if (ccl
->status
== CCL_STAT_INVALID_CMD
)
1928 #if 0 /* If the remaining bytes contain 0x80..0x9F, copying them
1929 results in an invalid multibyte sequence. */
1931 /* Copy the remaining source data. */
1932 int i
= src_end
- src
;
1933 if (dst_bytes
&& (dst_end
- dst
) < i
)
1935 bcopy (src
, dst
, i
);
1939 /* Signal that we've consumed everything. */
1947 ccl
->stack_idx
= stack_idx
;
1948 ccl
->prog
= ccl_prog
;
1949 ccl
->eight_bit_control
= (extra_bytes
> 1);
1951 *consumed
= src
- source
;
1952 return (dst
? dst
- destination
: 0);
1955 /* Resolve symbols in the specified CCL code (Lisp vector). This
1956 function converts symbols of code conversion maps and character
1957 translation tables embeded in the CCL code into their ID numbers.
1959 The return value is a vector (CCL itself or a new vector in which
1960 all symbols are resolved), Qt if resolving of some symbol failed,
1961 or nil if CCL contains invalid data. */
1964 resolve_symbol_ccl_program (ccl
)
1967 int i
, veclen
, unresolved
= 0;
1968 Lisp_Object result
, contents
, val
;
1971 veclen
= ASIZE (result
);
1973 for (i
= 0; i
< veclen
; i
++)
1975 contents
= AREF (result
, i
);
1976 if (INTEGERP (contents
))
1978 else if (CONSP (contents
)
1979 && SYMBOLP (XCAR (contents
))
1980 && SYMBOLP (XCDR (contents
)))
1982 /* This is the new style for embedding symbols. The form is
1983 (SYMBOL . PROPERTY). (get SYMBOL PROPERTY) should give
1986 if (EQ (result
, ccl
))
1987 result
= Fcopy_sequence (ccl
);
1989 val
= Fget (XCAR (contents
), XCDR (contents
));
1991 AREF (result
, i
) = val
;
1996 else if (SYMBOLP (contents
))
1998 /* This is the old style for embedding symbols. This style
1999 may lead to a bug if, for instance, a translation table
2000 and a code conversion map have the same name. */
2001 if (EQ (result
, ccl
))
2002 result
= Fcopy_sequence (ccl
);
2004 val
= Fget (contents
, Qtranslation_table_id
);
2006 AREF (result
, i
) = val
;
2009 val
= Fget (contents
, Qcode_conversion_map_id
);
2011 AREF (result
, i
) = val
;
2014 val
= Fget (contents
, Qccl_program_idx
);
2016 AREF (result
, i
) = val
;
2026 return (unresolved
? Qt
: result
);
2029 /* Return the compiled code (vector) of CCL program CCL_PROG.
2030 CCL_PROG is a name (symbol) of the program or already compiled
2031 code. If necessary, resolve symbols in the compiled code to index
2032 numbers. If we failed to get the compiled code or to resolve
2033 symbols, return Qnil. */
2036 ccl_get_compiled_code (ccl_prog
, idx
)
2037 Lisp_Object ccl_prog
;
2040 Lisp_Object val
, slot
;
2042 if (VECTORP (ccl_prog
))
2044 val
= resolve_symbol_ccl_program (ccl_prog
);
2046 return (VECTORP (val
) ? val
: Qnil
);
2048 if (!SYMBOLP (ccl_prog
))
2051 val
= Fget (ccl_prog
, Qccl_program_idx
);
2053 || XINT (val
) >= ASIZE (Vccl_program_table
))
2055 slot
= AREF (Vccl_program_table
, XINT (val
));
2056 if (! VECTORP (slot
)
2057 || ASIZE (slot
) != 4
2058 || ! VECTORP (AREF (slot
, 1)))
2061 if (NILP (AREF (slot
, 2)))
2063 val
= resolve_symbol_ccl_program (AREF (slot
, 1));
2064 if (! VECTORP (val
))
2066 AREF (slot
, 1) = val
;
2067 AREF (slot
, 2) = Qt
;
2069 return AREF (slot
, 1);
2072 /* Setup fields of the structure pointed by CCL appropriately for the
2073 execution of CCL program CCL_PROG. CCL_PROG is the name (symbol)
2074 of the CCL program or the already compiled code (vector).
2075 Return 0 if we succeed this setup, else return -1.
2077 If CCL_PROG is nil, we just reset the structure pointed by CCL. */
2079 setup_ccl_program (ccl
, ccl_prog
)
2080 struct ccl_program
*ccl
;
2081 Lisp_Object ccl_prog
;
2085 if (! NILP (ccl_prog
))
2087 struct Lisp_Vector
*vp
;
2089 ccl_prog
= ccl_get_compiled_code (ccl_prog
, &ccl
->idx
);
2090 if (! VECTORP (ccl_prog
))
2092 vp
= XVECTOR (ccl_prog
);
2093 ccl
->size
= vp
->size
;
2094 ccl
->prog
= vp
->contents
;
2095 ccl
->eof_ic
= XINT (vp
->contents
[CCL_HEADER_EOF
]);
2096 ccl
->buf_magnification
= XINT (vp
->contents
[CCL_HEADER_BUF_MAG
]);
2101 slot
= AREF (Vccl_program_table
, ccl
->idx
);
2102 ASET (slot
, 3, Qnil
);
2105 ccl
->ic
= CCL_HEADER_MAIN
;
2106 for (i
= 0; i
< 8; i
++)
2108 ccl
->last_block
= 0;
2109 ccl
->private_state
= 0;
2112 ccl
->eol_type
= CODING_EOL_LF
;
2113 ccl
->suppress_error
= 0;
2114 ccl
->eight_bit_control
= 0;
2119 /* Check if CCL is updated or not. If not, re-setup members of CCL. */
2122 check_ccl_update (ccl
)
2123 struct ccl_program
*ccl
;
2125 Lisp_Object slot
, ccl_prog
;
2129 slot
= AREF (Vccl_program_table
, ccl
->idx
);
2130 if (NILP (AREF (slot
, 3)))
2132 ccl_prog
= ccl_get_compiled_code (AREF (slot
, 0), &ccl
->idx
);
2133 if (! VECTORP (ccl_prog
))
2135 ccl
->size
= ASIZE (ccl_prog
);
2136 ccl
->prog
= XVECTOR (ccl_prog
)->contents
;
2137 ccl
->eof_ic
= XINT (AREF (ccl_prog
, CCL_HEADER_EOF
));
2138 ccl
->buf_magnification
= XINT (AREF (ccl_prog
, CCL_HEADER_BUF_MAG
));
2139 ASET (slot
, 3, Qnil
);
2144 DEFUN ("ccl-program-p", Fccl_program_p
, Sccl_program_p
, 1, 1, 0,
2145 doc
: /* Return t if OBJECT is a CCL program name or a compiled CCL program code.
2146 See the documentation of `define-ccl-program' for the detail of CCL program. */)
2152 if (VECTORP (object
))
2154 val
= resolve_symbol_ccl_program (object
);
2155 return (VECTORP (val
) ? Qt
: Qnil
);
2157 if (!SYMBOLP (object
))
2160 val
= Fget (object
, Qccl_program_idx
);
2161 return ((! NATNUMP (val
)
2162 || XINT (val
) >= ASIZE (Vccl_program_table
))
2166 DEFUN ("ccl-execute", Fccl_execute
, Sccl_execute
, 2, 2, 0,
2167 doc
: /* Execute CCL-PROGRAM with registers initialized by REGISTERS.
2169 CCL-PROGRAM is a CCL program name (symbol)
2170 or compiled code generated by `ccl-compile' (for backward compatibility.
2171 In the latter case, the execution overhead is bigger than in the former).
2172 No I/O commands should appear in CCL-PROGRAM.
2174 REGISTERS is a vector of [R0 R1 ... R7] where RN is an initial value
2175 for the Nth register.
2177 As side effect, each element of REGISTERS holds the value of
2178 the corresponding register after the execution.
2180 See the documentation of `define-ccl-program' for a definition of CCL
2183 Lisp_Object ccl_prog
, reg
;
2185 struct ccl_program ccl
;
2188 if (setup_ccl_program (&ccl
, ccl_prog
) < 0)
2189 error ("Invalid CCL program");
2192 if (ASIZE (reg
) != 8)
2193 error ("Length of vector REGISTERS is not 8");
2195 for (i
= 0; i
< 8; i
++)
2196 ccl
.reg
[i
] = (INTEGERP (AREF (reg
, i
))
2197 ? XINT (AREF (reg
, i
))
2200 ccl_driver (&ccl
, (unsigned char *)0, (unsigned char *)0, 0, 0, (int *)0);
2202 if (ccl
.status
!= CCL_STAT_SUCCESS
)
2203 error ("Error in CCL program at %dth code", ccl
.ic
);
2205 for (i
= 0; i
< 8; i
++)
2206 XSETINT (AREF (reg
, i
), ccl
.reg
[i
]);
2210 DEFUN ("ccl-execute-on-string", Fccl_execute_on_string
, Sccl_execute_on_string
,
2212 doc
: /* Execute CCL-PROGRAM with initial STATUS on STRING.
2214 CCL-PROGRAM is a symbol registered by `register-ccl-program',
2215 or a compiled code generated by `ccl-compile' (for backward compatibility,
2216 in this case, the execution is slower).
2218 Read buffer is set to STRING, and write buffer is allocated automatically.
2220 STATUS is a vector of [R0 R1 ... R7 IC], where
2221 R0..R7 are initial values of corresponding registers,
2222 IC is the instruction counter specifying from where to start the program.
2223 If R0..R7 are nil, they are initialized to 0.
2224 If IC is nil, it is initialized to head of the CCL program.
2226 If optional 4th arg CONTINUE is non-nil, keep IC on read operation
2227 when read buffer is exausted, else, IC is always set to the end of
2228 CCL-PROGRAM on exit.
2230 It returns the contents of write buffer as a string,
2231 and as side effect, STATUS is updated.
2232 If the optional 5th arg UNIBYTE-P is non-nil, the returned string
2233 is a unibyte string. By default it is a multibyte string.
2235 See the documentation of `define-ccl-program' for the detail of CCL program.
2236 usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBYTE-P) */)
2237 (ccl_prog
, status
, str
, contin
, unibyte_p
)
2238 Lisp_Object ccl_prog
, status
, str
, contin
, unibyte_p
;
2241 struct ccl_program ccl
;
2245 struct gcpro gcpro1
, gcpro2
;
2247 if (setup_ccl_program (&ccl
, ccl_prog
) < 0)
2248 error ("Invalid CCL program");
2250 CHECK_VECTOR (status
);
2251 if (ASIZE (status
) != 9)
2252 error ("Length of vector STATUS is not 9");
2255 GCPRO2 (status
, str
);
2257 for (i
= 0; i
< 8; i
++)
2259 if (NILP (AREF (status
, i
)))
2260 XSETINT (AREF (status
, i
), 0);
2261 if (INTEGERP (AREF (status
, i
)))
2262 ccl
.reg
[i
] = XINT (AREF (status
, i
));
2264 if (INTEGERP (AREF (status
, i
)))
2266 i
= XFASTINT (AREF (status
, 8));
2267 if (ccl
.ic
< i
&& i
< ccl
.size
)
2270 outbufsize
= SBYTES (str
) * ccl
.buf_magnification
+ 256;
2271 outbuf
= (char *) xmalloc (outbufsize
);
2272 ccl
.last_block
= NILP (contin
);
2273 ccl
.multibyte
= STRING_MULTIBYTE (str
);
2274 produced
= ccl_driver (&ccl
, SDATA (str
), outbuf
,
2275 SBYTES (str
), outbufsize
, (int *) 0);
2276 for (i
= 0; i
< 8; i
++)
2277 ASET (status
, i
, make_number (ccl
.reg
[i
]));
2278 ASET (status
, 8, make_number (ccl
.ic
));
2281 if (NILP (unibyte_p
))
2285 produced
= str_as_multibyte (outbuf
, outbufsize
, produced
, &nchars
);
2286 val
= make_multibyte_string (outbuf
, nchars
, produced
);
2289 val
= make_unibyte_string (outbuf
, produced
);
2292 if (ccl
.status
== CCL_STAT_SUSPEND_BY_DST
)
2293 error ("Output buffer for the CCL programs overflow");
2294 if (ccl
.status
!= CCL_STAT_SUCCESS
2295 && ccl
.status
!= CCL_STAT_SUSPEND_BY_SRC
)
2296 error ("Error in CCL program at %dth code", ccl
.ic
);
2301 DEFUN ("register-ccl-program", Fregister_ccl_program
, Sregister_ccl_program
,
2303 doc
: /* Register CCL program CCL-PROG as NAME in `ccl-program-table'.
2304 CCL-PROG should be a compiled CCL program (vector), or nil.
2305 If it is nil, just reserve NAME as a CCL program name.
2306 Return index number of the registered CCL program. */)
2308 Lisp_Object name
, ccl_prog
;
2310 int len
= ASIZE (Vccl_program_table
);
2312 Lisp_Object resolved
;
2314 CHECK_SYMBOL (name
);
2316 if (!NILP (ccl_prog
))
2318 CHECK_VECTOR (ccl_prog
);
2319 resolved
= resolve_symbol_ccl_program (ccl_prog
);
2320 if (NILP (resolved
))
2321 error ("Error in CCL program");
2322 if (VECTORP (resolved
))
2324 ccl_prog
= resolved
;
2331 for (idx
= 0; idx
< len
; idx
++)
2335 slot
= AREF (Vccl_program_table
, idx
);
2336 if (!VECTORP (slot
))
2337 /* This is the first unsed slot. Register NAME here. */
2340 if (EQ (name
, AREF (slot
, 0)))
2342 /* Update this slot. */
2343 ASET (slot
, 1, ccl_prog
);
2344 ASET (slot
, 2, resolved
);
2346 return make_number (idx
);
2352 /* Extend the table. */
2353 Lisp_Object new_table
;
2356 new_table
= Fmake_vector (make_number (len
* 2), Qnil
);
2357 for (j
= 0; j
< len
; j
++)
2358 ASET (new_table
, j
, AREF (Vccl_program_table
, j
));
2359 Vccl_program_table
= new_table
;
2365 elt
= Fmake_vector (make_number (4), Qnil
);
2366 ASET (elt
, 0, name
);
2367 ASET (elt
, 1, ccl_prog
);
2368 ASET (elt
, 2, resolved
);
2370 ASET (Vccl_program_table
, idx
, elt
);
2373 Fput (name
, Qccl_program_idx
, make_number (idx
));
2374 return make_number (idx
);
2377 /* Register code conversion map.
2378 A code conversion map consists of numbers, Qt, Qnil, and Qlambda.
2379 The first element is the start code point.
2380 The other elements are mapped numbers.
2381 Symbol t means to map to an original number before mapping.
2382 Symbol nil means that the corresponding element is empty.
2383 Symbol lambda means to terminate mapping here.
2386 DEFUN ("register-code-conversion-map", Fregister_code_conversion_map
,
2387 Sregister_code_conversion_map
,
2389 doc
: /* Register SYMBOL as code conversion map MAP.
2390 Return index number of the registered map. */)
2392 Lisp_Object symbol
, map
;
2394 int len
= ASIZE (Vcode_conversion_map_vector
);
2398 CHECK_SYMBOL (symbol
);
2401 for (i
= 0; i
< len
; i
++)
2403 Lisp_Object slot
= AREF (Vcode_conversion_map_vector
, i
);
2408 if (EQ (symbol
, XCAR (slot
)))
2410 index
= make_number (i
);
2411 XSETCDR (slot
, map
);
2412 Fput (symbol
, Qcode_conversion_map
, map
);
2413 Fput (symbol
, Qcode_conversion_map_id
, index
);
2420 Lisp_Object new_vector
= Fmake_vector (make_number (len
* 2), Qnil
);
2423 for (j
= 0; j
< len
; j
++)
2424 AREF (new_vector
, j
)
2425 = AREF (Vcode_conversion_map_vector
, j
);
2426 Vcode_conversion_map_vector
= new_vector
;
2429 index
= make_number (i
);
2430 Fput (symbol
, Qcode_conversion_map
, map
);
2431 Fput (symbol
, Qcode_conversion_map_id
, index
);
2432 AREF (Vcode_conversion_map_vector
, i
) = Fcons (symbol
, map
);
2440 staticpro (&Vccl_program_table
);
2441 Vccl_program_table
= Fmake_vector (make_number (32), Qnil
);
2443 Qccl_program
= intern ("ccl-program");
2444 staticpro (&Qccl_program
);
2446 Qccl_program_idx
= intern ("ccl-program-idx");
2447 staticpro (&Qccl_program_idx
);
2449 Qcode_conversion_map
= intern ("code-conversion-map");
2450 staticpro (&Qcode_conversion_map
);
2452 Qcode_conversion_map_id
= intern ("code-conversion-map-id");
2453 staticpro (&Qcode_conversion_map_id
);
2455 DEFVAR_LISP ("code-conversion-map-vector", &Vcode_conversion_map_vector
,
2456 doc
: /* Vector of code conversion maps. */);
2457 Vcode_conversion_map_vector
= Fmake_vector (make_number (16), Qnil
);
2459 DEFVAR_LISP ("font-ccl-encoder-alist", &Vfont_ccl_encoder_alist
,
2460 doc
: /* Alist of fontname patterns vs corresponding CCL program.
2461 Each element looks like (REGEXP . CCL-CODE),
2462 where CCL-CODE is a compiled CCL program.
2463 When a font whose name matches REGEXP is used for displaying a character,
2464 CCL-CODE is executed to calculate the code point in the font
2465 from the charset number and position code(s) of the character which are set
2466 in CCL registers R0, R1, and R2 before the execution.
2467 The code point in the font is set in CCL registers R1 and R2
2468 when the execution terminated.
2469 If the font is single-byte font, the register R2 is not used. */);
2470 Vfont_ccl_encoder_alist
= Qnil
;
2472 DEFVAR_LISP ("translation-hash-table-vector", &Vtranslation_hash_table_vector
,
2473 doc
: /* Vector containing all translation hash tables ever defined.
2474 Comprises pairs (SYMBOL . TABLE) where SYMBOL and TABLE were set up by calls
2475 to `define-translation-hash-table'. The vector is indexed by the table id
2477 Vtranslation_hash_table_vector
= Qnil
;
2479 defsubr (&Sccl_program_p
);
2480 defsubr (&Sccl_execute
);
2481 defsubr (&Sccl_execute_on_string
);
2482 defsubr (&Sregister_ccl_program
);
2483 defsubr (&Sregister_code_conversion_map
);
2486 /* arch-tag: bb9a37be-68ce-4576-8d3d-15d750e4a860
2487 (do not change this comment) */