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