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