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