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