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_
24 #define valid_char_p(ch) 1
26 #define CHAR_ASCII_P(ch) ((ch) <= 0x7F)
29 /************************************************************************/
31 /************************************************************************/
33 struct Lisp_Uint8_Byte_Table
35 struct lcrecord_header header;
37 unsigned char property[256];
39 typedef struct Lisp_Uint8_Byte_Table Lisp_Uint8_Byte_Table;
41 DECLARE_LRECORD (uint8_byte_table, Lisp_Uint8_Byte_Table);
42 #define XUINT8_BYTE_TABLE(x) \
43 XRECORD (x, uint8_byte_table, Lisp_Uint8_Byte_Table)
44 #define XSETUINT8_BYTE_TABLE(x, p) XSETRECORD (x, p, uint8_byte_table)
45 #define UINT8_BYTE_TABLE_P(x) RECORDP (x, uint8_byte_table)
46 #define GC_UINT8_BYTE_TABLE_P(x) GC_RECORDP (x, uint8_byte_table)
47 /* #define CHECK_UINT8_BYTE_TABLE(x) CHECK_RECORD (x, uint8_byte_table)
48 char table entries should never escape to Lisp */
51 struct Lisp_Uint16_Byte_Table
53 struct lcrecord_header header;
55 unsigned short property[256];
57 typedef struct Lisp_Uint16_Byte_Table Lisp_Uint16_Byte_Table;
59 DECLARE_LRECORD (uint16_byte_table, Lisp_Uint16_Byte_Table);
60 #define XUINT16_BYTE_TABLE(x) \
61 XRECORD (x, uint16_byte_table, Lisp_Uint16_Byte_Table)
62 #define XSETUINT16_BYTE_TABLE(x, p) XSETRECORD (x, p, uint16_byte_table)
63 #define UINT16_BYTE_TABLE_P(x) RECORDP (x, uint16_byte_table)
64 #define GC_UINT16_BYTE_TABLE_P(x) GC_RECORDP (x, uint16_byte_table)
65 /* #define CHECK_UINT16_BYTE_TABLE(x) CHECK_RECORD (x, uint16_byte_table)
66 char table entries should never escape to Lisp */
69 struct Lisp_Byte_Table
71 struct lcrecord_header header;
73 Lisp_Object property[256];
75 typedef struct Lisp_Byte_Table Lisp_Byte_Table;
77 DECLARE_LRECORD (byte_table, Lisp_Byte_Table);
78 #define XBYTE_TABLE(x) XRECORD (x, byte_table, Lisp_Byte_Table)
79 #define XSETBYTE_TABLE(x, p) XSETRECORD (x, p, byte_table)
80 #define BYTE_TABLE_P(x) RECORDP (x, byte_table)
81 #define GC_BYTE_TABLE_P(x) GC_RECORDP (x, byte_table)
82 /* #define CHECK_BYTE_TABLE(x) CHECK_RECORD (x, byte_table)
83 char table entries should never escape to Lisp */
86 struct Lisp_Char_ID_Table
88 struct lcrecord_header header;
92 typedef struct Lisp_Char_ID_Table Lisp_Char_ID_Table;
94 DECLARE_LRECORD (char_id_table, Lisp_Char_ID_Table);
95 #define XCHAR_ID_TABLE(x) XRECORD (x, char_id_table, Lisp_Char_ID_Table)
96 #define XSETCHAR_ID_TABLE(x, p) XSETRECORD (x, p, char_id_table)
97 #define CHAR_ID_TABLE_P(x) RECORDP (x, char_id_table)
98 #define GC_CHAR_ID_TABLE_P(x) GC_RECORDP (x, char_id_table)
99 /* #define CHECK_CHAR_ID_TABLE(x) CHECK_RECORD (x, char_id_table)
100 char table entries should never escape to Lisp */
103 Lisp_Object get_char_id_table (Emchar ch, Lisp_Object table);
106 extern Lisp_Object Vcharset_mojikyo;
107 extern Lisp_Object Vcharset_mojikyo_2022_1;
108 extern Lisp_Object Vcharset_latin_jisx0201;
111 /************************************************************************/
112 /* Definition of leading bytes */
113 /************************************************************************/
115 typedef short Charset_ID;
117 #define MIN_LEADING_BYTE -0x70
118 #define CHARSET_ID_OFFSET 0x00
121 #define LEADING_BYTE_UCS (CHARSET_ID_OFFSET - 1)
123 /* represent normal 80-9F */
124 #define LEADING_BYTE_CONTROL_1 (CHARSET_ID_OFFSET - 2)
126 /* ISO/IEC 10646 BMP */
127 #define LEADING_BYTE_UCS_BMP (CHARSET_ID_OFFSET - 3)
129 /* ISO/IEC 10646 for CNS */
130 #define LEADING_BYTE_UCS_CNS (CHARSET_ID_OFFSET - 5)
132 /* ISO/IEC 10646 for JIS */
133 #define LEADING_BYTE_UCS_JIS (CHARSET_ID_OFFSET - 6)
135 /* ISO/IEC 10646 for Big5 */
136 #define LEADING_BYTE_UCS_BIG5 (CHARSET_ID_OFFSET - 9)
138 /* Japanese JIS X0208-1990 2/4 2/{(8),9,10,11} 4/2 (B) */
139 #define LEADING_BYTE_JAPANESE_JISX0208_1990 (CHARSET_ID_OFFSET - 10)
141 /* Chinese GB 12345-1990 */
142 #define LEADING_BYTE_CHINESE_GB12345 (CHARSET_ID_OFFSET - 11)
144 #define LEADING_BYTE_CHINESE_BIG5 (CHARSET_ID_OFFSET - 20)
146 /* Big5 Level 1 2/4 2/{(8),9,10,11} 4/0 '0' */
147 #define LEADING_BYTE_CHINESE_BIG5_1 (CHARSET_ID_OFFSET - 21)
149 /* Big5 Level 2 2/4 2/{(8),9,10,11} 4/0 '1' */
150 #define LEADING_BYTE_CHINESE_BIG5_2 (CHARSET_ID_OFFSET - 22)
152 #define LEADING_BYTE_CHINESE_BIG5_CDP (CHARSET_ID_OFFSET - 23)
155 #define LEADING_BYTE_LATIN_VISCII (CHARSET_ID_OFFSET - 24)
157 /* MULE VISCII-LOWER (CHARSET_ID_OFFSET_96 + '1') */
158 #define LEADING_BYTE_LATIN_VISCII_LOWER (CHARSET_ID_OFFSET - 25)
160 /* MULE VISCII-UPPER (CHARSET_ID_OFFSET_96 + '2') */
161 #define LEADING_BYTE_LATIN_VISCII_UPPER (CHARSET_ID_OFFSET - 26)
163 #define LEADING_BYTE_ETHIOPIC_UCS (CHARSET_ID_OFFSET - 27)
165 #define LEADING_BYTE_DAIKANWA (CHARSET_ID_OFFSET - 28)
166 #define LEADING_BYTE_DAIKANWA_EKANJI (CHARSET_ID_OFFSET - 29)
168 #define LEADING_BYTE_GT (CHARSET_ID_OFFSET - 30)
169 #define LEADING_BYTE_GT_PJ_1 (CHARSET_ID_OFFSET - 31)
170 #define LEADING_BYTE_GT_PJ_2 (CHARSET_ID_OFFSET - 32)
171 #define LEADING_BYTE_GT_PJ_3 (CHARSET_ID_OFFSET - 33)
172 #define LEADING_BYTE_GT_PJ_4 (CHARSET_ID_OFFSET - 34)
173 #define LEADING_BYTE_GT_PJ_5 (CHARSET_ID_OFFSET - 35)
174 #define LEADING_BYTE_GT_PJ_6 (CHARSET_ID_OFFSET - 36)
175 #define LEADING_BYTE_GT_PJ_7 (CHARSET_ID_OFFSET - 37)
176 #define LEADING_BYTE_GT_PJ_8 (CHARSET_ID_OFFSET - 38)
177 #define LEADING_BYTE_GT_PJ_9 (CHARSET_ID_OFFSET - 39)
178 #define LEADING_BYTE_GT_PJ_10 (CHARSET_ID_OFFSET - 40)
179 #define LEADING_BYTE_GT_PJ_11 (CHARSET_ID_OFFSET - 41)
181 #define LEADING_BYTE_MOJIKYO (CHARSET_ID_OFFSET - 48)
182 #define LEADING_BYTE_MOJIKYO_2022_1 (CHARSET_ID_OFFSET - 49)
183 #define LEADING_BYTE_MOJIKYO_2022_2 (CHARSET_ID_OFFSET - 50)
185 /* Konjaku-Mojikyo font (for pseudo-JIS X 0208 encoding) */
186 #define LEADING_BYTE_MOJIKYO_PJ_1 (CHARSET_ID_OFFSET - 51)
187 #define LEADING_BYTE_MOJIKYO_PJ_2 (CHARSET_ID_OFFSET - 52)
188 #define LEADING_BYTE_MOJIKYO_PJ_3 (CHARSET_ID_OFFSET - 53)
189 #define LEADING_BYTE_MOJIKYO_PJ_4 (CHARSET_ID_OFFSET - 54)
190 #define LEADING_BYTE_MOJIKYO_PJ_5 (CHARSET_ID_OFFSET - 55)
191 #define LEADING_BYTE_MOJIKYO_PJ_6 (CHARSET_ID_OFFSET - 56)
192 #define LEADING_BYTE_MOJIKYO_PJ_7 (CHARSET_ID_OFFSET - 57)
193 #define LEADING_BYTE_MOJIKYO_PJ_8 (CHARSET_ID_OFFSET - 58)
194 #define LEADING_BYTE_MOJIKYO_PJ_9 (CHARSET_ID_OFFSET - 59)
195 #define LEADING_BYTE_MOJIKYO_PJ_10 (CHARSET_ID_OFFSET - 60)
196 #define LEADING_BYTE_MOJIKYO_PJ_11 (CHARSET_ID_OFFSET - 61)
197 #define LEADING_BYTE_MOJIKYO_PJ_12 (CHARSET_ID_OFFSET - 62)
198 #define LEADING_BYTE_MOJIKYO_PJ_13 (CHARSET_ID_OFFSET - 63)
199 #define LEADING_BYTE_MOJIKYO_PJ_14 (CHARSET_ID_OFFSET - 64)
200 #define LEADING_BYTE_MOJIKYO_PJ_15 (CHARSET_ID_OFFSET - 65)
201 #define LEADING_BYTE_MOJIKYO_PJ_16 (CHARSET_ID_OFFSET - 66)
202 #define LEADING_BYTE_MOJIKYO_PJ_17 (CHARSET_ID_OFFSET - 67)
203 #define LEADING_BYTE_MOJIKYO_PJ_18 (CHARSET_ID_OFFSET - 68)
204 #define LEADING_BYTE_MOJIKYO_PJ_19 (CHARSET_ID_OFFSET - 69)
205 #define LEADING_BYTE_MOJIKYO_PJ_20 (CHARSET_ID_OFFSET - 70)
206 #define LEADING_BYTE_MOJIKYO_PJ_21 (CHARSET_ID_OFFSET - 71)
208 #define MIN_LEADING_BYTE_PRIVATE MIN_LEADING_BYTE
209 #define MAX_LEADING_BYTE_PRIVATE (CHARSET_ID_OFFSET - 72)
212 /* #define CHARSET_ID_OFFSET_94 (CHARSET_ID_OFFSET - '0') */
214 /* #define MIN_CHARSET_ID_PRIVATE_94 (CHARSET_ID_OFFSET_94 + '0') */
215 /* #define MAX_CHARSET_ID_PRIVATE_94 (CHARSET_ID_OFFSET_94 + '?') */
218 #define LEADING_BYTE_ASCII 6 /* (CHARSET_ID_OFFSET_94 + 'B') */
220 /* Right half of JIS X0201-1976 */
221 #define LEADING_BYTE_KATAKANA_JISX0201 13 /* (CHARSET_ID_OFFSET_94 + 'I') */
223 /* Left half of JIS X0201-1976 */
224 #define LEADING_BYTE_LATIN_JISX0201 14 /* (CHARSET_ID_OFFSET_94 + 'J') */
227 /* #define CHARSET_ID_OFFSET_96 (CHARSET_ID_OFFSET_94 + 80) */
229 /* Right half of ISO 8859-1 */
230 #define LEADING_BYTE_LATIN_ISO8859_1 100 /* (CHARSET_ID_OFFSET_96 + 'A') */
232 /* Right half of ISO 8859-2 */
233 #define LEADING_BYTE_LATIN_ISO8859_2 101 /* (CHARSET_ID_OFFSET_96 + 'B') */
235 /* Right half of ISO 8859-3 */
236 #define LEADING_BYTE_LATIN_ISO8859_3 109 /* (CHARSET_ID_OFFSET_96 + 'C') */
238 /* Right half of ISO 8859-4 */
239 #define LEADING_BYTE_LATIN_ISO8859_4 110 /* (CHARSET_ID_OFFSET_96 + 'D') */
241 /* Right half of ISO 8859-7 */
242 #define LEADING_BYTE_GREEK_ISO8859_7 126 /* (CHARSET_ID_OFFSET_96 + 'F') */
244 /* Right half of ISO 8859-6 */
245 #define LEADING_BYTE_ARABIC_ISO8859_6 127 /* (CHARSET_ID_OFFSET_96 + 'G') */
247 /* Right half of ISO 8859-8 */
248 #define LEADING_BYTE_HEBREW_ISO8859_8 138 /* (CHARSET_ID_OFFSET_96 + 'H') */
250 /* Right half of ISO 8859-5 */
251 #define LEADING_BYTE_CYRILLIC_ISO8859_5 144 /* (CHARSET_ID_OFFSET_96 + 'L') */
253 /* Right half of ISO 8859-9 */
254 #define LEADING_BYTE_LATIN_ISO8859_9 148 /* (CHARSET_ID_OFFSET_96 + 'M') */
257 #define LEADING_BYTE_THAI_TIS620 166 /* (CHARSET_ID_OFFSET_96 + 'T') */
259 /* Right-hand Part of the VSCII-2 (TCVN 5712:1983) */
260 #define LEADING_BYTE_LATIN_TCVN5712 180 /* F = 5/10 0x5A `Z' */
263 /* #define CHARSET_ID_OFFSET_94x94 (CHARSET_ID_OFFSET_96 + 80) */
265 /* #define MIN_LEADING_BYTE_PRIVATE_2 ('0' + CHARSET_ID_OFFSET_94x94) */
266 /* #define MAX_LEADING_BYTE_PRIVATE_2 ('?' + CHARSET_ID_OFFSET_94x94) */
268 /* Japanese JIS X0208-1978 2/4 2/{(8),9,10,11} 4/0 (@) */
269 #define LEADING_BYTE_JAPANESE_JISX0208_1978 42
271 /* Chinese Hanzi GB2312-1980 2/4 2/{(8),9,10,11} 4/1 (A) */
272 #define LEADING_BYTE_CHINESE_GB2312 58
274 /* Japanese JIS X0208-1983 2/4 2/{(8),9,10,11} 4/2 (B) */
275 #define LEADING_BYTE_JAPANESE_JISX0208 87
277 /* Hangul KS C5601-1987 2/4 2/{8,9,10,11} 4/3 (C) */
278 #define LEADING_BYTE_KOREAN_KSC5601 149
280 /* Japanese JIS X0212-1990 2/4 2/{8,9,10,11} 4/4 (D) */
281 #define LEADING_BYTE_JAPANESE_JISX0212 159
283 /* CCITT Extended GB 2/4 2/{8,9,10,11} 4/5 (E) */
284 #define LEADING_BYTE_CHINESE_CCITT_GB 165
286 /* Chinese CNS11643 Set 1 2/4 2/{8,9,10,11} 4/7 (G) */
287 #define LEADING_BYTE_CHINESE_CNS11643_1 171
289 /* Chinese CNS11643 Set 2 2/4 2/{8,9,10,11} 4/8 (H) */
290 #define LEADING_BYTE_CHINESE_CNS11643_2 172
292 /* Chinese CNS11643 Set 3 2/4 2/{8,9,10,11} 4/9 (I) */
293 #define LEADING_BYTE_CHINESE_CNS11643_3 183
295 /* Chinese CNS11643 Set 4 2/4 2/{8,9,10,11} 4/10 (J) */
296 #define LEADING_BYTE_CHINESE_CNS11643_4 184
298 /* Chinese CNS11643 Set 5 2/4 2/{8,9,10,11} 4/11 (K) */
299 #define LEADING_BYTE_CHINESE_CNS11643_5 185
301 /* Chinese CNS11643 Set 6 2/4 2/{8,9,10,11} 4/12 (L) */
302 #define LEADING_BYTE_CHINESE_CNS11643_6 186
304 /* Chinese CNS11643 Set 7 2/4 2/{8,9,10,11} 4/13 (M) */
305 #define LEADING_BYTE_CHINESE_CNS11643_7 187
307 /* DPRK Hangul KPS 9566-1997 2/4 2/{8,9,10,11} 4/14 (N) */
308 #define LEADING_BYTE_KOREAN_KPS9566 202
311 #define NUM_LEADING_BYTES (80 * 3 - MIN_LEADING_BYTE)
314 /************************************************************************/
315 /* Information about a particular character set */
316 /************************************************************************/
320 struct lcrecord_header header;
324 Lisp_Object doc_string;
325 Lisp_Object registry;
326 Lisp_Object short_name;
327 Lisp_Object long_name;
329 Lisp_Object reverse_direction_charset;
331 Lisp_Object ccl_program;
333 /* Final byte of this character set in ISO2022 designating escape sequence */
336 /* Number of columns a character in this charset takes up, on TTY
337 devices. Not used for X devices. */
338 unsigned int columns;
340 /* Direction of this character set */
341 unsigned int direction;
343 /* Number of bytes used in encoding of this character set (1 .. 4) */
344 unsigned short dimension;
346 /* Number of chars in each dimension (94, 96, 128, 256) */
347 unsigned short chars;
349 /* Which half of font to be used to display this character set */
350 unsigned int graphic;
352 /* Code-point->character mapping table */
353 Lisp_Object decoding_table;
355 /* Character->code-point mapping table */
356 Lisp_Object encoding_table;
358 /* Range of character code */
359 Emchar ucs_min, ucs_max;
361 /* Offset for external code */
364 /* Offset for each byte */
367 typedef struct Lisp_Charset Lisp_Charset;
369 DECLARE_LRECORD (charset, Lisp_Charset);
370 #define XCHARSET(x) XRECORD (x, charset, Lisp_Charset)
371 #define XSETCHARSET(x, p) XSETRECORD (x, p, charset)
372 #define CHARSETP(x) RECORDP (x, charset)
373 #define GC_CHARSETP(x) GC_RECORDP (x, charset)
374 #define CHECK_CHARSET(x) CHECK_RECORD (x, charset)
375 #define CONCHECK_CHARSET(x) CONCHECK_RECORD (x, charset)
377 #define CHARSET_LEFT_TO_RIGHT 0
378 #define CHARSET_RIGHT_TO_LEFT 1
380 /* Leading byte and id have been regrouped. -- OG */
381 #define CHARSET_ID(cs) ((cs)->id)
382 #define CHARSET_LEADING_BYTE(cs) (CHARSET_ID(cs))
383 #define CHARSET_NAME(cs) ((cs)->name)
384 #define CHARSET_SHORT_NAME(cs) ((cs)->short_name)
385 #define CHARSET_LONG_NAME(cs) ((cs)->long_name)
386 #define CHARSET_COLUMNS(cs) ((cs)->columns)
387 #define CHARSET_GRAPHIC(cs) ((cs)->graphic)
388 #define CHARSET_DIRECTION(cs) ((cs)->direction)
389 #define CHARSET_FINAL(cs) ((cs)->final)
390 #define CHARSET_DOC_STRING(cs) ((cs)->doc_string)
391 #define CHARSET_REGISTRY(cs) ((cs)->registry)
392 #define CHARSET_CCL_PROGRAM(cs) ((cs)->ccl_program)
393 #define CHARSET_DIMENSION(cs) ((cs)->dimension)
394 #define CHARSET_CHARS(cs) ((cs)->chars)
395 #define CHARSET_REVERSE_DIRECTION_CHARSET(cs) ((cs)->reverse_direction_charset)
396 #define CHARSET_DECODING_TABLE(cs) ((cs)->decoding_table)
397 #define CHARSET_ENCODING_TABLE(cs) ((cs)->encoding_table)
398 #define CHARSET_UCS_MIN(cs) ((cs)->ucs_min)
399 #define CHARSET_UCS_MAX(cs) ((cs)->ucs_max)
400 #define CHARSET_CODE_OFFSET(cs) ((cs)->code_offset)
401 #define CHARSET_BYTE_OFFSET(cs) ((cs)->byte_offset)
404 #define XCHARSET_ID(cs) CHARSET_ID (XCHARSET (cs))
405 #define XCHARSET_NAME(cs) CHARSET_NAME (XCHARSET (cs))
406 #define XCHARSET_SHORT_NAME(cs) CHARSET_SHORT_NAME (XCHARSET (cs))
407 #define XCHARSET_LONG_NAME(cs) CHARSET_LONG_NAME (XCHARSET (cs))
408 #define XCHARSET_GRAPHIC(cs) CHARSET_GRAPHIC (XCHARSET (cs))
409 #define XCHARSET_DIRECTION(cs) CHARSET_DIRECTION (XCHARSET (cs))
410 #define XCHARSET_FINAL(cs) CHARSET_FINAL (XCHARSET (cs))
411 #define XCHARSET_DOC_STRING(cs) CHARSET_DOC_STRING (XCHARSET (cs))
412 #define XCHARSET_REGISTRY(cs) CHARSET_REGISTRY (XCHARSET (cs))
413 #define XCHARSET_LEADING_BYTE(cs) CHARSET_LEADING_BYTE (XCHARSET (cs))
414 #define XCHARSET_CCL_PROGRAM(cs) CHARSET_CCL_PROGRAM (XCHARSET (cs))
415 #define XCHARSET_DIMENSION(cs) CHARSET_DIMENSION (XCHARSET (cs))
416 #define XCHARSET_CHARS(cs) CHARSET_CHARS (XCHARSET (cs))
417 #define XCHARSET_REVERSE_DIRECTION_CHARSET(cs) \
418 CHARSET_REVERSE_DIRECTION_CHARSET (XCHARSET (cs))
419 #define XCHARSET_DECODING_TABLE(cs) CHARSET_DECODING_TABLE(XCHARSET(cs))
420 #define XCHARSET_ENCODING_TABLE(cs) CHARSET_ENCODING_TABLE(XCHARSET(cs))
421 #define XCHARSET_UCS_MIN(cs) CHARSET_UCS_MIN(XCHARSET(cs))
422 #define XCHARSET_UCS_MAX(cs) CHARSET_UCS_MAX(XCHARSET(cs))
423 #define XCHARSET_CODE_OFFSET(cs) CHARSET_CODE_OFFSET(XCHARSET(cs))
424 #define XCHARSET_BYTE_OFFSET(cs) CHARSET_BYTE_OFFSET(XCHARSET(cs))
426 struct charset_lookup {
427 /* Table of charsets indexed by (leading byte - 128). */
428 Lisp_Object charset_by_leading_byte[NUM_LEADING_BYTES];
430 /* Table of charsets indexed by type/final-byte/direction. */
431 Lisp_Object charset_by_attributes[4][128];
433 Charset_ID next_allocated_leading_byte;
436 extern struct charset_lookup *chlook;
438 #ifdef ERROR_CHECK_TYPECHECK
439 /* int not Bufbyte even though that is the actual type of a leading byte.
440 This way, out-ot-range values will get caught rather than automatically
442 INLINE_HEADER Lisp_Object CHARSET_BY_LEADING_BYTE (Charset_ID lb);
443 INLINE_HEADER Lisp_Object
444 CHARSET_BY_LEADING_BYTE (Charset_ID lb)
446 assert (lb >= MIN_LEADING_BYTE &&
447 lb < (MIN_LEADING_BYTE + NUM_LEADING_BYTES));
448 return chlook->charset_by_leading_byte[lb - MIN_LEADING_BYTE];
453 #define CHARSET_BY_LEADING_BYTE(lb) \
454 (chlook->charset_by_leading_byte[(lb) - MIN_LEADING_BYTE])
458 INLINE_HEADER Lisp_Object
459 CHARSET_BY_ATTRIBUTES (int chars, int dimension, int final, int dir);
460 INLINE_HEADER Lisp_Object
461 CHARSET_BY_ATTRIBUTES (int chars, int dimension, int final, int dir)
467 else if (chars == 96)
471 type += dimension == 1 ? 0 : 2;
472 return chlook->charset_by_attributes[type][final];
476 /************************************************************************/
477 /* Dealing with characters */
478 /************************************************************************/
480 #define MAX_CHAR_BASIC_LATIN 0x007F
483 #define MIN_CHAR_HEBREW 0x0590
484 #define MAX_CHAR_HEBREW 0x05EF
487 #define MIN_CHAR_THAI 0x0E00
488 #define MAX_CHAR_THAI 0x0E5F
491 #define MIN_CHAR_HIRAGANA 0x3041
492 #define MAX_CHAR_HIRAGANA 0x3093
494 #define MIN_CHAR_KATAKANA 0x30A1
495 #define MAX_CHAR_KATAKANA 0x30F6
498 #define MIN_CHAR_HALFWIDTH_KATAKANA 0xFF61
499 #define MAX_CHAR_HALFWIDTH_KATAKANA 0xFF9F
501 #define MAX_CHAR_BMP 0x00FFFF
503 #define MIN_CHAR_DAIKANWA 0x00E00000
504 #define MAX_CHAR_DAIKANWA (MIN_CHAR_DAIKANWA + 50100) /* 0xE0FFFF */
505 #define MIN_CHAR_MOJIKYO_0 MIN_CHAR_DAIKANWA
506 #define MAX_CHAR_MOJIKYO_0 (MIN_CHAR_MOJIKYO_0 + 94 * 60 * 22)
508 #define MIN_CHAR_94 0xE90940
509 #define MAX_CHAR_94 (MIN_CHAR_94 + 94 * 80 - 1)
510 #define MIN_CHAR_96 (MIN_CHAR_94 + 94 * 80)
511 #define MAX_CHAR_96 (MIN_CHAR_96 + 96 * 80 - 1)
513 #define MIN_CHAR_94x94 0xE9F6C0
514 #define MIN_CHAR_JIS_X0208_1990 (MIN_CHAR_94x94 + 94 * 94 * 79)
515 #define MAX_CHAR_94x94 (MIN_CHAR_94x94 + 94 * 94 * 80 - 1)
516 #define MAX_CHAR_JIS_X0208_1990 MAX_CHAR_94x94
517 #define MIN_CHAR_96x96 0xF4C000
518 #define MAX_CHAR_96x96 (MIN_CHAR_96x96 + 96 * 96 * 80 - 1)
520 #define MIN_CHAR_MOJIKYO 0x60000000
521 #define MAX_CHAR_MOJIKYO (MIN_CHAR_MOJIKYO + 94 * 60 * 22)
522 #define MIN_CHAR_GT 0x61000000
523 #define MAX_CHAR_GT (MIN_CHAR_GT + 66773)
525 Emchar decode_builtin_char (Lisp_Object charset, int code_point);
528 DECODE_MOJIKYO_2022 (unsigned char b1, unsigned char b2, unsigned char b3);
530 DECODE_MOJIKYO_2022 (unsigned char b1, unsigned char b2, unsigned char b3)
534 else if (b2 < 16 + 32 + 30)
536 (b1 - 33) * (94 * 60)
537 + (b2 - (16 + 32)) * 94
540 else if (b2 < 18 + 32 + 30)
542 else if (b2 < 18 + 32 + 60)
544 (b1 - 33) * (94 * 60)
545 + (b2 - (18 + 32)) * 94
552 extern Lisp_Object Vcharset_chinese_big5;
553 extern Lisp_Object Vcharset_chinese_big5_1;
554 extern Lisp_Object Vcharset_chinese_big5_2;
556 INLINE_HEADER Emchar DECODE_CHAR (Lisp_Object charset, int code_point);
558 DECODE_CHAR (Lisp_Object charset, int code_point)
560 int dim = XCHARSET_DIMENSION (charset);
561 Lisp_Object decoding_table = XCHARSET_DECODING_TABLE (charset);
568 if ( VECTORP (decoding_table)
569 && ( 0 <= (idx = ((code_point >> (dim * 8))
570 & 255) - XCHARSET_BYTE_OFFSET (charset)) )
571 && ( idx < XVECTOR_LENGTH (decoding_table) )
572 && !NILP (ch = XVECTOR_DATA(decoding_table)[idx]) )
582 if (XCHARSET_DIMENSION (charset) == 1)
583 return decode_builtin_char (charset, code_point);
584 else if (EQ (charset, Vcharset_chinese_big5_1))
587 = ((code_point >> 8) - 33) * (0xFF - 0xA1)
588 + ((code_point & 0xFF) - 33);
589 unsigned char b1 = I / (0xFF - 0xA1 + 0x7F - 0x40) + 0xA1;
590 unsigned char b2 = I % (0xFF - 0xA1 + 0x7F - 0x40);
592 b2 += b2 < 0x3F ? 0x40 : 0x62;
593 return DECODE_CHAR (Vcharset_chinese_big5, (b1 << 8) | b2);
595 else if (EQ (charset, Vcharset_chinese_big5_2))
598 = ((code_point >> 8) - 33) * (0xFF - 0xA1)
599 + ((code_point & 0xFF) - 33);
600 unsigned char b1, b2;
602 I += (0xFF - 0xA1 + 0x7F - 0x40) * (0xC9 - 0xA1);
603 b1 = I / (0xFF - 0xA1 + 0x7F - 0x40) + 0xA1;
604 b2 = I % (0xFF - 0xA1 + 0x7F - 0x40);
605 b2 += b2 < 0x3F ? 0x40 : 0x62;
606 return DECODE_CHAR (Vcharset_chinese_big5, (b1 << 8) | b2);
608 else if (EQ (charset, Vcharset_mojikyo_2022_1))
612 ((unsigned char)(code_point >> 16),
613 (unsigned char)(code_point >> 8),
614 (unsigned char) code_point);
617 return DECODE_CHAR (Vcharset_mojikyo, m);
623 int plane = LEADING_BYTE_MOJIKYO_PJ_1 - XCHARSET_ID (charset);
625 if ( (0 <= plane) && (plane <= 21) )
627 int m = DECODE_MOJIKYO_2022 (plane + 33,
629 (unsigned char)code_point);
631 return DECODE_CHAR (Vcharset_mojikyo, m);
636 return decode_builtin_char (charset, code_point);
640 /* Return a character whose charset is CHARSET and position-codes
641 are C1 and C2. TYPE9N character ignores C2. */
643 INLINE_HEADER Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2);
645 MAKE_CHAR (Lisp_Object charset, int c1, int c2)
647 if (XCHARSET_DIMENSION (charset) == 1)
648 return DECODE_CHAR (charset, c1);
650 return DECODE_CHAR (charset, (c1 << 8) | c2);
653 extern Lisp_Object Vcharacter_attribute_table;
655 int encode_builtin_char_1 (Emchar c, Lisp_Object* charset);
656 int range_charset_code_point (Lisp_Object charset, Emchar ch);
658 INLINE_HEADER int charset_code_point (Lisp_Object charset, Emchar ch);
660 charset_code_point (Lisp_Object charset, Emchar ch)
662 Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (charset);
665 if ( CHAR_ID_TABLE_P (encoding_table)
666 && INTP (ret = get_char_id_table (ch, encoding_table)) )
669 return range_charset_code_point (charset, ch);
672 extern Lisp_Object Vdefault_coded_charset_priority_list;
673 EXFUN (Ffind_charset, 1);
675 INLINE_HEADER int encode_char_1 (Emchar ch, Lisp_Object* charset);
677 encode_char_1 (Emchar ch, Lisp_Object* charset)
679 Lisp_Object charsets = Vdefault_coded_charset_priority_list;
681 while (!NILP (charsets))
683 *charset = Ffind_charset (Fcar (charsets));
684 if (!NILP (*charset))
686 Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (*charset);
689 if ( CHAR_ID_TABLE_P (encoding_table)
690 && INTP (ret = get_char_id_table (ch, encoding_table)) )
694 int code_point = range_charset_code_point (*charset, ch);
700 charsets = Fcdr (charsets);
703 /* otherwise --- maybe for bootstrap */
704 return encode_builtin_char_1 (ch, charset);
707 #define ENCODE_CHAR(ch, charset) encode_char_1 (ch, &(charset))
710 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2);
712 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
714 int code_point = encode_char_1 (c, charset);
718 int dim = XCHARSET_DIMENSION (*charset);
725 else /* if (dim == 2) */
727 *c1 = code_point >> 8;
728 *c2 = code_point & 255;
736 #define BREAKUP_CHAR(ch, charset, b1, b2) \
737 breakup_char_1 (ch, &(charset), &(b1), &(b2))
739 INLINE_HEADER Lisp_Object CHAR_CHARSET (Emchar ch);
740 INLINE_HEADER Lisp_Object
741 CHAR_CHARSET (Emchar ch)
745 ENCODE_CHAR (ch, charset);
749 #define CHAR_CHARSET_ID(c) (XCHARSET_ID(CHAR_CHARSET(c)))
750 #define CHAR_COLUMNS(c) (CHARSET_COLUMNS(XCHARSET(CHAR_CHARSET(c))))
759 INLINE_HEADER Charc CHAR_TO_CHARC (Emchar ch);
761 CHAR_TO_CHARC (Emchar ch)
765 cc.code_point = encode_char_1 (ch, &cc.charset);
766 if (EQ (cc.charset, Vcharset_mojikyo))
768 int plane, byte1, byte2;
771 plane = cc.code_point / (94 * 60);
772 byte1 = (cc.code_point % (94 * 60)) / 94;
777 byte2 = cc.code_point % 94 + 33;
779 = CHARSET_BY_LEADING_BYTE (LEADING_BYTE_MOJIKYO_PJ_1 - plane);
780 cc.code_point = (byte1 << 8) | byte2;
786 /************************************************************************/
787 /* Exported functions */
788 /************************************************************************/
790 EXFUN (Fget_charset, 1);
792 extern Lisp_Object Qucs;
794 extern Lisp_Object Vcharset_japanese_jisx0208;
795 extern Lisp_Object Vcharset_japanese_jisx0208_1990;
796 extern Lisp_Object Vcharset_japanese_jisx0212;
798 Lisp_Object put_char_ccs_code_point (Lisp_Object character,
799 Lisp_Object ccs, Lisp_Object value);
800 Lisp_Object remove_char_ccs (Lisp_Object character, Lisp_Object ccs);
802 #endif /* INCLUDED_char_ucs_h_ */