428
|
1 /* CCL (Code Conversion Language) interpreter.
|
444
|
2 Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN.
|
826
|
3 Copyright (C) 2002 Ben Wing.
|
428
|
4 Licensed to the Free Software Foundation.
|
|
5
|
613
|
6 This file is part of XEmacs.
|
428
|
7
|
613
|
8 XEmacs is free software; you can redistribute it and/or modify
|
428
|
9 it under the terms of the GNU General Public License as published by
|
|
10 the Free Software Foundation; either version 2, or (at your option)
|
|
11 any later version.
|
|
12
|
613
|
13 XEmacs is distributed in the hope that it will be useful,
|
428
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 GNU General Public License for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
613
|
19 along with XEmacs; see the file COPYING. If not, write to
|
428
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
444
|
23 /* Synched up with : FSF Emacs 21.0.90 except TranslateCharacter */
|
428
|
24
|
|
25 #include <config.h>
|
771
|
26 #include "lisp.h"
|
444
|
27
|
428
|
28 #include "buffer.h"
|
771
|
29 #include "charset.h"
|
428
|
30 #include "mule-ccl.h"
|
|
31 #include "file-coding.h"
|
4072
|
32 #include "elhash.h"
|
428
|
33
|
565
|
34 Lisp_Object Qccl_error;
|
|
35
|
428
|
36 /* This contains all code conversion map available to CCL. */
|
|
37 Lisp_Object Vcode_conversion_map_vector;
|
|
38
|
444
|
39 /* This symbol is a property which associates with ccl program vector.
|
3452
|
40 Ex: (get 'ccl-big5-encoder 'ccl-program) returns ccl program vector.
|
|
41 Moved to general-slots.h. */
|
|
42 /* Lisp_Object Qccl_program; */
|
428
|
43
|
|
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;
|
|
48
|
|
49 /* Symbols of ccl program have this property, a value of the property
|
444
|
50 is an index for Vccl_program_table. */
|
428
|
51 Lisp_Object Qccl_program_idx;
|
|
52
|
444
|
53 /* Table of registered CCL programs. Each element is a vector of
|
|
54 NAME, CCL_PROG, and RESOLVEDP where NAME (symbol) is the name of
|
|
55 the program, CCL_PROG (vector) is the compiled code of the program,
|
|
56 RESOLVEDP (t or nil) is the flag to tell if symbols in CCL_PROG is
|
|
57 already resolved to index numbers or not. */
|
428
|
58 Lisp_Object Vccl_program_table;
|
|
59
|
4072
|
60 /* Vector of registered hash tables for translation. */
|
|
61 Lisp_Object Vtranslation_hash_table_vector;
|
|
62
|
|
63 /* Return a hash table of id number ID. */
|
|
64 #define GET_HASH_TABLE(id) \
|
|
65 (XHASH_TABLE (XCDR(XVECTOR(Vtranslation_hash_table_vector)->contents[(id)])))
|
|
66 /* Copied from fns.c. */
|
|
67 #define HASH_VALUE(H, IDX) AREF ((H)->key_and_value, 2 * (IDX) + 1)
|
|
68
|
428
|
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
|
|
78 codes. */
|
|
79
|
|
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
|
|
84
|
|
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
|
|
87 following format:
|
|
88
|
|
89 |----------------- integer (28-bit) ------------------|
|
|
90 |------- 17-bit ------|- 3-bit --|- 3-bit --|- 5-bit -|
|
|
91 |--constant argument--|-register-|-register-|-command-|
|
|
92 ccccccccccccccccc RRR rrr XXXXX
|
|
93 or
|
|
94 |------- relative address -------|-register-|-command-|
|
|
95 cccccccccccccccccccc rrr XXXXX
|
|
96 or
|
|
97 |------------- constant or other args ----------------|
|
|
98 cccccccccccccccccccccccccccc
|
|
99
|
|
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
|
|
103 CCL commands. */
|
|
104
|
|
105 /* CCL commands
|
|
106
|
|
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. */
|
|
110
|
|
111 #define CCL_SetRegister 0x00 /* Set register a register value:
|
|
112 1:00000000000000000RRRrrrXXXXX
|
|
113 ------------------------------
|
|
114 reg[rrr] = reg[RRR];
|
|
115 */
|
|
116
|
|
117 #define CCL_SetShortConst 0x01 /* Set register a short constant value:
|
|
118 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
|
|
119 ------------------------------
|
|
120 reg[rrr] = CCCCCCCCCCCCCCCCCCC;
|
|
121 */
|
|
122
|
|
123 #define CCL_SetConst 0x02 /* Set register a constant value:
|
|
124 1:00000000000000000000rrrXXXXX
|
|
125 2:CONSTANT
|
|
126 ------------------------------
|
|
127 reg[rrr] = CONSTANT;
|
|
128 IC++;
|
|
129 */
|
|
130
|
|
131 #define CCL_SetArray 0x03 /* Set register an element of array:
|
|
132 1:CCCCCCCCCCCCCCCCCRRRrrrXXXXX
|
|
133 2:ELEMENT[0]
|
|
134 3:ELEMENT[1]
|
|
135 ...
|
|
136 ------------------------------
|
|
137 if (0 <= reg[RRR] < CC..C)
|
|
138 reg[rrr] = ELEMENT[reg[RRR]];
|
|
139 IC += CC..C;
|
|
140 */
|
|
141
|
|
142 #define CCL_Jump 0x04 /* Jump:
|
|
143 1:A--D--D--R--E--S--S-000XXXXX
|
|
144 ------------------------------
|
|
145 IC += ADDRESS;
|
|
146 */
|
|
147
|
|
148 /* Note: If CC..C is greater than 0, the second code is omitted. */
|
|
149
|
|
150 #define CCL_JumpCond 0x05 /* Jump conditional:
|
|
151 1:A--D--D--R--E--S--S-rrrXXXXX
|
|
152 ------------------------------
|
|
153 if (!reg[rrr])
|
|
154 IC += ADDRESS;
|
|
155 */
|
|
156
|
|
157
|
|
158 #define CCL_WriteRegisterJump 0x06 /* Write register and jump:
|
|
159 1:A--D--D--R--E--S--S-rrrXXXXX
|
|
160 ------------------------------
|
|
161 write (reg[rrr]);
|
|
162 IC += ADDRESS;
|
|
163 */
|
|
164
|
|
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 -----------------------------
|
|
169 write (reg[rrr]);
|
|
170 IC++;
|
|
171 read (reg[rrr]);
|
|
172 IC += ADDRESS;
|
|
173 */
|
|
174 /* Note: If read is suspended, the resumed execution starts from the
|
|
175 second code (YYYYY == CCL_ReadJump). */
|
|
176
|
|
177 #define CCL_WriteConstJump 0x08 /* Write constant and jump:
|
|
178 1:A--D--D--R--E--S--S-000XXXXX
|
444
|
179 2:CONST
|
428
|
180 ------------------------------
|
444
|
181 write (CONST);
|
428
|
182 IC += ADDRESS;
|
|
183 */
|
|
184
|
|
185 #define CCL_WriteConstReadJump 0x09 /* Write constant, read, and jump:
|
|
186 1:A--D--D--R--E--S--S-rrrXXXXX
|
444
|
187 2:CONST
|
428
|
188 3:A--D--D--R--E--S--S-rrrYYYYY
|
|
189 -----------------------------
|
444
|
190 write (CONST);
|
428
|
191 IC += 2;
|
|
192 read (reg[rrr]);
|
|
193 IC += ADDRESS;
|
|
194 */
|
|
195 /* Note: If read is suspended, the resumed execution starts from the
|
|
196 second code (YYYYY == CCL_ReadJump). */
|
|
197
|
|
198 #define CCL_WriteStringJump 0x0A /* Write string and jump:
|
|
199 1:A--D--D--R--E--S--S-000XXXXX
|
|
200 2:LENGTH
|
|
201 3:0000STRIN[0]STRIN[1]STRIN[2]
|
|
202 ...
|
|
203 ------------------------------
|
|
204 write_string (STRING, LENGTH);
|
|
205 IC += ADDRESS;
|
|
206 */
|
|
207
|
|
208 #define CCL_WriteArrayReadJump 0x0B /* Write an array element, read, and jump:
|
|
209 1:A--D--D--R--E--S--S-rrrXXXXX
|
|
210 2:LENGTH
|
|
211 3:ELEMENET[0]
|
|
212 4:ELEMENET[1]
|
|
213 ...
|
|
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)
|
|
219 read (reg[rrr]);
|
|
220 IC += ADDRESS;
|
|
221 */
|
|
222 /* Note: If read is suspended, the resumed execution starts from the
|
|
223 Nth code (YYYYY == CCL_ReadJump). */
|
|
224
|
|
225 #define CCL_ReadJump 0x0C /* Read and jump:
|
|
226 1:A--D--D--R--E--S--S-rrrYYYYY
|
|
227 -----------------------------
|
|
228 read (reg[rrr]);
|
|
229 IC += ADDRESS;
|
|
230 */
|
|
231
|
|
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
|
|
236 ...
|
|
237 ------------------------------
|
|
238 if (0 <= reg[rrr] < CC..C)
|
|
239 IC += ADDRESS[reg[rrr]];
|
|
240 else
|
|
241 IC += ADDRESS[CC..C];
|
|
242 */
|
|
243
|
|
244 #define CCL_ReadRegister 0x0E /* Read bytes into registers:
|
|
245 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
|
|
246 2:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
|
|
247 ...
|
|
248 ------------------------------
|
|
249 while (CCC--)
|
|
250 read (reg[rrr]);
|
|
251 */
|
|
252
|
|
253 #define CCL_WriteExprConst 0x0F /* write result of expression:
|
|
254 1:00000OPERATION000RRR000XXXXX
|
|
255 2:CONSTANT
|
|
256 ------------------------------
|
|
257 write (reg[RRR] OPERATION CONSTANT);
|
|
258 IC++;
|
|
259 */
|
|
260
|
|
261 /* Note: If the Nth read is suspended, the resumed execution starts
|
|
262 from the Nth code. */
|
|
263
|
|
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
|
|
269 ...
|
|
270 ------------------------------
|
|
271 read (read[rrr]);
|
|
272 if (0 <= reg[rrr] < CC..C)
|
|
273 IC += ADDRESS[reg[rrr]];
|
|
274 else
|
|
275 IC += ADDRESS[CC..C];
|
|
276 */
|
|
277
|
|
278 #define CCL_WriteRegister 0x11 /* Write registers:
|
|
279 1:CCCCCCCCCCCCCCCCCCCrrrXXXXX
|
|
280 2:CCCCCCCCCCCCCCCCCCCrrrXXXXX
|
|
281 ...
|
|
282 ------------------------------
|
|
283 while (CCC--)
|
|
284 write (reg[rrr]);
|
|
285 ...
|
|
286 */
|
|
287
|
|
288 /* Note: If the Nth write is suspended, the resumed execution
|
|
289 starts from the Nth code. */
|
|
290
|
|
291 #define CCL_WriteExprRegister 0x12 /* Write result of expression
|
|
292 1:00000OPERATIONRrrRRR000XXXXX
|
|
293 ------------------------------
|
|
294 write (reg[RRR] OPERATION reg[Rrr]);
|
|
295 */
|
|
296
|
|
297 #define CCL_Call 0x13 /* Call the CCL program whose ID is
|
444
|
298 CC..C or cc..c.
|
|
299 1:CCCCCCCCCCCCCCCCCCCCFFFXXXXX
|
|
300 [2:00000000cccccccccccccccccccc]
|
428
|
301 ------------------------------
|
444
|
302 if (FFF)
|
|
303 call (cc..c)
|
|
304 IC++;
|
|
305 else
|
|
306 call (CC..C)
|
428
|
307 */
|
|
308
|
|
309 #define CCL_WriteConstString 0x14 /* Write a constant or a string:
|
|
310 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
|
|
311 [2:0000STRIN[0]STRIN[1]STRIN[2]]
|
|
312 [...]
|
|
313 -----------------------------
|
|
314 if (!rrr)
|
|
315 write (CC..C)
|
|
316 else
|
|
317 write_string (STRING, CC..C);
|
|
318 IC += (CC..C + 2) / 3;
|
|
319 */
|
|
320
|
|
321 #define CCL_WriteArray 0x15 /* Write an element of array:
|
|
322 1:CCCCCCCCCCCCCCCCCCCCrrrXXXXX
|
|
323 2:ELEMENT[0]
|
|
324 3:ELEMENT[1]
|
|
325 ...
|
|
326 ------------------------------
|
|
327 if (0 <= reg[rrr] < CC..C)
|
|
328 write (ELEMENT[reg[rrr]]);
|
|
329 IC += CC..C;
|
|
330 */
|
|
331
|
|
332 #define CCL_End 0x16 /* Terminate:
|
|
333 1:00000000000000000000000XXXXX
|
|
334 ------------------------------
|
|
335 terminate ();
|
|
336 */
|
|
337
|
|
338 /* The following two codes execute an assignment arithmetic/logical
|
|
339 operation. The form of the operation is like REG OP= OPERAND. */
|
|
340
|
|
341 #define CCL_ExprSelfConst 0x17 /* REG OP= constant:
|
|
342 1:00000OPERATION000000rrrXXXXX
|
|
343 2:CONSTANT
|
|
344 ------------------------------
|
|
345 reg[rrr] OPERATION= CONSTANT;
|
|
346 */
|
|
347
|
|
348 #define CCL_ExprSelfReg 0x18 /* REG1 OP= REG2:
|
|
349 1:00000OPERATION000RRRrrrXXXXX
|
|
350 ------------------------------
|
|
351 reg[rrr] OPERATION= reg[RRR];
|
|
352 */
|
|
353
|
|
354 /* The following codes execute an arithmetic/logical operation. The
|
|
355 form of the operation is like REG_X = REG_Y OP OPERAND2. */
|
|
356
|
|
357 #define CCL_SetExprConst 0x19 /* REG_X = REG_Y OP constant:
|
|
358 1:00000OPERATION000RRRrrrXXXXX
|
|
359 2:CONSTANT
|
|
360 ------------------------------
|
|
361 reg[rrr] = reg[RRR] OPERATION CONSTANT;
|
|
362 IC++;
|
|
363 */
|
|
364
|
|
365 #define CCL_SetExprReg 0x1A /* REG1 = REG2 OP REG3:
|
|
366 1:00000OPERATIONRrrRRRrrrXXXXX
|
|
367 ------------------------------
|
|
368 reg[rrr] = reg[RRR] OPERATION reg[Rrr];
|
|
369 */
|
|
370
|
|
371 #define CCL_JumpCondExprConst 0x1B /* Jump conditional according to
|
|
372 an operation on constant:
|
|
373 1:A--D--D--R--E--S--S-rrrXXXXX
|
|
374 2:OPERATION
|
|
375 3:CONSTANT
|
|
376 -----------------------------
|
|
377 reg[7] = reg[rrr] OPERATION CONSTANT;
|
|
378 if (!(reg[7]))
|
|
379 IC += ADDRESS;
|
|
380 else
|
|
381 IC += 2
|
|
382 */
|
|
383
|
|
384 #define CCL_JumpCondExprReg 0x1C /* Jump conditional according to
|
|
385 an operation on register:
|
|
386 1:A--D--D--R--E--S--S-rrrXXXXX
|
|
387 2:OPERATION
|
|
388 3:RRR
|
|
389 -----------------------------
|
|
390 reg[7] = reg[rrr] OPERATION reg[RRR];
|
|
391 if (!reg[7])
|
|
392 IC += ADDRESS;
|
|
393 else
|
|
394 IC += 2;
|
|
395 */
|
|
396
|
|
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
|
|
400 2:OPERATION
|
|
401 3:CONSTANT
|
|
402 -----------------------------
|
|
403 read (reg[rrr]);
|
|
404 reg[7] = reg[rrr] OPERATION CONSTANT;
|
|
405 if (!reg[7])
|
|
406 IC += ADDRESS;
|
|
407 else
|
|
408 IC += 2;
|
|
409 */
|
|
410
|
|
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
|
|
414 2:OPERATION
|
|
415 3:RRR
|
|
416 -----------------------------
|
|
417 read (reg[rrr]);
|
|
418 reg[7] = reg[rrr] OPERATION reg[RRR];
|
|
419 if (!reg[7])
|
|
420 IC += ADDRESS;
|
|
421 else
|
|
422 IC += 2;
|
|
423 */
|
|
424
|
456
|
425 #define CCL_Extension 0x1F /* Extended CCL code
|
428
|
426 1:ExtendedCOMMNDRrrRRRrrrXXXXX
|
444
|
427 2:ARGUMENT
|
428
|
428 3:...
|
|
429 ------------------------------
|
|
430 extended_command (rrr,RRR,Rrr,ARGS)
|
|
431 */
|
|
432
|
442
|
433 /*
|
428
|
434 Here after, Extended CCL Instructions.
|
|
435 Bit length of extended command is 14.
|
|
436 Therefore, the instruction code range is 0..16384(0x3fff).
|
|
437 */
|
|
438
|
|
439 /* Read a multibyte characeter.
|
|
440 A code point is stored into reg[rrr]. A charset ID is stored into
|
|
441 reg[RRR]. */
|
|
442
|
|
443 #define CCL_ReadMultibyteChar2 0x00 /* Read Multibyte Character
|
|
444 1:ExtendedCOMMNDRrrRRRrrrXXXXX */
|
|
445
|
|
446 /* Write a multibyte character.
|
|
447 Write a character whose code point is reg[rrr] and the charset ID
|
|
448 is reg[RRR]. */
|
|
449
|
|
450 #define CCL_WriteMultibyteChar2 0x01 /* Write Multibyte Character
|
|
451 1:ExtendedCOMMNDRrrRRRrrrXXXXX */
|
|
452
|
|
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].
|
|
455
|
|
456 A translated character is set in reg[rrr] (code point) and reg[RRR]
|
|
457 (charset ID). */
|
|
458
|
|
459 #define CCL_TranslateCharacter 0x02 /* Translate a multibyte character
|
|
460 1:ExtendedCOMMNDRrrRRRrrrXXXXX */
|
|
461
|
|
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.
|
|
464
|
|
465 A translated character is set in reg[rrr] (code point) and reg[RRR]
|
|
466 (charset ID). */
|
|
467
|
|
468 #define CCL_TranslateCharacterConstTbl 0x03 /* Translate a multibyte character
|
|
469 1:ExtendedCOMMNDRrrRRRrrrXXXXX
|
|
470 2:ARGUMENT(Translation Table ID)
|
|
471 */
|
3439
|
472 /* Translate a character whose code point is reg[rrr] and charset ID is
|
|
473 reg[RRR], into its Unicode code point, which will be written into
|
|
474 reg[rrr]. */
|
|
475
|
|
476 #define CCL_MuleToUnicode 0x04
|
|
477
|
|
478 /* Translate a Unicode code point, in reg[rrr], into a Mule character,
|
|
479 writing the charset ID into reg[RRR] and the code point into reg[Rrr]. */
|
|
480
|
|
481 #define CCL_UnicodeToMule 0x05
|
428
|
482
|
|
483 /* Iterate looking up MAPs for reg[rrr] starting from the Nth (N =
|
|
484 reg[RRR]) MAP until some value is found.
|
|
485
|
|
486 Each MAP is a Lisp vector whose element is number, nil, t, or
|
|
487 lambda.
|
|
488 If the element is nil, ignore the map and proceed to the next map.
|
|
489 If the element is t or lambda, finish without changing reg[rrr].
|
|
490 If the element is a number, set reg[rrr] to the number and finish.
|
|
491
|
444
|
492 Detail of the map structure is described in the comment for
|
428
|
493 CCL_MapMultiple below. */
|
|
494
|
|
495 #define CCL_IterateMultipleMap 0x10 /* Iterate multiple maps
|
|
496 1:ExtendedCOMMNDXXXRRRrrrXXXXX
|
|
497 2:NUMBER of MAPs
|
|
498 3:MAP-ID1
|
|
499 4:MAP-ID2
|
|
500 ...
|
442
|
501 */
|
428
|
502
|
|
503 /* Map the code in reg[rrr] by MAPs starting from the Nth (N =
|
|
504 reg[RRR]) map.
|
|
505
|
|
506 MAPs are supplied in the succeeding CCL codes as follows:
|
|
507
|
|
508 When CCL program gives this nested structure of map to this command:
|
|
509 ((MAP-ID11
|
|
510 MAP-ID12
|
|
511 (MAP-ID121 MAP-ID122 MAP-ID123)
|
|
512 MAP-ID13)
|
|
513 (MAP-ID21
|
|
514 (MAP-ID211 (MAP-ID2111) MAP-ID212)
|
|
515 MAP-ID22)),
|
444
|
516 the compiled CCL code has this sequence:
|
428
|
517 CCL_MapMultiple (CCL code of this command)
|
|
518 16 (total number of MAPs and SEPARATORs)
|
|
519 -7 (1st SEPARATOR)
|
|
520 MAP-ID11
|
|
521 MAP-ID12
|
|
522 -3 (2nd SEPARATOR)
|
|
523 MAP-ID121
|
|
524 MAP-ID122
|
|
525 MAP-ID123
|
|
526 MAP-ID13
|
|
527 -7 (3rd SEPARATOR)
|
|
528 MAP-ID21
|
|
529 -4 (4th SEPARATOR)
|
|
530 MAP-ID211
|
|
531 -1 (5th SEPARATOR)
|
|
532 MAP_ID2111
|
|
533 MAP-ID212
|
|
534 MAP-ID22
|
|
535
|
|
536 A value of each SEPARATOR follows this rule:
|
|
537 MAP-SET := SEPARATOR [(MAP-ID | MAP-SET)]+
|
|
538 SEPARATOR := -(number of MAP-IDs and SEPARATORs in the MAP-SET)
|
|
539
|
|
540 (*)....Nest level of MAP-SET must not be over than MAX_MAP_SET_LEVEL.
|
|
541
|
|
542 When some map fails to map (i.e. it doesn't have a value for
|
|
543 reg[rrr]), the mapping is treated as identity.
|
|
544
|
|
545 The mapping is iterated for all maps in each map set (set of maps
|
|
546 separated by SEPARATOR) except in the case that lambda is
|
|
547 encountered. More precisely, the mapping proceeds as below:
|
|
548
|
|
549 At first, VAL0 is set to reg[rrr], and it is translated by the
|
|
550 first map to VAL1. Then, VAL1 is translated by the next map to
|
|
551 VAL2. This mapping is iterated until the last map is used. The
|
444
|
552 result of the mapping is the last value of VAL?. When the mapping
|
|
553 process reached to the end of the map set, it moves to the next
|
|
554 map set. If the next does not exit, the mapping process terminates,
|
|
555 and regard the last value as a result.
|
428
|
556
|
|
557 But, when VALm is mapped to VALn and VALn is not a number, the
|
444
|
558 mapping proceeds as follows:
|
428
|
559
|
|
560 If VALn is nil, the lastest map is ignored and the mapping of VALm
|
444
|
561 proceeds to the next map.
|
428
|
562
|
|
563 In VALn is t, VALm is reverted to reg[rrr] and the mapping of VALm
|
444
|
564 proceeds to the next map.
|
428
|
565
|
444
|
566 If VALn is lambda, move to the next map set like reaching to the
|
|
567 end of the current map set.
|
|
568
|
|
569 If VALn is a symbol, call the CCL program refered by it.
|
|
570 Then, use reg[rrr] as a mapped value except for -1, -2 and -3.
|
|
571 Such special values are regarded as nil, t, and lambda respectively.
|
428
|
572
|
|
573 Each map is a Lisp vector of the following format (a) or (b):
|
|
574 (a)......[STARTPOINT VAL1 VAL2 ...]
|
|
575 (b)......[t VAL STARTPOINT ENDPOINT],
|
|
576 where
|
|
577 STARTPOINT is an offset to be used for indexing a map,
|
|
578 ENDPOINT is a maximum index number of a map,
|
442
|
579 VAL and VALn is a number, nil, t, or lambda.
|
428
|
580
|
|
581 Valid index range of a map of type (a) is:
|
|
582 STARTPOINT <= index < STARTPOINT + map_size - 1
|
|
583 Valid index range of a map of type (b) is:
|
|
584 STARTPOINT <= index < ENDPOINT */
|
|
585
|
|
586 #define CCL_MapMultiple 0x11 /* Mapping by multiple code conversion maps
|
|
587 1:ExtendedCOMMNDXXXRRRrrrXXXXX
|
|
588 2:N-2
|
|
589 3:SEPARATOR_1 (< 0)
|
|
590 4:MAP-ID_1
|
|
591 5:MAP-ID_2
|
|
592 ...
|
|
593 M:SEPARATOR_x (< 0)
|
|
594 M+1:MAP-ID_y
|
|
595 ...
|
|
596 N:SEPARATOR_z (< 0)
|
|
597 */
|
444
|
598 #define MAX_MAP_SET_LEVEL 30
|
428
|
599
|
|
600 typedef struct
|
|
601 {
|
|
602 int rest_length;
|
|
603 int orig_val;
|
|
604 } tr_stack;
|
|
605
|
|
606 static tr_stack mapping_stack[MAX_MAP_SET_LEVEL];
|
|
607 static tr_stack *mapping_stack_pointer;
|
444
|
608
|
|
609 /* If this variable is non-zero, it indicates the stack_idx
|
|
610 of immediately called by CCL_MapMultiple. */
|
450
|
611 static int stack_idx_of_map_multiple;
|
444
|
612
|
|
613 #define PUSH_MAPPING_STACK(restlen, orig) \
|
|
614 do { \
|
|
615 mapping_stack_pointer->rest_length = (restlen); \
|
|
616 mapping_stack_pointer->orig_val = (orig); \
|
|
617 mapping_stack_pointer++; \
|
|
618 } while (0)
|
|
619
|
|
620 #define POP_MAPPING_STACK(restlen, orig) \
|
|
621 do { \
|
|
622 mapping_stack_pointer--; \
|
|
623 (restlen) = mapping_stack_pointer->rest_length; \
|
|
624 (orig) = mapping_stack_pointer->orig_val; \
|
|
625 } while (0)
|
428
|
626
|
444
|
627 #define CCL_CALL_FOR_MAP_INSTRUCTION(symbol, ret_ic) \
|
|
628 do { \
|
|
629 struct ccl_program called_ccl; \
|
|
630 if (stack_idx >= 256 \
|
|
631 || (setup_ccl_program (&called_ccl, (symbol)) != 0)) \
|
|
632 { \
|
|
633 if (stack_idx > 0) \
|
|
634 { \
|
|
635 ccl_prog = ccl_prog_stack_struct[0].ccl_prog; \
|
|
636 ic = ccl_prog_stack_struct[0].ic; \
|
4193
|
637 eof_ic = ccl_prog_stack_struct[0].eof_ic; \
|
444
|
638 } \
|
|
639 CCL_INVALID_CMD; \
|
|
640 } \
|
|
641 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog; \
|
|
642 ccl_prog_stack_struct[stack_idx].ic = (ret_ic); \
|
4193
|
643 ccl_prog_stack_struct[stack_idx].eof_ic = eof_ic; \
|
444
|
644 stack_idx++; \
|
|
645 ccl_prog = called_ccl.prog; \
|
|
646 ic = CCL_HEADER_MAIN; \
|
4193
|
647 eof_ic = XINT (ccl_prog[CCL_HEADER_EOF]); \
|
456
|
648 /* The "if (1)" prevents warning \
|
|
649 "end-of loop code not reached" */ \
|
|
650 if (1) goto ccl_repeat; \
|
444
|
651 } while (0)
|
428
|
652
|
|
653 #define CCL_MapSingle 0x12 /* Map by single code conversion map
|
|
654 1:ExtendedCOMMNDXXXRRRrrrXXXXX
|
|
655 2:MAP-ID
|
|
656 ------------------------------
|
|
657 Map reg[rrr] by MAP-ID.
|
|
658 If some valid mapping is found,
|
|
659 set reg[rrr] to the result,
|
|
660 else
|
|
661 set reg[RRR] to -1.
|
|
662 */
|
|
663
|
4072
|
664 #define CCL_LookupIntConstTbl 0x13 /* Lookup multibyte character by
|
|
665 integer key. Afterwards R7 set
|
|
666 to 1 iff lookup succeeded.
|
|
667 1:ExtendedCOMMNDRrrRRRXXXXXXXX
|
|
668 2:ARGUMENT(Hash table ID) */
|
|
669
|
|
670 #define CCL_LookupCharConstTbl 0x14 /* Lookup integer by multibyte
|
|
671 character key. Afterwards R7 set
|
|
672 to 1 iff lookup succeeded.
|
|
673 1:ExtendedCOMMNDRrrRRRrrrXXXXX
|
|
674 2:ARGUMENT(Hash table ID) */
|
|
675
|
|
676
|
428
|
677 /* CCL arithmetic/logical operators. */
|
|
678 #define CCL_PLUS 0x00 /* X = Y + Z */
|
|
679 #define CCL_MINUS 0x01 /* X = Y - Z */
|
|
680 #define CCL_MUL 0x02 /* X = Y * Z */
|
|
681 #define CCL_DIV 0x03 /* X = Y / Z */
|
|
682 #define CCL_MOD 0x04 /* X = Y % Z */
|
|
683 #define CCL_AND 0x05 /* X = Y & Z */
|
|
684 #define CCL_OR 0x06 /* X = Y | Z */
|
|
685 #define CCL_XOR 0x07 /* X = Y ^ Z */
|
|
686 #define CCL_LSH 0x08 /* X = Y << Z */
|
|
687 #define CCL_RSH 0x09 /* X = Y >> Z */
|
|
688 #define CCL_LSH8 0x0A /* X = (Y << 8) | Z */
|
|
689 #define CCL_RSH8 0x0B /* X = Y >> 8, r[7] = Y & 0xFF */
|
|
690 #define CCL_DIVMOD 0x0C /* X = Y / Z, r[7] = Y % Z */
|
|
691 #define CCL_LS 0x10 /* X = (X < Y) */
|
|
692 #define CCL_GT 0x11 /* X = (X > Y) */
|
|
693 #define CCL_EQ 0x12 /* X = (X == Y) */
|
|
694 #define CCL_LE 0x13 /* X = (X <= Y) */
|
|
695 #define CCL_GE 0x14 /* X = (X >= Y) */
|
|
696 #define CCL_NE 0x15 /* X = (X != Y) */
|
|
697
|
|
698 #define CCL_DECODE_SJIS 0x16 /* X = HIGHER_BYTE (DE-SJIS (Y, Z))
|
|
699 r[7] = LOWER_BYTE (DE-SJIS (Y, Z)) */
|
|
700 #define CCL_ENCODE_SJIS 0x17 /* X = HIGHER_BYTE (SJIS (Y, Z))
|
|
701 r[7] = LOWER_BYTE (SJIS (Y, Z) */
|
|
702
|
444
|
703 /* Terminate CCL program successfully. */
|
462
|
704 #define CCL_SUCCESS \
|
|
705 do { \
|
|
706 ccl->status = CCL_STAT_SUCCESS; \
|
456
|
707 /* The "if (1)" inhibits the warning \
|
|
708 "end-of loop code not reached" */ \
|
|
709 if (1) goto ccl_finish; \
|
462
|
710 } while (0)
|
444
|
711
|
428
|
712 /* Suspend CCL program because of reading from empty input buffer or
|
|
713 writing to full output buffer. When this program is resumed, the
|
444
|
714 same I/O command is executed. */
|
462
|
715 #define CCL_SUSPEND(stat) \
|
|
716 do { \
|
|
717 ic--; \
|
456
|
718 ccl->status = (stat); \
|
|
719 /* The "if (1)" inhibits the warning \
|
|
720 "end-of loop code not reached" */ \
|
|
721 if (1) goto ccl_finish; \
|
462
|
722 } while (0)
|
428
|
723
|
|
724 /* Terminate CCL program because of invalid command. Should not occur
|
444
|
725 in the normal case. */
|
771
|
726 #define CCL_INVALID_CMD \
|
|
727 do { \
|
|
728 ccl->status = CCL_STAT_INVALID_CMD; \
|
|
729 /* enable this to debug invalid cmd errors */ \
|
|
730 /* debug_break (); */ \
|
|
731 /* The "if (1)" inhibits the warning \
|
|
732 "end-of loop code not reached" */ \
|
|
733 if (1) goto ccl_error_handler; \
|
462
|
734 } while (0)
|
428
|
735
|
|
736 /* Encode one character CH to multibyte form and write to the current
|
444
|
737 output buffer. At encoding time, if CH is less than 256, CH is
|
|
738 written as is. At decoding time, if CH cannot be regarded as an
|
|
739 ASCII character, write it in multibyte form. */
|
|
740 #define CCL_WRITE_CHAR(ch) \
|
|
741 do { \
|
|
742 if (!destination) \
|
|
743 CCL_INVALID_CMD; \
|
|
744 if (conversion_mode == CCL_MODE_ENCODING) \
|
|
745 { \
|
456
|
746 if ((ch) == '\n') \
|
444
|
747 { \
|
|
748 if (ccl->eol_type == CCL_CODING_EOL_CRLF) \
|
|
749 { \
|
|
750 Dynarr_add (destination, '\r'); \
|
|
751 Dynarr_add (destination, '\n'); \
|
|
752 } \
|
|
753 else if (ccl->eol_type == CCL_CODING_EOL_CR) \
|
|
754 Dynarr_add (destination, '\r'); \
|
|
755 else \
|
|
756 Dynarr_add (destination, '\n'); \
|
|
757 } \
|
456
|
758 else if ((ch) < 0x100) \
|
444
|
759 { \
|
|
760 Dynarr_add (destination, ch); \
|
|
761 } \
|
|
762 else \
|
|
763 { \
|
2286
|
764 Ibyte work[MAX_ICHAR_LEN]; \
|
444
|
765 int len; \
|
2286
|
766 len = non_ascii_set_itext_ichar (work, ch); \
|
444
|
767 Dynarr_add_many (destination, work, len); \
|
|
768 } \
|
|
769 } \
|
|
770 else \
|
|
771 { \
|
867
|
772 if (!ichar_multibyte_p(ch)) \
|
444
|
773 { \
|
|
774 Dynarr_add (destination, ch); \
|
|
775 } \
|
|
776 else \
|
|
777 { \
|
2286
|
778 Ibyte work[MAX_ICHAR_LEN]; \
|
444
|
779 int len; \
|
2286
|
780 len = non_ascii_set_itext_ichar (work, ch); \
|
444
|
781 Dynarr_add_many (destination, work, len); \
|
|
782 } \
|
|
783 } \
|
|
784 } while (0)
|
428
|
785
|
|
786 /* Write a string at ccl_prog[IC] of length LEN to the current output
|
444
|
787 buffer. But this macro treat this string as a binary. Therefore,
|
|
788 cannot handle a multibyte string except for Control-1 characters. */
|
|
789 #define CCL_WRITE_STRING(len) \
|
|
790 do { \
|
2286
|
791 Ibyte work[MAX_ICHAR_LEN]; \
|
|
792 int ch; \
|
444
|
793 if (!destination) \
|
|
794 CCL_INVALID_CMD; \
|
|
795 else if (conversion_mode == CCL_MODE_ENCODING) \
|
|
796 { \
|
456
|
797 for (i = 0; i < (len); i++) \
|
444
|
798 { \
|
4072
|
799 ch = ((XCHAR_OR_INT (ccl_prog[ic + (i / 3)])) \
|
444
|
800 >> ((2 - (i % 3)) * 8)) & 0xFF; \
|
|
801 if (ch == '\n') \
|
|
802 { \
|
|
803 if (ccl->eol_type == CCL_CODING_EOL_CRLF) \
|
|
804 { \
|
|
805 Dynarr_add (destination, '\r'); \
|
|
806 Dynarr_add (destination, '\n'); \
|
|
807 } \
|
|
808 else if (ccl->eol_type == CCL_CODING_EOL_CR) \
|
|
809 Dynarr_add (destination, '\r'); \
|
|
810 else \
|
|
811 Dynarr_add (destination, '\n'); \
|
|
812 } \
|
|
813 if (ch < 0x100) \
|
|
814 { \
|
|
815 Dynarr_add (destination, ch); \
|
|
816 } \
|
|
817 else \
|
|
818 { \
|
2286
|
819 non_ascii_set_itext_ichar (work, ch); \
|
444
|
820 Dynarr_add_many (destination, work, len); \
|
|
821 } \
|
|
822 } \
|
|
823 } \
|
|
824 else \
|
|
825 { \
|
456
|
826 for (i = 0; i < (len); i++) \
|
444
|
827 { \
|
4072
|
828 ch = ((XCHAR_OR_INT (ccl_prog[ic + (i / 3)])) \
|
444
|
829 >> ((2 - (i % 3)) * 8)) & 0xFF; \
|
867
|
830 if (!ichar_multibyte_p(ch)) \
|
444
|
831 { \
|
|
832 Dynarr_add (destination, ch); \
|
|
833 } \
|
|
834 else \
|
|
835 { \
|
2286
|
836 non_ascii_set_itext_ichar (work, ch); \
|
444
|
837 Dynarr_add_many (destination, work, len); \
|
|
838 } \
|
|
839 } \
|
|
840 } \
|
|
841 } while (0)
|
428
|
842
|
|
843 /* Read one byte from the current input buffer into Rth register. */
|
444
|
844 #define CCL_READ_CHAR(r) \
|
|
845 do { \
|
|
846 if (!src) \
|
|
847 CCL_INVALID_CMD; \
|
|
848 if (src < src_end) \
|
456
|
849 (r) = *src++; \
|
444
|
850 else \
|
|
851 { \
|
|
852 if (ccl->last_block) \
|
|
853 { \
|
|
854 ic = ccl->eof_ic; \
|
|
855 goto ccl_repeat; \
|
|
856 } \
|
|
857 else \
|
|
858 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC); \
|
|
859 } \
|
|
860 } while (0)
|
|
861
|
2830
|
862 #define POSSIBLE_LEADING_BYTE_P(leading_byte) \
|
4072
|
863 ((leading_byte >= MIN_LEADING_BYTE) && \
|
2829
|
864 (leading_byte - MIN_LEADING_BYTE) < NUM_LEADING_BYTES)
|
444
|
865
|
|
866 /* Set C to the character code made from CHARSET and CODE. This is
|
867
|
867 like make_ichar but check the validity of CHARSET and CODE. If they
|
444
|
868 are not valid, set C to (CODE & 0xFF) because that is usually the
|
|
869 case that CCL_ReadMultibyteChar2 read an invalid code and it set
|
|
870 CODE to that invalid byte. */
|
|
871
|
|
872 /* On XEmacs, TranslateCharacter is not supported. Thus, this
|
3439
|
873 macro is only used in the MuleToUnicode transformation. */
|
444
|
874 #define CCL_MAKE_CHAR(charset, code, c) \
|
|
875 do { \
|
3690
|
876 \
|
|
877 if (!POSSIBLE_LEADING_BYTE_P(charset)) \
|
|
878 CCL_INVALID_CMD; \
|
|
879 \
|
3439
|
880 if ((charset) == LEADING_BYTE_ASCII) \
|
|
881 { \
|
|
882 c = (code) & 0xFF; \
|
|
883 } \
|
|
884 else if ((charset) == LEADING_BYTE_CONTROL_1) \
|
|
885 { \
|
3690
|
886 c = ((code) & 0x1F) + 0x80; \
|
3439
|
887 } \
|
|
888 else if (!NILP(charset_by_leading_byte(charset)) \
|
|
889 && ((code) >= 32) \
|
4072
|
890 && ((code) < 256 || ((code >> 7) & 0x7F) >= 32)) \
|
444
|
891 { \
|
3439
|
892 int c1, c2 = 0; \
|
444
|
893 \
|
3439
|
894 if ((code) < 256) \
|
|
895 { \
|
|
896 c1 = (code) & 0x7F; \
|
|
897 c2 = 0; \
|
|
898 } \
|
|
899 else \
|
|
900 { \
|
4072
|
901 c1 = ((code) >> 7) & 0x7F; \
|
3439
|
902 c2 = (code) & 0x7F; \
|
|
903 } \
|
|
904 c = make_ichar (charset_by_leading_byte(charset), \
|
|
905 c1, c2); \
|
444
|
906 } \
|
|
907 else \
|
3439
|
908 { \
|
|
909 c = (code) & 0xFF; \
|
|
910 } \
|
|
911 } while (0)
|
428
|
912
|
|
913
|
|
914 /* Execute CCL code on SRC_BYTES length text at SOURCE. The resulting
|
444
|
915 text goes to a place pointed by DESTINATION, the length of which
|
|
916 should not exceed DST_BYTES. The bytes actually processed is
|
|
917 returned as *CONSUMED. The return value is the length of the
|
|
918 resulting text. As a side effect, the contents of CCL registers
|
428
|
919 are updated. If SOURCE or DESTINATION is NULL, only operations on
|
|
920 registers are permitted. */
|
|
921
|
|
922 #ifdef CCL_DEBUG
|
|
923 #define CCL_DEBUG_BACKTRACE_LEN 256
|
4072
|
924 int ccl_backtrace_table[CCL_DEBUG_BACKTRACE_LEN];
|
428
|
925 int ccl_backtrace_idx;
|
|
926 #endif
|
|
927
|
|
928 struct ccl_prog_stack
|
|
929 {
|
|
930 Lisp_Object *ccl_prog; /* Pointer to an array of CCL code. */
|
|
931 int ic; /* Instruction Counter. */
|
4193
|
932 int eof_ic; /* Instruction Counter to jump on EOF. */
|
428
|
933 };
|
|
934
|
442
|
935 /* For the moment, we only support depth 256 of stack. */
|
428
|
936 static struct ccl_prog_stack ccl_prog_stack_struct[256];
|
|
937
|
|
938 int
|
444
|
939 ccl_driver (struct ccl_program *ccl,
|
|
940 const unsigned char *source,
|
|
941 unsigned_char_dynarr *destination,
|
|
942 int src_bytes,
|
|
943 int *consumed,
|
|
944 int conversion_mode)
|
428
|
945 {
|
444
|
946 register int *reg = ccl->reg;
|
|
947 register int ic = ccl->ic;
|
|
948 register int code = -1;
|
|
949 register int field1, field2;
|
|
950 register Lisp_Object *ccl_prog = ccl->prog;
|
442
|
951 const unsigned char *src = source, *src_end = src + src_bytes;
|
444
|
952 int jump_address;
|
428
|
953 int i, j, op;
|
|
954 int stack_idx = ccl->stack_idx;
|
|
955 /* Instruction counter of the current CCL code. */
|
|
956 int this_ic = 0;
|
4193
|
957 int eof_ic = ccl->eof_ic;
|
|
958 int eof_hit = 0;
|
|
959 static int ccl_driver_calls;
|
428
|
960
|
4193
|
961 if (ic >= eof_ic)
|
428
|
962 ic = CCL_HEADER_MAIN;
|
|
963
|
|
964 if (ccl->buf_magnification ==0) /* We can't produce any bytes. */
|
444
|
965 destination = NULL;
|
|
966
|
|
967 /* Set mapping stack pointer. */
|
|
968 mapping_stack_pointer = mapping_stack;
|
428
|
969
|
|
970 #ifdef CCL_DEBUG
|
|
971 ccl_backtrace_idx = 0;
|
|
972 #endif
|
|
973
|
4193
|
974 ++ccl_driver_calls;
|
|
975
|
428
|
976 for (;;)
|
|
977 {
|
|
978 ccl_repeat:
|
|
979 #ifdef CCL_DEBUG
|
|
980 ccl_backtrace_table[ccl_backtrace_idx++] = ic;
|
|
981 if (ccl_backtrace_idx >= CCL_DEBUG_BACKTRACE_LEN)
|
|
982 ccl_backtrace_idx = 0;
|
|
983 ccl_backtrace_table[ccl_backtrace_idx] = 0;
|
|
984 #endif
|
|
985
|
|
986 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit))
|
|
987 {
|
|
988 /* We can't just signal Qquit, instead break the loop as if
|
|
989 the whole data is processed. Don't reset Vquit_flag, it
|
|
990 must be handled later at a safer place. */
|
|
991 if (consumed)
|
|
992 src = source + src_bytes;
|
|
993 ccl->status = CCL_STAT_QUIT;
|
|
994 break;
|
|
995 }
|
|
996
|
|
997 this_ic = ic;
|
4072
|
998 code = XCHAR_OR_INT (ccl_prog[ic]); ic++;
|
428
|
999 field1 = code >> 8;
|
|
1000 field2 = (code & 0xFF) >> 5;
|
|
1001
|
|
1002 #define rrr field2
|
|
1003 #define RRR (field1 & 7)
|
|
1004 #define Rrr ((field1 >> 3) & 7)
|
|
1005 #define ADDR field1
|
|
1006 #define EXCMD (field1 >> 6)
|
|
1007
|
|
1008 switch (code & 0x1F)
|
|
1009 {
|
|
1010 case CCL_SetRegister: /* 00000000000000000RRRrrrXXXXX */
|
|
1011 reg[rrr] = reg[RRR];
|
|
1012 break;
|
|
1013
|
|
1014 case CCL_SetShortConst: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1015 reg[rrr] = field1;
|
|
1016 break;
|
|
1017
|
|
1018 case CCL_SetConst: /* 00000000000000000000rrrXXXXX */
|
4072
|
1019 reg[rrr] = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1020 ic++;
|
|
1021 break;
|
|
1022
|
|
1023 case CCL_SetArray: /* CCCCCCCCCCCCCCCCCCCCRRRrrrXXXXX */
|
|
1024 i = reg[RRR];
|
|
1025 j = field1 >> 3;
|
647
|
1026 /* #### it's non-obvious to me that we need these casts,
|
|
1027 but the left one was already there so clearly the intention
|
|
1028 was an unsigned comparison. --ben */
|
|
1029 if ((unsigned int) i < (unsigned int) j)
|
4072
|
1030 reg[rrr] = XCHAR_OR_INT (ccl_prog[ic + i]);
|
428
|
1031 ic += j;
|
|
1032 break;
|
|
1033
|
|
1034 case CCL_Jump: /* A--D--D--R--E--S--S-000XXXXX */
|
|
1035 ic += ADDR;
|
|
1036 break;
|
|
1037
|
|
1038 case CCL_JumpCond: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1039 if (!reg[rrr])
|
|
1040 ic += ADDR;
|
|
1041 break;
|
|
1042
|
|
1043 case CCL_WriteRegisterJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1044 i = reg[rrr];
|
|
1045 CCL_WRITE_CHAR (i);
|
|
1046 ic += ADDR;
|
|
1047 break;
|
|
1048
|
|
1049 case CCL_WriteRegisterReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1050 i = reg[rrr];
|
|
1051 CCL_WRITE_CHAR (i);
|
|
1052 ic++;
|
|
1053 CCL_READ_CHAR (reg[rrr]);
|
|
1054 ic += ADDR - 1;
|
|
1055 break;
|
|
1056
|
|
1057 case CCL_WriteConstJump: /* A--D--D--R--E--S--S-000XXXXX */
|
4072
|
1058 i = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1059 CCL_WRITE_CHAR (i);
|
|
1060 ic += ADDR;
|
|
1061 break;
|
|
1062
|
|
1063 case CCL_WriteConstReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
4072
|
1064 i = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1065 CCL_WRITE_CHAR (i);
|
|
1066 ic++;
|
|
1067 CCL_READ_CHAR (reg[rrr]);
|
|
1068 ic += ADDR - 1;
|
|
1069 break;
|
|
1070
|
|
1071 case CCL_WriteStringJump: /* A--D--D--R--E--S--S-000XXXXX */
|
4072
|
1072 j = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1073 ic++;
|
|
1074 CCL_WRITE_STRING (j);
|
|
1075 ic += ADDR - 1;
|
|
1076 break;
|
|
1077
|
|
1078 case CCL_WriteArrayReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1079 i = reg[rrr];
|
4072
|
1080 j = XCHAR_OR_INT (ccl_prog[ic]);
|
647
|
1081 /* #### see comment at CCL_SetArray */
|
|
1082 if ((unsigned int) i < (unsigned int) j)
|
428
|
1083 {
|
4072
|
1084 i = XCHAR_OR_INT (ccl_prog[ic + 1 + i]);
|
428
|
1085 CCL_WRITE_CHAR (i);
|
|
1086 }
|
|
1087 ic += j + 2;
|
|
1088 CCL_READ_CHAR (reg[rrr]);
|
|
1089 ic += ADDR - (j + 2);
|
|
1090 break;
|
|
1091
|
|
1092 case CCL_ReadJump: /* A--D--D--R--E--S--S-rrrYYYYY */
|
|
1093 CCL_READ_CHAR (reg[rrr]);
|
|
1094 ic += ADDR;
|
|
1095 break;
|
|
1096
|
|
1097 case CCL_ReadBranch: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1098 CCL_READ_CHAR (reg[rrr]);
|
|
1099 /* fall through ... */
|
|
1100 case CCL_Branch: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
647
|
1101 /* #### see comment at CCL_SetArray */
|
|
1102 if ((unsigned int) reg[rrr] < (unsigned int) field1)
|
4072
|
1103 ic += XCHAR_OR_INT (ccl_prog[ic + reg[rrr]]);
|
428
|
1104 else
|
4072
|
1105 ic += XCHAR_OR_INT (ccl_prog[ic + field1]);
|
428
|
1106 break;
|
|
1107
|
|
1108 case CCL_ReadRegister: /* CCCCCCCCCCCCCCCCCCCCrrXXXXX */
|
|
1109 while (1)
|
|
1110 {
|
|
1111 CCL_READ_CHAR (reg[rrr]);
|
|
1112 if (!field1) break;
|
4072
|
1113 code = XCHAR_OR_INT (ccl_prog[ic]); ic++;
|
428
|
1114 field1 = code >> 8;
|
|
1115 field2 = (code & 0xFF) >> 5;
|
|
1116 }
|
|
1117 break;
|
|
1118
|
|
1119 case CCL_WriteExprConst: /* 1:00000OPERATION000RRR000XXXXX */
|
|
1120 rrr = 7;
|
|
1121 i = reg[RRR];
|
4072
|
1122 j = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1123 op = field1 >> 6;
|
444
|
1124 jump_address = ic + 1;
|
428
|
1125 goto ccl_set_expr;
|
|
1126
|
|
1127 case CCL_WriteRegister: /* CCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1128 while (1)
|
|
1129 {
|
|
1130 i = reg[rrr];
|
|
1131 CCL_WRITE_CHAR (i);
|
|
1132 if (!field1) break;
|
4072
|
1133 code = XCHAR_OR_INT (ccl_prog[ic]); ic++;
|
428
|
1134 field1 = code >> 8;
|
|
1135 field2 = (code & 0xFF) >> 5;
|
|
1136 }
|
|
1137 break;
|
|
1138
|
|
1139 case CCL_WriteExprRegister: /* 1:00000OPERATIONRrrRRR000XXXXX */
|
|
1140 rrr = 7;
|
|
1141 i = reg[RRR];
|
|
1142 j = reg[Rrr];
|
|
1143 op = field1 >> 6;
|
444
|
1144 jump_address = ic;
|
428
|
1145 goto ccl_set_expr;
|
|
1146
|
444
|
1147 case CCL_Call: /* 1:CCCCCCCCCCCCCCCCCCCCFFFXXXXX */
|
428
|
1148 {
|
|
1149 Lisp_Object slot;
|
444
|
1150 int prog_id;
|
|
1151
|
|
1152 /* If FFF is nonzero, the CCL program ID is in the
|
|
1153 following code. */
|
|
1154 if (rrr)
|
|
1155 {
|
4072
|
1156 prog_id = XCHAR_OR_INT (ccl_prog[ic]);
|
444
|
1157 ic++;
|
|
1158 }
|
|
1159 else
|
|
1160 prog_id = field1;
|
428
|
1161
|
|
1162 if (stack_idx >= 256
|
444
|
1163 || prog_id < 0
|
|
1164 || prog_id >= XVECTOR (Vccl_program_table)->size
|
|
1165 || (slot = XVECTOR (Vccl_program_table)->contents[prog_id],
|
|
1166 !VECTORP (slot))
|
|
1167 || !VECTORP (XVECTOR (slot)->contents[1]))
|
428
|
1168 {
|
|
1169 if (stack_idx > 0)
|
|
1170 {
|
|
1171 ccl_prog = ccl_prog_stack_struct[0].ccl_prog;
|
|
1172 ic = ccl_prog_stack_struct[0].ic;
|
4193
|
1173 eof_ic = ccl_prog_stack_struct[0].eof_ic;
|
428
|
1174 }
|
444
|
1175 CCL_INVALID_CMD;
|
428
|
1176 }
|
|
1177
|
|
1178 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog;
|
|
1179 ccl_prog_stack_struct[stack_idx].ic = ic;
|
4193
|
1180 ccl_prog_stack_struct[stack_idx].eof_ic = eof_ic;
|
428
|
1181 stack_idx++;
|
444
|
1182 ccl_prog = XVECTOR (XVECTOR (slot)->contents[1])->contents;
|
428
|
1183 ic = CCL_HEADER_MAIN;
|
4193
|
1184 eof_ic = XINT (ccl_prog[CCL_HEADER_EOF]);
|
428
|
1185 }
|
|
1186 break;
|
|
1187
|
|
1188 case CCL_WriteConstString: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1189 if (!rrr)
|
|
1190 CCL_WRITE_CHAR (field1);
|
|
1191 else
|
|
1192 {
|
|
1193 CCL_WRITE_STRING (field1);
|
|
1194 ic += (field1 + 2) / 3;
|
|
1195 }
|
|
1196 break;
|
|
1197
|
|
1198 case CCL_WriteArray: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1199 i = reg[rrr];
|
647
|
1200 /* #### see comment at CCL_SetArray */
|
|
1201 if ((unsigned int) i < (unsigned int) field1)
|
428
|
1202 {
|
4072
|
1203 j = XCHAR_OR_INT (ccl_prog[ic + i]);
|
428
|
1204 CCL_WRITE_CHAR (j);
|
|
1205 }
|
|
1206 ic += field1;
|
|
1207 break;
|
|
1208
|
|
1209 case CCL_End: /* 0000000000000000000000XXXXX */
|
444
|
1210 if (stack_idx > 0)
|
428
|
1211 {
|
444
|
1212 stack_idx--;
|
428
|
1213 ccl_prog = ccl_prog_stack_struct[stack_idx].ccl_prog;
|
|
1214 ic = ccl_prog_stack_struct[stack_idx].ic;
|
4193
|
1215 eof_ic = ccl_prog_stack_struct[stack_idx].eof_ic;
|
|
1216 if (eof_hit)
|
|
1217 ic = eof_ic;
|
428
|
1218 break;
|
|
1219 }
|
|
1220 if (src)
|
|
1221 src = src_end;
|
|
1222 /* ccl->ic should points to this command code again to
|
|
1223 suppress further processing. */
|
|
1224 ic--;
|
444
|
1225 CCL_SUCCESS;
|
428
|
1226
|
|
1227 case CCL_ExprSelfConst: /* 00000OPERATION000000rrrXXXXX */
|
4072
|
1228 i = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1229 ic++;
|
|
1230 op = field1 >> 6;
|
|
1231 goto ccl_expr_self;
|
|
1232
|
|
1233 case CCL_ExprSelfReg: /* 00000OPERATION000RRRrrrXXXXX */
|
|
1234 i = reg[RRR];
|
|
1235 op = field1 >> 6;
|
|
1236
|
|
1237 ccl_expr_self:
|
|
1238 switch (op)
|
|
1239 {
|
|
1240 case CCL_PLUS: reg[rrr] += i; break;
|
|
1241 case CCL_MINUS: reg[rrr] -= i; break;
|
|
1242 case CCL_MUL: reg[rrr] *= i; break;
|
|
1243 case CCL_DIV: reg[rrr] /= i; break;
|
|
1244 case CCL_MOD: reg[rrr] %= i; break;
|
|
1245 case CCL_AND: reg[rrr] &= i; break;
|
|
1246 case CCL_OR: reg[rrr] |= i; break;
|
|
1247 case CCL_XOR: reg[rrr] ^= i; break;
|
|
1248 case CCL_LSH: reg[rrr] <<= i; break;
|
|
1249 case CCL_RSH: reg[rrr] >>= i; break;
|
|
1250 case CCL_LSH8: reg[rrr] <<= 8; reg[rrr] |= i; break;
|
|
1251 case CCL_RSH8: reg[7] = reg[rrr] & 0xFF; reg[rrr] >>= 8; break;
|
|
1252 case CCL_DIVMOD: reg[7] = reg[rrr] % i; reg[rrr] /= i; break;
|
|
1253 case CCL_LS: reg[rrr] = reg[rrr] < i; break;
|
|
1254 case CCL_GT: reg[rrr] = reg[rrr] > i; break;
|
|
1255 case CCL_EQ: reg[rrr] = reg[rrr] == i; break;
|
|
1256 case CCL_LE: reg[rrr] = reg[rrr] <= i; break;
|
|
1257 case CCL_GE: reg[rrr] = reg[rrr] >= i; break;
|
|
1258 case CCL_NE: reg[rrr] = reg[rrr] != i; break;
|
444
|
1259 default: CCL_INVALID_CMD;
|
428
|
1260 }
|
|
1261 break;
|
|
1262
|
|
1263 case CCL_SetExprConst: /* 00000OPERATION000RRRrrrXXXXX */
|
|
1264 i = reg[RRR];
|
4072
|
1265 j = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1266 op = field1 >> 6;
|
|
1267 jump_address = ++ic;
|
|
1268 goto ccl_set_expr;
|
|
1269
|
|
1270 case CCL_SetExprReg: /* 00000OPERATIONRrrRRRrrrXXXXX */
|
|
1271 i = reg[RRR];
|
|
1272 j = reg[Rrr];
|
|
1273 op = field1 >> 6;
|
|
1274 jump_address = ic;
|
|
1275 goto ccl_set_expr;
|
|
1276
|
|
1277 case CCL_ReadJumpCondExprConst: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1278 CCL_READ_CHAR (reg[rrr]);
|
|
1279 case CCL_JumpCondExprConst: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1280 i = reg[rrr];
|
4072
|
1281 op = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1282 jump_address = ic++ + ADDR;
|
4072
|
1283 j = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1284 ic++;
|
|
1285 rrr = 7;
|
|
1286 goto ccl_set_expr;
|
|
1287
|
|
1288 case CCL_ReadJumpCondExprReg: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1289 CCL_READ_CHAR (reg[rrr]);
|
|
1290 case CCL_JumpCondExprReg:
|
|
1291 i = reg[rrr];
|
4072
|
1292 op = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1293 jump_address = ic++ + ADDR;
|
4072
|
1294 j = reg[XCHAR_OR_INT (ccl_prog[ic])];
|
428
|
1295 ic++;
|
|
1296 rrr = 7;
|
|
1297
|
|
1298 ccl_set_expr:
|
|
1299 switch (op)
|
|
1300 {
|
|
1301 case CCL_PLUS: reg[rrr] = i + j; break;
|
|
1302 case CCL_MINUS: reg[rrr] = i - j; break;
|
|
1303 case CCL_MUL: reg[rrr] = i * j; break;
|
|
1304 case CCL_DIV: reg[rrr] = i / j; break;
|
|
1305 case CCL_MOD: reg[rrr] = i % j; break;
|
|
1306 case CCL_AND: reg[rrr] = i & j; break;
|
|
1307 case CCL_OR: reg[rrr] = i | j; break;
|
444
|
1308 case CCL_XOR: reg[rrr] = i ^ j;; break;
|
428
|
1309 case CCL_LSH: reg[rrr] = i << j; break;
|
|
1310 case CCL_RSH: reg[rrr] = i >> j; break;
|
|
1311 case CCL_LSH8: reg[rrr] = (i << 8) | j; break;
|
|
1312 case CCL_RSH8: reg[rrr] = i >> 8; reg[7] = i & 0xFF; break;
|
|
1313 case CCL_DIVMOD: reg[rrr] = i / j; reg[7] = i % j; break;
|
|
1314 case CCL_LS: reg[rrr] = i < j; break;
|
|
1315 case CCL_GT: reg[rrr] = i > j; break;
|
|
1316 case CCL_EQ: reg[rrr] = i == j; break;
|
|
1317 case CCL_LE: reg[rrr] = i <= j; break;
|
|
1318 case CCL_GE: reg[rrr] = i >= j; break;
|
|
1319 case CCL_NE: reg[rrr] = i != j; break;
|
444
|
1320 case CCL_DECODE_SJIS:
|
771
|
1321 /* DECODE_SHIFT_JIS set MSB for internal format
|
444
|
1322 as opposed to Emacs. */
|
771
|
1323 DECODE_SHIFT_JIS (i, j, reg[rrr], reg[7]);
|
444
|
1324 reg[rrr] &= 0x7F;
|
|
1325 reg[7] &= 0x7F;
|
|
1326 break;
|
|
1327 case CCL_ENCODE_SJIS:
|
771
|
1328 /* ENCODE_SHIFT_JIS assumes MSB of SHIFT-JIS-char is set
|
444
|
1329 as opposed to Emacs. */
|
771
|
1330 ENCODE_SHIFT_JIS (i | 0x80, j | 0x80, reg[rrr], reg[7]);
|
444
|
1331 break;
|
|
1332 default: CCL_INVALID_CMD;
|
428
|
1333 }
|
|
1334 code &= 0x1F;
|
|
1335 if (code == CCL_WriteExprConst || code == CCL_WriteExprRegister)
|
|
1336 {
|
|
1337 i = reg[rrr];
|
|
1338 CCL_WRITE_CHAR (i);
|
444
|
1339 ic = jump_address;
|
428
|
1340 }
|
|
1341 else if (!reg[rrr])
|
|
1342 ic = jump_address;
|
|
1343 break;
|
|
1344
|
456
|
1345 case CCL_Extension:
|
428
|
1346 switch (EXCMD)
|
|
1347 {
|
|
1348 case CCL_ReadMultibyteChar2:
|
|
1349 if (!src)
|
|
1350 CCL_INVALID_CMD;
|
|
1351
|
462
|
1352 if (src >= src_end)
|
|
1353 {
|
|
1354 src++;
|
456
|
1355 goto ccl_read_multibyte_character_suspend;
|
462
|
1356 }
|
|
1357
|
|
1358 i = *src++;
|
|
1359 if (i < 0x80)
|
|
1360 {
|
|
1361 /* ASCII */
|
|
1362 reg[rrr] = i;
|
|
1363 reg[RRR] = LEADING_BYTE_ASCII;
|
|
1364 }
|
2829
|
1365 /* Previously, these next two elses were reversed in order,
|
|
1366 which should have worked fine, but is more fragile than
|
|
1367 this order. */
|
|
1368 else if (LEADING_BYTE_CONTROL_1 == i)
|
|
1369 {
|
|
1370 if (src >= src_end)
|
|
1371 goto ccl_read_multibyte_character_suspend;
|
|
1372 reg[RRR] = i;
|
|
1373 reg[rrr] = (*src++ - 0xA0);
|
|
1374 }
|
462
|
1375 else if (i <= MAX_LEADING_BYTE_OFFICIAL_1)
|
|
1376 {
|
|
1377 if (src >= src_end)
|
|
1378 goto ccl_read_multibyte_character_suspend;
|
|
1379 reg[RRR] = i;
|
|
1380 reg[rrr] = (*src++ & 0x7F);
|
|
1381 }
|
|
1382 else if (i <= MAX_LEADING_BYTE_OFFICIAL_2)
|
|
1383 {
|
|
1384 if ((src + 1) >= src_end)
|
|
1385 goto ccl_read_multibyte_character_suspend;
|
|
1386 reg[RRR] = i;
|
|
1387 i = (*src++ & 0x7F);
|
|
1388 reg[rrr] = ((i << 7) | (*src & 0x7F));
|
|
1389 src++;
|
|
1390 }
|
|
1391 else if (i == PRE_LEADING_BYTE_PRIVATE_1)
|
|
1392 {
|
|
1393 if ((src + 1) >= src_end)
|
|
1394 goto ccl_read_multibyte_character_suspend;
|
|
1395 reg[RRR] = *src++;
|
4072
|
1396 reg[rrr] = (*src++ & 0xFF);
|
462
|
1397 }
|
|
1398 else if (i == PRE_LEADING_BYTE_PRIVATE_2)
|
|
1399 {
|
|
1400 if ((src + 2) >= src_end)
|
|
1401 goto ccl_read_multibyte_character_suspend;
|
|
1402 reg[RRR] = *src++;
|
|
1403 i = (*src++ & 0x7F);
|
|
1404 reg[rrr] = ((i << 7) | (*src & 0x7F));
|
|
1405 src++;
|
|
1406 }
|
|
1407 else
|
|
1408 {
|
|
1409 /* INVALID CODE. Return a single byte character. */
|
|
1410 reg[RRR] = LEADING_BYTE_ASCII;
|
|
1411 reg[rrr] = i;
|
|
1412 }
|
428
|
1413 break;
|
|
1414
|
|
1415 ccl_read_multibyte_character_suspend:
|
4193
|
1416 if (src <= src_end && ccl->last_block)
|
|
1417 {
|
|
1418 /* #### Unclear when this happens. GNU use
|
|
1419 CHARSET_8_BIT_CONTROL here, which we can't. */
|
|
1420 if (i < 0x80)
|
|
1421 {
|
|
1422 reg[RRR] = LEADING_BYTE_ASCII;
|
|
1423 reg[rrr] = i;
|
|
1424 }
|
|
1425 else if (i < 0xA0)
|
|
1426 {
|
|
1427 reg[RRR] = LEADING_BYTE_CONTROL_1;
|
|
1428 reg[rrr] = i - 0xA0;
|
|
1429 }
|
|
1430 else
|
|
1431 {
|
|
1432 reg[RRR] = LEADING_BYTE_LATIN_ISO8859_1;
|
|
1433 reg[rrr] = i & 0x7F;
|
|
1434 }
|
|
1435 break;
|
|
1436 }
|
428
|
1437 src--;
|
|
1438 if (ccl->last_block)
|
|
1439 {
|
4193
|
1440 ic = eof_ic;
|
|
1441 eof_hit = 1;
|
428
|
1442 goto ccl_repeat;
|
|
1443 }
|
|
1444 else
|
|
1445 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC);
|
|
1446
|
|
1447 break;
|
|
1448
|
|
1449 case CCL_WriteMultibyteChar2:
|
|
1450 i = reg[RRR]; /* charset */
|
2829
|
1451 if (i == LEADING_BYTE_ASCII)
|
428
|
1452 i = reg[rrr] & 0xFF;
|
2829
|
1453 else if (LEADING_BYTE_CONTROL_1 == i)
|
3690
|
1454 i = ((reg[rrr] & 0x1F) + 0x80);
|
2829
|
1455 else if (POSSIBLE_LEADING_BYTE_P(i) &&
|
2830
|
1456 !NILP(charset_by_leading_byte(i)))
|
2829
|
1457 {
|
|
1458 if (XCHARSET_DIMENSION (charset_by_leading_byte (i)) == 1)
|
|
1459 i = (((i - FIELD2_TO_OFFICIAL_LEADING_BYTE) << 7)
|
|
1460 | (reg[rrr] & 0x7F));
|
|
1461 else if (i < MAX_LEADING_BYTE_OFFICIAL_2)
|
|
1462 i = ((i - FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14)
|
|
1463 | reg[rrr];
|
|
1464 else
|
|
1465 i = ((i - FIELD1_TO_PRIVATE_LEADING_BYTE) << 14) | reg[rrr];
|
|
1466 }
|
|
1467 else
|
|
1468 {
|
|
1469 /* No charset we know about; use U+3012 GETA MARK */
|
|
1470 i = make_ichar
|
|
1471 (charset_by_leading_byte(LEADING_BYTE_JAPANESE_JISX0208),
|
|
1472 34, 46);
|
|
1473 }
|
428
|
1474
|
|
1475 CCL_WRITE_CHAR (i);
|
|
1476
|
|
1477 break;
|
|
1478
|
444
|
1479 case CCL_TranslateCharacter:
|
428
|
1480 #if 0
|
3439
|
1481 /* XEmacs does not have translate_char, nor an
|
|
1482 equivalent. We do nothing on this operation. */
|
|
1483 CCL_MAKE_CHAR(reg[RRR], reg[rrr], op);
|
428
|
1484 op = translate_char (GET_TRANSLATION_TABLE (reg[Rrr]),
|
|
1485 i, -1, 0, 0);
|
|
1486 SPLIT_CHAR (op, reg[RRR], i, j);
|
|
1487 if (j != -1)
|
|
1488 i = (i << 7) | j;
|
442
|
1489
|
428
|
1490 reg[rrr] = i;
|
444
|
1491 #endif
|
428
|
1492 break;
|
|
1493
|
|
1494 case CCL_TranslateCharacterConstTbl:
|
444
|
1495 #if 0
|
771
|
1496 /* XEmacs does not have translate_char or an equivalent. We
|
|
1497 do nothing on this operation. */
|
4072
|
1498 op = XCHAR_OR_INT (ccl_prog[ic]); /* table */
|
428
|
1499 ic++;
|
444
|
1500 CCL_MAKE_CHAR (reg[RRR], reg[rrr], i);
|
428
|
1501 op = translate_char (GET_TRANSLATION_TABLE (op), i, -1, 0, 0);
|
|
1502 SPLIT_CHAR (op, reg[RRR], i, j);
|
|
1503 if (j != -1)
|
|
1504 i = (i << 7) | j;
|
442
|
1505
|
428
|
1506 reg[rrr] = i;
|
444
|
1507 #endif
|
428
|
1508 break;
|
|
1509
|
3439
|
1510 case CCL_MuleToUnicode:
|
|
1511 {
|
|
1512 Lisp_Object ucs;
|
|
1513
|
4072
|
1514 CCL_MAKE_CHAR (reg[rrr], reg[RRR], op);
|
|
1515
|
3439
|
1516 ucs = Fchar_to_unicode(make_char(op));
|
|
1517
|
|
1518 if (NILP(ucs))
|
|
1519 {
|
|
1520 /* Uhh, char-to-unicode doesn't return nil at the
|
|
1521 moment, only ever -1. */
|
|
1522 reg[rrr] = 0xFFFD; /* REPLACEMENT CHARACTER */
|
|
1523 }
|
|
1524 else
|
|
1525 {
|
4072
|
1526 reg[rrr] = XCHAR_OR_INT(ucs);
|
3439
|
1527 if (-1 == reg[rrr])
|
|
1528 {
|
|
1529 reg[rrr] = 0xFFFD; /* REPLACEMENT CHARACTER */
|
|
1530 }
|
|
1531 }
|
|
1532 break;
|
|
1533 }
|
|
1534
|
|
1535 case CCL_UnicodeToMule:
|
|
1536 {
|
|
1537 Lisp_Object scratch;
|
|
1538
|
|
1539 scratch = Funicode_to_char(make_int(reg[rrr]), Qnil);
|
|
1540
|
|
1541 if (!NILP(scratch))
|
|
1542 {
|
|
1543 op = XCHAR(scratch);
|
|
1544 BREAKUP_ICHAR (op, scratch, i, j);
|
|
1545 reg[RRR] = XCHARSET_ID(scratch);
|
|
1546
|
|
1547 if (j != 0)
|
|
1548 {
|
4072
|
1549 i = (i << 7) | j;
|
3439
|
1550 }
|
|
1551
|
|
1552 reg[rrr] = i;
|
|
1553 }
|
|
1554 else
|
|
1555 {
|
|
1556 reg[rrr] = reg[RRR] = 0;
|
|
1557 }
|
|
1558 break;
|
|
1559 }
|
|
1560
|
4072
|
1561 case CCL_LookupIntConstTbl:
|
|
1562 op = XCHAR_OR_INT (ccl_prog[ic]); /* table */
|
|
1563 ic++;
|
|
1564 {
|
|
1565 struct Lisp_Hash_Table *h = GET_HASH_TABLE (op);
|
|
1566 htentry *e = find_htentry(make_int (reg[RRR]), h);
|
|
1567 Lisp_Object scratch;
|
|
1568
|
|
1569 if (!HTENTRY_CLEAR_P(e))
|
|
1570 {
|
|
1571 op = XCHARVAL (e->value);
|
|
1572 if (!valid_ichar_p(op))
|
|
1573 {
|
|
1574 CCL_INVALID_CMD;
|
|
1575 }
|
|
1576
|
|
1577 BREAKUP_ICHAR (op, scratch, i, j);
|
|
1578 reg[RRR] = XCHARSET_ID(scratch);
|
|
1579
|
|
1580 if (j != 0)
|
|
1581 {
|
|
1582 i = (i << 7) | j;
|
|
1583 }
|
|
1584 reg[rrr] = i;
|
|
1585 reg[7] = 1; /* r7 true for success */
|
|
1586 }
|
|
1587 else
|
|
1588 reg[7] = 0;
|
|
1589 }
|
|
1590 break;
|
|
1591
|
|
1592 case CCL_LookupCharConstTbl:
|
|
1593 op = XCHAR_OR_INT (ccl_prog[ic]); /* table */
|
|
1594 ic++;
|
|
1595 CCL_MAKE_CHAR (reg[RRR], reg[rrr], i);
|
|
1596 {
|
|
1597 struct Lisp_Hash_Table *h = GET_HASH_TABLE (op);
|
|
1598 htentry *e = find_htentry(make_int(i), h);
|
|
1599
|
|
1600 if (!HTENTRY_CLEAR_P(e))
|
|
1601 {
|
4078
|
1602 if (!INTP (e->value))
|
4072
|
1603 CCL_INVALID_CMD;
|
4078
|
1604 reg[RRR] = XCHAR_OR_INT (e->value);
|
4072
|
1605 reg[7] = 1; /* r7 true for success */
|
|
1606 }
|
|
1607 else
|
|
1608 reg[7] = 0;
|
|
1609 }
|
|
1610 break;
|
|
1611
|
|
1612
|
428
|
1613 case CCL_IterateMultipleMap:
|
|
1614 {
|
|
1615 Lisp_Object map, content, attrib, value;
|
|
1616 int point, size, fin_ic;
|
|
1617
|
4150
|
1618 j = XCHAR_OR_INT (ccl_prog[ic++]); /* number of maps. */
|
428
|
1619 fin_ic = ic + j;
|
|
1620 op = reg[rrr];
|
|
1621 if ((j > reg[RRR]) && (j >= 0))
|
|
1622 {
|
|
1623 ic += reg[RRR];
|
|
1624 i = reg[RRR];
|
|
1625 }
|
|
1626 else
|
|
1627 {
|
|
1628 reg[RRR] = -1;
|
|
1629 ic = fin_ic;
|
|
1630 break;
|
|
1631 }
|
|
1632
|
|
1633 for (;i < j;i++)
|
|
1634 {
|
|
1635 size = XVECTOR (Vcode_conversion_map_vector)->size;
|
4072
|
1636 point = XCHAR_OR_INT (ccl_prog[ic++]);
|
428
|
1637 if (point >= size) continue;
|
|
1638 map =
|
|
1639 XVECTOR (Vcode_conversion_map_vector)->contents[point];
|
|
1640
|
444
|
1641 /* Check map validity. */
|
428
|
1642 if (!CONSP (map)) continue;
|
444
|
1643 map = XCDR (map);
|
428
|
1644 if (!VECTORP (map)) continue;
|
|
1645 size = XVECTOR (map)->size;
|
|
1646 if (size <= 1) continue;
|
|
1647
|
|
1648 content = XVECTOR (map)->contents[0];
|
|
1649
|
|
1650 /* check map type,
|
|
1651 [STARTPOINT VAL1 VAL2 ...] or
|
444
|
1652 [t ELEMENT STARTPOINT ENDPOINT] */
|
|
1653 if (INTP (content))
|
428
|
1654 {
|
|
1655 point = XUINT (content);
|
|
1656 point = op - point + 1;
|
|
1657 if (!((point >= 1) && (point < size))) continue;
|
|
1658 content = XVECTOR (map)->contents[point];
|
|
1659 }
|
|
1660 else if (EQ (content, Qt))
|
|
1661 {
|
|
1662 if (size != 4) continue;
|
647
|
1663 /* #### see comment at CCL_SetArray; in this
|
|
1664 case the casts are added but the XUINT was
|
|
1665 already present */
|
|
1666 if (((unsigned int) op >=
|
|
1667 XUINT (XVECTOR (map)->contents[2]))
|
|
1668 && ((unsigned int) op <
|
|
1669 XUINT (XVECTOR (map)->contents[3])))
|
428
|
1670 content = XVECTOR (map)->contents[1];
|
|
1671 else
|
|
1672 continue;
|
|
1673 }
|
442
|
1674 else
|
428
|
1675 continue;
|
|
1676
|
|
1677 if (NILP (content))
|
|
1678 continue;
|
444
|
1679 else if (INTP (content))
|
428
|
1680 {
|
|
1681 reg[RRR] = i;
|
4072
|
1682 reg[rrr] = XCHAR_OR_INT(content);
|
428
|
1683 break;
|
|
1684 }
|
|
1685 else if (EQ (content, Qt) || EQ (content, Qlambda))
|
|
1686 {
|
|
1687 reg[RRR] = i;
|
|
1688 break;
|
|
1689 }
|
|
1690 else if (CONSP (content))
|
|
1691 {
|
444
|
1692 attrib = XCAR (content);
|
|
1693 value = XCDR (content);
|
|
1694 if (!INTP (attrib) || !INTP (value))
|
428
|
1695 continue;
|
|
1696 reg[RRR] = i;
|
|
1697 reg[rrr] = XUINT (value);
|
|
1698 break;
|
|
1699 }
|
444
|
1700 else if (SYMBOLP (content))
|
|
1701 CCL_CALL_FOR_MAP_INSTRUCTION (content, fin_ic);
|
|
1702 else
|
|
1703 CCL_INVALID_CMD;
|
428
|
1704 }
|
|
1705 if (i == j)
|
|
1706 reg[RRR] = -1;
|
|
1707 ic = fin_ic;
|
|
1708 }
|
|
1709 break;
|
442
|
1710
|
428
|
1711 case CCL_MapMultiple:
|
|
1712 {
|
|
1713 Lisp_Object map, content, attrib, value;
|
|
1714 int point, size, map_vector_size;
|
|
1715 int map_set_rest_length, fin_ic;
|
444
|
1716 int current_ic = this_ic;
|
|
1717
|
|
1718 /* inhibit recursive call on MapMultiple. */
|
|
1719 if (stack_idx_of_map_multiple > 0)
|
|
1720 {
|
|
1721 if (stack_idx_of_map_multiple <= stack_idx)
|
|
1722 {
|
|
1723 stack_idx_of_map_multiple = 0;
|
|
1724 mapping_stack_pointer = mapping_stack;
|
|
1725 CCL_INVALID_CMD;
|
|
1726 }
|
|
1727 }
|
|
1728 else
|
|
1729 mapping_stack_pointer = mapping_stack;
|
|
1730 stack_idx_of_map_multiple = 0;
|
428
|
1731
|
|
1732 map_set_rest_length =
|
4150
|
1733 XCHAR_OR_INT (ccl_prog[ic++]); /* number of maps and separators. */
|
428
|
1734 fin_ic = ic + map_set_rest_length;
|
444
|
1735 op = reg[rrr];
|
|
1736
|
428
|
1737 if ((map_set_rest_length > reg[RRR]) && (reg[RRR] >= 0))
|
|
1738 {
|
|
1739 ic += reg[RRR];
|
|
1740 i = reg[RRR];
|
|
1741 map_set_rest_length -= i;
|
|
1742 }
|
|
1743 else
|
|
1744 {
|
|
1745 ic = fin_ic;
|
|
1746 reg[RRR] = -1;
|
444
|
1747 mapping_stack_pointer = mapping_stack;
|
428
|
1748 break;
|
|
1749 }
|
444
|
1750
|
|
1751 if (mapping_stack_pointer <= (mapping_stack + 1))
|
428
|
1752 {
|
444
|
1753 /* Set up initial state. */
|
|
1754 mapping_stack_pointer = mapping_stack;
|
|
1755 PUSH_MAPPING_STACK (0, op);
|
|
1756 reg[RRR] = -1;
|
|
1757 }
|
|
1758 else
|
|
1759 {
|
|
1760 /* Recover after calling other ccl program. */
|
|
1761 int orig_op;
|
428
|
1762
|
444
|
1763 POP_MAPPING_STACK (map_set_rest_length, orig_op);
|
|
1764 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1765 switch (op)
|
428
|
1766 {
|
444
|
1767 case -1:
|
|
1768 /* Regard it as Qnil. */
|
|
1769 op = orig_op;
|
|
1770 i++;
|
|
1771 ic++;
|
|
1772 map_set_rest_length--;
|
|
1773 break;
|
|
1774 case -2:
|
|
1775 /* Regard it as Qt. */
|
|
1776 op = reg[rrr];
|
|
1777 i++;
|
|
1778 ic++;
|
|
1779 map_set_rest_length--;
|
|
1780 break;
|
|
1781 case -3:
|
|
1782 /* Regard it as Qlambda. */
|
|
1783 op = orig_op;
|
428
|
1784 i += map_set_rest_length;
|
444
|
1785 ic += map_set_rest_length;
|
|
1786 map_set_rest_length = 0;
|
|
1787 break;
|
|
1788 default:
|
|
1789 /* Regard it as normal mapping. */
|
428
|
1790 i += map_set_rest_length;
|
444
|
1791 ic += map_set_rest_length;
|
428
|
1792 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1793 break;
|
|
1794 }
|
|
1795 }
|
444
|
1796 map_vector_size = XVECTOR (Vcode_conversion_map_vector)->size;
|
|
1797
|
|
1798 do {
|
|
1799 for (;map_set_rest_length > 0;i++, ic++, map_set_rest_length--)
|
|
1800 {
|
4072
|
1801 point = XCHAR_OR_INT(ccl_prog[ic]);
|
444
|
1802 if (point < 0)
|
|
1803 {
|
|
1804 /* +1 is for including separator. */
|
|
1805 point = -point + 1;
|
|
1806 if (mapping_stack_pointer
|
460
|
1807 >= mapping_stack + countof (mapping_stack))
|
444
|
1808 CCL_INVALID_CMD;
|
|
1809 PUSH_MAPPING_STACK (map_set_rest_length - point,
|
|
1810 reg[rrr]);
|
|
1811 map_set_rest_length = point;
|
|
1812 reg[rrr] = op;
|
|
1813 continue;
|
|
1814 }
|
|
1815
|
|
1816 if (point >= map_vector_size) continue;
|
|
1817 map = (XVECTOR (Vcode_conversion_map_vector)
|
|
1818 ->contents[point]);
|
|
1819
|
|
1820 /* Check map validity. */
|
|
1821 if (!CONSP (map)) continue;
|
|
1822 map = XCDR (map);
|
|
1823 if (!VECTORP (map)) continue;
|
|
1824 size = XVECTOR (map)->size;
|
|
1825 if (size <= 1) continue;
|
|
1826
|
|
1827 content = XVECTOR (map)->contents[0];
|
|
1828
|
|
1829 /* check map type,
|
|
1830 [STARTPOINT VAL1 VAL2 ...] or
|
|
1831 [t ELEMENT STARTPOINT ENDPOINT] */
|
|
1832 if (INTP (content))
|
|
1833 {
|
|
1834 point = XUINT (content);
|
|
1835 point = op - point + 1;
|
|
1836 if (!((point >= 1) && (point < size))) continue;
|
|
1837 content = XVECTOR (map)->contents[point];
|
|
1838 }
|
|
1839 else if (EQ (content, Qt))
|
|
1840 {
|
|
1841 if (size != 4) continue;
|
647
|
1842 /* #### see comment at CCL_SetArray; in this
|
|
1843 case the casts are added but the XUINT was
|
|
1844 already present */
|
|
1845 if (((unsigned int) op >=
|
|
1846 XUINT (XVECTOR (map)->contents[2])) &&
|
|
1847 ((unsigned int) op <
|
|
1848 XUINT (XVECTOR (map)->contents[3])))
|
444
|
1849 content = XVECTOR (map)->contents[1];
|
|
1850 else
|
|
1851 continue;
|
|
1852 }
|
|
1853 else
|
|
1854 continue;
|
|
1855
|
|
1856 if (NILP (content))
|
|
1857 continue;
|
|
1858
|
|
1859 reg[RRR] = i;
|
|
1860 if (INTP (content))
|
|
1861 {
|
4072
|
1862 op = XCHAR_OR_INT (content);
|
444
|
1863 i += map_set_rest_length - 1;
|
|
1864 ic += map_set_rest_length - 1;
|
|
1865 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1866 map_set_rest_length++;
|
|
1867 }
|
|
1868 else if (CONSP (content))
|
|
1869 {
|
|
1870 attrib = XCAR (content);
|
|
1871 value = XCDR (content);
|
|
1872 if (!INTP (attrib) || !INTP (value))
|
|
1873 continue;
|
|
1874 op = XUINT (value);
|
|
1875 i += map_set_rest_length - 1;
|
|
1876 ic += map_set_rest_length - 1;
|
|
1877 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1878 map_set_rest_length++;
|
|
1879 }
|
|
1880 else if (EQ (content, Qt))
|
|
1881 {
|
|
1882 op = reg[rrr];
|
|
1883 }
|
|
1884 else if (EQ (content, Qlambda))
|
|
1885 {
|
|
1886 i += map_set_rest_length;
|
|
1887 ic += map_set_rest_length;
|
|
1888 break;
|
|
1889 }
|
|
1890 else if (SYMBOLP (content))
|
|
1891 {
|
|
1892 if (mapping_stack_pointer
|
460
|
1893 >= mapping_stack + countof (mapping_stack))
|
444
|
1894 CCL_INVALID_CMD;
|
|
1895 PUSH_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1896 PUSH_MAPPING_STACK (map_set_rest_length, op);
|
|
1897 stack_idx_of_map_multiple = stack_idx + 1;
|
|
1898 CCL_CALL_FOR_MAP_INSTRUCTION (content, current_ic);
|
|
1899 }
|
|
1900 else
|
|
1901 CCL_INVALID_CMD;
|
|
1902 }
|
|
1903 if (mapping_stack_pointer <= (mapping_stack + 1))
|
|
1904 break;
|
|
1905 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1906 i += map_set_rest_length;
|
|
1907 ic += map_set_rest_length;
|
|
1908 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1909 } while (1);
|
|
1910
|
428
|
1911 ic = fin_ic;
|
|
1912 }
|
|
1913 reg[rrr] = op;
|
|
1914 break;
|
|
1915
|
|
1916 case CCL_MapSingle:
|
|
1917 {
|
|
1918 Lisp_Object map, attrib, value, content;
|
|
1919 int size, point;
|
4150
|
1920 j = XCHAR_OR_INT (ccl_prog[ic++]); /* map_id */
|
428
|
1921 op = reg[rrr];
|
|
1922 if (j >= XVECTOR (Vcode_conversion_map_vector)->size)
|
|
1923 {
|
|
1924 reg[RRR] = -1;
|
|
1925 break;
|
|
1926 }
|
|
1927 map = XVECTOR (Vcode_conversion_map_vector)->contents[j];
|
|
1928 if (!CONSP (map))
|
|
1929 {
|
|
1930 reg[RRR] = -1;
|
|
1931 break;
|
|
1932 }
|
444
|
1933 map = XCDR (map);
|
428
|
1934 if (!VECTORP (map))
|
|
1935 {
|
|
1936 reg[RRR] = -1;
|
|
1937 break;
|
|
1938 }
|
|
1939 size = XVECTOR (map)->size;
|
|
1940 point = XUINT (XVECTOR (map)->contents[0]);
|
|
1941 point = op - point + 1;
|
|
1942 reg[RRR] = 0;
|
|
1943 if ((size <= 1) ||
|
|
1944 (!((point >= 1) && (point < size))))
|
|
1945 reg[RRR] = -1;
|
|
1946 else
|
|
1947 {
|
444
|
1948 reg[RRR] = 0;
|
428
|
1949 content = XVECTOR (map)->contents[point];
|
|
1950 if (NILP (content))
|
|
1951 reg[RRR] = -1;
|
444
|
1952 else if (INTP (content))
|
4072
|
1953 reg[rrr] = XCHAR_OR_INT (content);
|
444
|
1954 else if (EQ (content, Qt));
|
428
|
1955 else if (CONSP (content))
|
|
1956 {
|
444
|
1957 attrib = XCAR (content);
|
|
1958 value = XCDR (content);
|
|
1959 if (!INTP (attrib) || !INTP (value))
|
428
|
1960 continue;
|
|
1961 reg[rrr] = XUINT(value);
|
|
1962 break;
|
|
1963 }
|
444
|
1964 else if (SYMBOLP (content))
|
|
1965 CCL_CALL_FOR_MAP_INSTRUCTION (content, ic);
|
428
|
1966 else
|
|
1967 reg[RRR] = -1;
|
|
1968 }
|
|
1969 }
|
|
1970 break;
|
442
|
1971
|
428
|
1972 default:
|
|
1973 CCL_INVALID_CMD;
|
|
1974 }
|
|
1975 break;
|
|
1976
|
|
1977 default:
|
444
|
1978 CCL_INVALID_CMD;
|
428
|
1979 }
|
|
1980 }
|
|
1981
|
|
1982 ccl_error_handler:
|
|
1983 if (destination)
|
|
1984 {
|
|
1985 /* We can insert an error message only if DESTINATION is
|
|
1986 specified and we still have a room to store the message
|
|
1987 there. */
|
|
1988 char msg[256];
|
|
1989
|
|
1990 switch (ccl->status)
|
|
1991 {
|
|
1992 case CCL_STAT_INVALID_CMD:
|
|
1993 sprintf(msg, "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
|
|
1994 code & 0x1F, code, this_ic);
|
|
1995 #ifdef CCL_DEBUG
|
|
1996 {
|
|
1997 int i = ccl_backtrace_idx - 1;
|
|
1998 int j;
|
|
1999
|
|
2000 Dynarr_add_many (destination, (unsigned char *) msg, strlen (msg));
|
|
2001
|
|
2002 for (j = 0; j < CCL_DEBUG_BACKTRACE_LEN; j++, i--)
|
|
2003 {
|
|
2004 if (i < 0) i = CCL_DEBUG_BACKTRACE_LEN - 1;
|
|
2005 if (ccl_backtrace_table[i] == 0)
|
|
2006 break;
|
|
2007 sprintf(msg, " %d", ccl_backtrace_table[i]);
|
|
2008 Dynarr_add_many (destination, (unsigned char *) msg, strlen (msg));
|
|
2009 }
|
|
2010 goto ccl_finish;
|
|
2011 }
|
|
2012 #endif
|
|
2013 break;
|
|
2014
|
|
2015 case CCL_STAT_QUIT:
|
444
|
2016 sprintf(msg, "\nCCL: Exited.");
|
428
|
2017 break;
|
|
2018
|
|
2019 default:
|
|
2020 sprintf(msg, "\nCCL: Unknown error type (%d).", ccl->status);
|
|
2021 }
|
|
2022
|
|
2023 Dynarr_add_many (destination, (unsigned char *) msg, strlen (msg));
|
|
2024 }
|
|
2025
|
|
2026 ccl_finish:
|
|
2027 ccl->ic = ic;
|
|
2028 ccl->stack_idx = stack_idx;
|
|
2029 ccl->prog = ccl_prog;
|
|
2030 if (consumed) *consumed = src - source;
|
444
|
2031 if (!destination)
|
428
|
2032 return 0;
|
444
|
2033 return Dynarr_length (destination);
|
|
2034 }
|
|
2035
|
|
2036 /* Resolve symbols in the specified CCL code (Lisp vector). This
|
|
2037 function converts symbols of code conversion maps and character
|
|
2038 translation tables embedded in the CCL code into their ID numbers.
|
|
2039
|
|
2040 The return value is a vector (CCL itself or a new vector in which
|
|
2041 all symbols are resolved), Qt if resolving of some symbol failed,
|
|
2042 or nil if CCL contains invalid data. */
|
|
2043
|
|
2044 static Lisp_Object
|
|
2045 resolve_symbol_ccl_program (Lisp_Object ccl)
|
|
2046 {
|
|
2047 int i, veclen, unresolved = 0;
|
|
2048 Lisp_Object result, contents, val;
|
|
2049
|
|
2050 result = ccl;
|
|
2051 veclen = XVECTOR (result)->size;
|
|
2052
|
|
2053 for (i = 0; i < veclen; i++)
|
|
2054 {
|
|
2055 contents = XVECTOR (result)->contents[i];
|
4072
|
2056 /* XEmacs change; accept characters as well as integers, on the basis
|
|
2057 that most CCL code written doesn't make a distinction. */
|
|
2058 if (INTP (contents) || CHARP(contents))
|
444
|
2059 continue;
|
|
2060 else if (CONSP (contents)
|
|
2061 && SYMBOLP (XCAR (contents))
|
|
2062 && SYMBOLP (XCDR (contents)))
|
|
2063 {
|
|
2064 /* This is the new style for embedding symbols. The form is
|
|
2065 (SYMBOL . PROPERTY). (get SYMBOL PROPERTY) should give
|
|
2066 an index number. */
|
|
2067
|
|
2068 if (EQ (result, ccl))
|
|
2069 result = Fcopy_sequence (ccl);
|
|
2070
|
|
2071 val = Fget (XCAR (contents), XCDR (contents), Qnil);
|
|
2072 if (NATNUMP (val))
|
|
2073 XVECTOR (result)->contents[i] = val;
|
|
2074 else
|
|
2075 unresolved = 1;
|
|
2076 continue;
|
|
2077 }
|
|
2078 else if (SYMBOLP (contents))
|
|
2079 {
|
|
2080 /* This is the old style for embedding symbols. This style
|
|
2081 may lead to a bug if, for instance, a translation table
|
|
2082 and a code conversion map have the same name. */
|
|
2083 if (EQ (result, ccl))
|
|
2084 result = Fcopy_sequence (ccl);
|
|
2085
|
|
2086 val = Fget (contents, Qcode_conversion_map_id, Qnil);
|
|
2087 if (NATNUMP (val))
|
|
2088 XVECTOR (result)->contents[i] = val;
|
|
2089 else
|
|
2090 {
|
|
2091 val = Fget (contents, Qccl_program_idx, Qnil);
|
|
2092 if (NATNUMP (val))
|
|
2093 XVECTOR (result)->contents[i] = val;
|
|
2094 else
|
|
2095 unresolved = 1;
|
|
2096 }
|
|
2097 continue;
|
|
2098 }
|
|
2099 return Qnil;
|
|
2100 }
|
|
2101
|
|
2102 return (unresolved ? Qt : result);
|
|
2103 }
|
|
2104
|
|
2105 /* Return the compiled code (vector) of CCL program CCL_PROG.
|
|
2106 CCL_PROG is a name (symbol) of the program or already compiled
|
|
2107 code. If necessary, resolve symbols in the compiled code to index
|
|
2108 numbers. If we failed to get the compiled code or to resolve
|
|
2109 symbols, return Qnil. */
|
|
2110
|
|
2111 static Lisp_Object
|
|
2112 ccl_get_compiled_code (Lisp_Object ccl_prog)
|
|
2113 {
|
|
2114 Lisp_Object val, slot;
|
|
2115
|
|
2116 if (VECTORP (ccl_prog))
|
|
2117 {
|
|
2118 val = resolve_symbol_ccl_program (ccl_prog);
|
|
2119 return (VECTORP (val) ? val : Qnil);
|
|
2120 }
|
|
2121 if (!SYMBOLP (ccl_prog))
|
|
2122 return Qnil;
|
|
2123
|
|
2124 val = Fget (ccl_prog, Qccl_program_idx, Qnil);
|
|
2125 if (! NATNUMP (val)
|
|
2126 || XINT (val) >= XVECTOR_LENGTH (Vccl_program_table))
|
|
2127 return Qnil;
|
|
2128 slot = XVECTOR_DATA (Vccl_program_table)[XINT (val)];
|
|
2129 if (! VECTORP (slot)
|
|
2130 || XVECTOR (slot)->size != 3
|
|
2131 || ! VECTORP (XVECTOR_DATA (slot)[1]))
|
|
2132 return Qnil;
|
|
2133 if (NILP (XVECTOR_DATA (slot)[2]))
|
|
2134 {
|
|
2135 val = resolve_symbol_ccl_program (XVECTOR_DATA (slot)[1]);
|
|
2136 if (! VECTORP (val))
|
|
2137 return Qnil;
|
|
2138 XVECTOR_DATA (slot)[1] = val;
|
|
2139 XVECTOR_DATA (slot)[2] = Qt;
|
|
2140 }
|
|
2141 return XVECTOR_DATA (slot)[1];
|
428
|
2142 }
|
|
2143
|
|
2144 /* Setup fields of the structure pointed by CCL appropriately for the
|
444
|
2145 execution of CCL program CCL_PROG. CCL_PROG is the name (symbol)
|
|
2146 of the CCL program or the already compiled code (vector).
|
|
2147 Return 0 if we succeed this setup, else return -1.
|
|
2148
|
|
2149 If CCL_PROG is nil, we just reset the structure pointed by CCL. */
|
|
2150 int
|
|
2151 setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog)
|
428
|
2152 {
|
771
|
2153 xzero (*ccl); /* XEmacs change */
|
444
|
2154 if (! NILP (ccl_prog))
|
428
|
2155 {
|
444
|
2156 ccl_prog = ccl_get_compiled_code (ccl_prog);
|
|
2157 if (! VECTORP (ccl_prog))
|
|
2158 return -1;
|
|
2159 ccl->size = XVECTOR_LENGTH (ccl_prog);
|
|
2160 ccl->prog = XVECTOR_DATA (ccl_prog);
|
|
2161 ccl->eof_ic = XINT (XVECTOR_DATA (ccl_prog)[CCL_HEADER_EOF]);
|
|
2162 ccl->buf_magnification = XINT (XVECTOR_DATA (ccl_prog)[CCL_HEADER_BUF_MAG]);
|
428
|
2163 }
|
|
2164 ccl->ic = CCL_HEADER_MAIN;
|
444
|
2165 ccl->eol_type = CCL_CODING_EOL_LF;
|
|
2166 return 0;
|
428
|
2167 }
|
|
2168
|
444
|
2169 #ifdef emacs
|
428
|
2170
|
444
|
2171 DEFUN ("ccl-program-p", Fccl_program_p, 1, 1, 0, /*
|
|
2172 Return t if OBJECT is a CCL program name or a compiled CCL program code.
|
|
2173 See the documentation of `define-ccl-program' for the detail of CCL program.
|
|
2174 */
|
|
2175 (object))
|
|
2176 {
|
|
2177 Lisp_Object val;
|
428
|
2178
|
444
|
2179 if (VECTORP (object))
|
|
2180 {
|
|
2181 val = resolve_symbol_ccl_program (object);
|
|
2182 return (VECTORP (val) ? Qt : Qnil);
|
428
|
2183 }
|
444
|
2184 if (!SYMBOLP (object))
|
|
2185 return Qnil;
|
428
|
2186
|
444
|
2187 val = Fget (object, Qccl_program_idx, Qnil);
|
|
2188 return ((! NATNUMP (val)
|
|
2189 || XINT (val) >= XVECTOR_LENGTH (Vccl_program_table))
|
|
2190 ? Qnil : Qt);
|
428
|
2191 }
|
|
2192
|
|
2193 DEFUN ("ccl-execute", Fccl_execute, 2, 2, 0, /*
|
|
2194 Execute CCL-PROGRAM with registers initialized by REGISTERS.
|
|
2195
|
444
|
2196 CCL-PROGRAM is a CCL program name (symbol)
|
428
|
2197 or a compiled code generated by `ccl-compile' (for backward compatibility,
|
444
|
2198 in this case, the overhead of the execution is bigger than the former case).
|
428
|
2199 No I/O commands should appear in CCL-PROGRAM.
|
|
2200
|
|
2201 REGISTERS is a vector of [R0 R1 ... R7] where RN is an initial value
|
|
2202 of Nth register.
|
|
2203
|
444
|
2204 As side effect, each element of REGISTERS holds the value of
|
428
|
2205 corresponding register after the execution.
|
444
|
2206
|
|
2207 See the documentation of `define-ccl-program' for the detail of CCL program.
|
428
|
2208 */
|
444
|
2209 (ccl_prog, reg))
|
428
|
2210 {
|
|
2211 struct ccl_program ccl;
|
|
2212 int i;
|
|
2213
|
444
|
2214 if (setup_ccl_program (&ccl, ccl_prog) < 0)
|
563
|
2215 syntax_error ("Invalid CCL program", Qunbound);
|
428
|
2216
|
|
2217 CHECK_VECTOR (reg);
|
|
2218 if (XVECTOR_LENGTH (reg) != 8)
|
563
|
2219 syntax_error ("Length of vector REGISTERS is not 8", Qunbound);
|
428
|
2220
|
|
2221 for (i = 0; i < 8; i++)
|
4072
|
2222 ccl.reg[i] = (INTP (XVECTOR_DATA (reg)[i]) || CHARP (XVECTOR_DATA (reg)[i])
|
|
2223 ? XCHAR_OR_INT (XVECTOR_DATA (reg)[i])
|
428
|
2224 : 0);
|
|
2225
|
444
|
2226 ccl_driver (&ccl, (const unsigned char *)0,
|
|
2227 (unsigned_char_dynarr *)0, 0, (int *)0,
|
|
2228 CCL_MODE_ENCODING);
|
428
|
2229 QUIT;
|
|
2230 if (ccl.status != CCL_STAT_SUCCESS)
|
563
|
2231 signal_error (Qccl_error, "Error in CCL program at code numbered ...", make_int (ccl.ic));
|
428
|
2232
|
|
2233 for (i = 0; i < 8; i++)
|
793
|
2234 XVECTOR (reg)->contents[i] = make_int (ccl.reg[i]);
|
428
|
2235 return Qnil;
|
|
2236 }
|
|
2237
|
444
|
2238 DEFUN ("ccl-execute-on-string", Fccl_execute_on_string,
|
|
2239 3, 4, 0, /*
|
428
|
2240 Execute CCL-PROGRAM with initial STATUS on STRING.
|
|
2241
|
|
2242 CCL-PROGRAM is a symbol registered by register-ccl-program,
|
|
2243 or a compiled code generated by `ccl-compile' (for backward compatibility,
|
|
2244 in this case, the execution is slower).
|
|
2245
|
|
2246 Read buffer is set to STRING, and write buffer is allocated automatically.
|
|
2247
|
|
2248 STATUS is a vector of [R0 R1 ... R7 IC], where
|
|
2249 R0..R7 are initial values of corresponding registers,
|
|
2250 IC is the instruction counter specifying from where to start the program.
|
|
2251 If R0..R7 are nil, they are initialized to 0.
|
|
2252 If IC is nil, it is initialized to head of the CCL program.
|
|
2253
|
|
2254 If optional 4th arg CONTINUE is non-nil, keep IC on read operation
|
444
|
2255 when read buffer is exhausted, else, IC is always set to the end of
|
428
|
2256 CCL-PROGRAM on exit.
|
|
2257
|
|
2258 It returns the contents of write buffer as a string,
|
|
2259 and as side effect, STATUS is updated.
|
444
|
2260
|
|
2261 See the documentation of `define-ccl-program' for the detail of CCL program.
|
428
|
2262 */
|
444
|
2263 (ccl_prog, status, string, continue_))
|
428
|
2264 {
|
|
2265 Lisp_Object val;
|
|
2266 struct ccl_program ccl;
|
|
2267 int i, produced;
|
|
2268 unsigned_char_dynarr *outbuf;
|
444
|
2269 struct gcpro gcpro1, gcpro2;
|
428
|
2270
|
444
|
2271 if (setup_ccl_program (&ccl, ccl_prog) < 0)
|
563
|
2272 syntax_error ("Invalid CCL program", Qunbound);
|
428
|
2273
|
|
2274 CHECK_VECTOR (status);
|
444
|
2275 if (XVECTOR (status)->size != 9)
|
563
|
2276 syntax_error ("Length of vector STATUS is not 9", Qunbound);
|
444
|
2277 CHECK_STRING (string);
|
428
|
2278
|
444
|
2279 GCPRO2 (status, string);
|
|
2280
|
428
|
2281 for (i = 0; i < 8; i++)
|
|
2282 {
|
|
2283 if (NILP (XVECTOR_DATA (status)[i]))
|
793
|
2284 XVECTOR_DATA (status)[i] = make_int (0);
|
428
|
2285 if (INTP (XVECTOR_DATA (status)[i]))
|
|
2286 ccl.reg[i] = XINT (XVECTOR_DATA (status)[i]);
|
4072
|
2287 if (CHARP (XVECTOR_DATA (status)[i]))
|
|
2288 ccl.reg[i] = XCHAR (XVECTOR_DATA (status)[i]);
|
428
|
2289 }
|
4072
|
2290 if (INTP (XVECTOR (status)->contents[i]) ||
|
|
2291 CHARP (XVECTOR (status)->contents[i]))
|
428
|
2292 {
|
4072
|
2293 i = XCHAR_OR_INT (XVECTOR_DATA (status)[8]);
|
428
|
2294 if (ccl.ic < i && i < ccl.size)
|
|
2295 ccl.ic = i;
|
|
2296 }
|
|
2297 outbuf = Dynarr_new (unsigned_char);
|
444
|
2298 ccl.last_block = NILP (continue_);
|
|
2299 produced = ccl_driver (&ccl, XSTRING_DATA (string), outbuf,
|
|
2300 XSTRING_LENGTH (string),
|
|
2301 (int *) 0,
|
|
2302 CCL_MODE_DECODING);
|
428
|
2303 for (i = 0; i < 8; i++)
|
793
|
2304 XVECTOR_DATA (status)[i] = make_int (ccl.reg[i]);
|
|
2305 XVECTOR_DATA (status)[8] = make_int (ccl.ic);
|
428
|
2306 UNGCPRO;
|
|
2307
|
|
2308 val = make_string (Dynarr_atp (outbuf, 0), produced);
|
|
2309 Dynarr_free (outbuf);
|
|
2310 QUIT;
|
444
|
2311 if (ccl.status == CCL_STAT_SUSPEND_BY_DST)
|
563
|
2312 signal_error (Qccl_error, "Output buffer for the CCL programs overflow", Qunbound);
|
428
|
2313 if (ccl.status != CCL_STAT_SUCCESS
|
444
|
2314 && ccl.status != CCL_STAT_SUSPEND_BY_SRC)
|
563
|
2315 signal_error (Qccl_error, "Error in CCL program at code numbered...", make_int (ccl.ic));
|
428
|
2316
|
|
2317 return val;
|
|
2318 }
|
|
2319
|
444
|
2320 DEFUN ("register-ccl-program", Fregister_ccl_program,
|
|
2321 2, 2, 0, /*
|
|
2322 Register CCL program CCL-PROG as NAME in `ccl-program-table'.
|
|
2323 CCL-PROG should be a compiled CCL program (vector), or nil.
|
|
2324 If it is nil, just reserve NAME as a CCL program name.
|
428
|
2325 Return index number of the registered CCL program.
|
|
2326 */
|
444
|
2327 (name, ccl_prog))
|
428
|
2328 {
|
|
2329 int len = XVECTOR_LENGTH (Vccl_program_table);
|
444
|
2330 int idx;
|
|
2331 Lisp_Object resolved;
|
428
|
2332
|
|
2333 CHECK_SYMBOL (name);
|
444
|
2334 resolved = Qnil;
|
428
|
2335 if (!NILP (ccl_prog))
|
|
2336 {
|
|
2337 CHECK_VECTOR (ccl_prog);
|
444
|
2338 resolved = resolve_symbol_ccl_program (ccl_prog);
|
|
2339 if (! NILP (resolved))
|
428
|
2340 {
|
444
|
2341 ccl_prog = resolved;
|
|
2342 resolved = Qt;
|
428
|
2343 }
|
|
2344 }
|
|
2345
|
444
|
2346 for (idx = 0; idx < len; idx++)
|
428
|
2347 {
|
444
|
2348 Lisp_Object slot;
|
|
2349
|
|
2350 slot = XVECTOR_DATA (Vccl_program_table)[idx];
|
|
2351 if (!VECTORP (slot))
|
|
2352 /* This is the first unused slot. Register NAME here. */
|
|
2353 break;
|
|
2354
|
|
2355 if (EQ (name, XVECTOR_DATA (slot)[0]))
|
|
2356 {
|
|
2357 /* Update this slot. */
|
|
2358 XVECTOR_DATA (slot)[1] = ccl_prog;
|
|
2359 XVECTOR_DATA (slot)[2] = resolved;
|
|
2360 return make_int (idx);
|
|
2361 }
|
|
2362 }
|
|
2363
|
|
2364 if (idx == len)
|
|
2365 {
|
|
2366 /* Extend the table. */
|
|
2367 Lisp_Object new_table;
|
428
|
2368 int j;
|
|
2369
|
444
|
2370 new_table = Fmake_vector (make_int (len * 2), Qnil);
|
428
|
2371 for (j = 0; j < len; j++)
|
|
2372 XVECTOR_DATA (new_table)[j]
|
|
2373 = XVECTOR_DATA (Vccl_program_table)[j];
|
|
2374 Vccl_program_table = new_table;
|
|
2375 }
|
|
2376
|
444
|
2377 {
|
|
2378 Lisp_Object elt;
|
|
2379
|
|
2380 elt = Fmake_vector (make_int (3), Qnil);
|
|
2381 XVECTOR_DATA (elt)[0] = name;
|
|
2382 XVECTOR_DATA (elt)[1] = ccl_prog;
|
|
2383 XVECTOR_DATA (elt)[2] = resolved;
|
|
2384 XVECTOR_DATA (Vccl_program_table)[idx] = elt;
|
|
2385 }
|
|
2386
|
|
2387 Fput (name, Qccl_program_idx, make_int (idx));
|
|
2388 return make_int (idx);
|
428
|
2389 }
|
|
2390
|
|
2391 /* Register code conversion map.
|
|
2392 A code conversion map consists of numbers, Qt, Qnil, and Qlambda.
|
|
2393 The first element is start code point.
|
|
2394 The rest elements are mapped numbers.
|
|
2395 Symbol t means to map to an original number before mapping.
|
|
2396 Symbol nil means that the corresponding element is empty.
|
442
|
2397 Symbol lambda means to terminate mapping here.
|
428
|
2398 */
|
|
2399
|
|
2400 DEFUN ("register-code-conversion-map", Fregister_code_conversion_map,
|
444
|
2401 2, 2, 0, /*
|
|
2402 Register SYMBOL as code conversion map MAP.
|
|
2403 Return index number of the registered map.
|
|
2404 */
|
|
2405 (symbol, map))
|
428
|
2406 {
|
444
|
2407 int len = XVECTOR_LENGTH (Vcode_conversion_map_vector);
|
428
|
2408 int i;
|
444
|
2409 Lisp_Object idx;
|
428
|
2410
|
444
|
2411 CHECK_SYMBOL (symbol);
|
|
2412 CHECK_VECTOR (map);
|
442
|
2413
|
428
|
2414 for (i = 0; i < len; i++)
|
|
2415 {
|
444
|
2416 Lisp_Object slot = XVECTOR_DATA (Vcode_conversion_map_vector)[i];
|
428
|
2417
|
|
2418 if (!CONSP (slot))
|
|
2419 break;
|
|
2420
|
444
|
2421 if (EQ (symbol, XCAR (slot)))
|
428
|
2422 {
|
444
|
2423 idx = make_int (i);
|
|
2424 XCDR (slot) = map;
|
428
|
2425 Fput (symbol, Qcode_conversion_map, map);
|
444
|
2426 Fput (symbol, Qcode_conversion_map_id, idx);
|
|
2427 return idx;
|
428
|
2428 }
|
|
2429 }
|
|
2430
|
|
2431 if (i == len)
|
|
2432 {
|
|
2433 Lisp_Object new_vector = Fmake_vector (make_int (len * 2), Qnil);
|
|
2434 int j;
|
|
2435
|
|
2436 for (j = 0; j < len; j++)
|
444
|
2437 XVECTOR_DATA (new_vector)[j]
|
|
2438 = XVECTOR_DATA (Vcode_conversion_map_vector)[j];
|
428
|
2439 Vcode_conversion_map_vector = new_vector;
|
|
2440 }
|
|
2441
|
444
|
2442 idx = make_int (i);
|
428
|
2443 Fput (symbol, Qcode_conversion_map, map);
|
444
|
2444 Fput (symbol, Qcode_conversion_map_id, idx);
|
|
2445 XVECTOR_DATA (Vcode_conversion_map_vector)[i] = Fcons (symbol, map);
|
|
2446 return idx;
|
428
|
2447 }
|
|
2448
|
|
2449
|
|
2450 void
|
|
2451 syms_of_mule_ccl (void)
|
|
2452 {
|
565
|
2453 DEFERROR_STANDARD (Qccl_error, Qconversion_error);
|
|
2454
|
444
|
2455 DEFSUBR (Fccl_program_p);
|
428
|
2456 DEFSUBR (Fccl_execute);
|
|
2457 DEFSUBR (Fccl_execute_on_string);
|
|
2458 DEFSUBR (Fregister_ccl_program);
|
444
|
2459 DEFSUBR (Fregister_code_conversion_map);
|
428
|
2460 }
|
|
2461
|
|
2462 void
|
|
2463 vars_of_mule_ccl (void)
|
|
2464 {
|
4072
|
2465
|
428
|
2466 staticpro (&Vccl_program_table);
|
|
2467 Vccl_program_table = Fmake_vector (make_int (32), Qnil);
|
|
2468
|
4072
|
2469 #ifdef DEBUG_XEMACS
|
|
2470 DEFVAR_LISP ("ccl-program-table",
|
|
2471 &Vccl_program_table /*
|
|
2472 Vector containing all registered CCL programs.
|
|
2473 */ );
|
|
2474 #endif
|
563
|
2475 DEFSYMBOL (Qccl_program);
|
|
2476 DEFSYMBOL (Qccl_program_idx);
|
|
2477 DEFSYMBOL (Qcode_conversion_map);
|
|
2478 DEFSYMBOL (Qcode_conversion_map_id);
|
428
|
2479
|
|
2480 DEFVAR_LISP ("code-conversion-map-vector", &Vcode_conversion_map_vector /*
|
444
|
2481 Vector of code conversion maps.
|
|
2482 */ );
|
428
|
2483 Vcode_conversion_map_vector = Fmake_vector (make_int (16), Qnil);
|
|
2484
|
4072
|
2485 DEFVAR_LISP ("translation-hash-table-vector",
|
|
2486 &Vtranslation_hash_table_vector /*
|
|
2487 Vector containing all translation hash tables ever defined.
|
|
2488 Comprises pairs (SYMBOL . TABLE) where SYMBOL and TABLE were set up by calls
|
|
2489 to `define-translation-hash-table'. The vector is indexed by the table id
|
|
2490 used by CCL.
|
428
|
2491 */ );
|
4072
|
2492 Vtranslation_hash_table_vector = Qnil;
|
|
2493
|
428
|
2494 }
|
|
2495
|
|
2496 #endif /* emacs */
|