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; \
|
|
637 } \
|
|
638 CCL_INVALID_CMD; \
|
|
639 } \
|
|
640 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog; \
|
|
641 ccl_prog_stack_struct[stack_idx].ic = (ret_ic); \
|
|
642 stack_idx++; \
|
|
643 ccl_prog = called_ccl.prog; \
|
|
644 ic = CCL_HEADER_MAIN; \
|
456
|
645 /* The "if (1)" prevents warning \
|
|
646 "end-of loop code not reached" */ \
|
|
647 if (1) goto ccl_repeat; \
|
444
|
648 } while (0)
|
428
|
649
|
|
650 #define CCL_MapSingle 0x12 /* Map by single code conversion map
|
|
651 1:ExtendedCOMMNDXXXRRRrrrXXXXX
|
|
652 2:MAP-ID
|
|
653 ------------------------------
|
|
654 Map reg[rrr] by MAP-ID.
|
|
655 If some valid mapping is found,
|
|
656 set reg[rrr] to the result,
|
|
657 else
|
|
658 set reg[RRR] to -1.
|
|
659 */
|
|
660
|
4072
|
661 #define CCL_LookupIntConstTbl 0x13 /* Lookup multibyte character by
|
|
662 integer key. Afterwards R7 set
|
|
663 to 1 iff lookup succeeded.
|
|
664 1:ExtendedCOMMNDRrrRRRXXXXXXXX
|
|
665 2:ARGUMENT(Hash table ID) */
|
|
666
|
|
667 #define CCL_LookupCharConstTbl 0x14 /* Lookup integer by multibyte
|
|
668 character key. Afterwards R7 set
|
|
669 to 1 iff lookup succeeded.
|
|
670 1:ExtendedCOMMNDRrrRRRrrrXXXXX
|
|
671 2:ARGUMENT(Hash table ID) */
|
|
672
|
|
673
|
428
|
674 /* CCL arithmetic/logical operators. */
|
|
675 #define CCL_PLUS 0x00 /* X = Y + Z */
|
|
676 #define CCL_MINUS 0x01 /* X = Y - Z */
|
|
677 #define CCL_MUL 0x02 /* X = Y * Z */
|
|
678 #define CCL_DIV 0x03 /* X = Y / Z */
|
|
679 #define CCL_MOD 0x04 /* X = Y % Z */
|
|
680 #define CCL_AND 0x05 /* X = Y & Z */
|
|
681 #define CCL_OR 0x06 /* X = Y | Z */
|
|
682 #define CCL_XOR 0x07 /* X = Y ^ Z */
|
|
683 #define CCL_LSH 0x08 /* X = Y << Z */
|
|
684 #define CCL_RSH 0x09 /* X = Y >> Z */
|
|
685 #define CCL_LSH8 0x0A /* X = (Y << 8) | Z */
|
|
686 #define CCL_RSH8 0x0B /* X = Y >> 8, r[7] = Y & 0xFF */
|
|
687 #define CCL_DIVMOD 0x0C /* X = Y / Z, r[7] = Y % Z */
|
|
688 #define CCL_LS 0x10 /* X = (X < Y) */
|
|
689 #define CCL_GT 0x11 /* X = (X > Y) */
|
|
690 #define CCL_EQ 0x12 /* X = (X == Y) */
|
|
691 #define CCL_LE 0x13 /* X = (X <= Y) */
|
|
692 #define CCL_GE 0x14 /* X = (X >= Y) */
|
|
693 #define CCL_NE 0x15 /* X = (X != Y) */
|
|
694
|
|
695 #define CCL_DECODE_SJIS 0x16 /* X = HIGHER_BYTE (DE-SJIS (Y, Z))
|
|
696 r[7] = LOWER_BYTE (DE-SJIS (Y, Z)) */
|
|
697 #define CCL_ENCODE_SJIS 0x17 /* X = HIGHER_BYTE (SJIS (Y, Z))
|
|
698 r[7] = LOWER_BYTE (SJIS (Y, Z) */
|
|
699
|
444
|
700 /* Terminate CCL program successfully. */
|
462
|
701 #define CCL_SUCCESS \
|
|
702 do { \
|
|
703 ccl->status = CCL_STAT_SUCCESS; \
|
456
|
704 /* The "if (1)" inhibits the warning \
|
|
705 "end-of loop code not reached" */ \
|
|
706 if (1) goto ccl_finish; \
|
462
|
707 } while (0)
|
444
|
708
|
428
|
709 /* Suspend CCL program because of reading from empty input buffer or
|
|
710 writing to full output buffer. When this program is resumed, the
|
444
|
711 same I/O command is executed. */
|
462
|
712 #define CCL_SUSPEND(stat) \
|
|
713 do { \
|
|
714 ic--; \
|
456
|
715 ccl->status = (stat); \
|
|
716 /* The "if (1)" inhibits the warning \
|
|
717 "end-of loop code not reached" */ \
|
|
718 if (1) goto ccl_finish; \
|
462
|
719 } while (0)
|
428
|
720
|
|
721 /* Terminate CCL program because of invalid command. Should not occur
|
444
|
722 in the normal case. */
|
771
|
723 #define CCL_INVALID_CMD \
|
|
724 do { \
|
|
725 ccl->status = CCL_STAT_INVALID_CMD; \
|
|
726 /* enable this to debug invalid cmd errors */ \
|
|
727 /* debug_break (); */ \
|
|
728 /* The "if (1)" inhibits the warning \
|
|
729 "end-of loop code not reached" */ \
|
|
730 if (1) goto ccl_error_handler; \
|
462
|
731 } while (0)
|
428
|
732
|
|
733 /* Encode one character CH to multibyte form and write to the current
|
444
|
734 output buffer. At encoding time, if CH is less than 256, CH is
|
|
735 written as is. At decoding time, if CH cannot be regarded as an
|
|
736 ASCII character, write it in multibyte form. */
|
|
737 #define CCL_WRITE_CHAR(ch) \
|
|
738 do { \
|
|
739 if (!destination) \
|
|
740 CCL_INVALID_CMD; \
|
|
741 if (conversion_mode == CCL_MODE_ENCODING) \
|
|
742 { \
|
456
|
743 if ((ch) == '\n') \
|
444
|
744 { \
|
|
745 if (ccl->eol_type == CCL_CODING_EOL_CRLF) \
|
|
746 { \
|
|
747 Dynarr_add (destination, '\r'); \
|
|
748 Dynarr_add (destination, '\n'); \
|
|
749 } \
|
|
750 else if (ccl->eol_type == CCL_CODING_EOL_CR) \
|
|
751 Dynarr_add (destination, '\r'); \
|
|
752 else \
|
|
753 Dynarr_add (destination, '\n'); \
|
|
754 } \
|
456
|
755 else if ((ch) < 0x100) \
|
444
|
756 { \
|
|
757 Dynarr_add (destination, ch); \
|
|
758 } \
|
|
759 else \
|
|
760 { \
|
2286
|
761 Ibyte work[MAX_ICHAR_LEN]; \
|
444
|
762 int len; \
|
2286
|
763 len = non_ascii_set_itext_ichar (work, ch); \
|
444
|
764 Dynarr_add_many (destination, work, len); \
|
|
765 } \
|
|
766 } \
|
|
767 else \
|
|
768 { \
|
867
|
769 if (!ichar_multibyte_p(ch)) \
|
444
|
770 { \
|
|
771 Dynarr_add (destination, ch); \
|
|
772 } \
|
|
773 else \
|
|
774 { \
|
2286
|
775 Ibyte work[MAX_ICHAR_LEN]; \
|
444
|
776 int len; \
|
2286
|
777 len = non_ascii_set_itext_ichar (work, ch); \
|
444
|
778 Dynarr_add_many (destination, work, len); \
|
|
779 } \
|
|
780 } \
|
|
781 } while (0)
|
428
|
782
|
|
783 /* Write a string at ccl_prog[IC] of length LEN to the current output
|
444
|
784 buffer. But this macro treat this string as a binary. Therefore,
|
|
785 cannot handle a multibyte string except for Control-1 characters. */
|
|
786 #define CCL_WRITE_STRING(len) \
|
|
787 do { \
|
2286
|
788 Ibyte work[MAX_ICHAR_LEN]; \
|
|
789 int ch; \
|
444
|
790 if (!destination) \
|
|
791 CCL_INVALID_CMD; \
|
|
792 else if (conversion_mode == CCL_MODE_ENCODING) \
|
|
793 { \
|
456
|
794 for (i = 0; i < (len); i++) \
|
444
|
795 { \
|
4072
|
796 ch = ((XCHAR_OR_INT (ccl_prog[ic + (i / 3)])) \
|
444
|
797 >> ((2 - (i % 3)) * 8)) & 0xFF; \
|
|
798 if (ch == '\n') \
|
|
799 { \
|
|
800 if (ccl->eol_type == CCL_CODING_EOL_CRLF) \
|
|
801 { \
|
|
802 Dynarr_add (destination, '\r'); \
|
|
803 Dynarr_add (destination, '\n'); \
|
|
804 } \
|
|
805 else if (ccl->eol_type == CCL_CODING_EOL_CR) \
|
|
806 Dynarr_add (destination, '\r'); \
|
|
807 else \
|
|
808 Dynarr_add (destination, '\n'); \
|
|
809 } \
|
|
810 if (ch < 0x100) \
|
|
811 { \
|
|
812 Dynarr_add (destination, ch); \
|
|
813 } \
|
|
814 else \
|
|
815 { \
|
2286
|
816 non_ascii_set_itext_ichar (work, ch); \
|
444
|
817 Dynarr_add_many (destination, work, len); \
|
|
818 } \
|
|
819 } \
|
|
820 } \
|
|
821 else \
|
|
822 { \
|
456
|
823 for (i = 0; i < (len); i++) \
|
444
|
824 { \
|
4072
|
825 ch = ((XCHAR_OR_INT (ccl_prog[ic + (i / 3)])) \
|
444
|
826 >> ((2 - (i % 3)) * 8)) & 0xFF; \
|
867
|
827 if (!ichar_multibyte_p(ch)) \
|
444
|
828 { \
|
|
829 Dynarr_add (destination, ch); \
|
|
830 } \
|
|
831 else \
|
|
832 { \
|
2286
|
833 non_ascii_set_itext_ichar (work, ch); \
|
444
|
834 Dynarr_add_many (destination, work, len); \
|
|
835 } \
|
|
836 } \
|
|
837 } \
|
|
838 } while (0)
|
428
|
839
|
|
840 /* Read one byte from the current input buffer into Rth register. */
|
444
|
841 #define CCL_READ_CHAR(r) \
|
|
842 do { \
|
|
843 if (!src) \
|
|
844 CCL_INVALID_CMD; \
|
|
845 if (src < src_end) \
|
456
|
846 (r) = *src++; \
|
444
|
847 else \
|
|
848 { \
|
|
849 if (ccl->last_block) \
|
|
850 { \
|
|
851 ic = ccl->eof_ic; \
|
|
852 goto ccl_repeat; \
|
|
853 } \
|
|
854 else \
|
|
855 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC); \
|
|
856 } \
|
|
857 } while (0)
|
|
858
|
2830
|
859 #define POSSIBLE_LEADING_BYTE_P(leading_byte) \
|
4072
|
860 ((leading_byte >= MIN_LEADING_BYTE) && \
|
2829
|
861 (leading_byte - MIN_LEADING_BYTE) < NUM_LEADING_BYTES)
|
444
|
862
|
|
863 /* Set C to the character code made from CHARSET and CODE. This is
|
867
|
864 like make_ichar but check the validity of CHARSET and CODE. If they
|
444
|
865 are not valid, set C to (CODE & 0xFF) because that is usually the
|
|
866 case that CCL_ReadMultibyteChar2 read an invalid code and it set
|
|
867 CODE to that invalid byte. */
|
|
868
|
|
869 /* On XEmacs, TranslateCharacter is not supported. Thus, this
|
3439
|
870 macro is only used in the MuleToUnicode transformation. */
|
444
|
871 #define CCL_MAKE_CHAR(charset, code, c) \
|
|
872 do { \
|
3690
|
873 \
|
|
874 if (!POSSIBLE_LEADING_BYTE_P(charset)) \
|
|
875 CCL_INVALID_CMD; \
|
|
876 \
|
3439
|
877 if ((charset) == LEADING_BYTE_ASCII) \
|
|
878 { \
|
|
879 c = (code) & 0xFF; \
|
|
880 } \
|
|
881 else if ((charset) == LEADING_BYTE_CONTROL_1) \
|
|
882 { \
|
3690
|
883 c = ((code) & 0x1F) + 0x80; \
|
3439
|
884 } \
|
|
885 else if (!NILP(charset_by_leading_byte(charset)) \
|
|
886 && ((code) >= 32) \
|
4072
|
887 && ((code) < 256 || ((code >> 7) & 0x7F) >= 32)) \
|
444
|
888 { \
|
3439
|
889 int c1, c2 = 0; \
|
444
|
890 \
|
3439
|
891 if ((code) < 256) \
|
|
892 { \
|
|
893 c1 = (code) & 0x7F; \
|
|
894 c2 = 0; \
|
|
895 } \
|
|
896 else \
|
|
897 { \
|
4072
|
898 c1 = ((code) >> 7) & 0x7F; \
|
3439
|
899 c2 = (code) & 0x7F; \
|
|
900 } \
|
|
901 c = make_ichar (charset_by_leading_byte(charset), \
|
|
902 c1, c2); \
|
444
|
903 } \
|
|
904 else \
|
3439
|
905 { \
|
|
906 c = (code) & 0xFF; \
|
|
907 } \
|
|
908 } while (0)
|
428
|
909
|
|
910
|
|
911 /* Execute CCL code on SRC_BYTES length text at SOURCE. The resulting
|
444
|
912 text goes to a place pointed by DESTINATION, the length of which
|
|
913 should not exceed DST_BYTES. The bytes actually processed is
|
|
914 returned as *CONSUMED. The return value is the length of the
|
|
915 resulting text. As a side effect, the contents of CCL registers
|
428
|
916 are updated. If SOURCE or DESTINATION is NULL, only operations on
|
|
917 registers are permitted. */
|
|
918
|
|
919 #ifdef CCL_DEBUG
|
|
920 #define CCL_DEBUG_BACKTRACE_LEN 256
|
4072
|
921 int ccl_backtrace_table[CCL_DEBUG_BACKTRACE_LEN];
|
428
|
922 int ccl_backtrace_idx;
|
|
923 #endif
|
|
924
|
|
925 struct ccl_prog_stack
|
|
926 {
|
|
927 Lisp_Object *ccl_prog; /* Pointer to an array of CCL code. */
|
|
928 int ic; /* Instruction Counter. */
|
|
929 };
|
|
930
|
442
|
931 /* For the moment, we only support depth 256 of stack. */
|
428
|
932 static struct ccl_prog_stack ccl_prog_stack_struct[256];
|
|
933
|
|
934 int
|
444
|
935 ccl_driver (struct ccl_program *ccl,
|
|
936 const unsigned char *source,
|
|
937 unsigned_char_dynarr *destination,
|
|
938 int src_bytes,
|
|
939 int *consumed,
|
|
940 int conversion_mode)
|
428
|
941 {
|
444
|
942 register int *reg = ccl->reg;
|
|
943 register int ic = ccl->ic;
|
|
944 register int code = -1;
|
|
945 register int field1, field2;
|
|
946 register Lisp_Object *ccl_prog = ccl->prog;
|
442
|
947 const unsigned char *src = source, *src_end = src + src_bytes;
|
444
|
948 int jump_address;
|
428
|
949 int i, j, op;
|
|
950 int stack_idx = ccl->stack_idx;
|
|
951 /* Instruction counter of the current CCL code. */
|
|
952 int this_ic = 0;
|
|
953
|
|
954 if (ic >= ccl->eof_ic)
|
|
955 ic = CCL_HEADER_MAIN;
|
|
956
|
|
957 if (ccl->buf_magnification ==0) /* We can't produce any bytes. */
|
444
|
958 destination = NULL;
|
|
959
|
|
960 /* Set mapping stack pointer. */
|
|
961 mapping_stack_pointer = mapping_stack;
|
428
|
962
|
|
963 #ifdef CCL_DEBUG
|
|
964 ccl_backtrace_idx = 0;
|
|
965 #endif
|
|
966
|
|
967 for (;;)
|
|
968 {
|
|
969 ccl_repeat:
|
|
970 #ifdef CCL_DEBUG
|
|
971 ccl_backtrace_table[ccl_backtrace_idx++] = ic;
|
|
972 if (ccl_backtrace_idx >= CCL_DEBUG_BACKTRACE_LEN)
|
|
973 ccl_backtrace_idx = 0;
|
|
974 ccl_backtrace_table[ccl_backtrace_idx] = 0;
|
|
975 #endif
|
|
976
|
|
977 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit))
|
|
978 {
|
|
979 /* We can't just signal Qquit, instead break the loop as if
|
|
980 the whole data is processed. Don't reset Vquit_flag, it
|
|
981 must be handled later at a safer place. */
|
|
982 if (consumed)
|
|
983 src = source + src_bytes;
|
|
984 ccl->status = CCL_STAT_QUIT;
|
|
985 break;
|
|
986 }
|
|
987
|
|
988 this_ic = ic;
|
4072
|
989 code = XCHAR_OR_INT (ccl_prog[ic]); ic++;
|
428
|
990 field1 = code >> 8;
|
|
991 field2 = (code & 0xFF) >> 5;
|
|
992
|
|
993 #define rrr field2
|
|
994 #define RRR (field1 & 7)
|
|
995 #define Rrr ((field1 >> 3) & 7)
|
|
996 #define ADDR field1
|
|
997 #define EXCMD (field1 >> 6)
|
|
998
|
|
999 switch (code & 0x1F)
|
|
1000 {
|
|
1001 case CCL_SetRegister: /* 00000000000000000RRRrrrXXXXX */
|
|
1002 reg[rrr] = reg[RRR];
|
|
1003 break;
|
|
1004
|
|
1005 case CCL_SetShortConst: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1006 reg[rrr] = field1;
|
|
1007 break;
|
|
1008
|
|
1009 case CCL_SetConst: /* 00000000000000000000rrrXXXXX */
|
4072
|
1010 reg[rrr] = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1011 ic++;
|
|
1012 break;
|
|
1013
|
|
1014 case CCL_SetArray: /* CCCCCCCCCCCCCCCCCCCCRRRrrrXXXXX */
|
|
1015 i = reg[RRR];
|
|
1016 j = field1 >> 3;
|
647
|
1017 /* #### it's non-obvious to me that we need these casts,
|
|
1018 but the left one was already there so clearly the intention
|
|
1019 was an unsigned comparison. --ben */
|
|
1020 if ((unsigned int) i < (unsigned int) j)
|
4072
|
1021 reg[rrr] = XCHAR_OR_INT (ccl_prog[ic + i]);
|
428
|
1022 ic += j;
|
|
1023 break;
|
|
1024
|
|
1025 case CCL_Jump: /* A--D--D--R--E--S--S-000XXXXX */
|
|
1026 ic += ADDR;
|
|
1027 break;
|
|
1028
|
|
1029 case CCL_JumpCond: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1030 if (!reg[rrr])
|
|
1031 ic += ADDR;
|
|
1032 break;
|
|
1033
|
|
1034 case CCL_WriteRegisterJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1035 i = reg[rrr];
|
|
1036 CCL_WRITE_CHAR (i);
|
|
1037 ic += ADDR;
|
|
1038 break;
|
|
1039
|
|
1040 case CCL_WriteRegisterReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1041 i = reg[rrr];
|
|
1042 CCL_WRITE_CHAR (i);
|
|
1043 ic++;
|
|
1044 CCL_READ_CHAR (reg[rrr]);
|
|
1045 ic += ADDR - 1;
|
|
1046 break;
|
|
1047
|
|
1048 case CCL_WriteConstJump: /* A--D--D--R--E--S--S-000XXXXX */
|
4072
|
1049 i = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1050 CCL_WRITE_CHAR (i);
|
|
1051 ic += ADDR;
|
|
1052 break;
|
|
1053
|
|
1054 case CCL_WriteConstReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
4072
|
1055 i = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1056 CCL_WRITE_CHAR (i);
|
|
1057 ic++;
|
|
1058 CCL_READ_CHAR (reg[rrr]);
|
|
1059 ic += ADDR - 1;
|
|
1060 break;
|
|
1061
|
|
1062 case CCL_WriteStringJump: /* A--D--D--R--E--S--S-000XXXXX */
|
4072
|
1063 j = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1064 ic++;
|
|
1065 CCL_WRITE_STRING (j);
|
|
1066 ic += ADDR - 1;
|
|
1067 break;
|
|
1068
|
|
1069 case CCL_WriteArrayReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1070 i = reg[rrr];
|
4072
|
1071 j = XCHAR_OR_INT (ccl_prog[ic]);
|
647
|
1072 /* #### see comment at CCL_SetArray */
|
|
1073 if ((unsigned int) i < (unsigned int) j)
|
428
|
1074 {
|
4072
|
1075 i = XCHAR_OR_INT (ccl_prog[ic + 1 + i]);
|
428
|
1076 CCL_WRITE_CHAR (i);
|
|
1077 }
|
|
1078 ic += j + 2;
|
|
1079 CCL_READ_CHAR (reg[rrr]);
|
|
1080 ic += ADDR - (j + 2);
|
|
1081 break;
|
|
1082
|
|
1083 case CCL_ReadJump: /* A--D--D--R--E--S--S-rrrYYYYY */
|
|
1084 CCL_READ_CHAR (reg[rrr]);
|
|
1085 ic += ADDR;
|
|
1086 break;
|
|
1087
|
|
1088 case CCL_ReadBranch: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1089 CCL_READ_CHAR (reg[rrr]);
|
|
1090 /* fall through ... */
|
|
1091 case CCL_Branch: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
647
|
1092 /* #### see comment at CCL_SetArray */
|
|
1093 if ((unsigned int) reg[rrr] < (unsigned int) field1)
|
4072
|
1094 ic += XCHAR_OR_INT (ccl_prog[ic + reg[rrr]]);
|
428
|
1095 else
|
4072
|
1096 ic += XCHAR_OR_INT (ccl_prog[ic + field1]);
|
428
|
1097 break;
|
|
1098
|
|
1099 case CCL_ReadRegister: /* CCCCCCCCCCCCCCCCCCCCrrXXXXX */
|
|
1100 while (1)
|
|
1101 {
|
|
1102 CCL_READ_CHAR (reg[rrr]);
|
|
1103 if (!field1) break;
|
4072
|
1104 code = XCHAR_OR_INT (ccl_prog[ic]); ic++;
|
428
|
1105 field1 = code >> 8;
|
|
1106 field2 = (code & 0xFF) >> 5;
|
|
1107 }
|
|
1108 break;
|
|
1109
|
|
1110 case CCL_WriteExprConst: /* 1:00000OPERATION000RRR000XXXXX */
|
|
1111 rrr = 7;
|
|
1112 i = reg[RRR];
|
4072
|
1113 j = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1114 op = field1 >> 6;
|
444
|
1115 jump_address = ic + 1;
|
428
|
1116 goto ccl_set_expr;
|
|
1117
|
|
1118 case CCL_WriteRegister: /* CCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1119 while (1)
|
|
1120 {
|
|
1121 i = reg[rrr];
|
|
1122 CCL_WRITE_CHAR (i);
|
|
1123 if (!field1) break;
|
4072
|
1124 code = XCHAR_OR_INT (ccl_prog[ic]); ic++;
|
428
|
1125 field1 = code >> 8;
|
|
1126 field2 = (code & 0xFF) >> 5;
|
|
1127 }
|
|
1128 break;
|
|
1129
|
|
1130 case CCL_WriteExprRegister: /* 1:00000OPERATIONRrrRRR000XXXXX */
|
|
1131 rrr = 7;
|
|
1132 i = reg[RRR];
|
|
1133 j = reg[Rrr];
|
|
1134 op = field1 >> 6;
|
444
|
1135 jump_address = ic;
|
428
|
1136 goto ccl_set_expr;
|
|
1137
|
444
|
1138 case CCL_Call: /* 1:CCCCCCCCCCCCCCCCCCCCFFFXXXXX */
|
428
|
1139 {
|
|
1140 Lisp_Object slot;
|
444
|
1141 int prog_id;
|
|
1142
|
|
1143 /* If FFF is nonzero, the CCL program ID is in the
|
|
1144 following code. */
|
|
1145 if (rrr)
|
|
1146 {
|
4072
|
1147 prog_id = XCHAR_OR_INT (ccl_prog[ic]);
|
444
|
1148 ic++;
|
|
1149 }
|
|
1150 else
|
|
1151 prog_id = field1;
|
428
|
1152
|
|
1153 if (stack_idx >= 256
|
444
|
1154 || prog_id < 0
|
|
1155 || prog_id >= XVECTOR (Vccl_program_table)->size
|
|
1156 || (slot = XVECTOR (Vccl_program_table)->contents[prog_id],
|
|
1157 !VECTORP (slot))
|
|
1158 || !VECTORP (XVECTOR (slot)->contents[1]))
|
428
|
1159 {
|
|
1160 if (stack_idx > 0)
|
|
1161 {
|
|
1162 ccl_prog = ccl_prog_stack_struct[0].ccl_prog;
|
|
1163 ic = ccl_prog_stack_struct[0].ic;
|
|
1164 }
|
444
|
1165 CCL_INVALID_CMD;
|
428
|
1166 }
|
|
1167
|
|
1168 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog;
|
|
1169 ccl_prog_stack_struct[stack_idx].ic = ic;
|
|
1170 stack_idx++;
|
444
|
1171 ccl_prog = XVECTOR (XVECTOR (slot)->contents[1])->contents;
|
428
|
1172 ic = CCL_HEADER_MAIN;
|
|
1173 }
|
|
1174 break;
|
|
1175
|
|
1176 case CCL_WriteConstString: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1177 if (!rrr)
|
|
1178 CCL_WRITE_CHAR (field1);
|
|
1179 else
|
|
1180 {
|
|
1181 CCL_WRITE_STRING (field1);
|
|
1182 ic += (field1 + 2) / 3;
|
|
1183 }
|
|
1184 break;
|
|
1185
|
|
1186 case CCL_WriteArray: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1187 i = reg[rrr];
|
647
|
1188 /* #### see comment at CCL_SetArray */
|
|
1189 if ((unsigned int) i < (unsigned int) field1)
|
428
|
1190 {
|
4072
|
1191 j = XCHAR_OR_INT (ccl_prog[ic + i]);
|
428
|
1192 CCL_WRITE_CHAR (j);
|
|
1193 }
|
|
1194 ic += field1;
|
|
1195 break;
|
|
1196
|
|
1197 case CCL_End: /* 0000000000000000000000XXXXX */
|
444
|
1198 if (stack_idx > 0)
|
428
|
1199 {
|
444
|
1200 stack_idx--;
|
428
|
1201 ccl_prog = ccl_prog_stack_struct[stack_idx].ccl_prog;
|
|
1202 ic = ccl_prog_stack_struct[stack_idx].ic;
|
|
1203 break;
|
|
1204 }
|
|
1205 if (src)
|
|
1206 src = src_end;
|
|
1207 /* ccl->ic should points to this command code again to
|
|
1208 suppress further processing. */
|
|
1209 ic--;
|
444
|
1210 CCL_SUCCESS;
|
428
|
1211
|
|
1212 case CCL_ExprSelfConst: /* 00000OPERATION000000rrrXXXXX */
|
4072
|
1213 i = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1214 ic++;
|
|
1215 op = field1 >> 6;
|
|
1216 goto ccl_expr_self;
|
|
1217
|
|
1218 case CCL_ExprSelfReg: /* 00000OPERATION000RRRrrrXXXXX */
|
|
1219 i = reg[RRR];
|
|
1220 op = field1 >> 6;
|
|
1221
|
|
1222 ccl_expr_self:
|
|
1223 switch (op)
|
|
1224 {
|
|
1225 case CCL_PLUS: reg[rrr] += i; break;
|
|
1226 case CCL_MINUS: reg[rrr] -= i; break;
|
|
1227 case CCL_MUL: reg[rrr] *= i; break;
|
|
1228 case CCL_DIV: reg[rrr] /= i; break;
|
|
1229 case CCL_MOD: reg[rrr] %= i; break;
|
|
1230 case CCL_AND: reg[rrr] &= i; break;
|
|
1231 case CCL_OR: reg[rrr] |= i; break;
|
|
1232 case CCL_XOR: reg[rrr] ^= i; break;
|
|
1233 case CCL_LSH: reg[rrr] <<= i; break;
|
|
1234 case CCL_RSH: reg[rrr] >>= i; break;
|
|
1235 case CCL_LSH8: reg[rrr] <<= 8; reg[rrr] |= i; break;
|
|
1236 case CCL_RSH8: reg[7] = reg[rrr] & 0xFF; reg[rrr] >>= 8; break;
|
|
1237 case CCL_DIVMOD: reg[7] = reg[rrr] % i; reg[rrr] /= i; break;
|
|
1238 case CCL_LS: reg[rrr] = reg[rrr] < i; break;
|
|
1239 case CCL_GT: reg[rrr] = reg[rrr] > i; break;
|
|
1240 case CCL_EQ: reg[rrr] = reg[rrr] == i; break;
|
|
1241 case CCL_LE: reg[rrr] = reg[rrr] <= i; break;
|
|
1242 case CCL_GE: reg[rrr] = reg[rrr] >= i; break;
|
|
1243 case CCL_NE: reg[rrr] = reg[rrr] != i; break;
|
444
|
1244 default: CCL_INVALID_CMD;
|
428
|
1245 }
|
|
1246 break;
|
|
1247
|
|
1248 case CCL_SetExprConst: /* 00000OPERATION000RRRrrrXXXXX */
|
|
1249 i = reg[RRR];
|
4072
|
1250 j = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1251 op = field1 >> 6;
|
|
1252 jump_address = ++ic;
|
|
1253 goto ccl_set_expr;
|
|
1254
|
|
1255 case CCL_SetExprReg: /* 00000OPERATIONRrrRRRrrrXXXXX */
|
|
1256 i = reg[RRR];
|
|
1257 j = reg[Rrr];
|
|
1258 op = field1 >> 6;
|
|
1259 jump_address = ic;
|
|
1260 goto ccl_set_expr;
|
|
1261
|
|
1262 case CCL_ReadJumpCondExprConst: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1263 CCL_READ_CHAR (reg[rrr]);
|
|
1264 case CCL_JumpCondExprConst: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1265 i = reg[rrr];
|
4072
|
1266 op = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1267 jump_address = ic++ + ADDR;
|
4072
|
1268 j = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1269 ic++;
|
|
1270 rrr = 7;
|
|
1271 goto ccl_set_expr;
|
|
1272
|
|
1273 case CCL_ReadJumpCondExprReg: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1274 CCL_READ_CHAR (reg[rrr]);
|
|
1275 case CCL_JumpCondExprReg:
|
|
1276 i = reg[rrr];
|
4072
|
1277 op = XCHAR_OR_INT (ccl_prog[ic]);
|
428
|
1278 jump_address = ic++ + ADDR;
|
4072
|
1279 j = reg[XCHAR_OR_INT (ccl_prog[ic])];
|
428
|
1280 ic++;
|
|
1281 rrr = 7;
|
|
1282
|
|
1283 ccl_set_expr:
|
|
1284 switch (op)
|
|
1285 {
|
|
1286 case CCL_PLUS: reg[rrr] = i + j; break;
|
|
1287 case CCL_MINUS: reg[rrr] = i - j; break;
|
|
1288 case CCL_MUL: reg[rrr] = i * j; break;
|
|
1289 case CCL_DIV: reg[rrr] = i / j; break;
|
|
1290 case CCL_MOD: reg[rrr] = i % j; break;
|
|
1291 case CCL_AND: reg[rrr] = i & j; break;
|
|
1292 case CCL_OR: reg[rrr] = i | j; break;
|
444
|
1293 case CCL_XOR: reg[rrr] = i ^ j;; break;
|
428
|
1294 case CCL_LSH: reg[rrr] = i << j; break;
|
|
1295 case CCL_RSH: reg[rrr] = i >> j; break;
|
|
1296 case CCL_LSH8: reg[rrr] = (i << 8) | j; break;
|
|
1297 case CCL_RSH8: reg[rrr] = i >> 8; reg[7] = i & 0xFF; break;
|
|
1298 case CCL_DIVMOD: reg[rrr] = i / j; reg[7] = i % j; break;
|
|
1299 case CCL_LS: reg[rrr] = i < j; break;
|
|
1300 case CCL_GT: reg[rrr] = i > j; break;
|
|
1301 case CCL_EQ: reg[rrr] = i == j; break;
|
|
1302 case CCL_LE: reg[rrr] = i <= j; break;
|
|
1303 case CCL_GE: reg[rrr] = i >= j; break;
|
|
1304 case CCL_NE: reg[rrr] = i != j; break;
|
444
|
1305 case CCL_DECODE_SJIS:
|
771
|
1306 /* DECODE_SHIFT_JIS set MSB for internal format
|
444
|
1307 as opposed to Emacs. */
|
771
|
1308 DECODE_SHIFT_JIS (i, j, reg[rrr], reg[7]);
|
444
|
1309 reg[rrr] &= 0x7F;
|
|
1310 reg[7] &= 0x7F;
|
|
1311 break;
|
|
1312 case CCL_ENCODE_SJIS:
|
771
|
1313 /* ENCODE_SHIFT_JIS assumes MSB of SHIFT-JIS-char is set
|
444
|
1314 as opposed to Emacs. */
|
771
|
1315 ENCODE_SHIFT_JIS (i | 0x80, j | 0x80, reg[rrr], reg[7]);
|
444
|
1316 break;
|
|
1317 default: CCL_INVALID_CMD;
|
428
|
1318 }
|
|
1319 code &= 0x1F;
|
|
1320 if (code == CCL_WriteExprConst || code == CCL_WriteExprRegister)
|
|
1321 {
|
|
1322 i = reg[rrr];
|
|
1323 CCL_WRITE_CHAR (i);
|
444
|
1324 ic = jump_address;
|
428
|
1325 }
|
|
1326 else if (!reg[rrr])
|
|
1327 ic = jump_address;
|
|
1328 break;
|
|
1329
|
456
|
1330 case CCL_Extension:
|
428
|
1331 switch (EXCMD)
|
|
1332 {
|
|
1333 case CCL_ReadMultibyteChar2:
|
|
1334 if (!src)
|
|
1335 CCL_INVALID_CMD;
|
|
1336
|
462
|
1337 if (src >= src_end)
|
|
1338 {
|
|
1339 src++;
|
456
|
1340 goto ccl_read_multibyte_character_suspend;
|
462
|
1341 }
|
|
1342
|
|
1343 i = *src++;
|
|
1344 if (i < 0x80)
|
|
1345 {
|
|
1346 /* ASCII */
|
|
1347 reg[rrr] = i;
|
|
1348 reg[RRR] = LEADING_BYTE_ASCII;
|
|
1349 }
|
2829
|
1350 /* Previously, these next two elses were reversed in order,
|
|
1351 which should have worked fine, but is more fragile than
|
|
1352 this order. */
|
|
1353 else if (LEADING_BYTE_CONTROL_1 == i)
|
|
1354 {
|
|
1355 if (src >= src_end)
|
|
1356 goto ccl_read_multibyte_character_suspend;
|
|
1357 reg[RRR] = i;
|
|
1358 reg[rrr] = (*src++ - 0xA0);
|
|
1359 }
|
462
|
1360 else if (i <= MAX_LEADING_BYTE_OFFICIAL_1)
|
|
1361 {
|
|
1362 if (src >= src_end)
|
|
1363 goto ccl_read_multibyte_character_suspend;
|
|
1364 reg[RRR] = i;
|
|
1365 reg[rrr] = (*src++ & 0x7F);
|
|
1366 }
|
|
1367 else if (i <= MAX_LEADING_BYTE_OFFICIAL_2)
|
|
1368 {
|
|
1369 if ((src + 1) >= src_end)
|
|
1370 goto ccl_read_multibyte_character_suspend;
|
|
1371 reg[RRR] = i;
|
|
1372 i = (*src++ & 0x7F);
|
|
1373 reg[rrr] = ((i << 7) | (*src & 0x7F));
|
|
1374 src++;
|
|
1375 }
|
|
1376 else if (i == PRE_LEADING_BYTE_PRIVATE_1)
|
|
1377 {
|
|
1378 if ((src + 1) >= src_end)
|
|
1379 goto ccl_read_multibyte_character_suspend;
|
|
1380 reg[RRR] = *src++;
|
4072
|
1381 reg[rrr] = (*src++ & 0xFF);
|
462
|
1382 }
|
|
1383 else if (i == PRE_LEADING_BYTE_PRIVATE_2)
|
|
1384 {
|
|
1385 if ((src + 2) >= src_end)
|
|
1386 goto ccl_read_multibyte_character_suspend;
|
|
1387 reg[RRR] = *src++;
|
|
1388 i = (*src++ & 0x7F);
|
|
1389 reg[rrr] = ((i << 7) | (*src & 0x7F));
|
|
1390 src++;
|
|
1391 }
|
|
1392 else
|
|
1393 {
|
|
1394 /* INVALID CODE. Return a single byte character. */
|
|
1395 reg[RRR] = LEADING_BYTE_ASCII;
|
|
1396 reg[rrr] = i;
|
|
1397 }
|
428
|
1398 break;
|
|
1399
|
|
1400 ccl_read_multibyte_character_suspend:
|
|
1401 src--;
|
|
1402 if (ccl->last_block)
|
|
1403 {
|
|
1404 ic = ccl->eof_ic;
|
|
1405 goto ccl_repeat;
|
|
1406 }
|
|
1407 else
|
|
1408 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC);
|
|
1409
|
|
1410 break;
|
|
1411
|
|
1412 case CCL_WriteMultibyteChar2:
|
|
1413 i = reg[RRR]; /* charset */
|
2829
|
1414 if (i == LEADING_BYTE_ASCII)
|
428
|
1415 i = reg[rrr] & 0xFF;
|
2829
|
1416 else if (LEADING_BYTE_CONTROL_1 == i)
|
3690
|
1417 i = ((reg[rrr] & 0x1F) + 0x80);
|
2829
|
1418 else if (POSSIBLE_LEADING_BYTE_P(i) &&
|
2830
|
1419 !NILP(charset_by_leading_byte(i)))
|
2829
|
1420 {
|
|
1421 if (XCHARSET_DIMENSION (charset_by_leading_byte (i)) == 1)
|
|
1422 i = (((i - FIELD2_TO_OFFICIAL_LEADING_BYTE) << 7)
|
|
1423 | (reg[rrr] & 0x7F));
|
|
1424 else if (i < MAX_LEADING_BYTE_OFFICIAL_2)
|
|
1425 i = ((i - FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14)
|
|
1426 | reg[rrr];
|
|
1427 else
|
|
1428 i = ((i - FIELD1_TO_PRIVATE_LEADING_BYTE) << 14) | reg[rrr];
|
|
1429 }
|
|
1430 else
|
|
1431 {
|
|
1432 /* No charset we know about; use U+3012 GETA MARK */
|
|
1433 i = make_ichar
|
|
1434 (charset_by_leading_byte(LEADING_BYTE_JAPANESE_JISX0208),
|
|
1435 34, 46);
|
|
1436 }
|
428
|
1437
|
|
1438 CCL_WRITE_CHAR (i);
|
|
1439
|
|
1440 break;
|
|
1441
|
444
|
1442 case CCL_TranslateCharacter:
|
428
|
1443 #if 0
|
3439
|
1444 /* XEmacs does not have translate_char, nor an
|
|
1445 equivalent. We do nothing on this operation. */
|
|
1446 CCL_MAKE_CHAR(reg[RRR], reg[rrr], op);
|
428
|
1447 op = translate_char (GET_TRANSLATION_TABLE (reg[Rrr]),
|
|
1448 i, -1, 0, 0);
|
|
1449 SPLIT_CHAR (op, reg[RRR], i, j);
|
|
1450 if (j != -1)
|
|
1451 i = (i << 7) | j;
|
442
|
1452
|
428
|
1453 reg[rrr] = i;
|
444
|
1454 #endif
|
428
|
1455 break;
|
|
1456
|
|
1457 case CCL_TranslateCharacterConstTbl:
|
444
|
1458 #if 0
|
771
|
1459 /* XEmacs does not have translate_char or an equivalent. We
|
|
1460 do nothing on this operation. */
|
4072
|
1461 op = XCHAR_OR_INT (ccl_prog[ic]); /* table */
|
428
|
1462 ic++;
|
444
|
1463 CCL_MAKE_CHAR (reg[RRR], reg[rrr], i);
|
428
|
1464 op = translate_char (GET_TRANSLATION_TABLE (op), i, -1, 0, 0);
|
|
1465 SPLIT_CHAR (op, reg[RRR], i, j);
|
|
1466 if (j != -1)
|
|
1467 i = (i << 7) | j;
|
442
|
1468
|
428
|
1469 reg[rrr] = i;
|
444
|
1470 #endif
|
428
|
1471 break;
|
|
1472
|
3439
|
1473 case CCL_MuleToUnicode:
|
|
1474 {
|
|
1475 Lisp_Object ucs;
|
|
1476
|
4072
|
1477 CCL_MAKE_CHAR (reg[rrr], reg[RRR], op);
|
|
1478
|
3439
|
1479 ucs = Fchar_to_unicode(make_char(op));
|
|
1480
|
|
1481 if (NILP(ucs))
|
|
1482 {
|
|
1483 /* Uhh, char-to-unicode doesn't return nil at the
|
|
1484 moment, only ever -1. */
|
|
1485 reg[rrr] = 0xFFFD; /* REPLACEMENT CHARACTER */
|
|
1486 }
|
|
1487 else
|
|
1488 {
|
4072
|
1489 reg[rrr] = XCHAR_OR_INT(ucs);
|
3439
|
1490 if (-1 == reg[rrr])
|
|
1491 {
|
|
1492 reg[rrr] = 0xFFFD; /* REPLACEMENT CHARACTER */
|
|
1493 }
|
|
1494 }
|
|
1495 break;
|
|
1496 }
|
|
1497
|
|
1498 case CCL_UnicodeToMule:
|
|
1499 {
|
|
1500 Lisp_Object scratch;
|
|
1501
|
|
1502 scratch = Funicode_to_char(make_int(reg[rrr]), Qnil);
|
|
1503
|
|
1504 if (!NILP(scratch))
|
|
1505 {
|
|
1506 op = XCHAR(scratch);
|
|
1507 BREAKUP_ICHAR (op, scratch, i, j);
|
|
1508 reg[RRR] = XCHARSET_ID(scratch);
|
|
1509
|
|
1510 if (j != 0)
|
|
1511 {
|
4072
|
1512 i = (i << 7) | j;
|
3439
|
1513 }
|
|
1514
|
|
1515 reg[rrr] = i;
|
|
1516 }
|
|
1517 else
|
|
1518 {
|
|
1519 reg[rrr] = reg[RRR] = 0;
|
|
1520 }
|
|
1521 break;
|
|
1522 }
|
|
1523
|
4072
|
1524 case CCL_LookupIntConstTbl:
|
|
1525 op = XCHAR_OR_INT (ccl_prog[ic]); /* table */
|
|
1526 ic++;
|
|
1527 {
|
|
1528 struct Lisp_Hash_Table *h = GET_HASH_TABLE (op);
|
|
1529 htentry *e = find_htentry(make_int (reg[RRR]), h);
|
|
1530 Lisp_Object scratch;
|
|
1531
|
|
1532 if (!HTENTRY_CLEAR_P(e))
|
|
1533 {
|
|
1534 op = XCHARVAL (e->value);
|
|
1535 if (!valid_ichar_p(op))
|
|
1536 {
|
|
1537 CCL_INVALID_CMD;
|
|
1538 }
|
|
1539
|
|
1540 BREAKUP_ICHAR (op, scratch, i, j);
|
|
1541 reg[RRR] = XCHARSET_ID(scratch);
|
|
1542
|
|
1543 if (j != 0)
|
|
1544 {
|
|
1545 i = (i << 7) | j;
|
|
1546 }
|
|
1547 reg[rrr] = i;
|
|
1548 reg[7] = 1; /* r7 true for success */
|
|
1549 }
|
|
1550 else
|
|
1551 reg[7] = 0;
|
|
1552 }
|
|
1553 break;
|
|
1554
|
|
1555 case CCL_LookupCharConstTbl:
|
|
1556 op = XCHAR_OR_INT (ccl_prog[ic]); /* table */
|
|
1557 ic++;
|
|
1558 CCL_MAKE_CHAR (reg[RRR], reg[rrr], i);
|
|
1559 {
|
|
1560 struct Lisp_Hash_Table *h = GET_HASH_TABLE (op);
|
|
1561 htentry *e = find_htentry(make_int(i), h);
|
|
1562
|
|
1563 if (!HTENTRY_CLEAR_P(e))
|
|
1564 {
|
4078
|
1565 if (!INTP (e->value))
|
4072
|
1566 CCL_INVALID_CMD;
|
4078
|
1567 reg[RRR] = XCHAR_OR_INT (e->value);
|
4072
|
1568 reg[7] = 1; /* r7 true for success */
|
|
1569 }
|
|
1570 else
|
|
1571 reg[7] = 0;
|
|
1572 }
|
|
1573 break;
|
|
1574
|
|
1575
|
428
|
1576 case CCL_IterateMultipleMap:
|
|
1577 {
|
|
1578 Lisp_Object map, content, attrib, value;
|
|
1579 int point, size, fin_ic;
|
|
1580
|
4134
|
1581 j = XCHAR_OR_INT (ccl_prog[ic]); ic++; /* number of maps. */
|
428
|
1582 fin_ic = ic + j;
|
|
1583 op = reg[rrr];
|
|
1584 if ((j > reg[RRR]) && (j >= 0))
|
|
1585 {
|
|
1586 ic += reg[RRR];
|
|
1587 i = reg[RRR];
|
|
1588 }
|
|
1589 else
|
|
1590 {
|
|
1591 reg[RRR] = -1;
|
|
1592 ic = fin_ic;
|
|
1593 break;
|
|
1594 }
|
|
1595
|
|
1596 for (;i < j;i++)
|
|
1597 {
|
|
1598 size = XVECTOR (Vcode_conversion_map_vector)->size;
|
4072
|
1599 point = XCHAR_OR_INT (ccl_prog[ic++]);
|
428
|
1600 if (point >= size) continue;
|
|
1601 map =
|
|
1602 XVECTOR (Vcode_conversion_map_vector)->contents[point];
|
|
1603
|
444
|
1604 /* Check map validity. */
|
428
|
1605 if (!CONSP (map)) continue;
|
444
|
1606 map = XCDR (map);
|
428
|
1607 if (!VECTORP (map)) continue;
|
|
1608 size = XVECTOR (map)->size;
|
|
1609 if (size <= 1) continue;
|
|
1610
|
|
1611 content = XVECTOR (map)->contents[0];
|
|
1612
|
|
1613 /* check map type,
|
|
1614 [STARTPOINT VAL1 VAL2 ...] or
|
444
|
1615 [t ELEMENT STARTPOINT ENDPOINT] */
|
|
1616 if (INTP (content))
|
428
|
1617 {
|
|
1618 point = XUINT (content);
|
|
1619 point = op - point + 1;
|
|
1620 if (!((point >= 1) && (point < size))) continue;
|
|
1621 content = XVECTOR (map)->contents[point];
|
|
1622 }
|
|
1623 else if (EQ (content, Qt))
|
|
1624 {
|
|
1625 if (size != 4) continue;
|
647
|
1626 /* #### see comment at CCL_SetArray; in this
|
|
1627 case the casts are added but the XUINT was
|
|
1628 already present */
|
|
1629 if (((unsigned int) op >=
|
|
1630 XUINT (XVECTOR (map)->contents[2]))
|
|
1631 && ((unsigned int) op <
|
|
1632 XUINT (XVECTOR (map)->contents[3])))
|
428
|
1633 content = XVECTOR (map)->contents[1];
|
|
1634 else
|
|
1635 continue;
|
|
1636 }
|
442
|
1637 else
|
428
|
1638 continue;
|
|
1639
|
|
1640 if (NILP (content))
|
|
1641 continue;
|
444
|
1642 else if (INTP (content))
|
428
|
1643 {
|
|
1644 reg[RRR] = i;
|
4072
|
1645 reg[rrr] = XCHAR_OR_INT(content);
|
428
|
1646 break;
|
|
1647 }
|
|
1648 else if (EQ (content, Qt) || EQ (content, Qlambda))
|
|
1649 {
|
|
1650 reg[RRR] = i;
|
|
1651 break;
|
|
1652 }
|
|
1653 else if (CONSP (content))
|
|
1654 {
|
444
|
1655 attrib = XCAR (content);
|
|
1656 value = XCDR (content);
|
|
1657 if (!INTP (attrib) || !INTP (value))
|
428
|
1658 continue;
|
|
1659 reg[RRR] = i;
|
|
1660 reg[rrr] = XUINT (value);
|
|
1661 break;
|
|
1662 }
|
444
|
1663 else if (SYMBOLP (content))
|
|
1664 CCL_CALL_FOR_MAP_INSTRUCTION (content, fin_ic);
|
|
1665 else
|
|
1666 CCL_INVALID_CMD;
|
428
|
1667 }
|
|
1668 if (i == j)
|
|
1669 reg[RRR] = -1;
|
|
1670 ic = fin_ic;
|
|
1671 }
|
|
1672 break;
|
442
|
1673
|
428
|
1674 case CCL_MapMultiple:
|
|
1675 {
|
|
1676 Lisp_Object map, content, attrib, value;
|
|
1677 int point, size, map_vector_size;
|
|
1678 int map_set_rest_length, fin_ic;
|
444
|
1679 int current_ic = this_ic;
|
|
1680
|
|
1681 /* inhibit recursive call on MapMultiple. */
|
|
1682 if (stack_idx_of_map_multiple > 0)
|
|
1683 {
|
|
1684 if (stack_idx_of_map_multiple <= stack_idx)
|
|
1685 {
|
|
1686 stack_idx_of_map_multiple = 0;
|
|
1687 mapping_stack_pointer = mapping_stack;
|
|
1688 CCL_INVALID_CMD;
|
|
1689 }
|
|
1690 }
|
|
1691 else
|
|
1692 mapping_stack_pointer = mapping_stack;
|
|
1693 stack_idx_of_map_multiple = 0;
|
428
|
1694
|
|
1695 map_set_rest_length =
|
4134
|
1696 XCHAR_OR_INT (ccl_prog[ic]); ic++; /* number of maps and separators. */
|
428
|
1697 fin_ic = ic + map_set_rest_length;
|
444
|
1698 op = reg[rrr];
|
|
1699
|
428
|
1700 if ((map_set_rest_length > reg[RRR]) && (reg[RRR] >= 0))
|
|
1701 {
|
|
1702 ic += reg[RRR];
|
|
1703 i = reg[RRR];
|
|
1704 map_set_rest_length -= i;
|
|
1705 }
|
|
1706 else
|
|
1707 {
|
|
1708 ic = fin_ic;
|
|
1709 reg[RRR] = -1;
|
444
|
1710 mapping_stack_pointer = mapping_stack;
|
428
|
1711 break;
|
|
1712 }
|
444
|
1713
|
|
1714 if (mapping_stack_pointer <= (mapping_stack + 1))
|
428
|
1715 {
|
444
|
1716 /* Set up initial state. */
|
|
1717 mapping_stack_pointer = mapping_stack;
|
|
1718 PUSH_MAPPING_STACK (0, op);
|
|
1719 reg[RRR] = -1;
|
|
1720 }
|
|
1721 else
|
|
1722 {
|
|
1723 /* Recover after calling other ccl program. */
|
|
1724 int orig_op;
|
428
|
1725
|
444
|
1726 POP_MAPPING_STACK (map_set_rest_length, orig_op);
|
|
1727 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1728 switch (op)
|
428
|
1729 {
|
444
|
1730 case -1:
|
|
1731 /* Regard it as Qnil. */
|
|
1732 op = orig_op;
|
|
1733 i++;
|
|
1734 ic++;
|
|
1735 map_set_rest_length--;
|
|
1736 break;
|
|
1737 case -2:
|
|
1738 /* Regard it as Qt. */
|
|
1739 op = reg[rrr];
|
|
1740 i++;
|
|
1741 ic++;
|
|
1742 map_set_rest_length--;
|
|
1743 break;
|
|
1744 case -3:
|
|
1745 /* Regard it as Qlambda. */
|
|
1746 op = orig_op;
|
428
|
1747 i += map_set_rest_length;
|
444
|
1748 ic += map_set_rest_length;
|
|
1749 map_set_rest_length = 0;
|
|
1750 break;
|
|
1751 default:
|
|
1752 /* Regard it as normal mapping. */
|
428
|
1753 i += map_set_rest_length;
|
444
|
1754 ic += map_set_rest_length;
|
428
|
1755 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1756 break;
|
|
1757 }
|
|
1758 }
|
444
|
1759 map_vector_size = XVECTOR (Vcode_conversion_map_vector)->size;
|
|
1760
|
|
1761 do {
|
|
1762 for (;map_set_rest_length > 0;i++, ic++, map_set_rest_length--)
|
|
1763 {
|
4072
|
1764 point = XCHAR_OR_INT(ccl_prog[ic]);
|
444
|
1765 if (point < 0)
|
|
1766 {
|
|
1767 /* +1 is for including separator. */
|
|
1768 point = -point + 1;
|
|
1769 if (mapping_stack_pointer
|
460
|
1770 >= mapping_stack + countof (mapping_stack))
|
444
|
1771 CCL_INVALID_CMD;
|
|
1772 PUSH_MAPPING_STACK (map_set_rest_length - point,
|
|
1773 reg[rrr]);
|
|
1774 map_set_rest_length = point;
|
|
1775 reg[rrr] = op;
|
|
1776 continue;
|
|
1777 }
|
|
1778
|
|
1779 if (point >= map_vector_size) continue;
|
|
1780 map = (XVECTOR (Vcode_conversion_map_vector)
|
|
1781 ->contents[point]);
|
|
1782
|
|
1783 /* Check map validity. */
|
|
1784 if (!CONSP (map)) continue;
|
|
1785 map = XCDR (map);
|
|
1786 if (!VECTORP (map)) continue;
|
|
1787 size = XVECTOR (map)->size;
|
|
1788 if (size <= 1) continue;
|
|
1789
|
|
1790 content = XVECTOR (map)->contents[0];
|
|
1791
|
|
1792 /* check map type,
|
|
1793 [STARTPOINT VAL1 VAL2 ...] or
|
|
1794 [t ELEMENT STARTPOINT ENDPOINT] */
|
|
1795 if (INTP (content))
|
|
1796 {
|
|
1797 point = XUINT (content);
|
|
1798 point = op - point + 1;
|
|
1799 if (!((point >= 1) && (point < size))) continue;
|
|
1800 content = XVECTOR (map)->contents[point];
|
|
1801 }
|
|
1802 else if (EQ (content, Qt))
|
|
1803 {
|
|
1804 if (size != 4) continue;
|
647
|
1805 /* #### see comment at CCL_SetArray; in this
|
|
1806 case the casts are added but the XUINT was
|
|
1807 already present */
|
|
1808 if (((unsigned int) op >=
|
|
1809 XUINT (XVECTOR (map)->contents[2])) &&
|
|
1810 ((unsigned int) op <
|
|
1811 XUINT (XVECTOR (map)->contents[3])))
|
444
|
1812 content = XVECTOR (map)->contents[1];
|
|
1813 else
|
|
1814 continue;
|
|
1815 }
|
|
1816 else
|
|
1817 continue;
|
|
1818
|
|
1819 if (NILP (content))
|
|
1820 continue;
|
|
1821
|
|
1822 reg[RRR] = i;
|
|
1823 if (INTP (content))
|
|
1824 {
|
4072
|
1825 op = XCHAR_OR_INT (content);
|
444
|
1826 i += map_set_rest_length - 1;
|
|
1827 ic += map_set_rest_length - 1;
|
|
1828 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1829 map_set_rest_length++;
|
|
1830 }
|
|
1831 else if (CONSP (content))
|
|
1832 {
|
|
1833 attrib = XCAR (content);
|
|
1834 value = XCDR (content);
|
|
1835 if (!INTP (attrib) || !INTP (value))
|
|
1836 continue;
|
|
1837 op = XUINT (value);
|
|
1838 i += map_set_rest_length - 1;
|
|
1839 ic += map_set_rest_length - 1;
|
|
1840 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1841 map_set_rest_length++;
|
|
1842 }
|
|
1843 else if (EQ (content, Qt))
|
|
1844 {
|
|
1845 op = reg[rrr];
|
|
1846 }
|
|
1847 else if (EQ (content, Qlambda))
|
|
1848 {
|
|
1849 i += map_set_rest_length;
|
|
1850 ic += map_set_rest_length;
|
|
1851 break;
|
|
1852 }
|
|
1853 else if (SYMBOLP (content))
|
|
1854 {
|
|
1855 if (mapping_stack_pointer
|
460
|
1856 >= mapping_stack + countof (mapping_stack))
|
444
|
1857 CCL_INVALID_CMD;
|
|
1858 PUSH_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1859 PUSH_MAPPING_STACK (map_set_rest_length, op);
|
|
1860 stack_idx_of_map_multiple = stack_idx + 1;
|
|
1861 CCL_CALL_FOR_MAP_INSTRUCTION (content, current_ic);
|
|
1862 }
|
|
1863 else
|
|
1864 CCL_INVALID_CMD;
|
|
1865 }
|
|
1866 if (mapping_stack_pointer <= (mapping_stack + 1))
|
|
1867 break;
|
|
1868 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1869 i += map_set_rest_length;
|
|
1870 ic += map_set_rest_length;
|
|
1871 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1872 } while (1);
|
|
1873
|
428
|
1874 ic = fin_ic;
|
|
1875 }
|
|
1876 reg[rrr] = op;
|
|
1877 break;
|
|
1878
|
|
1879 case CCL_MapSingle:
|
|
1880 {
|
|
1881 Lisp_Object map, attrib, value, content;
|
|
1882 int size, point;
|
4134
|
1883 j = XCHAR_OR_INT (ccl_prog[ic]); ic++;/* map_id */
|
428
|
1884 op = reg[rrr];
|
|
1885 if (j >= XVECTOR (Vcode_conversion_map_vector)->size)
|
|
1886 {
|
|
1887 reg[RRR] = -1;
|
|
1888 break;
|
|
1889 }
|
|
1890 map = XVECTOR (Vcode_conversion_map_vector)->contents[j];
|
|
1891 if (!CONSP (map))
|
|
1892 {
|
|
1893 reg[RRR] = -1;
|
|
1894 break;
|
|
1895 }
|
444
|
1896 map = XCDR (map);
|
428
|
1897 if (!VECTORP (map))
|
|
1898 {
|
|
1899 reg[RRR] = -1;
|
|
1900 break;
|
|
1901 }
|
|
1902 size = XVECTOR (map)->size;
|
|
1903 point = XUINT (XVECTOR (map)->contents[0]);
|
|
1904 point = op - point + 1;
|
|
1905 reg[RRR] = 0;
|
|
1906 if ((size <= 1) ||
|
|
1907 (!((point >= 1) && (point < size))))
|
|
1908 reg[RRR] = -1;
|
|
1909 else
|
|
1910 {
|
444
|
1911 reg[RRR] = 0;
|
428
|
1912 content = XVECTOR (map)->contents[point];
|
|
1913 if (NILP (content))
|
|
1914 reg[RRR] = -1;
|
444
|
1915 else if (INTP (content))
|
4072
|
1916 reg[rrr] = XCHAR_OR_INT (content);
|
444
|
1917 else if (EQ (content, Qt));
|
428
|
1918 else if (CONSP (content))
|
|
1919 {
|
444
|
1920 attrib = XCAR (content);
|
|
1921 value = XCDR (content);
|
|
1922 if (!INTP (attrib) || !INTP (value))
|
428
|
1923 continue;
|
|
1924 reg[rrr] = XUINT(value);
|
|
1925 break;
|
|
1926 }
|
444
|
1927 else if (SYMBOLP (content))
|
|
1928 CCL_CALL_FOR_MAP_INSTRUCTION (content, ic);
|
428
|
1929 else
|
|
1930 reg[RRR] = -1;
|
|
1931 }
|
|
1932 }
|
|
1933 break;
|
442
|
1934
|
428
|
1935 default:
|
|
1936 CCL_INVALID_CMD;
|
|
1937 }
|
|
1938 break;
|
|
1939
|
|
1940 default:
|
444
|
1941 CCL_INVALID_CMD;
|
428
|
1942 }
|
|
1943 }
|
|
1944
|
|
1945 ccl_error_handler:
|
|
1946 if (destination)
|
|
1947 {
|
|
1948 /* We can insert an error message only if DESTINATION is
|
|
1949 specified and we still have a room to store the message
|
|
1950 there. */
|
|
1951 char msg[256];
|
|
1952
|
|
1953 switch (ccl->status)
|
|
1954 {
|
|
1955 case CCL_STAT_INVALID_CMD:
|
|
1956 sprintf(msg, "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
|
|
1957 code & 0x1F, code, this_ic);
|
|
1958 #ifdef CCL_DEBUG
|
|
1959 {
|
|
1960 int i = ccl_backtrace_idx - 1;
|
|
1961 int j;
|
|
1962
|
|
1963 Dynarr_add_many (destination, (unsigned char *) msg, strlen (msg));
|
|
1964
|
|
1965 for (j = 0; j < CCL_DEBUG_BACKTRACE_LEN; j++, i--)
|
|
1966 {
|
|
1967 if (i < 0) i = CCL_DEBUG_BACKTRACE_LEN - 1;
|
|
1968 if (ccl_backtrace_table[i] == 0)
|
|
1969 break;
|
|
1970 sprintf(msg, " %d", ccl_backtrace_table[i]);
|
|
1971 Dynarr_add_many (destination, (unsigned char *) msg, strlen (msg));
|
|
1972 }
|
|
1973 goto ccl_finish;
|
|
1974 }
|
|
1975 #endif
|
|
1976 break;
|
|
1977
|
|
1978 case CCL_STAT_QUIT:
|
444
|
1979 sprintf(msg, "\nCCL: Exited.");
|
428
|
1980 break;
|
|
1981
|
|
1982 default:
|
|
1983 sprintf(msg, "\nCCL: Unknown error type (%d).", ccl->status);
|
|
1984 }
|
|
1985
|
|
1986 Dynarr_add_many (destination, (unsigned char *) msg, strlen (msg));
|
|
1987 }
|
|
1988
|
|
1989 ccl_finish:
|
|
1990 ccl->ic = ic;
|
|
1991 ccl->stack_idx = stack_idx;
|
|
1992 ccl->prog = ccl_prog;
|
|
1993 if (consumed) *consumed = src - source;
|
444
|
1994 if (!destination)
|
428
|
1995 return 0;
|
444
|
1996 return Dynarr_length (destination);
|
|
1997 }
|
|
1998
|
|
1999 /* Resolve symbols in the specified CCL code (Lisp vector). This
|
|
2000 function converts symbols of code conversion maps and character
|
|
2001 translation tables embedded in the CCL code into their ID numbers.
|
|
2002
|
|
2003 The return value is a vector (CCL itself or a new vector in which
|
|
2004 all symbols are resolved), Qt if resolving of some symbol failed,
|
|
2005 or nil if CCL contains invalid data. */
|
|
2006
|
|
2007 static Lisp_Object
|
|
2008 resolve_symbol_ccl_program (Lisp_Object ccl)
|
|
2009 {
|
|
2010 int i, veclen, unresolved = 0;
|
|
2011 Lisp_Object result, contents, val;
|
|
2012
|
|
2013 result = ccl;
|
|
2014 veclen = XVECTOR (result)->size;
|
|
2015
|
|
2016 for (i = 0; i < veclen; i++)
|
|
2017 {
|
|
2018 contents = XVECTOR (result)->contents[i];
|
4072
|
2019 /* XEmacs change; accept characters as well as integers, on the basis
|
|
2020 that most CCL code written doesn't make a distinction. */
|
|
2021 if (INTP (contents) || CHARP(contents))
|
444
|
2022 continue;
|
|
2023 else if (CONSP (contents)
|
|
2024 && SYMBOLP (XCAR (contents))
|
|
2025 && SYMBOLP (XCDR (contents)))
|
|
2026 {
|
|
2027 /* This is the new style for embedding symbols. The form is
|
|
2028 (SYMBOL . PROPERTY). (get SYMBOL PROPERTY) should give
|
|
2029 an index number. */
|
|
2030
|
|
2031 if (EQ (result, ccl))
|
|
2032 result = Fcopy_sequence (ccl);
|
|
2033
|
|
2034 val = Fget (XCAR (contents), XCDR (contents), Qnil);
|
|
2035 if (NATNUMP (val))
|
|
2036 XVECTOR (result)->contents[i] = val;
|
|
2037 else
|
|
2038 unresolved = 1;
|
|
2039 continue;
|
|
2040 }
|
|
2041 else if (SYMBOLP (contents))
|
|
2042 {
|
|
2043 /* This is the old style for embedding symbols. This style
|
|
2044 may lead to a bug if, for instance, a translation table
|
|
2045 and a code conversion map have the same name. */
|
|
2046 if (EQ (result, ccl))
|
|
2047 result = Fcopy_sequence (ccl);
|
|
2048
|
|
2049 val = Fget (contents, Qcode_conversion_map_id, Qnil);
|
|
2050 if (NATNUMP (val))
|
|
2051 XVECTOR (result)->contents[i] = val;
|
|
2052 else
|
|
2053 {
|
|
2054 val = Fget (contents, Qccl_program_idx, Qnil);
|
|
2055 if (NATNUMP (val))
|
|
2056 XVECTOR (result)->contents[i] = val;
|
|
2057 else
|
|
2058 unresolved = 1;
|
|
2059 }
|
|
2060 continue;
|
|
2061 }
|
|
2062 return Qnil;
|
|
2063 }
|
|
2064
|
|
2065 return (unresolved ? Qt : result);
|
|
2066 }
|
|
2067
|
|
2068 /* Return the compiled code (vector) of CCL program CCL_PROG.
|
|
2069 CCL_PROG is a name (symbol) of the program or already compiled
|
|
2070 code. If necessary, resolve symbols in the compiled code to index
|
|
2071 numbers. If we failed to get the compiled code or to resolve
|
|
2072 symbols, return Qnil. */
|
|
2073
|
|
2074 static Lisp_Object
|
|
2075 ccl_get_compiled_code (Lisp_Object ccl_prog)
|
|
2076 {
|
|
2077 Lisp_Object val, slot;
|
|
2078
|
|
2079 if (VECTORP (ccl_prog))
|
|
2080 {
|
|
2081 val = resolve_symbol_ccl_program (ccl_prog);
|
|
2082 return (VECTORP (val) ? val : Qnil);
|
|
2083 }
|
|
2084 if (!SYMBOLP (ccl_prog))
|
|
2085 return Qnil;
|
|
2086
|
|
2087 val = Fget (ccl_prog, Qccl_program_idx, Qnil);
|
|
2088 if (! NATNUMP (val)
|
|
2089 || XINT (val) >= XVECTOR_LENGTH (Vccl_program_table))
|
|
2090 return Qnil;
|
|
2091 slot = XVECTOR_DATA (Vccl_program_table)[XINT (val)];
|
|
2092 if (! VECTORP (slot)
|
|
2093 || XVECTOR (slot)->size != 3
|
|
2094 || ! VECTORP (XVECTOR_DATA (slot)[1]))
|
|
2095 return Qnil;
|
|
2096 if (NILP (XVECTOR_DATA (slot)[2]))
|
|
2097 {
|
|
2098 val = resolve_symbol_ccl_program (XVECTOR_DATA (slot)[1]);
|
|
2099 if (! VECTORP (val))
|
|
2100 return Qnil;
|
|
2101 XVECTOR_DATA (slot)[1] = val;
|
|
2102 XVECTOR_DATA (slot)[2] = Qt;
|
|
2103 }
|
|
2104 return XVECTOR_DATA (slot)[1];
|
428
|
2105 }
|
|
2106
|
|
2107 /* Setup fields of the structure pointed by CCL appropriately for the
|
444
|
2108 execution of CCL program CCL_PROG. CCL_PROG is the name (symbol)
|
|
2109 of the CCL program or the already compiled code (vector).
|
|
2110 Return 0 if we succeed this setup, else return -1.
|
|
2111
|
|
2112 If CCL_PROG is nil, we just reset the structure pointed by CCL. */
|
|
2113 int
|
|
2114 setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog)
|
428
|
2115 {
|
771
|
2116 xzero (*ccl); /* XEmacs change */
|
444
|
2117 if (! NILP (ccl_prog))
|
428
|
2118 {
|
444
|
2119 ccl_prog = ccl_get_compiled_code (ccl_prog);
|
|
2120 if (! VECTORP (ccl_prog))
|
|
2121 return -1;
|
|
2122 ccl->size = XVECTOR_LENGTH (ccl_prog);
|
|
2123 ccl->prog = XVECTOR_DATA (ccl_prog);
|
|
2124 ccl->eof_ic = XINT (XVECTOR_DATA (ccl_prog)[CCL_HEADER_EOF]);
|
|
2125 ccl->buf_magnification = XINT (XVECTOR_DATA (ccl_prog)[CCL_HEADER_BUF_MAG]);
|
428
|
2126 }
|
|
2127 ccl->ic = CCL_HEADER_MAIN;
|
444
|
2128 ccl->eol_type = CCL_CODING_EOL_LF;
|
|
2129 return 0;
|
428
|
2130 }
|
|
2131
|
444
|
2132 #ifdef emacs
|
428
|
2133
|
444
|
2134 DEFUN ("ccl-program-p", Fccl_program_p, 1, 1, 0, /*
|
|
2135 Return t if OBJECT is a CCL program name or a compiled CCL program code.
|
|
2136 See the documentation of `define-ccl-program' for the detail of CCL program.
|
|
2137 */
|
|
2138 (object))
|
|
2139 {
|
|
2140 Lisp_Object val;
|
428
|
2141
|
444
|
2142 if (VECTORP (object))
|
|
2143 {
|
|
2144 val = resolve_symbol_ccl_program (object);
|
|
2145 return (VECTORP (val) ? Qt : Qnil);
|
428
|
2146 }
|
444
|
2147 if (!SYMBOLP (object))
|
|
2148 return Qnil;
|
428
|
2149
|
444
|
2150 val = Fget (object, Qccl_program_idx, Qnil);
|
|
2151 return ((! NATNUMP (val)
|
|
2152 || XINT (val) >= XVECTOR_LENGTH (Vccl_program_table))
|
|
2153 ? Qnil : Qt);
|
428
|
2154 }
|
|
2155
|
|
2156 DEFUN ("ccl-execute", Fccl_execute, 2, 2, 0, /*
|
|
2157 Execute CCL-PROGRAM with registers initialized by REGISTERS.
|
|
2158
|
444
|
2159 CCL-PROGRAM is a CCL program name (symbol)
|
428
|
2160 or a compiled code generated by `ccl-compile' (for backward compatibility,
|
444
|
2161 in this case, the overhead of the execution is bigger than the former case).
|
428
|
2162 No I/O commands should appear in CCL-PROGRAM.
|
|
2163
|
|
2164 REGISTERS is a vector of [R0 R1 ... R7] where RN is an initial value
|
|
2165 of Nth register.
|
|
2166
|
444
|
2167 As side effect, each element of REGISTERS holds the value of
|
428
|
2168 corresponding register after the execution.
|
444
|
2169
|
|
2170 See the documentation of `define-ccl-program' for the detail of CCL program.
|
428
|
2171 */
|
444
|
2172 (ccl_prog, reg))
|
428
|
2173 {
|
|
2174 struct ccl_program ccl;
|
|
2175 int i;
|
|
2176
|
444
|
2177 if (setup_ccl_program (&ccl, ccl_prog) < 0)
|
563
|
2178 syntax_error ("Invalid CCL program", Qunbound);
|
428
|
2179
|
|
2180 CHECK_VECTOR (reg);
|
|
2181 if (XVECTOR_LENGTH (reg) != 8)
|
563
|
2182 syntax_error ("Length of vector REGISTERS is not 8", Qunbound);
|
428
|
2183
|
|
2184 for (i = 0; i < 8; i++)
|
4072
|
2185 ccl.reg[i] = (INTP (XVECTOR_DATA (reg)[i]) || CHARP (XVECTOR_DATA (reg)[i])
|
|
2186 ? XCHAR_OR_INT (XVECTOR_DATA (reg)[i])
|
428
|
2187 : 0);
|
|
2188
|
444
|
2189 ccl_driver (&ccl, (const unsigned char *)0,
|
|
2190 (unsigned_char_dynarr *)0, 0, (int *)0,
|
|
2191 CCL_MODE_ENCODING);
|
428
|
2192 QUIT;
|
|
2193 if (ccl.status != CCL_STAT_SUCCESS)
|
563
|
2194 signal_error (Qccl_error, "Error in CCL program at code numbered ...", make_int (ccl.ic));
|
428
|
2195
|
|
2196 for (i = 0; i < 8; i++)
|
793
|
2197 XVECTOR (reg)->contents[i] = make_int (ccl.reg[i]);
|
428
|
2198 return Qnil;
|
|
2199 }
|
|
2200
|
444
|
2201 DEFUN ("ccl-execute-on-string", Fccl_execute_on_string,
|
|
2202 3, 4, 0, /*
|
428
|
2203 Execute CCL-PROGRAM with initial STATUS on STRING.
|
|
2204
|
|
2205 CCL-PROGRAM is a symbol registered by register-ccl-program,
|
|
2206 or a compiled code generated by `ccl-compile' (for backward compatibility,
|
|
2207 in this case, the execution is slower).
|
|
2208
|
|
2209 Read buffer is set to STRING, and write buffer is allocated automatically.
|
|
2210
|
|
2211 STATUS is a vector of [R0 R1 ... R7 IC], where
|
|
2212 R0..R7 are initial values of corresponding registers,
|
|
2213 IC is the instruction counter specifying from where to start the program.
|
|
2214 If R0..R7 are nil, they are initialized to 0.
|
|
2215 If IC is nil, it is initialized to head of the CCL program.
|
|
2216
|
|
2217 If optional 4th arg CONTINUE is non-nil, keep IC on read operation
|
444
|
2218 when read buffer is exhausted, else, IC is always set to the end of
|
428
|
2219 CCL-PROGRAM on exit.
|
|
2220
|
|
2221 It returns the contents of write buffer as a string,
|
|
2222 and as side effect, STATUS is updated.
|
444
|
2223
|
|
2224 See the documentation of `define-ccl-program' for the detail of CCL program.
|
428
|
2225 */
|
444
|
2226 (ccl_prog, status, string, continue_))
|
428
|
2227 {
|
|
2228 Lisp_Object val;
|
|
2229 struct ccl_program ccl;
|
|
2230 int i, produced;
|
|
2231 unsigned_char_dynarr *outbuf;
|
444
|
2232 struct gcpro gcpro1, gcpro2;
|
428
|
2233
|
444
|
2234 if (setup_ccl_program (&ccl, ccl_prog) < 0)
|
563
|
2235 syntax_error ("Invalid CCL program", Qunbound);
|
428
|
2236
|
|
2237 CHECK_VECTOR (status);
|
444
|
2238 if (XVECTOR (status)->size != 9)
|
563
|
2239 syntax_error ("Length of vector STATUS is not 9", Qunbound);
|
444
|
2240 CHECK_STRING (string);
|
428
|
2241
|
444
|
2242 GCPRO2 (status, string);
|
|
2243
|
428
|
2244 for (i = 0; i < 8; i++)
|
|
2245 {
|
|
2246 if (NILP (XVECTOR_DATA (status)[i]))
|
793
|
2247 XVECTOR_DATA (status)[i] = make_int (0);
|
428
|
2248 if (INTP (XVECTOR_DATA (status)[i]))
|
|
2249 ccl.reg[i] = XINT (XVECTOR_DATA (status)[i]);
|
4072
|
2250 if (CHARP (XVECTOR_DATA (status)[i]))
|
|
2251 ccl.reg[i] = XCHAR (XVECTOR_DATA (status)[i]);
|
428
|
2252 }
|
4072
|
2253 if (INTP (XVECTOR (status)->contents[i]) ||
|
|
2254 CHARP (XVECTOR (status)->contents[i]))
|
428
|
2255 {
|
4072
|
2256 i = XCHAR_OR_INT (XVECTOR_DATA (status)[8]);
|
428
|
2257 if (ccl.ic < i && i < ccl.size)
|
|
2258 ccl.ic = i;
|
|
2259 }
|
|
2260 outbuf = Dynarr_new (unsigned_char);
|
444
|
2261 ccl.last_block = NILP (continue_);
|
|
2262 produced = ccl_driver (&ccl, XSTRING_DATA (string), outbuf,
|
|
2263 XSTRING_LENGTH (string),
|
|
2264 (int *) 0,
|
|
2265 CCL_MODE_DECODING);
|
428
|
2266 for (i = 0; i < 8; i++)
|
793
|
2267 XVECTOR_DATA (status)[i] = make_int (ccl.reg[i]);
|
|
2268 XVECTOR_DATA (status)[8] = make_int (ccl.ic);
|
428
|
2269 UNGCPRO;
|
|
2270
|
|
2271 val = make_string (Dynarr_atp (outbuf, 0), produced);
|
|
2272 Dynarr_free (outbuf);
|
|
2273 QUIT;
|
444
|
2274 if (ccl.status == CCL_STAT_SUSPEND_BY_DST)
|
563
|
2275 signal_error (Qccl_error, "Output buffer for the CCL programs overflow", Qunbound);
|
428
|
2276 if (ccl.status != CCL_STAT_SUCCESS
|
444
|
2277 && ccl.status != CCL_STAT_SUSPEND_BY_SRC)
|
563
|
2278 signal_error (Qccl_error, "Error in CCL program at code numbered...", make_int (ccl.ic));
|
428
|
2279
|
|
2280 return val;
|
|
2281 }
|
|
2282
|
444
|
2283 DEFUN ("register-ccl-program", Fregister_ccl_program,
|
|
2284 2, 2, 0, /*
|
|
2285 Register CCL program CCL-PROG as NAME in `ccl-program-table'.
|
|
2286 CCL-PROG should be a compiled CCL program (vector), or nil.
|
|
2287 If it is nil, just reserve NAME as a CCL program name.
|
428
|
2288 Return index number of the registered CCL program.
|
|
2289 */
|
444
|
2290 (name, ccl_prog))
|
428
|
2291 {
|
|
2292 int len = XVECTOR_LENGTH (Vccl_program_table);
|
444
|
2293 int idx;
|
|
2294 Lisp_Object resolved;
|
428
|
2295
|
|
2296 CHECK_SYMBOL (name);
|
444
|
2297 resolved = Qnil;
|
428
|
2298 if (!NILP (ccl_prog))
|
|
2299 {
|
|
2300 CHECK_VECTOR (ccl_prog);
|
444
|
2301 resolved = resolve_symbol_ccl_program (ccl_prog);
|
|
2302 if (! NILP (resolved))
|
428
|
2303 {
|
444
|
2304 ccl_prog = resolved;
|
|
2305 resolved = Qt;
|
428
|
2306 }
|
|
2307 }
|
|
2308
|
444
|
2309 for (idx = 0; idx < len; idx++)
|
428
|
2310 {
|
444
|
2311 Lisp_Object slot;
|
|
2312
|
|
2313 slot = XVECTOR_DATA (Vccl_program_table)[idx];
|
|
2314 if (!VECTORP (slot))
|
|
2315 /* This is the first unused slot. Register NAME here. */
|
|
2316 break;
|
|
2317
|
|
2318 if (EQ (name, XVECTOR_DATA (slot)[0]))
|
|
2319 {
|
|
2320 /* Update this slot. */
|
|
2321 XVECTOR_DATA (slot)[1] = ccl_prog;
|
|
2322 XVECTOR_DATA (slot)[2] = resolved;
|
|
2323 return make_int (idx);
|
|
2324 }
|
|
2325 }
|
|
2326
|
|
2327 if (idx == len)
|
|
2328 {
|
|
2329 /* Extend the table. */
|
|
2330 Lisp_Object new_table;
|
428
|
2331 int j;
|
|
2332
|
444
|
2333 new_table = Fmake_vector (make_int (len * 2), Qnil);
|
428
|
2334 for (j = 0; j < len; j++)
|
|
2335 XVECTOR_DATA (new_table)[j]
|
|
2336 = XVECTOR_DATA (Vccl_program_table)[j];
|
|
2337 Vccl_program_table = new_table;
|
|
2338 }
|
|
2339
|
444
|
2340 {
|
|
2341 Lisp_Object elt;
|
|
2342
|
|
2343 elt = Fmake_vector (make_int (3), Qnil);
|
|
2344 XVECTOR_DATA (elt)[0] = name;
|
|
2345 XVECTOR_DATA (elt)[1] = ccl_prog;
|
|
2346 XVECTOR_DATA (elt)[2] = resolved;
|
|
2347 XVECTOR_DATA (Vccl_program_table)[idx] = elt;
|
|
2348 }
|
|
2349
|
|
2350 Fput (name, Qccl_program_idx, make_int (idx));
|
|
2351 return make_int (idx);
|
428
|
2352 }
|
|
2353
|
|
2354 /* Register code conversion map.
|
|
2355 A code conversion map consists of numbers, Qt, Qnil, and Qlambda.
|
|
2356 The first element is start code point.
|
|
2357 The rest elements are mapped numbers.
|
|
2358 Symbol t means to map to an original number before mapping.
|
|
2359 Symbol nil means that the corresponding element is empty.
|
442
|
2360 Symbol lambda means to terminate mapping here.
|
428
|
2361 */
|
|
2362
|
|
2363 DEFUN ("register-code-conversion-map", Fregister_code_conversion_map,
|
444
|
2364 2, 2, 0, /*
|
|
2365 Register SYMBOL as code conversion map MAP.
|
|
2366 Return index number of the registered map.
|
|
2367 */
|
|
2368 (symbol, map))
|
428
|
2369 {
|
444
|
2370 int len = XVECTOR_LENGTH (Vcode_conversion_map_vector);
|
428
|
2371 int i;
|
444
|
2372 Lisp_Object idx;
|
428
|
2373
|
444
|
2374 CHECK_SYMBOL (symbol);
|
|
2375 CHECK_VECTOR (map);
|
442
|
2376
|
428
|
2377 for (i = 0; i < len; i++)
|
|
2378 {
|
444
|
2379 Lisp_Object slot = XVECTOR_DATA (Vcode_conversion_map_vector)[i];
|
428
|
2380
|
|
2381 if (!CONSP (slot))
|
|
2382 break;
|
|
2383
|
444
|
2384 if (EQ (symbol, XCAR (slot)))
|
428
|
2385 {
|
444
|
2386 idx = make_int (i);
|
|
2387 XCDR (slot) = map;
|
428
|
2388 Fput (symbol, Qcode_conversion_map, map);
|
444
|
2389 Fput (symbol, Qcode_conversion_map_id, idx);
|
|
2390 return idx;
|
428
|
2391 }
|
|
2392 }
|
|
2393
|
|
2394 if (i == len)
|
|
2395 {
|
|
2396 Lisp_Object new_vector = Fmake_vector (make_int (len * 2), Qnil);
|
|
2397 int j;
|
|
2398
|
|
2399 for (j = 0; j < len; j++)
|
444
|
2400 XVECTOR_DATA (new_vector)[j]
|
|
2401 = XVECTOR_DATA (Vcode_conversion_map_vector)[j];
|
428
|
2402 Vcode_conversion_map_vector = new_vector;
|
|
2403 }
|
|
2404
|
444
|
2405 idx = make_int (i);
|
428
|
2406 Fput (symbol, Qcode_conversion_map, map);
|
444
|
2407 Fput (symbol, Qcode_conversion_map_id, idx);
|
|
2408 XVECTOR_DATA (Vcode_conversion_map_vector)[i] = Fcons (symbol, map);
|
|
2409 return idx;
|
428
|
2410 }
|
|
2411
|
|
2412
|
|
2413 void
|
|
2414 syms_of_mule_ccl (void)
|
|
2415 {
|
565
|
2416 DEFERROR_STANDARD (Qccl_error, Qconversion_error);
|
|
2417
|
444
|
2418 DEFSUBR (Fccl_program_p);
|
428
|
2419 DEFSUBR (Fccl_execute);
|
|
2420 DEFSUBR (Fccl_execute_on_string);
|
|
2421 DEFSUBR (Fregister_ccl_program);
|
444
|
2422 DEFSUBR (Fregister_code_conversion_map);
|
428
|
2423 }
|
|
2424
|
|
2425 void
|
|
2426 vars_of_mule_ccl (void)
|
|
2427 {
|
4072
|
2428
|
428
|
2429 staticpro (&Vccl_program_table);
|
|
2430 Vccl_program_table = Fmake_vector (make_int (32), Qnil);
|
|
2431
|
4072
|
2432 #ifdef DEBUG_XEMACS
|
|
2433 DEFVAR_LISP ("ccl-program-table",
|
|
2434 &Vccl_program_table /*
|
|
2435 Vector containing all registered CCL programs.
|
|
2436 */ );
|
|
2437 #endif
|
563
|
2438 DEFSYMBOL (Qccl_program);
|
|
2439 DEFSYMBOL (Qccl_program_idx);
|
|
2440 DEFSYMBOL (Qcode_conversion_map);
|
|
2441 DEFSYMBOL (Qcode_conversion_map_id);
|
428
|
2442
|
|
2443 DEFVAR_LISP ("code-conversion-map-vector", &Vcode_conversion_map_vector /*
|
444
|
2444 Vector of code conversion maps.
|
|
2445 */ );
|
428
|
2446 Vcode_conversion_map_vector = Fmake_vector (make_int (16), Qnil);
|
|
2447
|
4072
|
2448 DEFVAR_LISP ("translation-hash-table-vector",
|
|
2449 &Vtranslation_hash_table_vector /*
|
|
2450 Vector containing all translation hash tables ever defined.
|
|
2451 Comprises pairs (SYMBOL . TABLE) where SYMBOL and TABLE were set up by calls
|
|
2452 to `define-translation-hash-table'. The vector is indexed by the table id
|
|
2453 used by CCL.
|
428
|
2454 */ );
|
4072
|
2455 Vtranslation_hash_table_vector = Qnil;
|
|
2456
|
428
|
2457 }
|
|
2458
|
|
2459 #endif /* emacs */
|