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