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
|
444
|
5 This file is part of GNU Emacs.
|
428
|
6
|
|
7 GNU Emacs is free software; you can redistribute it and/or modify
|
|
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
|
|
12 GNU Emacs is distributed in the hope that it will be useful,
|
|
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
|
|
18 along with GNU Emacs; see the file COPYING. If not, write to
|
|
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 { \
|
|
740 Bufbyte work[MAX_EMCHAR_LEN]; \
|
|
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 { \
|
|
754 Bufbyte work[MAX_EMCHAR_LEN]; \
|
|
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 { \
|
|
767 Bufbyte work[MAX_EMCHAR_LEN]; \
|
|
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;
|
|
974 if ((unsigned int) i < j)
|
|
975 reg[rrr] = XINT (ccl_prog[ic + i]);
|
|
976 ic += j;
|
|
977 break;
|
|
978
|
|
979 case CCL_Jump: /* A--D--D--R--E--S--S-000XXXXX */
|
|
980 ic += ADDR;
|
|
981 break;
|
|
982
|
|
983 case CCL_JumpCond: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
984 if (!reg[rrr])
|
|
985 ic += ADDR;
|
|
986 break;
|
|
987
|
|
988 case CCL_WriteRegisterJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
989 i = reg[rrr];
|
|
990 CCL_WRITE_CHAR (i);
|
|
991 ic += ADDR;
|
|
992 break;
|
|
993
|
|
994 case CCL_WriteRegisterReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
995 i = reg[rrr];
|
|
996 CCL_WRITE_CHAR (i);
|
|
997 ic++;
|
|
998 CCL_READ_CHAR (reg[rrr]);
|
|
999 ic += ADDR - 1;
|
|
1000 break;
|
|
1001
|
|
1002 case CCL_WriteConstJump: /* A--D--D--R--E--S--S-000XXXXX */
|
|
1003 i = XINT (ccl_prog[ic]);
|
|
1004 CCL_WRITE_CHAR (i);
|
|
1005 ic += ADDR;
|
|
1006 break;
|
|
1007
|
|
1008 case CCL_WriteConstReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1009 i = XINT (ccl_prog[ic]);
|
|
1010 CCL_WRITE_CHAR (i);
|
|
1011 ic++;
|
|
1012 CCL_READ_CHAR (reg[rrr]);
|
|
1013 ic += ADDR - 1;
|
|
1014 break;
|
|
1015
|
|
1016 case CCL_WriteStringJump: /* A--D--D--R--E--S--S-000XXXXX */
|
|
1017 j = XINT (ccl_prog[ic]);
|
|
1018 ic++;
|
|
1019 CCL_WRITE_STRING (j);
|
|
1020 ic += ADDR - 1;
|
|
1021 break;
|
|
1022
|
|
1023 case CCL_WriteArrayReadJump: /* A--D--D--R--E--S--S-rrrXXXXX */
|
|
1024 i = reg[rrr];
|
|
1025 j = XINT (ccl_prog[ic]);
|
|
1026 if ((unsigned int) i < j)
|
|
1027 {
|
|
1028 i = XINT (ccl_prog[ic + 1 + i]);
|
|
1029 CCL_WRITE_CHAR (i);
|
|
1030 }
|
|
1031 ic += j + 2;
|
|
1032 CCL_READ_CHAR (reg[rrr]);
|
|
1033 ic += ADDR - (j + 2);
|
|
1034 break;
|
|
1035
|
|
1036 case CCL_ReadJump: /* A--D--D--R--E--S--S-rrrYYYYY */
|
|
1037 CCL_READ_CHAR (reg[rrr]);
|
|
1038 ic += ADDR;
|
|
1039 break;
|
|
1040
|
|
1041 case CCL_ReadBranch: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1042 CCL_READ_CHAR (reg[rrr]);
|
|
1043 /* fall through ... */
|
|
1044 case CCL_Branch: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1045 if ((unsigned int) reg[rrr] < field1)
|
|
1046 ic += XINT (ccl_prog[ic + reg[rrr]]);
|
|
1047 else
|
|
1048 ic += XINT (ccl_prog[ic + field1]);
|
|
1049 break;
|
|
1050
|
|
1051 case CCL_ReadRegister: /* CCCCCCCCCCCCCCCCCCCCrrXXXXX */
|
|
1052 while (1)
|
|
1053 {
|
|
1054 CCL_READ_CHAR (reg[rrr]);
|
|
1055 if (!field1) break;
|
|
1056 code = XINT (ccl_prog[ic]); ic++;
|
|
1057 field1 = code >> 8;
|
|
1058 field2 = (code & 0xFF) >> 5;
|
|
1059 }
|
|
1060 break;
|
|
1061
|
|
1062 case CCL_WriteExprConst: /* 1:00000OPERATION000RRR000XXXXX */
|
|
1063 rrr = 7;
|
|
1064 i = reg[RRR];
|
|
1065 j = XINT (ccl_prog[ic]);
|
|
1066 op = field1 >> 6;
|
444
|
1067 jump_address = ic + 1;
|
428
|
1068 goto ccl_set_expr;
|
|
1069
|
|
1070 case CCL_WriteRegister: /* CCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1071 while (1)
|
|
1072 {
|
|
1073 i = reg[rrr];
|
|
1074 CCL_WRITE_CHAR (i);
|
|
1075 if (!field1) break;
|
|
1076 code = XINT (ccl_prog[ic]); ic++;
|
|
1077 field1 = code >> 8;
|
|
1078 field2 = (code & 0xFF) >> 5;
|
|
1079 }
|
|
1080 break;
|
|
1081
|
|
1082 case CCL_WriteExprRegister: /* 1:00000OPERATIONRrrRRR000XXXXX */
|
|
1083 rrr = 7;
|
|
1084 i = reg[RRR];
|
|
1085 j = reg[Rrr];
|
|
1086 op = field1 >> 6;
|
444
|
1087 jump_address = ic;
|
428
|
1088 goto ccl_set_expr;
|
|
1089
|
444
|
1090 case CCL_Call: /* 1:CCCCCCCCCCCCCCCCCCCCFFFXXXXX */
|
428
|
1091 {
|
|
1092 Lisp_Object slot;
|
444
|
1093 int prog_id;
|
|
1094
|
|
1095 /* If FFF is nonzero, the CCL program ID is in the
|
|
1096 following code. */
|
|
1097 if (rrr)
|
|
1098 {
|
|
1099 prog_id = XINT (ccl_prog[ic]);
|
|
1100 ic++;
|
|
1101 }
|
|
1102 else
|
|
1103 prog_id = field1;
|
428
|
1104
|
|
1105 if (stack_idx >= 256
|
444
|
1106 || prog_id < 0
|
|
1107 || prog_id >= XVECTOR (Vccl_program_table)->size
|
|
1108 || (slot = XVECTOR (Vccl_program_table)->contents[prog_id],
|
|
1109 !VECTORP (slot))
|
|
1110 || !VECTORP (XVECTOR (slot)->contents[1]))
|
428
|
1111 {
|
|
1112 if (stack_idx > 0)
|
|
1113 {
|
|
1114 ccl_prog = ccl_prog_stack_struct[0].ccl_prog;
|
|
1115 ic = ccl_prog_stack_struct[0].ic;
|
|
1116 }
|
444
|
1117 CCL_INVALID_CMD;
|
428
|
1118 }
|
|
1119
|
|
1120 ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog;
|
|
1121 ccl_prog_stack_struct[stack_idx].ic = ic;
|
|
1122 stack_idx++;
|
444
|
1123 ccl_prog = XVECTOR (XVECTOR (slot)->contents[1])->contents;
|
428
|
1124 ic = CCL_HEADER_MAIN;
|
|
1125 }
|
|
1126 break;
|
|
1127
|
|
1128 case CCL_WriteConstString: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1129 if (!rrr)
|
|
1130 CCL_WRITE_CHAR (field1);
|
|
1131 else
|
|
1132 {
|
|
1133 CCL_WRITE_STRING (field1);
|
|
1134 ic += (field1 + 2) / 3;
|
|
1135 }
|
|
1136 break;
|
|
1137
|
|
1138 case CCL_WriteArray: /* CCCCCCCCCCCCCCCCCCCCrrrXXXXX */
|
|
1139 i = reg[rrr];
|
|
1140 if ((unsigned int) i < field1)
|
|
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:
|
|
1257 /* DECODE_SJIS set MSB for internal format
|
|
1258 as opposed to Emacs. */
|
|
1259 DECODE_SJIS (i, j, reg[rrr], reg[7]);
|
|
1260 reg[rrr] &= 0x7F;
|
|
1261 reg[7] &= 0x7F;
|
|
1262 break;
|
|
1263 case CCL_ENCODE_SJIS:
|
|
1264 /* ENCODE_SJIS assumes MSB of SJIS-char is set
|
|
1265 as opposed to Emacs. */
|
|
1266 ENCODE_SJIS (i | 0x80, j | 0x80, reg[rrr], reg[7]);
|
|
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 }
|
|
1301 else if (i <= MAX_LEADING_BYTE_OFFICIAL_1)
|
|
1302 {
|
|
1303 if (src >= src_end)
|
|
1304 goto ccl_read_multibyte_character_suspend;
|
|
1305 reg[RRR] = i;
|
|
1306 reg[rrr] = (*src++ & 0x7F);
|
|
1307 }
|
|
1308 else if (i <= MAX_LEADING_BYTE_OFFICIAL_2)
|
|
1309 {
|
|
1310 if ((src + 1) >= src_end)
|
|
1311 goto ccl_read_multibyte_character_suspend;
|
|
1312 reg[RRR] = i;
|
|
1313 i = (*src++ & 0x7F);
|
|
1314 reg[rrr] = ((i << 7) | (*src & 0x7F));
|
|
1315 src++;
|
|
1316 }
|
|
1317 else if (i == PRE_LEADING_BYTE_PRIVATE_1)
|
|
1318 {
|
|
1319 if ((src + 1) >= src_end)
|
|
1320 goto ccl_read_multibyte_character_suspend;
|
|
1321 reg[RRR] = *src++;
|
|
1322 reg[rrr] = (*src++ & 0x7F);
|
|
1323 }
|
|
1324 else if (i == PRE_LEADING_BYTE_PRIVATE_2)
|
|
1325 {
|
|
1326 if ((src + 2) >= src_end)
|
|
1327 goto ccl_read_multibyte_character_suspend;
|
|
1328 reg[RRR] = *src++;
|
|
1329 i = (*src++ & 0x7F);
|
|
1330 reg[rrr] = ((i << 7) | (*src & 0x7F));
|
|
1331 src++;
|
|
1332 }
|
|
1333 else
|
|
1334 {
|
|
1335 /* INVALID CODE. Return a single byte character. */
|
|
1336 reg[RRR] = LEADING_BYTE_ASCII;
|
|
1337 reg[rrr] = i;
|
|
1338 }
|
428
|
1339 break;
|
|
1340
|
|
1341 ccl_read_multibyte_character_suspend:
|
|
1342 src--;
|
|
1343 if (ccl->last_block)
|
|
1344 {
|
|
1345 ic = ccl->eof_ic;
|
|
1346 goto ccl_repeat;
|
|
1347 }
|
|
1348 else
|
|
1349 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC);
|
|
1350
|
|
1351 break;
|
|
1352
|
|
1353 case CCL_WriteMultibyteChar2:
|
|
1354 i = reg[RRR]; /* charset */
|
|
1355 if (i == LEADING_BYTE_ASCII)
|
|
1356 i = reg[rrr] & 0xFF;
|
|
1357 else if (XCHARSET_DIMENSION (CHARSET_BY_LEADING_BYTE (i)) == 1)
|
444
|
1358 i = (((i - FIELD2_TO_OFFICIAL_LEADING_BYTE) << 7)
|
|
1359 | (reg[rrr] & 0x7F));
|
|
1360 else if (i < MAX_LEADING_BYTE_OFFICIAL_2)
|
428
|
1361 i = ((i - FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14) | reg[rrr];
|
|
1362 else
|
|
1363 i = ((i - FIELD1_TO_PRIVATE_LEADING_BYTE) << 14) | reg[rrr];
|
|
1364
|
|
1365 CCL_WRITE_CHAR (i);
|
|
1366
|
|
1367 break;
|
|
1368
|
444
|
1369 case CCL_TranslateCharacter:
|
428
|
1370 #if 0
|
444
|
1371 /* XEmacs does not have translate_char, and its
|
|
1372 equivalent nor. We do nothing on this operation. */
|
|
1373 CCL_MAKE_CHAR (reg[RRR], reg[rrr], i);
|
428
|
1374 op = translate_char (GET_TRANSLATION_TABLE (reg[Rrr]),
|
|
1375 i, -1, 0, 0);
|
|
1376 SPLIT_CHAR (op, reg[RRR], i, j);
|
|
1377 if (j != -1)
|
|
1378 i = (i << 7) | j;
|
442
|
1379
|
428
|
1380 reg[rrr] = i;
|
444
|
1381 #endif
|
428
|
1382 break;
|
|
1383
|
|
1384 case CCL_TranslateCharacterConstTbl:
|
444
|
1385 #if 0
|
|
1386 /* XEmacs does not have translate_char, and its
|
|
1387 equivalent nor. We do nothing on this operation. */
|
428
|
1388 op = XINT (ccl_prog[ic]); /* table */
|
|
1389 ic++;
|
444
|
1390 CCL_MAKE_CHAR (reg[RRR], reg[rrr], i);
|
428
|
1391 op = translate_char (GET_TRANSLATION_TABLE (op), i, -1, 0, 0);
|
|
1392 SPLIT_CHAR (op, reg[RRR], i, j);
|
|
1393 if (j != -1)
|
|
1394 i = (i << 7) | j;
|
442
|
1395
|
428
|
1396 reg[rrr] = i;
|
444
|
1397 #endif
|
428
|
1398 break;
|
|
1399
|
|
1400 case CCL_IterateMultipleMap:
|
|
1401 {
|
|
1402 Lisp_Object map, content, attrib, value;
|
|
1403 int point, size, fin_ic;
|
|
1404
|
|
1405 j = XINT (ccl_prog[ic++]); /* number of maps. */
|
|
1406 fin_ic = ic + j;
|
|
1407 op = reg[rrr];
|
|
1408 if ((j > reg[RRR]) && (j >= 0))
|
|
1409 {
|
|
1410 ic += reg[RRR];
|
|
1411 i = reg[RRR];
|
|
1412 }
|
|
1413 else
|
|
1414 {
|
|
1415 reg[RRR] = -1;
|
|
1416 ic = fin_ic;
|
|
1417 break;
|
|
1418 }
|
|
1419
|
|
1420 for (;i < j;i++)
|
|
1421 {
|
|
1422
|
|
1423 size = XVECTOR (Vcode_conversion_map_vector)->size;
|
|
1424 point = XINT (ccl_prog[ic++]);
|
|
1425 if (point >= size) continue;
|
|
1426 map =
|
|
1427 XVECTOR (Vcode_conversion_map_vector)->contents[point];
|
|
1428
|
444
|
1429 /* Check map validity. */
|
428
|
1430 if (!CONSP (map)) continue;
|
444
|
1431 map = XCDR (map);
|
428
|
1432 if (!VECTORP (map)) continue;
|
|
1433 size = XVECTOR (map)->size;
|
|
1434 if (size <= 1) continue;
|
|
1435
|
|
1436 content = XVECTOR (map)->contents[0];
|
|
1437
|
|
1438 /* check map type,
|
|
1439 [STARTPOINT VAL1 VAL2 ...] or
|
444
|
1440 [t ELEMENT STARTPOINT ENDPOINT] */
|
|
1441 if (INTP (content))
|
428
|
1442 {
|
|
1443 point = XUINT (content);
|
|
1444 point = op - point + 1;
|
|
1445 if (!((point >= 1) && (point < size))) continue;
|
|
1446 content = XVECTOR (map)->contents[point];
|
|
1447 }
|
|
1448 else if (EQ (content, Qt))
|
|
1449 {
|
|
1450 if (size != 4) continue;
|
|
1451 if ((op >= XUINT (XVECTOR (map)->contents[2]))
|
|
1452 && (op < XUINT (XVECTOR (map)->contents[3])))
|
|
1453 content = XVECTOR (map)->contents[1];
|
|
1454 else
|
|
1455 continue;
|
|
1456 }
|
442
|
1457 else
|
428
|
1458 continue;
|
|
1459
|
|
1460 if (NILP (content))
|
|
1461 continue;
|
444
|
1462 else if (INTP (content))
|
428
|
1463 {
|
|
1464 reg[RRR] = i;
|
|
1465 reg[rrr] = XINT(content);
|
|
1466 break;
|
|
1467 }
|
|
1468 else if (EQ (content, Qt) || EQ (content, Qlambda))
|
|
1469 {
|
|
1470 reg[RRR] = i;
|
|
1471 break;
|
|
1472 }
|
|
1473 else if (CONSP (content))
|
|
1474 {
|
444
|
1475 attrib = XCAR (content);
|
|
1476 value = XCDR (content);
|
|
1477 if (!INTP (attrib) || !INTP (value))
|
428
|
1478 continue;
|
|
1479 reg[RRR] = i;
|
|
1480 reg[rrr] = XUINT (value);
|
|
1481 break;
|
|
1482 }
|
444
|
1483 else if (SYMBOLP (content))
|
|
1484 CCL_CALL_FOR_MAP_INSTRUCTION (content, fin_ic);
|
|
1485 else
|
|
1486 CCL_INVALID_CMD;
|
428
|
1487 }
|
|
1488 if (i == j)
|
|
1489 reg[RRR] = -1;
|
|
1490 ic = fin_ic;
|
|
1491 }
|
|
1492 break;
|
442
|
1493
|
428
|
1494 case CCL_MapMultiple:
|
|
1495 {
|
|
1496 Lisp_Object map, content, attrib, value;
|
|
1497 int point, size, map_vector_size;
|
|
1498 int map_set_rest_length, fin_ic;
|
444
|
1499 int current_ic = this_ic;
|
|
1500
|
|
1501 /* inhibit recursive call on MapMultiple. */
|
|
1502 if (stack_idx_of_map_multiple > 0)
|
|
1503 {
|
|
1504 if (stack_idx_of_map_multiple <= stack_idx)
|
|
1505 {
|
|
1506 stack_idx_of_map_multiple = 0;
|
|
1507 mapping_stack_pointer = mapping_stack;
|
|
1508 CCL_INVALID_CMD;
|
|
1509 }
|
|
1510 }
|
|
1511 else
|
|
1512 mapping_stack_pointer = mapping_stack;
|
|
1513 stack_idx_of_map_multiple = 0;
|
428
|
1514
|
|
1515 map_set_rest_length =
|
|
1516 XINT (ccl_prog[ic++]); /* number of maps and separators. */
|
|
1517 fin_ic = ic + map_set_rest_length;
|
444
|
1518 op = reg[rrr];
|
|
1519
|
428
|
1520 if ((map_set_rest_length > reg[RRR]) && (reg[RRR] >= 0))
|
|
1521 {
|
|
1522 ic += reg[RRR];
|
|
1523 i = reg[RRR];
|
|
1524 map_set_rest_length -= i;
|
|
1525 }
|
|
1526 else
|
|
1527 {
|
|
1528 ic = fin_ic;
|
|
1529 reg[RRR] = -1;
|
444
|
1530 mapping_stack_pointer = mapping_stack;
|
428
|
1531 break;
|
|
1532 }
|
444
|
1533
|
|
1534 if (mapping_stack_pointer <= (mapping_stack + 1))
|
428
|
1535 {
|
444
|
1536 /* Set up initial state. */
|
|
1537 mapping_stack_pointer = mapping_stack;
|
|
1538 PUSH_MAPPING_STACK (0, op);
|
|
1539 reg[RRR] = -1;
|
|
1540 }
|
|
1541 else
|
|
1542 {
|
|
1543 /* Recover after calling other ccl program. */
|
|
1544 int orig_op;
|
428
|
1545
|
444
|
1546 POP_MAPPING_STACK (map_set_rest_length, orig_op);
|
|
1547 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1548 switch (op)
|
428
|
1549 {
|
444
|
1550 case -1:
|
|
1551 /* Regard it as Qnil. */
|
|
1552 op = orig_op;
|
|
1553 i++;
|
|
1554 ic++;
|
|
1555 map_set_rest_length--;
|
|
1556 break;
|
|
1557 case -2:
|
|
1558 /* Regard it as Qt. */
|
|
1559 op = reg[rrr];
|
|
1560 i++;
|
|
1561 ic++;
|
|
1562 map_set_rest_length--;
|
|
1563 break;
|
|
1564 case -3:
|
|
1565 /* Regard it as Qlambda. */
|
|
1566 op = orig_op;
|
428
|
1567 i += map_set_rest_length;
|
444
|
1568 ic += map_set_rest_length;
|
|
1569 map_set_rest_length = 0;
|
|
1570 break;
|
|
1571 default:
|
|
1572 /* Regard it as normal mapping. */
|
428
|
1573 i += map_set_rest_length;
|
444
|
1574 ic += map_set_rest_length;
|
428
|
1575 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1576 break;
|
|
1577 }
|
|
1578 }
|
444
|
1579 map_vector_size = XVECTOR (Vcode_conversion_map_vector)->size;
|
|
1580
|
|
1581 do {
|
|
1582 for (;map_set_rest_length > 0;i++, ic++, map_set_rest_length--)
|
|
1583 {
|
|
1584 point = XINT(ccl_prog[ic]);
|
|
1585 if (point < 0)
|
|
1586 {
|
|
1587 /* +1 is for including separator. */
|
|
1588 point = -point + 1;
|
|
1589 if (mapping_stack_pointer
|
460
|
1590 >= mapping_stack + countof (mapping_stack))
|
444
|
1591 CCL_INVALID_CMD;
|
|
1592 PUSH_MAPPING_STACK (map_set_rest_length - point,
|
|
1593 reg[rrr]);
|
|
1594 map_set_rest_length = point;
|
|
1595 reg[rrr] = op;
|
|
1596 continue;
|
|
1597 }
|
|
1598
|
|
1599 if (point >= map_vector_size) continue;
|
|
1600 map = (XVECTOR (Vcode_conversion_map_vector)
|
|
1601 ->contents[point]);
|
|
1602
|
|
1603 /* Check map validity. */
|
|
1604 if (!CONSP (map)) continue;
|
|
1605 map = XCDR (map);
|
|
1606 if (!VECTORP (map)) continue;
|
|
1607 size = XVECTOR (map)->size;
|
|
1608 if (size <= 1) continue;
|
|
1609
|
|
1610 content = XVECTOR (map)->contents[0];
|
|
1611
|
|
1612 /* check map type,
|
|
1613 [STARTPOINT VAL1 VAL2 ...] or
|
|
1614 [t ELEMENT STARTPOINT ENDPOINT] */
|
|
1615 if (INTP (content))
|
|
1616 {
|
|
1617 point = XUINT (content);
|
|
1618 point = op - point + 1;
|
|
1619 if (!((point >= 1) && (point < size))) continue;
|
|
1620 content = XVECTOR (map)->contents[point];
|
|
1621 }
|
|
1622 else if (EQ (content, Qt))
|
|
1623 {
|
|
1624 if (size != 4) continue;
|
|
1625 if ((op >= XUINT (XVECTOR (map)->contents[2])) &&
|
|
1626 (op < XUINT (XVECTOR (map)->contents[3])))
|
|
1627 content = XVECTOR (map)->contents[1];
|
|
1628 else
|
|
1629 continue;
|
|
1630 }
|
|
1631 else
|
|
1632 continue;
|
|
1633
|
|
1634 if (NILP (content))
|
|
1635 continue;
|
|
1636
|
|
1637 reg[RRR] = i;
|
|
1638 if (INTP (content))
|
|
1639 {
|
|
1640 op = XINT (content);
|
|
1641 i += map_set_rest_length - 1;
|
|
1642 ic += map_set_rest_length - 1;
|
|
1643 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1644 map_set_rest_length++;
|
|
1645 }
|
|
1646 else if (CONSP (content))
|
|
1647 {
|
|
1648 attrib = XCAR (content);
|
|
1649 value = XCDR (content);
|
|
1650 if (!INTP (attrib) || !INTP (value))
|
|
1651 continue;
|
|
1652 op = XUINT (value);
|
|
1653 i += map_set_rest_length - 1;
|
|
1654 ic += map_set_rest_length - 1;
|
|
1655 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1656 map_set_rest_length++;
|
|
1657 }
|
|
1658 else if (EQ (content, Qt))
|
|
1659 {
|
|
1660 op = reg[rrr];
|
|
1661 }
|
|
1662 else if (EQ (content, Qlambda))
|
|
1663 {
|
|
1664 i += map_set_rest_length;
|
|
1665 ic += map_set_rest_length;
|
|
1666 break;
|
|
1667 }
|
|
1668 else if (SYMBOLP (content))
|
|
1669 {
|
|
1670 if (mapping_stack_pointer
|
460
|
1671 >= mapping_stack + countof (mapping_stack))
|
444
|
1672 CCL_INVALID_CMD;
|
|
1673 PUSH_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1674 PUSH_MAPPING_STACK (map_set_rest_length, op);
|
|
1675 stack_idx_of_map_multiple = stack_idx + 1;
|
|
1676 CCL_CALL_FOR_MAP_INSTRUCTION (content, current_ic);
|
|
1677 }
|
|
1678 else
|
|
1679 CCL_INVALID_CMD;
|
|
1680 }
|
|
1681 if (mapping_stack_pointer <= (mapping_stack + 1))
|
|
1682 break;
|
|
1683 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1684 i += map_set_rest_length;
|
|
1685 ic += map_set_rest_length;
|
|
1686 POP_MAPPING_STACK (map_set_rest_length, reg[rrr]);
|
|
1687 } while (1);
|
|
1688
|
428
|
1689 ic = fin_ic;
|
|
1690 }
|
|
1691 reg[rrr] = op;
|
|
1692 break;
|
|
1693
|
|
1694 case CCL_MapSingle:
|
|
1695 {
|
|
1696 Lisp_Object map, attrib, value, content;
|
|
1697 int size, point;
|
|
1698 j = XINT (ccl_prog[ic++]); /* map_id */
|
|
1699 op = reg[rrr];
|
|
1700 if (j >= XVECTOR (Vcode_conversion_map_vector)->size)
|
|
1701 {
|
|
1702 reg[RRR] = -1;
|
|
1703 break;
|
|
1704 }
|
|
1705 map = XVECTOR (Vcode_conversion_map_vector)->contents[j];
|
|
1706 if (!CONSP (map))
|
|
1707 {
|
|
1708 reg[RRR] = -1;
|
|
1709 break;
|
|
1710 }
|
444
|
1711 map = XCDR (map);
|
428
|
1712 if (!VECTORP (map))
|
|
1713 {
|
|
1714 reg[RRR] = -1;
|
|
1715 break;
|
|
1716 }
|
|
1717 size = XVECTOR (map)->size;
|
|
1718 point = XUINT (XVECTOR (map)->contents[0]);
|
|
1719 point = op - point + 1;
|
|
1720 reg[RRR] = 0;
|
|
1721 if ((size <= 1) ||
|
|
1722 (!((point >= 1) && (point < size))))
|
|
1723 reg[RRR] = -1;
|
|
1724 else
|
|
1725 {
|
444
|
1726 reg[RRR] = 0;
|
428
|
1727 content = XVECTOR (map)->contents[point];
|
|
1728 if (NILP (content))
|
|
1729 reg[RRR] = -1;
|
444
|
1730 else if (INTP (content))
|
428
|
1731 reg[rrr] = XINT (content);
|
444
|
1732 else if (EQ (content, Qt));
|
428
|
1733 else if (CONSP (content))
|
|
1734 {
|
444
|
1735 attrib = XCAR (content);
|
|
1736 value = XCDR (content);
|
|
1737 if (!INTP (attrib) || !INTP (value))
|
428
|
1738 continue;
|
|
1739 reg[rrr] = XUINT(value);
|
|
1740 break;
|
|
1741 }
|
444
|
1742 else if (SYMBOLP (content))
|
|
1743 CCL_CALL_FOR_MAP_INSTRUCTION (content, ic);
|
428
|
1744 else
|
|
1745 reg[RRR] = -1;
|
|
1746 }
|
|
1747 }
|
|
1748 break;
|
442
|
1749
|
428
|
1750 default:
|
|
1751 CCL_INVALID_CMD;
|
|
1752 }
|
|
1753 break;
|
|
1754
|
|
1755 default:
|
444
|
1756 CCL_INVALID_CMD;
|
428
|
1757 }
|
|
1758 }
|
|
1759
|
|
1760 ccl_error_handler:
|
|
1761 if (destination)
|
|
1762 {
|
|
1763 /* We can insert an error message only if DESTINATION is
|
|
1764 specified and we still have a room to store the message
|
|
1765 there. */
|
|
1766 char msg[256];
|
|
1767
|
|
1768 switch (ccl->status)
|
|
1769 {
|
|
1770 case CCL_STAT_INVALID_CMD:
|
|
1771 sprintf(msg, "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
|
|
1772 code & 0x1F, code, this_ic);
|
|
1773 #ifdef CCL_DEBUG
|
|
1774 {
|
|
1775 int i = ccl_backtrace_idx - 1;
|
|
1776 int j;
|
|
1777
|
|
1778 Dynarr_add_many (destination, (unsigned char *) msg, strlen (msg));
|
|
1779
|
|
1780 for (j = 0; j < CCL_DEBUG_BACKTRACE_LEN; j++, i--)
|
|
1781 {
|
|
1782 if (i < 0) i = CCL_DEBUG_BACKTRACE_LEN - 1;
|
|
1783 if (ccl_backtrace_table[i] == 0)
|
|
1784 break;
|
|
1785 sprintf(msg, " %d", ccl_backtrace_table[i]);
|
|
1786 Dynarr_add_many (destination, (unsigned char *) msg, strlen (msg));
|
|
1787 }
|
|
1788 goto ccl_finish;
|
|
1789 }
|
|
1790 #endif
|
|
1791 break;
|
|
1792
|
|
1793 case CCL_STAT_QUIT:
|
444
|
1794 sprintf(msg, "\nCCL: Exited.");
|
428
|
1795 break;
|
|
1796
|
|
1797 default:
|
|
1798 sprintf(msg, "\nCCL: Unknown error type (%d).", ccl->status);
|
|
1799 }
|
|
1800
|
|
1801 Dynarr_add_many (destination, (unsigned char *) msg, strlen (msg));
|
|
1802 }
|
|
1803
|
|
1804 ccl_finish:
|
|
1805 ccl->ic = ic;
|
|
1806 ccl->stack_idx = stack_idx;
|
|
1807 ccl->prog = ccl_prog;
|
|
1808 if (consumed) *consumed = src - source;
|
444
|
1809 if (!destination)
|
428
|
1810 return 0;
|
444
|
1811 return Dynarr_length (destination);
|
|
1812 }
|
|
1813
|
|
1814 /* Resolve symbols in the specified CCL code (Lisp vector). This
|
|
1815 function converts symbols of code conversion maps and character
|
|
1816 translation tables embedded in the CCL code into their ID numbers.
|
|
1817
|
|
1818 The return value is a vector (CCL itself or a new vector in which
|
|
1819 all symbols are resolved), Qt if resolving of some symbol failed,
|
|
1820 or nil if CCL contains invalid data. */
|
|
1821
|
|
1822 static Lisp_Object
|
|
1823 resolve_symbol_ccl_program (Lisp_Object ccl)
|
|
1824 {
|
|
1825 int i, veclen, unresolved = 0;
|
|
1826 Lisp_Object result, contents, val;
|
|
1827
|
|
1828 result = ccl;
|
|
1829 veclen = XVECTOR (result)->size;
|
|
1830
|
|
1831 for (i = 0; i < veclen; i++)
|
|
1832 {
|
|
1833 contents = XVECTOR (result)->contents[i];
|
|
1834 if (INTP (contents))
|
|
1835 continue;
|
|
1836 else if (CONSP (contents)
|
|
1837 && SYMBOLP (XCAR (contents))
|
|
1838 && SYMBOLP (XCDR (contents)))
|
|
1839 {
|
|
1840 /* This is the new style for embedding symbols. The form is
|
|
1841 (SYMBOL . PROPERTY). (get SYMBOL PROPERTY) should give
|
|
1842 an index number. */
|
|
1843
|
|
1844 if (EQ (result, ccl))
|
|
1845 result = Fcopy_sequence (ccl);
|
|
1846
|
|
1847 val = Fget (XCAR (contents), XCDR (contents), Qnil);
|
|
1848 if (NATNUMP (val))
|
|
1849 XVECTOR (result)->contents[i] = val;
|
|
1850 else
|
|
1851 unresolved = 1;
|
|
1852 continue;
|
|
1853 }
|
|
1854 else if (SYMBOLP (contents))
|
|
1855 {
|
|
1856 /* This is the old style for embedding symbols. This style
|
|
1857 may lead to a bug if, for instance, a translation table
|
|
1858 and a code conversion map have the same name. */
|
|
1859 if (EQ (result, ccl))
|
|
1860 result = Fcopy_sequence (ccl);
|
|
1861
|
|
1862 val = Fget (contents, Qcode_conversion_map_id, Qnil);
|
|
1863 if (NATNUMP (val))
|
|
1864 XVECTOR (result)->contents[i] = val;
|
|
1865 else
|
|
1866 {
|
|
1867 val = Fget (contents, Qccl_program_idx, Qnil);
|
|
1868 if (NATNUMP (val))
|
|
1869 XVECTOR (result)->contents[i] = val;
|
|
1870 else
|
|
1871 unresolved = 1;
|
|
1872 }
|
|
1873 continue;
|
|
1874 }
|
|
1875 return Qnil;
|
|
1876 }
|
|
1877
|
|
1878 return (unresolved ? Qt : result);
|
|
1879 }
|
|
1880
|
|
1881 /* Return the compiled code (vector) of CCL program CCL_PROG.
|
|
1882 CCL_PROG is a name (symbol) of the program or already compiled
|
|
1883 code. If necessary, resolve symbols in the compiled code to index
|
|
1884 numbers. If we failed to get the compiled code or to resolve
|
|
1885 symbols, return Qnil. */
|
|
1886
|
|
1887 static Lisp_Object
|
|
1888 ccl_get_compiled_code (Lisp_Object ccl_prog)
|
|
1889 {
|
|
1890 Lisp_Object val, slot;
|
|
1891
|
|
1892 if (VECTORP (ccl_prog))
|
|
1893 {
|
|
1894 val = resolve_symbol_ccl_program (ccl_prog);
|
|
1895 return (VECTORP (val) ? val : Qnil);
|
|
1896 }
|
|
1897 if (!SYMBOLP (ccl_prog))
|
|
1898 return Qnil;
|
|
1899
|
|
1900 val = Fget (ccl_prog, Qccl_program_idx, Qnil);
|
|
1901 if (! NATNUMP (val)
|
|
1902 || XINT (val) >= XVECTOR_LENGTH (Vccl_program_table))
|
|
1903 return Qnil;
|
|
1904 slot = XVECTOR_DATA (Vccl_program_table)[XINT (val)];
|
|
1905 if (! VECTORP (slot)
|
|
1906 || XVECTOR (slot)->size != 3
|
|
1907 || ! VECTORP (XVECTOR_DATA (slot)[1]))
|
|
1908 return Qnil;
|
|
1909 if (NILP (XVECTOR_DATA (slot)[2]))
|
|
1910 {
|
|
1911 val = resolve_symbol_ccl_program (XVECTOR_DATA (slot)[1]);
|
|
1912 if (! VECTORP (val))
|
|
1913 return Qnil;
|
|
1914 XVECTOR_DATA (slot)[1] = val;
|
|
1915 XVECTOR_DATA (slot)[2] = Qt;
|
|
1916 }
|
|
1917 return XVECTOR_DATA (slot)[1];
|
428
|
1918 }
|
|
1919
|
|
1920 /* Setup fields of the structure pointed by CCL appropriately for the
|
444
|
1921 execution of CCL program CCL_PROG. CCL_PROG is the name (symbol)
|
|
1922 of the CCL program or the already compiled code (vector).
|
|
1923 Return 0 if we succeed this setup, else return -1.
|
|
1924
|
|
1925 If CCL_PROG is nil, we just reset the structure pointed by CCL. */
|
|
1926 int
|
|
1927 setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog)
|
428
|
1928 {
|
|
1929 int i;
|
|
1930
|
444
|
1931 if (! NILP (ccl_prog))
|
428
|
1932 {
|
444
|
1933 ccl_prog = ccl_get_compiled_code (ccl_prog);
|
|
1934 if (! VECTORP (ccl_prog))
|
|
1935 return -1;
|
|
1936 ccl->size = XVECTOR_LENGTH (ccl_prog);
|
|
1937 ccl->prog = XVECTOR_DATA (ccl_prog);
|
|
1938 ccl->eof_ic = XINT (XVECTOR_DATA (ccl_prog)[CCL_HEADER_EOF]);
|
|
1939 ccl->buf_magnification = XINT (XVECTOR_DATA (ccl_prog)[CCL_HEADER_BUF_MAG]);
|
428
|
1940 }
|
|
1941 ccl->ic = CCL_HEADER_MAIN;
|
|
1942 for (i = 0; i < 8; i++)
|
|
1943 ccl->reg[i] = 0;
|
|
1944 ccl->last_block = 0;
|
|
1945 ccl->private_state = 0;
|
|
1946 ccl->status = 0;
|
|
1947 ccl->stack_idx = 0;
|
444
|
1948 ccl->eol_type = CCL_CODING_EOL_LF;
|
|
1949 return 0;
|
428
|
1950 }
|
|
1951
|
444
|
1952 #ifdef emacs
|
428
|
1953
|
444
|
1954 DEFUN ("ccl-program-p", Fccl_program_p, 1, 1, 0, /*
|
|
1955 Return t if OBJECT is a CCL program name or a compiled CCL program code.
|
|
1956 See the documentation of `define-ccl-program' for the detail of CCL program.
|
|
1957 */
|
|
1958 (object))
|
|
1959 {
|
|
1960 Lisp_Object val;
|
428
|
1961
|
444
|
1962 if (VECTORP (object))
|
|
1963 {
|
|
1964 val = resolve_symbol_ccl_program (object);
|
|
1965 return (VECTORP (val) ? Qt : Qnil);
|
428
|
1966 }
|
444
|
1967 if (!SYMBOLP (object))
|
|
1968 return Qnil;
|
428
|
1969
|
444
|
1970 val = Fget (object, Qccl_program_idx, Qnil);
|
|
1971 return ((! NATNUMP (val)
|
|
1972 || XINT (val) >= XVECTOR_LENGTH (Vccl_program_table))
|
|
1973 ? Qnil : Qt);
|
428
|
1974 }
|
|
1975
|
|
1976 DEFUN ("ccl-execute", Fccl_execute, 2, 2, 0, /*
|
|
1977 Execute CCL-PROGRAM with registers initialized by REGISTERS.
|
|
1978
|
444
|
1979 CCL-PROGRAM is a CCL program name (symbol)
|
428
|
1980 or a compiled code generated by `ccl-compile' (for backward compatibility,
|
444
|
1981 in this case, the overhead of the execution is bigger than the former case).
|
428
|
1982 No I/O commands should appear in CCL-PROGRAM.
|
|
1983
|
|
1984 REGISTERS is a vector of [R0 R1 ... R7] where RN is an initial value
|
|
1985 of Nth register.
|
|
1986
|
444
|
1987 As side effect, each element of REGISTERS holds the value of
|
428
|
1988 corresponding register after the execution.
|
444
|
1989
|
|
1990 See the documentation of `define-ccl-program' for the detail of CCL program.
|
428
|
1991 */
|
444
|
1992 (ccl_prog, reg))
|
428
|
1993 {
|
|
1994 struct ccl_program ccl;
|
|
1995 int i;
|
|
1996
|
444
|
1997 if (setup_ccl_program (&ccl, ccl_prog) < 0)
|
563
|
1998 syntax_error ("Invalid CCL program", Qunbound);
|
428
|
1999
|
|
2000 CHECK_VECTOR (reg);
|
|
2001 if (XVECTOR_LENGTH (reg) != 8)
|
563
|
2002 syntax_error ("Length of vector REGISTERS is not 8", Qunbound);
|
428
|
2003
|
|
2004 for (i = 0; i < 8; i++)
|
|
2005 ccl.reg[i] = (INTP (XVECTOR_DATA (reg)[i])
|
|
2006 ? XINT (XVECTOR_DATA (reg)[i])
|
|
2007 : 0);
|
|
2008
|
444
|
2009 ccl_driver (&ccl, (const unsigned char *)0,
|
|
2010 (unsigned_char_dynarr *)0, 0, (int *)0,
|
|
2011 CCL_MODE_ENCODING);
|
428
|
2012 QUIT;
|
|
2013 if (ccl.status != CCL_STAT_SUCCESS)
|
563
|
2014 signal_error (Qccl_error, "Error in CCL program at code numbered ...", make_int (ccl.ic));
|
428
|
2015
|
|
2016 for (i = 0; i < 8; i++)
|
444
|
2017 XSETINT (XVECTOR (reg)->contents[i], ccl.reg[i]);
|
428
|
2018 return Qnil;
|
|
2019 }
|
|
2020
|
444
|
2021 DEFUN ("ccl-execute-on-string", Fccl_execute_on_string,
|
|
2022 3, 4, 0, /*
|
428
|
2023 Execute CCL-PROGRAM with initial STATUS on STRING.
|
|
2024
|
|
2025 CCL-PROGRAM is a symbol registered by register-ccl-program,
|
|
2026 or a compiled code generated by `ccl-compile' (for backward compatibility,
|
|
2027 in this case, the execution is slower).
|
|
2028
|
|
2029 Read buffer is set to STRING, and write buffer is allocated automatically.
|
|
2030
|
|
2031 STATUS is a vector of [R0 R1 ... R7 IC], where
|
|
2032 R0..R7 are initial values of corresponding registers,
|
|
2033 IC is the instruction counter specifying from where to start the program.
|
|
2034 If R0..R7 are nil, they are initialized to 0.
|
|
2035 If IC is nil, it is initialized to head of the CCL program.
|
|
2036
|
|
2037 If optional 4th arg CONTINUE is non-nil, keep IC on read operation
|
444
|
2038 when read buffer is exhausted, else, IC is always set to the end of
|
428
|
2039 CCL-PROGRAM on exit.
|
|
2040
|
|
2041 It returns the contents of write buffer as a string,
|
|
2042 and as side effect, STATUS is updated.
|
444
|
2043
|
|
2044 See the documentation of `define-ccl-program' for the detail of CCL program.
|
428
|
2045 */
|
444
|
2046 (ccl_prog, status, string, continue_))
|
428
|
2047 {
|
|
2048 Lisp_Object val;
|
|
2049 struct ccl_program ccl;
|
|
2050 int i, produced;
|
|
2051 unsigned_char_dynarr *outbuf;
|
444
|
2052 struct gcpro gcpro1, gcpro2;
|
428
|
2053
|
444
|
2054 if (setup_ccl_program (&ccl, ccl_prog) < 0)
|
563
|
2055 syntax_error ("Invalid CCL program", Qunbound);
|
428
|
2056
|
|
2057 CHECK_VECTOR (status);
|
444
|
2058 if (XVECTOR (status)->size != 9)
|
563
|
2059 syntax_error ("Length of vector STATUS is not 9", Qunbound);
|
444
|
2060 CHECK_STRING (string);
|
428
|
2061
|
444
|
2062 GCPRO2 (status, string);
|
|
2063
|
428
|
2064 for (i = 0; i < 8; i++)
|
|
2065 {
|
|
2066 if (NILP (XVECTOR_DATA (status)[i]))
|
|
2067 XSETINT (XVECTOR_DATA (status)[i], 0);
|
|
2068 if (INTP (XVECTOR_DATA (status)[i]))
|
|
2069 ccl.reg[i] = XINT (XVECTOR_DATA (status)[i]);
|
|
2070 }
|
444
|
2071 if (INTP (XVECTOR (status)->contents[i]))
|
428
|
2072 {
|
|
2073 i = XINT (XVECTOR_DATA (status)[8]);
|
|
2074 if (ccl.ic < i && i < ccl.size)
|
|
2075 ccl.ic = i;
|
|
2076 }
|
|
2077 outbuf = Dynarr_new (unsigned_char);
|
444
|
2078 ccl.last_block = NILP (continue_);
|
|
2079 produced = ccl_driver (&ccl, XSTRING_DATA (string), outbuf,
|
|
2080 XSTRING_LENGTH (string),
|
|
2081 (int *) 0,
|
|
2082 CCL_MODE_DECODING);
|
428
|
2083 for (i = 0; i < 8; i++)
|
444
|
2084 XSETINT (XVECTOR_DATA (status)[i], ccl.reg[i]);
|
428
|
2085 XSETINT (XVECTOR_DATA (status)[8], ccl.ic);
|
|
2086 UNGCPRO;
|
|
2087
|
|
2088 val = make_string (Dynarr_atp (outbuf, 0), produced);
|
|
2089 Dynarr_free (outbuf);
|
|
2090 QUIT;
|
444
|
2091 if (ccl.status == CCL_STAT_SUSPEND_BY_DST)
|
563
|
2092 signal_error (Qccl_error, "Output buffer for the CCL programs overflow", Qunbound);
|
428
|
2093 if (ccl.status != CCL_STAT_SUCCESS
|
444
|
2094 && ccl.status != CCL_STAT_SUSPEND_BY_SRC)
|
563
|
2095 signal_error (Qccl_error, "Error in CCL program at code numbered...", make_int (ccl.ic));
|
428
|
2096
|
|
2097 return val;
|
|
2098 }
|
|
2099
|
444
|
2100 DEFUN ("register-ccl-program", Fregister_ccl_program,
|
|
2101 2, 2, 0, /*
|
|
2102 Register CCL program CCL-PROG as NAME in `ccl-program-table'.
|
|
2103 CCL-PROG should be a compiled CCL program (vector), or nil.
|
|
2104 If it is nil, just reserve NAME as a CCL program name.
|
428
|
2105 Return index number of the registered CCL program.
|
|
2106 */
|
444
|
2107 (name, ccl_prog))
|
428
|
2108 {
|
|
2109 int len = XVECTOR_LENGTH (Vccl_program_table);
|
444
|
2110 int idx;
|
|
2111 Lisp_Object resolved;
|
428
|
2112
|
|
2113 CHECK_SYMBOL (name);
|
444
|
2114 resolved = Qnil;
|
428
|
2115 if (!NILP (ccl_prog))
|
|
2116 {
|
|
2117 CHECK_VECTOR (ccl_prog);
|
444
|
2118 resolved = resolve_symbol_ccl_program (ccl_prog);
|
|
2119 if (! NILP (resolved))
|
428
|
2120 {
|
444
|
2121 ccl_prog = resolved;
|
|
2122 resolved = Qt;
|
428
|
2123 }
|
|
2124 }
|
|
2125
|
444
|
2126 for (idx = 0; idx < len; idx++)
|
428
|
2127 {
|
444
|
2128 Lisp_Object slot;
|
|
2129
|
|
2130 slot = XVECTOR_DATA (Vccl_program_table)[idx];
|
|
2131 if (!VECTORP (slot))
|
|
2132 /* This is the first unused slot. Register NAME here. */
|
|
2133 break;
|
|
2134
|
|
2135 if (EQ (name, XVECTOR_DATA (slot)[0]))
|
|
2136 {
|
|
2137 /* Update this slot. */
|
|
2138 XVECTOR_DATA (slot)[1] = ccl_prog;
|
|
2139 XVECTOR_DATA (slot)[2] = resolved;
|
|
2140 return make_int (idx);
|
|
2141 }
|
|
2142 }
|
|
2143
|
|
2144 if (idx == len)
|
|
2145 {
|
|
2146 /* Extend the table. */
|
|
2147 Lisp_Object new_table;
|
428
|
2148 int j;
|
|
2149
|
444
|
2150 new_table = Fmake_vector (make_int (len * 2), Qnil);
|
428
|
2151 for (j = 0; j < len; j++)
|
|
2152 XVECTOR_DATA (new_table)[j]
|
|
2153 = XVECTOR_DATA (Vccl_program_table)[j];
|
|
2154 Vccl_program_table = new_table;
|
|
2155 }
|
|
2156
|
444
|
2157 {
|
|
2158 Lisp_Object elt;
|
|
2159
|
|
2160 elt = Fmake_vector (make_int (3), Qnil);
|
|
2161 XVECTOR_DATA (elt)[0] = name;
|
|
2162 XVECTOR_DATA (elt)[1] = ccl_prog;
|
|
2163 XVECTOR_DATA (elt)[2] = resolved;
|
|
2164 XVECTOR_DATA (Vccl_program_table)[idx] = elt;
|
|
2165 }
|
|
2166
|
|
2167 Fput (name, Qccl_program_idx, make_int (idx));
|
|
2168 return make_int (idx);
|
428
|
2169 }
|
|
2170
|
|
2171 /* Register code conversion map.
|
|
2172 A code conversion map consists of numbers, Qt, Qnil, and Qlambda.
|
|
2173 The first element is start code point.
|
|
2174 The rest elements are mapped numbers.
|
|
2175 Symbol t means to map to an original number before mapping.
|
|
2176 Symbol nil means that the corresponding element is empty.
|
442
|
2177 Symbol lambda means to terminate mapping here.
|
428
|
2178 */
|
|
2179
|
|
2180 DEFUN ("register-code-conversion-map", Fregister_code_conversion_map,
|
444
|
2181 2, 2, 0, /*
|
|
2182 Register SYMBOL as code conversion map MAP.
|
|
2183 Return index number of the registered map.
|
|
2184 */
|
|
2185 (symbol, map))
|
428
|
2186 {
|
444
|
2187 int len = XVECTOR_LENGTH (Vcode_conversion_map_vector);
|
428
|
2188 int i;
|
444
|
2189 Lisp_Object idx;
|
428
|
2190
|
444
|
2191 CHECK_SYMBOL (symbol);
|
|
2192 CHECK_VECTOR (map);
|
442
|
2193
|
428
|
2194 for (i = 0; i < len; i++)
|
|
2195 {
|
444
|
2196 Lisp_Object slot = XVECTOR_DATA (Vcode_conversion_map_vector)[i];
|
428
|
2197
|
|
2198 if (!CONSP (slot))
|
|
2199 break;
|
|
2200
|
444
|
2201 if (EQ (symbol, XCAR (slot)))
|
428
|
2202 {
|
444
|
2203 idx = make_int (i);
|
|
2204 XCDR (slot) = map;
|
428
|
2205 Fput (symbol, Qcode_conversion_map, map);
|
444
|
2206 Fput (symbol, Qcode_conversion_map_id, idx);
|
|
2207 return idx;
|
428
|
2208 }
|
|
2209 }
|
|
2210
|
|
2211 if (i == len)
|
|
2212 {
|
|
2213 Lisp_Object new_vector = Fmake_vector (make_int (len * 2), Qnil);
|
|
2214 int j;
|
|
2215
|
|
2216 for (j = 0; j < len; j++)
|
444
|
2217 XVECTOR_DATA (new_vector)[j]
|
|
2218 = XVECTOR_DATA (Vcode_conversion_map_vector)[j];
|
428
|
2219 Vcode_conversion_map_vector = new_vector;
|
|
2220 }
|
|
2221
|
444
|
2222 idx = make_int (i);
|
428
|
2223 Fput (symbol, Qcode_conversion_map, map);
|
444
|
2224 Fput (symbol, Qcode_conversion_map_id, idx);
|
|
2225 XVECTOR_DATA (Vcode_conversion_map_vector)[i] = Fcons (symbol, map);
|
|
2226 return idx;
|
428
|
2227 }
|
|
2228
|
|
2229
|
|
2230 void
|
|
2231 syms_of_mule_ccl (void)
|
|
2232 {
|
565
|
2233 DEFERROR_STANDARD (Qccl_error, Qconversion_error);
|
|
2234
|
444
|
2235 DEFSUBR (Fccl_program_p);
|
428
|
2236 DEFSUBR (Fccl_execute);
|
|
2237 DEFSUBR (Fccl_execute_on_string);
|
|
2238 DEFSUBR (Fregister_ccl_program);
|
444
|
2239 DEFSUBR (Fregister_code_conversion_map);
|
428
|
2240 }
|
|
2241
|
|
2242 void
|
|
2243 vars_of_mule_ccl (void)
|
|
2244 {
|
|
2245 staticpro (&Vccl_program_table);
|
|
2246 Vccl_program_table = Fmake_vector (make_int (32), Qnil);
|
|
2247
|
563
|
2248 DEFSYMBOL (Qccl_program);
|
|
2249 DEFSYMBOL (Qccl_program_idx);
|
|
2250 DEFSYMBOL (Qcode_conversion_map);
|
|
2251 DEFSYMBOL (Qcode_conversion_map_id);
|
428
|
2252
|
|
2253 DEFVAR_LISP ("code-conversion-map-vector", &Vcode_conversion_map_vector /*
|
444
|
2254 Vector of code conversion maps.
|
|
2255 */ );
|
428
|
2256 Vcode_conversion_map_vector = Fmake_vector (make_int (16), Qnil);
|
|
2257
|
|
2258 DEFVAR_LISP ("font-ccl-encoder-alist", &Vfont_ccl_encoder_alist /*
|
|
2259 Alist of fontname patterns vs corresponding CCL program.
|
|
2260 Each element looks like (REGEXP . CCL-CODE),
|
|
2261 where CCL-CODE is a compiled CCL program.
|
|
2262 When a font whose name matches REGEXP is used for displaying a character,
|
|
2263 CCL-CODE is executed to calculate the code point in the font
|
|
2264 from the charset number and position code(s) of the character which are set
|
|
2265 in CCL registers R0, R1, and R2 before the execution.
|
|
2266 The code point in the font is set in CCL registers R1 and R2
|
|
2267 when the execution terminated.
|
|
2268 If the font is single-byte font, the register R2 is not used.
|
|
2269 */ );
|
|
2270 Vfont_ccl_encoder_alist = Qnil;
|
|
2271 }
|
|
2272
|
|
2273 #endif /* emacs */
|