1 /* Header for UCS-4 character representation.
2 Copyright (C) 1999,2000,2001 MORIOKA Tomohiko
4 This file is part of XEmacs.
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifndef INCLUDED_char_ucs_h_
22 #define INCLUDED_char_ucs_h_
26 #define valid_char_p(ch) 1
28 #define CHAR_ASCII_P(ch) ((ch) <= 0x7F)
30 extern Lisp_Object Vcharset_mojikyo;
31 extern Lisp_Object Vcharset_mojikyo_2022_1;
32 extern Lisp_Object Vcharset_latin_jisx0201;
35 /************************************************************************/
36 /* Definition of leading bytes */
37 /************************************************************************/
39 typedef short Charset_ID;
41 #define MIN_LEADING_BYTE -0x100
42 #define CHARSET_ID_OFFSET 0x00
45 #define LEADING_BYTE_UCS (CHARSET_ID_OFFSET - 1)
47 /* represent normal 80-9F */
48 #define LEADING_BYTE_CONTROL_1 (CHARSET_ID_OFFSET - 2)
50 /* ISO/IEC 10646 BMP */
51 #define LEADING_BYTE_UCS_BMP (CHARSET_ID_OFFSET - 3)
53 /* ISO/IEC 10646 for CNS */
54 #define LEADING_BYTE_UCS_CNS (CHARSET_ID_OFFSET - 5)
56 /* ISO/IEC 10646 for JIS */
57 #define LEADING_BYTE_UCS_JIS (CHARSET_ID_OFFSET - 6)
59 /* ISO/IEC 10646 for Big5 */
60 #define LEADING_BYTE_UCS_BIG5 (CHARSET_ID_OFFSET - 9)
62 /* Japanese JIS X0208-1990 2/4 2/{(8),9,10,11} 4/2 (B) */
63 #define LEADING_BYTE_JAPANESE_JISX0208_1990 (CHARSET_ID_OFFSET - 10)
65 /* Chinese GB 12345-1990 */
66 #define LEADING_BYTE_CHINESE_GB12345 (CHARSET_ID_OFFSET - 11)
68 #define LEADING_BYTE_CHINESE_BIG5 (CHARSET_ID_OFFSET - 20)
70 /* Big5 Level 1 2/4 2/{(8),9,10,11} 4/0 '0' */
71 #define LEADING_BYTE_CHINESE_BIG5_1 (CHARSET_ID_OFFSET - 21)
73 /* Big5 Level 2 2/4 2/{(8),9,10,11} 4/0 '1' */
74 #define LEADING_BYTE_CHINESE_BIG5_2 (CHARSET_ID_OFFSET - 22)
76 #define LEADING_BYTE_CHINESE_BIG5_CDP (CHARSET_ID_OFFSET - 23)
79 #define LEADING_BYTE_LATIN_VISCII (CHARSET_ID_OFFSET - 24)
81 /* MULE VISCII-LOWER (CHARSET_ID_OFFSET_96 + '1') */
82 #define LEADING_BYTE_LATIN_VISCII_LOWER (CHARSET_ID_OFFSET - 25)
84 /* MULE VISCII-UPPER (CHARSET_ID_OFFSET_96 + '2') */
85 #define LEADING_BYTE_LATIN_VISCII_UPPER (CHARSET_ID_OFFSET - 26)
87 #define LEADING_BYTE_ETHIOPIC_UCS (CHARSET_ID_OFFSET - 27)
89 #define LEADING_BYTE_DAIKANWA (CHARSET_ID_OFFSET - 28)
90 #define LEADING_BYTE_DAIKANWA_EKANJI (CHARSET_ID_OFFSET - 29)
92 #define LEADING_BYTE_GT (CHARSET_ID_OFFSET - 30)
93 #define LEADING_BYTE_GT_PJ_1 (CHARSET_ID_OFFSET - 31)
94 #define LEADING_BYTE_GT_PJ_2 (CHARSET_ID_OFFSET - 32)
95 #define LEADING_BYTE_GT_PJ_3 (CHARSET_ID_OFFSET - 33)
96 #define LEADING_BYTE_GT_PJ_4 (CHARSET_ID_OFFSET - 34)
97 #define LEADING_BYTE_GT_PJ_5 (CHARSET_ID_OFFSET - 35)
98 #define LEADING_BYTE_GT_PJ_6 (CHARSET_ID_OFFSET - 36)
99 #define LEADING_BYTE_GT_PJ_7 (CHARSET_ID_OFFSET - 37)
100 #define LEADING_BYTE_GT_PJ_8 (CHARSET_ID_OFFSET - 38)
101 #define LEADING_BYTE_GT_PJ_9 (CHARSET_ID_OFFSET - 39)
102 #define LEADING_BYTE_GT_PJ_10 (CHARSET_ID_OFFSET - 40)
103 #define LEADING_BYTE_GT_PJ_11 (CHARSET_ID_OFFSET - 41)
105 #define LEADING_BYTE_MOJIKYO (CHARSET_ID_OFFSET - 48)
106 #define LEADING_BYTE_MOJIKYO_2022_1 (CHARSET_ID_OFFSET - 49)
107 #define LEADING_BYTE_MOJIKYO_2022_2 (CHARSET_ID_OFFSET - 50)
109 /* Konjaku-Mojikyo font (for pseudo-JIS X 0208 encoding) */
110 #define LEADING_BYTE_MOJIKYO_PJ_1 (CHARSET_ID_OFFSET - 51)
111 #define LEADING_BYTE_MOJIKYO_PJ_2 (CHARSET_ID_OFFSET - 52)
112 #define LEADING_BYTE_MOJIKYO_PJ_3 (CHARSET_ID_OFFSET - 53)
113 #define LEADING_BYTE_MOJIKYO_PJ_4 (CHARSET_ID_OFFSET - 54)
114 #define LEADING_BYTE_MOJIKYO_PJ_5 (CHARSET_ID_OFFSET - 55)
115 #define LEADING_BYTE_MOJIKYO_PJ_6 (CHARSET_ID_OFFSET - 56)
116 #define LEADING_BYTE_MOJIKYO_PJ_7 (CHARSET_ID_OFFSET - 57)
117 #define LEADING_BYTE_MOJIKYO_PJ_8 (CHARSET_ID_OFFSET - 58)
118 #define LEADING_BYTE_MOJIKYO_PJ_9 (CHARSET_ID_OFFSET - 59)
119 #define LEADING_BYTE_MOJIKYO_PJ_10 (CHARSET_ID_OFFSET - 60)
120 #define LEADING_BYTE_MOJIKYO_PJ_11 (CHARSET_ID_OFFSET - 61)
121 #define LEADING_BYTE_MOJIKYO_PJ_12 (CHARSET_ID_OFFSET - 62)
122 #define LEADING_BYTE_MOJIKYO_PJ_13 (CHARSET_ID_OFFSET - 63)
123 #define LEADING_BYTE_MOJIKYO_PJ_14 (CHARSET_ID_OFFSET - 64)
124 #define LEADING_BYTE_MOJIKYO_PJ_15 (CHARSET_ID_OFFSET - 65)
125 #define LEADING_BYTE_MOJIKYO_PJ_16 (CHARSET_ID_OFFSET - 66)
126 #define LEADING_BYTE_MOJIKYO_PJ_17 (CHARSET_ID_OFFSET - 67)
127 #define LEADING_BYTE_MOJIKYO_PJ_18 (CHARSET_ID_OFFSET - 68)
128 #define LEADING_BYTE_MOJIKYO_PJ_19 (CHARSET_ID_OFFSET - 69)
129 #define LEADING_BYTE_MOJIKYO_PJ_20 (CHARSET_ID_OFFSET - 70)
130 #define LEADING_BYTE_MOJIKYO_PJ_21 (CHARSET_ID_OFFSET - 71)
132 #define LEADING_BYTE_JEF_CHINA3 (CHARSET_ID_OFFSET - 72)
134 #define MIN_LEADING_BYTE_PRIVATE MIN_LEADING_BYTE
135 #define MAX_LEADING_BYTE_PRIVATE (CHARSET_ID_OFFSET - 73)
138 /* #define CHARSET_ID_OFFSET_94 (CHARSET_ID_OFFSET - '0') */
140 /* #define MIN_CHARSET_ID_PRIVATE_94 (CHARSET_ID_OFFSET_94 + '0') */
141 /* #define MAX_CHARSET_ID_PRIVATE_94 (CHARSET_ID_OFFSET_94 + '?') */
144 #define LEADING_BYTE_ASCII 6 /* (CHARSET_ID_OFFSET_94 + 'B') */
146 /* Right half of JIS X0201-1976 */
147 #define LEADING_BYTE_KATAKANA_JISX0201 13 /* (CHARSET_ID_OFFSET_94 + 'I') */
149 /* Left half of JIS X0201-1976 */
150 #define LEADING_BYTE_LATIN_JISX0201 14 /* (CHARSET_ID_OFFSET_94 + 'J') */
153 /* #define CHARSET_ID_OFFSET_96 (CHARSET_ID_OFFSET_94 + 80) */
155 /* Right half of ISO 8859-1 */
156 #define LEADING_BYTE_LATIN_ISO8859_1 100 /* (CHARSET_ID_OFFSET_96 + 'A') */
158 /* Right half of ISO 8859-2 */
159 #define LEADING_BYTE_LATIN_ISO8859_2 101 /* (CHARSET_ID_OFFSET_96 + 'B') */
161 /* Right half of ISO 8859-3 */
162 #define LEADING_BYTE_LATIN_ISO8859_3 109 /* (CHARSET_ID_OFFSET_96 + 'C') */
164 /* Right half of ISO 8859-4 */
165 #define LEADING_BYTE_LATIN_ISO8859_4 110 /* (CHARSET_ID_OFFSET_96 + 'D') */
167 /* Right half of ISO 8859-7 */
168 #define LEADING_BYTE_GREEK_ISO8859_7 126 /* (CHARSET_ID_OFFSET_96 + 'F') */
170 /* Right half of ISO 8859-6 */
171 #define LEADING_BYTE_ARABIC_ISO8859_6 127 /* (CHARSET_ID_OFFSET_96 + 'G') */
173 /* Right half of ISO 8859-8 */
174 #define LEADING_BYTE_HEBREW_ISO8859_8 138 /* (CHARSET_ID_OFFSET_96 + 'H') */
176 /* Right half of ISO 8859-5 */
177 #define LEADING_BYTE_CYRILLIC_ISO8859_5 144 /* (CHARSET_ID_OFFSET_96 + 'L') */
179 /* Right half of ISO 8859-9 */
180 #define LEADING_BYTE_LATIN_ISO8859_9 148 /* (CHARSET_ID_OFFSET_96 + 'M') */
183 #define LEADING_BYTE_THAI_TIS620 166 /* (CHARSET_ID_OFFSET_96 + 'T') */
185 /* Right-hand Part of the VSCII-2 (TCVN 5712:1983) */
186 #define LEADING_BYTE_LATIN_TCVN5712 180 /* F = 5/10 0x5A `Z' */
189 /* #define CHARSET_ID_OFFSET_94x94 (CHARSET_ID_OFFSET_96 + 80) */
191 /* #define MIN_LEADING_BYTE_PRIVATE_2 ('0' + CHARSET_ID_OFFSET_94x94) */
192 /* #define MAX_LEADING_BYTE_PRIVATE_2 ('?' + CHARSET_ID_OFFSET_94x94) */
194 /* Japanese JIS X0208-1978 2/4 2/{(8),9,10,11} 4/0 (@) */
195 #define LEADING_BYTE_JAPANESE_JISX0208_1978 42
197 /* Chinese Hanzi GB2312-1980 2/4 2/{(8),9,10,11} 4/1 (A) */
198 #define LEADING_BYTE_CHINESE_GB2312 58
200 /* Japanese JIS X0208-1983 2/4 2/{(8),9,10,11} 4/2 (B) */
201 #define LEADING_BYTE_JAPANESE_JISX0208 87
203 /* Hangul KS C5601-1987 2/4 2/{8,9,10,11} 4/3 (C) */
204 #define LEADING_BYTE_KOREAN_KSC5601 149
206 /* Japanese JIS X0212-1990 2/4 2/{8,9,10,11} 4/4 (D) */
207 #define LEADING_BYTE_JAPANESE_JISX0212 159
209 /* CCITT Extended GB 2/4 2/{8,9,10,11} 4/5 (E) */
210 #define LEADING_BYTE_CHINESE_CCITT_GB 165
212 /* Chinese CNS11643 Set 1 2/4 2/{8,9,10,11} 4/7 (G) */
213 #define LEADING_BYTE_CHINESE_CNS11643_1 171
215 /* Chinese CNS11643 Set 2 2/4 2/{8,9,10,11} 4/8 (H) */
216 #define LEADING_BYTE_CHINESE_CNS11643_2 172
218 /* Chinese CNS11643 Set 3 2/4 2/{8,9,10,11} 4/9 (I) */
219 #define LEADING_BYTE_CHINESE_CNS11643_3 183
221 /* Chinese CNS11643 Set 4 2/4 2/{8,9,10,11} 4/10 (J) */
222 #define LEADING_BYTE_CHINESE_CNS11643_4 184
224 /* Chinese CNS11643 Set 5 2/4 2/{8,9,10,11} 4/11 (K) */
225 #define LEADING_BYTE_CHINESE_CNS11643_5 185
227 /* Chinese CNS11643 Set 6 2/4 2/{8,9,10,11} 4/12 (L) */
228 #define LEADING_BYTE_CHINESE_CNS11643_6 186
230 /* Chinese CNS11643 Set 7 2/4 2/{8,9,10,11} 4/13 (M) */
231 #define LEADING_BYTE_CHINESE_CNS11643_7 187
233 /* DPRK Hangul KPS 9566-1997 2/4 2/{8,9,10,11} 4/14 (N) */
234 #define LEADING_BYTE_KOREAN_KPS9566 202
237 #define NUM_LEADING_BYTES (80 * 3 - MIN_LEADING_BYTE)
240 /************************************************************************/
241 /* Information about a particular character set */
242 /************************************************************************/
246 struct lcrecord_header header;
250 Lisp_Object doc_string;
251 Lisp_Object registry;
252 Lisp_Object short_name;
253 Lisp_Object long_name;
255 Lisp_Object reverse_direction_charset;
257 Lisp_Object ccl_program;
259 /* Final byte of this character set in ISO2022 designating escape sequence */
262 /* Number of columns a character in this charset takes up, on TTY
263 devices. Not used for X devices. */
264 unsigned int columns;
266 /* Direction of this character set */
267 unsigned int direction;
269 /* Number of bytes used in encoding of this character set (1 .. 4) */
270 unsigned short dimension;
272 /* Number of chars in each dimension (94, 96, 128, 256) */
273 unsigned short chars;
275 /* Which half of font to be used to display this character set */
276 unsigned int graphic;
278 /* Code-point->character mapping table */
279 Lisp_Object decoding_table;
281 /* Character->code-point mapping table */
282 Lisp_Object encoding_table;
284 /* Range of character code */
285 Emchar ucs_min, ucs_max;
287 /* Offset for external code */
290 /* Offset for each byte */
293 typedef struct Lisp_Charset Lisp_Charset;
295 DECLARE_LRECORD (charset, Lisp_Charset);
296 #define XCHARSET(x) XRECORD (x, charset, Lisp_Charset)
297 #define XSETCHARSET(x, p) XSETRECORD (x, p, charset)
298 #define CHARSETP(x) RECORDP (x, charset)
299 #define GC_CHARSETP(x) GC_RECORDP (x, charset)
300 #define CHECK_CHARSET(x) CHECK_RECORD (x, charset)
301 #define CONCHECK_CHARSET(x) CONCHECK_RECORD (x, charset)
303 #define CHARSET_LEFT_TO_RIGHT 0
304 #define CHARSET_RIGHT_TO_LEFT 1
306 /* Leading byte and id have been regrouped. -- OG */
307 #define CHARSET_ID(cs) ((cs)->id)
308 #define CHARSET_LEADING_BYTE(cs) (CHARSET_ID(cs))
309 #define CHARSET_NAME(cs) ((cs)->name)
310 #define CHARSET_SHORT_NAME(cs) ((cs)->short_name)
311 #define CHARSET_LONG_NAME(cs) ((cs)->long_name)
312 #define CHARSET_COLUMNS(cs) ((cs)->columns)
313 #define CHARSET_GRAPHIC(cs) ((cs)->graphic)
314 #define CHARSET_DIRECTION(cs) ((cs)->direction)
315 #define CHARSET_FINAL(cs) ((cs)->final)
316 #define CHARSET_DOC_STRING(cs) ((cs)->doc_string)
317 #define CHARSET_REGISTRY(cs) ((cs)->registry)
318 #define CHARSET_CCL_PROGRAM(cs) ((cs)->ccl_program)
319 #define CHARSET_DIMENSION(cs) ((cs)->dimension)
320 #define CHARSET_CHARS(cs) ((cs)->chars)
321 #define CHARSET_REVERSE_DIRECTION_CHARSET(cs) ((cs)->reverse_direction_charset)
322 #define CHARSET_DECODING_TABLE(cs) ((cs)->decoding_table)
323 #define CHARSET_ENCODING_TABLE(cs) ((cs)->encoding_table)
324 #define CHARSET_UCS_MIN(cs) ((cs)->ucs_min)
325 #define CHARSET_UCS_MAX(cs) ((cs)->ucs_max)
326 #define CHARSET_CODE_OFFSET(cs) ((cs)->code_offset)
327 #define CHARSET_BYTE_OFFSET(cs) ((cs)->byte_offset)
330 #define XCHARSET_ID(cs) CHARSET_ID (XCHARSET (cs))
331 #define XCHARSET_NAME(cs) CHARSET_NAME (XCHARSET (cs))
332 #define XCHARSET_SHORT_NAME(cs) CHARSET_SHORT_NAME (XCHARSET (cs))
333 #define XCHARSET_LONG_NAME(cs) CHARSET_LONG_NAME (XCHARSET (cs))
334 #define XCHARSET_GRAPHIC(cs) CHARSET_GRAPHIC (XCHARSET (cs))
335 #define XCHARSET_DIRECTION(cs) CHARSET_DIRECTION (XCHARSET (cs))
336 #define XCHARSET_FINAL(cs) CHARSET_FINAL (XCHARSET (cs))
337 #define XCHARSET_DOC_STRING(cs) CHARSET_DOC_STRING (XCHARSET (cs))
338 #define XCHARSET_REGISTRY(cs) CHARSET_REGISTRY (XCHARSET (cs))
339 #define XCHARSET_LEADING_BYTE(cs) CHARSET_LEADING_BYTE (XCHARSET (cs))
340 #define XCHARSET_CCL_PROGRAM(cs) CHARSET_CCL_PROGRAM (XCHARSET (cs))
341 #define XCHARSET_DIMENSION(cs) CHARSET_DIMENSION (XCHARSET (cs))
342 #define XCHARSET_CHARS(cs) CHARSET_CHARS (XCHARSET (cs))
343 #define XCHARSET_REVERSE_DIRECTION_CHARSET(cs) \
344 CHARSET_REVERSE_DIRECTION_CHARSET (XCHARSET (cs))
345 #define XCHARSET_DECODING_TABLE(cs) CHARSET_DECODING_TABLE(XCHARSET(cs))
346 #define XCHARSET_ENCODING_TABLE(cs) CHARSET_ENCODING_TABLE(XCHARSET(cs))
347 #define XCHARSET_UCS_MIN(cs) CHARSET_UCS_MIN(XCHARSET(cs))
348 #define XCHARSET_UCS_MAX(cs) CHARSET_UCS_MAX(XCHARSET(cs))
349 #define XCHARSET_CODE_OFFSET(cs) CHARSET_CODE_OFFSET(XCHARSET(cs))
350 #define XCHARSET_BYTE_OFFSET(cs) CHARSET_BYTE_OFFSET(XCHARSET(cs))
352 struct charset_lookup {
353 /* Table of charsets indexed by (leading byte - 128). */
354 Lisp_Object charset_by_leading_byte[NUM_LEADING_BYTES];
356 /* Table of charsets indexed by type/final-byte/direction. */
357 Lisp_Object charset_by_attributes[4][128];
359 Charset_ID next_allocated_leading_byte;
362 extern struct charset_lookup *chlook;
364 #ifdef ERROR_CHECK_TYPECHECK
365 /* int not Bufbyte even though that is the actual type of a leading byte.
366 This way, out-ot-range values will get caught rather than automatically
368 INLINE_HEADER Lisp_Object CHARSET_BY_LEADING_BYTE (Charset_ID lb);
369 INLINE_HEADER Lisp_Object
370 CHARSET_BY_LEADING_BYTE (Charset_ID lb)
372 assert (lb >= MIN_LEADING_BYTE &&
373 lb < (MIN_LEADING_BYTE + NUM_LEADING_BYTES));
374 return chlook->charset_by_leading_byte[lb - MIN_LEADING_BYTE];
379 #define CHARSET_BY_LEADING_BYTE(lb) \
380 (chlook->charset_by_leading_byte[(lb) - MIN_LEADING_BYTE])
384 INLINE_HEADER Lisp_Object
385 CHARSET_BY_ATTRIBUTES (int chars, int dimension, int final, int dir);
386 INLINE_HEADER Lisp_Object
387 CHARSET_BY_ATTRIBUTES (int chars, int dimension, int final, int dir)
393 else if (chars == 96)
397 type += dimension == 1 ? 0 : 2;
398 return chlook->charset_by_attributes[type][final];
402 /************************************************************************/
403 /* Dealing with characters */
404 /************************************************************************/
406 #define MAX_CHAR_BASIC_LATIN 0x007F
409 #define MIN_CHAR_HEBREW 0x0590
410 #define MAX_CHAR_HEBREW 0x05EF
413 #define MIN_CHAR_THAI 0x0E00
414 #define MAX_CHAR_THAI 0x0E5F
417 #define MIN_CHAR_HIRAGANA 0x3041
418 #define MAX_CHAR_HIRAGANA 0x3093
420 #define MIN_CHAR_KATAKANA 0x30A1
421 #define MAX_CHAR_KATAKANA 0x30F6
424 #define MIN_CHAR_HALFWIDTH_KATAKANA 0xFF61
425 #define MAX_CHAR_HALFWIDTH_KATAKANA 0xFF9F
427 #define MAX_CHAR_BMP 0x00FFFF
429 #define MIN_CHAR_DAIKANWA 0x00E00000
430 #define MAX_CHAR_DAIKANWA (MIN_CHAR_DAIKANWA + 50100) /* 0xE0FFFF */
431 #define MIN_CHAR_MOJIKYO_0 MIN_CHAR_DAIKANWA
432 #define MAX_CHAR_MOJIKYO_0 (MIN_CHAR_MOJIKYO_0 + 94 * 60 * 22)
434 #define MIN_CHAR_94 0xE90940
435 #define MAX_CHAR_94 (MIN_CHAR_94 + 94 * 80 - 1)
436 #define MIN_CHAR_96 (MIN_CHAR_94 + 94 * 80)
437 #define MAX_CHAR_96 (MIN_CHAR_96 + 96 * 80 - 1)
439 #define MIN_CHAR_94x94 0xE9F6C0
440 #define MIN_CHAR_JIS_X0208_1990 (MIN_CHAR_94x94 + 94 * 94 * 79)
441 #define MAX_CHAR_94x94 (MIN_CHAR_94x94 + 94 * 94 * 80 - 1)
442 #define MAX_CHAR_JIS_X0208_1990 MAX_CHAR_94x94
443 #define MIN_CHAR_96x96 0xF4C000
444 #define MAX_CHAR_96x96 (MIN_CHAR_96x96 + 96 * 96 * 80 - 1)
446 #define MIN_CHAR_MOJIKYO 0x60000000
447 #define MAX_CHAR_MOJIKYO (MIN_CHAR_MOJIKYO + 94 * 60 * 22)
448 #define MIN_CHAR_GT 0x61000000
449 #define MAX_CHAR_GT (MIN_CHAR_GT + 66773)
450 #define MIN_CHAR_JEF_CHINA3 0x62000000
451 #define MAX_CHAR_JEF_CHINA3 (MIN_CHAR_JEF_CHINA3 + 65535)
453 Emchar decode_builtin_char (Lisp_Object charset, int code_point);
456 DECODE_MOJIKYO_2022 (unsigned char b1, unsigned char b2, unsigned char b3);
458 DECODE_MOJIKYO_2022 (unsigned char b1, unsigned char b2, unsigned char b3)
462 else if (b2 < 16 + 32 + 30)
464 (b1 - 33) * (94 * 60)
465 + (b2 - (16 + 32)) * 94
468 else if (b2 < 18 + 32 + 30)
470 else if (b2 < 18 + 32 + 60)
472 (b1 - 33) * (94 * 60)
473 + (b2 - (18 + 32)) * 94
480 extern Lisp_Object Vcharset_chinese_big5;
481 extern Lisp_Object Vcharset_chinese_big5_1;
482 extern Lisp_Object Vcharset_chinese_big5_2;
484 INLINE_HEADER Emchar DECODE_CHAR (Lisp_Object charset, int code_point);
486 DECODE_CHAR (Lisp_Object charset, int code_point)
488 int dim = XCHARSET_DIMENSION (charset);
489 Lisp_Object decoding_table = XCHARSET_DECODING_TABLE (charset);
496 if ( VECTORP (decoding_table)
497 && ( 0 <= (idx = ((code_point >> (dim * 8))
498 & 255) - XCHARSET_BYTE_OFFSET (charset)) )
499 && ( idx < XVECTOR_LENGTH (decoding_table) )
500 && !NILP (ch = XVECTOR_DATA(decoding_table)[idx]) )
510 if (XCHARSET_DIMENSION (charset) == 1)
511 return decode_builtin_char (charset, code_point);
512 else if (EQ (charset, Vcharset_chinese_big5_1))
515 = ((code_point >> 8) - 33) * (0xFF - 0xA1)
516 + ((code_point & 0xFF) - 33);
517 unsigned char b1 = I / (0xFF - 0xA1 + 0x7F - 0x40) + 0xA1;
518 unsigned char b2 = I % (0xFF - 0xA1 + 0x7F - 0x40);
520 b2 += b2 < 0x3F ? 0x40 : 0x62;
521 return DECODE_CHAR (Vcharset_chinese_big5, (b1 << 8) | b2);
523 else if (EQ (charset, Vcharset_chinese_big5_2))
526 = ((code_point >> 8) - 33) * (0xFF - 0xA1)
527 + ((code_point & 0xFF) - 33);
528 unsigned char b1, b2;
530 I += (0xFF - 0xA1 + 0x7F - 0x40) * (0xC9 - 0xA1);
531 b1 = I / (0xFF - 0xA1 + 0x7F - 0x40) + 0xA1;
532 b2 = I % (0xFF - 0xA1 + 0x7F - 0x40);
533 b2 += b2 < 0x3F ? 0x40 : 0x62;
534 return DECODE_CHAR (Vcharset_chinese_big5, (b1 << 8) | b2);
536 else if (EQ (charset, Vcharset_mojikyo_2022_1))
540 ((unsigned char)(code_point >> 16),
541 (unsigned char)(code_point >> 8),
542 (unsigned char) code_point);
545 return DECODE_CHAR (Vcharset_mojikyo, m);
551 int plane = LEADING_BYTE_MOJIKYO_PJ_1 - XCHARSET_ID (charset);
553 if ( (0 <= plane) && (plane < 21) )
555 int m = DECODE_MOJIKYO_2022 (plane + 33,
557 (unsigned char)code_point);
559 return DECODE_CHAR (Vcharset_mojikyo, m);
564 return decode_builtin_char (charset, code_point);
568 /* Return a character whose charset is CHARSET and position-codes
569 are C1 and C2. TYPE9N character ignores C2. */
571 INLINE_HEADER Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2);
573 MAKE_CHAR (Lisp_Object charset, int c1, int c2)
575 if (XCHARSET_DIMENSION (charset) == 1)
576 return DECODE_CHAR (charset, c1);
578 return DECODE_CHAR (charset, (c1 << 8) | c2);
581 extern Lisp_Object Vcharacter_attribute_table;
583 int encode_builtin_char_1 (Emchar c, Lisp_Object* charset);
584 int range_charset_code_point (Lisp_Object charset, Emchar ch);
586 INLINE_HEADER int charset_code_point (Lisp_Object charset, Emchar ch);
588 charset_code_point (Lisp_Object charset, Emchar ch)
590 Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (charset);
593 if ( CHAR_TABLEP (encoding_table)
594 && INTP (ret = get_char_id_table (XCHAR_TABLE(encoding_table),
598 return range_charset_code_point (charset, ch);
601 extern Lisp_Object Vdefault_coded_charset_priority_list;
602 EXFUN (Ffind_charset, 1);
604 INLINE_HEADER int encode_char_1 (Emchar ch, Lisp_Object* charset);
606 encode_char_1 (Emchar ch, Lisp_Object* charset)
608 Lisp_Object charsets = Vdefault_coded_charset_priority_list;
610 while (!NILP (charsets))
612 *charset = Ffind_charset (Fcar (charsets));
613 if (!NILP (*charset))
615 Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (*charset);
618 if ( CHAR_TABLEP (encoding_table)
620 = get_char_id_table (XCHAR_TABLE(encoding_table),
625 int code_point = range_charset_code_point (*charset, ch);
631 charsets = Fcdr (charsets);
634 /* otherwise --- maybe for bootstrap */
635 return encode_builtin_char_1 (ch, charset);
638 #define ENCODE_CHAR(ch, charset) encode_char_1 (ch, &(charset))
641 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2);
643 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
645 int code_point = encode_char_1 (c, charset);
649 int dim = XCHARSET_DIMENSION (*charset);
656 else /* if (dim == 2) */
658 *c1 = code_point >> 8;
659 *c2 = code_point & 255;
667 #define BREAKUP_CHAR(ch, charset, b1, b2) \
668 breakup_char_1 (ch, &(charset), &(b1), &(b2))
670 INLINE_HEADER Lisp_Object CHAR_CHARSET (Emchar ch);
671 INLINE_HEADER Lisp_Object
672 CHAR_CHARSET (Emchar ch)
676 ENCODE_CHAR (ch, charset);
680 #define CHAR_CHARSET_ID(c) (XCHARSET_ID(CHAR_CHARSET(c)))
681 #define CHAR_COLUMNS(c) (CHARSET_COLUMNS(XCHARSET(CHAR_CHARSET(c))))
690 INLINE_HEADER Charc CHAR_TO_CHARC (Emchar ch);
692 CHAR_TO_CHARC (Emchar ch)
696 cc.code_point = encode_char_1 (ch, &cc.charset);
697 if (EQ (cc.charset, Vcharset_mojikyo))
699 int plane, byte1, byte2;
702 plane = cc.code_point / (94 * 60);
703 byte1 = (cc.code_point % (94 * 60)) / 94;
708 byte2 = cc.code_point % 94 + 33;
710 = CHARSET_BY_LEADING_BYTE (LEADING_BYTE_MOJIKYO_PJ_1 - plane);
711 cc.code_point = (byte1 << 8) | byte2;
717 /************************************************************************/
718 /* Exported functions */
719 /************************************************************************/
721 EXFUN (Fget_charset, 1);
723 extern Lisp_Object Qucs;
725 extern Lisp_Object Vcharset_japanese_jisx0208;
726 extern Lisp_Object Vcharset_japanese_jisx0208_1990;
727 extern Lisp_Object Vcharset_japanese_jisx0212;
729 Lisp_Object put_char_ccs_code_point (Lisp_Object character,
730 Lisp_Object ccs, Lisp_Object value);
731 Lisp_Object remove_char_ccs (Lisp_Object character, Lisp_Object ccs);
733 #endif /* INCLUDED_char_ucs_h_ */