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