(Vcharset_mojikyo): Deleted.
[chise/xemacs-chise.git] / src / char-ucs.h
1 /* Header for UCS-4 character representation.
2    Copyright (C) 1999,2000,2001 MORIOKA Tomohiko
3
4 This file is part of XEmacs.
5
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
9 later version.
10
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
14 for more details.
15
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.  */
20
21 #ifndef INCLUDED_char_ucs_h_
22 #define INCLUDED_char_ucs_h_
23
24 #include "chartab.h"
25 #include "elhash.h"
26
27 extern Lisp_Object Vchar_attribute_hash_table;
28
29 #define valid_char_p(ch) 1
30
31 #define CHAR_ASCII_P(ch) ((ch) <= 0x7F)
32
33 extern Lisp_Object Vcharset_latin_jisx0201;
34
35 \f
36 /************************************************************************/
37 /*                    Definition of leading bytes                       */
38 /************************************************************************/
39
40 typedef short Charset_ID;
41
42 #define MIN_LEADING_BYTE                -0x200
43 #define CHARSET_ID_OFFSET               0x00
44
45 /* ISO/IEC 10646 */
46 #define LEADING_BYTE_UCS                (CHARSET_ID_OFFSET - 1)
47
48 /* represent normal 80-9F */
49 #define LEADING_BYTE_CONTROL_1          (CHARSET_ID_OFFSET - 2)
50
51 /* ISO/IEC 10646 BMP */
52 #define LEADING_BYTE_UCS_BMP            (CHARSET_ID_OFFSET - 3)
53
54 /* ISO/IEC 10646 SMP */
55 #define LEADING_BYTE_UCS_SMP            (CHARSET_ID_OFFSET - 4)
56
57 /* ISO/IEC 10646 SIP */
58 #define LEADING_BYTE_UCS_SIP            (CHARSET_ID_OFFSET - 5)
59
60 /* ISO/IEC 10646 for CNS */
61 #define LEADING_BYTE_UCS_CNS            (CHARSET_ID_OFFSET - 6)
62
63 /* ISO/IEC 10646 for JIS */
64 #define LEADING_BYTE_UCS_JIS            (CHARSET_ID_OFFSET - 7)
65
66 /* ISO/IEC 10646 for KS */
67 #define LEADING_BYTE_UCS_KS             (CHARSET_ID_OFFSET - 8)
68
69 /* ISO/IEC 10646 for Big5 */
70 #define LEADING_BYTE_UCS_BIG5           (CHARSET_ID_OFFSET - 9)
71
72 /* Japanese JIS X0208-1990      2/4 2/{(8),9,10,11} 4/2 (B) */
73 #define LEADING_BYTE_JAPANESE_JISX0208_1990 (CHARSET_ID_OFFSET - 10)
74
75 /* Chinese GB 12345-1990 */
76 #define LEADING_BYTE_CHINESE_GB12345    (CHARSET_ID_OFFSET - 11)
77
78 #define LEADING_BYTE_CHINESE_BIG5       (CHARSET_ID_OFFSET - 20)
79
80 /* Big5 Level 1                 2/4 2/{(8),9,10,11} 4/0 '0' */
81 #define LEADING_BYTE_CHINESE_BIG5_1     (CHARSET_ID_OFFSET - 21)
82
83 /* Big5 Level 2                 2/4 2/{(8),9,10,11} 4/0 '1' */
84 #define LEADING_BYTE_CHINESE_BIG5_2     (CHARSET_ID_OFFSET - 22)
85
86 /* VISCII 1.1 */
87 #define LEADING_BYTE_LATIN_VISCII       (CHARSET_ID_OFFSET - 24)
88
89 /* MULE VISCII-LOWER                    (CHARSET_ID_OFFSET_96 + '1') */
90 #define LEADING_BYTE_LATIN_VISCII_LOWER (CHARSET_ID_OFFSET - 25)
91
92 /* MULE VISCII-UPPER                    (CHARSET_ID_OFFSET_96 + '2') */
93 #define LEADING_BYTE_LATIN_VISCII_UPPER (CHARSET_ID_OFFSET - 26)
94
95 #define LEADING_BYTE_ETHIOPIC_UCS       (CHARSET_ID_OFFSET - 27)
96
97 #define LEADING_BYTE_DAIKANWA_0         (CHARSET_ID_OFFSET - 28)
98 #define LEADING_BYTE_DAIKANWA_1         (CHARSET_ID_OFFSET - 29)
99 #define LEADING_BYTE_DAIKANWA_2         (CHARSET_ID_OFFSET - 30)
100 #define LEADING_BYTE_DAIKANWA_3         (CHARSET_ID_OFFSET - 31)
101
102 #define LEADING_BYTE_GT                 (CHARSET_ID_OFFSET - 40)
103 #define LEADING_BYTE_GT_PJ_1            (CHARSET_ID_OFFSET - 41)
104 #define LEADING_BYTE_GT_PJ_2            (CHARSET_ID_OFFSET - 42)
105 #define LEADING_BYTE_GT_PJ_3            (CHARSET_ID_OFFSET - 43)
106 #define LEADING_BYTE_GT_PJ_4            (CHARSET_ID_OFFSET - 44)
107 #define LEADING_BYTE_GT_PJ_5            (CHARSET_ID_OFFSET - 45)
108 #define LEADING_BYTE_GT_PJ_6            (CHARSET_ID_OFFSET - 46)
109 #define LEADING_BYTE_GT_PJ_7            (CHARSET_ID_OFFSET - 47)
110 #define LEADING_BYTE_GT_PJ_8            (CHARSET_ID_OFFSET - 48)
111 #define LEADING_BYTE_GT_PJ_9            (CHARSET_ID_OFFSET - 49)
112 #define LEADING_BYTE_GT_PJ_10           (CHARSET_ID_OFFSET - 50)
113 #define LEADING_BYTE_GT_PJ_11           (CHARSET_ID_OFFSET - 51)
114
115 #define LEADING_BYTE_CHINA3_JEF         (CHARSET_ID_OFFSET - 82)
116 #define LEADING_BYTE_CBETA              (CHARSET_ID_OFFSET - 83)
117 #define LEADING_BYTE_CHINESE_BIG5_CDP   (CHARSET_ID_OFFSET - 84)
118 #define LEADING_BYTE_HANZIKU_1          (CHARSET_ID_OFFSET - 85)
119 #define LEADING_BYTE_HANZIKU_2          (CHARSET_ID_OFFSET - 86)
120 #define LEADING_BYTE_HANZIKU_3          (CHARSET_ID_OFFSET - 87)
121 #define LEADING_BYTE_HANZIKU_4          (CHARSET_ID_OFFSET - 88)
122 #define LEADING_BYTE_HANZIKU_5          (CHARSET_ID_OFFSET - 89)
123 #define LEADING_BYTE_HANZIKU_6          (CHARSET_ID_OFFSET - 90)
124 #define LEADING_BYTE_HANZIKU_7          (CHARSET_ID_OFFSET - 91)
125 #define LEADING_BYTE_HANZIKU_8          (CHARSET_ID_OFFSET - 92)
126 #define LEADING_BYTE_HANZIKU_9          (CHARSET_ID_OFFSET - 93)
127 #define LEADING_BYTE_HANZIKU_10         (CHARSET_ID_OFFSET - 94)
128 #define LEADING_BYTE_HANZIKU_11         (CHARSET_ID_OFFSET - 95)
129 #define LEADING_BYTE_HANZIKU_12         (CHARSET_ID_OFFSET - 96)
130
131 #define MIN_LEADING_BYTE_PRIVATE        MIN_LEADING_BYTE
132 #define MAX_LEADING_BYTE_PRIVATE        (CHARSET_ID_OFFSET - 97)
133
134
135 /* #define CHARSET_ID_OFFSET_94         (CHARSET_ID_OFFSET - '0') */
136
137 /* #define MIN_CHARSET_ID_PRIVATE_94    (CHARSET_ID_OFFSET_94 + '0') */
138 /* #define MAX_CHARSET_ID_PRIVATE_94    (CHARSET_ID_OFFSET_94 + '?') */
139
140 /* ISO 646 IRV */
141 #define LEADING_BYTE_ASCII                6 /* (CHARSET_ID_OFFSET_94 + 'B') */
142
143 /* Right half of JIS X0201-1976 */
144 #define LEADING_BYTE_KATAKANA_JISX0201   13 /* (CHARSET_ID_OFFSET_94 + 'I') */
145
146 /* Left  half of JIS X0201-1976 */
147 #define LEADING_BYTE_LATIN_JISX0201      14 /* (CHARSET_ID_OFFSET_94 + 'J') */
148
149
150 /* #define CHARSET_ID_OFFSET_96         (CHARSET_ID_OFFSET_94 + 80) */
151
152 /* Right half of ISO 8859-1 */
153 #define LEADING_BYTE_LATIN_ISO8859_1    100 /* (CHARSET_ID_OFFSET_96 + 'A') */
154
155 /* Right half of ISO 8859-2 */
156 #define LEADING_BYTE_LATIN_ISO8859_2    101 /* (CHARSET_ID_OFFSET_96 + 'B') */
157
158 /* Right half of ISO 8859-3 */
159 #define LEADING_BYTE_LATIN_ISO8859_3    109 /* (CHARSET_ID_OFFSET_96 + 'C') */
160
161 /* Right half of ISO 8859-4 */
162 #define LEADING_BYTE_LATIN_ISO8859_4    110 /* (CHARSET_ID_OFFSET_96 + 'D') */
163
164 /* Right half of ISO 8859-7 */
165 #define LEADING_BYTE_GREEK_ISO8859_7    126 /* (CHARSET_ID_OFFSET_96 + 'F') */
166
167 /* Right half of ISO 8859-6 */
168 #define LEADING_BYTE_ARABIC_ISO8859_6   127 /* (CHARSET_ID_OFFSET_96 + 'G') */
169
170 /* Right half of ISO 8859-8 */
171 #define LEADING_BYTE_HEBREW_ISO8859_8   138 /* (CHARSET_ID_OFFSET_96 + 'H') */
172
173 /* Right half of ISO 8859-5 */
174 #define LEADING_BYTE_CYRILLIC_ISO8859_5 144 /* (CHARSET_ID_OFFSET_96 + 'L') */
175
176 /* Right half of ISO 8859-9 */
177 #define LEADING_BYTE_LATIN_ISO8859_9    148 /* (CHARSET_ID_OFFSET_96 + 'M') */
178
179 /* TIS620-2533 */
180 #define LEADING_BYTE_THAI_TIS620        166 /* (CHARSET_ID_OFFSET_96 + 'T') */
181
182 /* Right-hand Part of the VSCII-2 (TCVN 5712:1983) */
183 #define LEADING_BYTE_LATIN_TCVN5712     180 /* F = 5/10 0x5A `Z' */
184
185
186 /* #define CHARSET_ID_OFFSET_94x94              (CHARSET_ID_OFFSET_96 + 80) */
187
188 /* #define MIN_LEADING_BYTE_PRIVATE_2   ('0' + CHARSET_ID_OFFSET_94x94) */
189 /* #define MAX_LEADING_BYTE_PRIVATE_2   ('?' + CHARSET_ID_OFFSET_94x94) */
190
191 /* Japanese JIS X0208-1978      2/4 2/{(8),9,10,11} 4/0 (@) */
192 #define LEADING_BYTE_JAPANESE_JISX0208_1978      42
193
194 /* Chinese Hanzi GB2312-1980    2/4 2/{(8),9,10,11} 4/1 (A) */
195 #define LEADING_BYTE_CHINESE_GB2312              58
196
197 /* Japanese JIS X0208-1983      2/4 2/{(8),9,10,11} 4/2 (B) */
198 #define LEADING_BYTE_JAPANESE_JISX0208           87
199
200 /* Hangul KS C5601-1987         2/4 2/{8,9,10,11} 4/3 (C) */
201 #define LEADING_BYTE_KOREAN_KSC5601             149
202
203 /* Japanese JIS X0212-1990      2/4 2/{8,9,10,11} 4/4 (D) */
204 #define LEADING_BYTE_JAPANESE_JISX0212          159
205
206 /* CCITT Extended GB            2/4 2/{8,9,10,11} 4/5 (E) */
207 #define LEADING_BYTE_CHINESE_CCITT_GB           165
208
209 /* Chinese CNS11643 Set 1       2/4 2/{8,9,10,11} 4/7 (G) */
210 #define LEADING_BYTE_CHINESE_CNS11643_1         171
211
212 /* Chinese CNS11643 Set 2       2/4 2/{8,9,10,11} 4/8 (H) */
213 #define LEADING_BYTE_CHINESE_CNS11643_2         172
214
215 /* Chinese CNS11643 Set 3       2/4 2/{8,9,10,11} 4/9 (I) */
216 #define LEADING_BYTE_CHINESE_CNS11643_3         183
217
218 /* Chinese CNS11643 Set 4       2/4 2/{8,9,10,11} 4/10 (J) */
219 #define LEADING_BYTE_CHINESE_CNS11643_4         184
220
221 /* Chinese CNS11643 Set 5       2/4 2/{8,9,10,11} 4/11 (K) */
222 #define LEADING_BYTE_CHINESE_CNS11643_5         185
223
224 /* Chinese CNS11643 Set 6       2/4 2/{8,9,10,11} 4/12 (L) */
225 #define LEADING_BYTE_CHINESE_CNS11643_6         186
226
227 /* Chinese CNS11643 Set 7       2/4 2/{8,9,10,11} 4/13 (M) */
228 #define LEADING_BYTE_CHINESE_CNS11643_7         187
229
230 /* DPRK Hangul KPS 9566-1997    2/4 2/{8,9,10,11} 4/14 (N) */
231 #define LEADING_BYTE_KOREAN_KPS9566             202
232
233
234 #define NUM_LEADING_BYTES       (80 * 3 - MIN_LEADING_BYTE)
235
236 \f
237 /************************************************************************/
238 /*            Information about a particular character set              */
239 /************************************************************************/
240
241 struct Lisp_Charset
242 {
243   struct lcrecord_header header;
244
245   int id;
246   Lisp_Object name;
247   Lisp_Object doc_string;
248   Lisp_Object registry;
249   Lisp_Object short_name;
250   Lisp_Object long_name;
251
252   Lisp_Object reverse_direction_charset;
253
254   Lisp_Object ccl_program;
255
256   /* Final byte of this character set in ISO2022 designating escape sequence */
257   Bufbyte final;
258
259   /* Number of columns a character in this charset takes up, on TTY
260      devices.  Not used for X devices. */
261   unsigned int columns;
262
263   /* Direction of this character set */
264   unsigned int direction;
265
266   /* Number of bytes used in encoding of this character set (1 .. 4) */
267   unsigned short dimension;
268
269   /* Number of chars in each dimension (94, 96, 128, 256) */
270   unsigned short chars;
271
272   /* Which half of font to be used to display this character set */
273   unsigned int graphic;
274
275   /* Code-point->character mapping table */
276   Lisp_Object decoding_table;
277
278   /* Base CCS */
279   Lisp_Object mother;
280
281   /* Range of character code */
282   int min_code, max_code;
283
284   /* Offset for external code */
285   int code_offset;
286
287   /* Type of conversion from mother CCS */
288   unsigned char conversion;
289
290   /* Offset for each byte */
291   int byte_offset;
292 };
293 typedef struct Lisp_Charset Lisp_Charset;
294
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)
302
303 #define CHARSET_LEFT_TO_RIGHT   0
304 #define CHARSET_RIGHT_TO_LEFT   1
305
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_MIN_CODE(cs)     ((cs)->min_code)
324 #define CHARSET_MAX_CODE(cs)     ((cs)->max_code)
325 #define CHARSET_CODE_OFFSET(cs)  ((cs)->code_offset)
326 #define CHARSET_BYTE_OFFSET(cs)  ((cs)->byte_offset)
327 #define CHARSET_MOTHER(cs)       ((cs)->mother)
328 #define CHARSET_CONVERSION(cs)   ((cs)->conversion)
329
330 INLINE_HEADER Lisp_Object CHARSET_ENCODING_TABLE (Lisp_Charset* cs);
331 INLINE_HEADER Lisp_Object
332 CHARSET_ENCODING_TABLE (Lisp_Charset* cs)
333 {
334   return Fgethash (CHARSET_NAME(cs),
335                    Vchar_attribute_hash_table,
336                    Qnil);
337 }
338
339 #define CONVERSION_IDENTICAL    0
340 #define CONVERSION_94x60        1
341
342 #define XCHARSET_ID(cs)           CHARSET_ID           (XCHARSET (cs))
343 #define XCHARSET_NAME(cs)         CHARSET_NAME         (XCHARSET (cs))
344 #define XCHARSET_SHORT_NAME(cs)   CHARSET_SHORT_NAME   (XCHARSET (cs))
345 #define XCHARSET_LONG_NAME(cs)    CHARSET_LONG_NAME    (XCHARSET (cs))
346 #define XCHARSET_GRAPHIC(cs)      CHARSET_GRAPHIC      (XCHARSET (cs))
347 #define XCHARSET_DIRECTION(cs)    CHARSET_DIRECTION    (XCHARSET (cs))
348 #define XCHARSET_FINAL(cs)        CHARSET_FINAL        (XCHARSET (cs))
349 #define XCHARSET_DOC_STRING(cs)   CHARSET_DOC_STRING   (XCHARSET (cs))
350 #define XCHARSET_REGISTRY(cs)     CHARSET_REGISTRY     (XCHARSET (cs))
351 #define XCHARSET_LEADING_BYTE(cs) CHARSET_LEADING_BYTE (XCHARSET (cs))
352 #define XCHARSET_CCL_PROGRAM(cs)  CHARSET_CCL_PROGRAM  (XCHARSET (cs))
353 #define XCHARSET_DIMENSION(cs)    CHARSET_DIMENSION    (XCHARSET (cs))
354 #define XCHARSET_CHARS(cs)        CHARSET_CHARS        (XCHARSET (cs))
355 #define XCHARSET_REVERSE_DIRECTION_CHARSET(cs) \
356   CHARSET_REVERSE_DIRECTION_CHARSET (XCHARSET (cs))
357 #define XCHARSET_DECODING_TABLE(cs) CHARSET_DECODING_TABLE(XCHARSET(cs))
358 #define XCHARSET_ENCODING_TABLE(cs) CHARSET_ENCODING_TABLE(XCHARSET(cs))
359 #define XCHARSET_MIN_CODE(cs)     CHARSET_MIN_CODE(XCHARSET(cs))
360 #define XCHARSET_MAX_CODE(cs)     CHARSET_MAX_CODE(XCHARSET(cs))
361 #define XCHARSET_CODE_OFFSET(cs)  CHARSET_CODE_OFFSET(XCHARSET(cs))
362 #define XCHARSET_BYTE_OFFSET(cs)  CHARSET_BYTE_OFFSET(XCHARSET(cs))
363 #define XCHARSET_MOTHER(cs)       CHARSET_MOTHER(XCHARSET(cs))
364 #define XCHARSET_CONVERSION(cs)   CHARSET_CONVERSION(XCHARSET(cs))
365
366 struct charset_lookup {
367   /* Table of charsets indexed by (leading byte - 128). */
368   Lisp_Object charset_by_leading_byte[NUM_LEADING_BYTES];
369   
370   /* Table of charsets indexed by type/final-byte/direction. */
371   Lisp_Object charset_by_attributes[4][128];
372
373   Charset_ID next_allocated_leading_byte;
374 };
375
376 extern struct charset_lookup *chlook;
377
378 #ifdef ERROR_CHECK_TYPECHECK
379 /* int not Bufbyte even though that is the actual type of a leading byte.
380    This way, out-ot-range values will get caught rather than automatically
381    truncated. */
382 INLINE_HEADER Lisp_Object CHARSET_BY_LEADING_BYTE (Charset_ID lb);
383 INLINE_HEADER Lisp_Object
384 CHARSET_BY_LEADING_BYTE (Charset_ID lb)
385 {
386   assert (lb >= MIN_LEADING_BYTE &&
387           lb < (MIN_LEADING_BYTE + NUM_LEADING_BYTES));
388   return chlook->charset_by_leading_byte[lb - MIN_LEADING_BYTE];
389 }
390
391 #else
392
393 #define CHARSET_BY_LEADING_BYTE(lb) \
394   (chlook->charset_by_leading_byte[(lb) - MIN_LEADING_BYTE])
395
396 #endif
397
398 INLINE_HEADER Lisp_Object
399 CHARSET_BY_ATTRIBUTES (int chars, int dimension, int final, int dir);
400 INLINE_HEADER Lisp_Object
401 CHARSET_BY_ATTRIBUTES (int chars, int dimension, int final, int dir)
402 {
403   int type;
404
405   if (chars == 94)
406     type = 0;
407   else if (chars == 96)
408     type = 1;
409   else
410     return Qnil;
411   type += dimension == 1 ? 0 : 2;
412   return chlook->charset_by_attributes[type][final];
413 }
414
415 \f
416 /************************************************************************/
417 /*                        Dealing with characters                       */
418 /************************************************************************/
419
420 #define MAX_CHAR_BASIC_LATIN    0x007F
421
422 /*
423 #define MIN_CHAR_HEBREW         0x0590
424 #define MAX_CHAR_HEBREW         0x05EF
425 */
426
427 #define MIN_CHAR_THAI           0x0E00
428 #define MAX_CHAR_THAI           0x0E5F
429
430 /*
431 #define MIN_CHAR_HIRAGANA       0x3041
432 #define MAX_CHAR_HIRAGANA       0x3093
433
434 #define MIN_CHAR_KATAKANA       0x30A1
435 #define MAX_CHAR_KATAKANA       0x30F6
436 */
437
438 #define MIN_CHAR_HALFWIDTH_KATAKANA     0xFF61
439 #define MAX_CHAR_HALFWIDTH_KATAKANA     0xFF9F
440
441 #define MAX_CHAR_BMP            0x00FFFF
442
443 #define MIN_CHAR_SMP            0x010000
444 #define MAX_CHAR_SMP            0x01FFFF
445
446 #define MIN_CHAR_SIP            0x020000
447 #define MAX_CHAR_SIP            0x02FFFF
448
449 #define MIN_CHAR_DAIKANWA       0x00E00000
450 #define MAX_CHAR_DAIKANWA       (MIN_CHAR_DAIKANWA + 50100) /* 0xE0FFFF */
451 #define MIN_CHAR_CBETA          0x00E20000
452 #define MAX_CHAR_CBETA          0x00E2FFFF
453 #define MIN_CHAR_CHINA3_JEF     0x00E80000
454 #define MAX_CHAR_CHINA3_JEF     0x00E8FFFF
455
456 #define MIN_CHAR_94             0x00E90940
457 #define MAX_CHAR_94             (MIN_CHAR_94 + 94 * 80 - 1)
458 #define MIN_CHAR_96             (MIN_CHAR_94 + 94 * 80)
459 #define MAX_CHAR_96             (MIN_CHAR_96 + 96 * 80 - 1)
460
461 #define MIN_CHAR_94x94          0xE9F6C0
462 #define MIN_CHAR_JIS_X0208_1990 (MIN_CHAR_94x94 + 94 * 94 * 79)
463 #define MAX_CHAR_94x94          (MIN_CHAR_94x94 + 94 * 94 * 80 - 1)
464 #define MAX_CHAR_JIS_X0208_1990 MAX_CHAR_94x94
465 #define MIN_CHAR_96x96          0xF4C000
466 #define MAX_CHAR_96x96          (MIN_CHAR_96x96 + 96 * 96 * 80 - 1)
467
468 #define MIN_CHAR_GT             0x61000000
469 #define MAX_CHAR_GT             (MIN_CHAR_GT + 66773)
470 #define MIN_CHAR_BIG5_CDP       0x62000000
471 #define MAX_CHAR_BIG5_CDP       0x6200FFFF
472 #define MIN_CHAR_HANZIKU_1      (0x62000000 + 65536 * 1)
473 #define MAX_CHAR_HANZIKU_1      (0x62000000 + 65536 * 1 + 65535)
474 #define MIN_CHAR_HANZIKU_2      (0x62000000 + 65536 * 2)
475 #define MAX_CHAR_HANZIKU_2      (0x62000000 + 65536 * 2 + 65535)
476 #define MIN_CHAR_HANZIKU_3      (0x62000000 + 65536 * 3)
477 #define MAX_CHAR_HANZIKU_3      (0x62000000 + 65536 * 3 + 65535)
478 #define MIN_CHAR_HANZIKU_4      (0x62000000 + 65536 * 4)
479 #define MAX_CHAR_HANZIKU_4      (0x62000000 + 65536 * 4 + 65535)
480 #define MIN_CHAR_HANZIKU_5      (0x62000000 + 65536 * 5)
481 #define MAX_CHAR_HANZIKU_5      (0x62000000 + 65536 * 5 + 65535)
482 #define MIN_CHAR_HANZIKU_6      (0x62000000 + 65536 * 6)
483 #define MAX_CHAR_HANZIKU_6      (0x62000000 + 65536 * 6 + 65535)
484 #define MIN_CHAR_HANZIKU_7      (0x62000000 + 65536 * 7)
485 #define MAX_CHAR_HANZIKU_7      (0x62000000 + 65536 * 7 + 65535)
486 #define MIN_CHAR_HANZIKU_8      (0x62000000 + 65536 * 8)
487 #define MAX_CHAR_HANZIKU_8      (0x62000000 + 65536 * 8 + 65535)
488 #define MIN_CHAR_HANZIKU_9      (0x62000000 + 65536 * 9)
489 #define MAX_CHAR_HANZIKU_9      (0x62000000 + 65536 * 9 + 65535)
490 #define MIN_CHAR_HANZIKU_10     (0x62000000 + 65536 * 10)
491 #define MAX_CHAR_HANZIKU_10     (0x62000000 + 65536 * 10 + 65535)
492 #define MIN_CHAR_HANZIKU_11     (0x62000000 + 65536 * 11)
493 #define MAX_CHAR_HANZIKU_11     (0x62000000 + 65536 * 11 + 65535)
494 #define MIN_CHAR_HANZIKU_12     (0x62000000 + 65536 * 12)
495 #define MAX_CHAR_HANZIKU_12     (0x62000000 + 65536 * 12 + 65535)
496
497 Emchar decode_builtin_char (Lisp_Object charset, int code_point);
498
499 extern Lisp_Object Vcharset_chinese_big5;
500 extern Lisp_Object Vcharset_chinese_big5_1;
501 extern Lisp_Object Vcharset_chinese_big5_2;
502
503 INLINE_HEADER Emchar
504 DECODE_DEFINED_CHAR (Lisp_Object charset, int code_point);
505 INLINE_HEADER Emchar
506 DECODE_DEFINED_CHAR (Lisp_Object charset, int code_point)
507 {
508   int dim = XCHARSET_DIMENSION (charset);
509   Lisp_Object decoding_table = XCHARSET_DECODING_TABLE (charset);
510   int idx;
511   Lisp_Object ch;
512
513   while (dim > 0)
514     {
515       dim--;
516       if ( VECTORP (decoding_table)
517            && ( 0 <= (idx = ((code_point >> (dim * 8))
518                              & 255) - XCHARSET_BYTE_OFFSET (charset)) )
519            && ( idx < XVECTOR_LENGTH (decoding_table) )
520            && !NILP (ch = XVECTOR_DATA(decoding_table)[idx]) )
521         {
522           if (CHARP (ch))
523             return XCHAR (ch);
524           else
525             decoding_table = ch;
526         }
527       else
528         break;
529     }
530   return -1;
531 }
532
533 INLINE_HEADER Emchar DECODE_CHAR (Lisp_Object charset, int code_point);
534 INLINE_HEADER Emchar
535 DECODE_CHAR (Lisp_Object charset, int code_point)
536 {
537   Emchar char_id = DECODE_DEFINED_CHAR (charset, code_point);
538
539   if (char_id >= 0)
540     return char_id;
541   else if (XCHARSET_DIMENSION (charset) == 1)
542     return decode_builtin_char (charset, code_point);
543   else if (EQ (charset, Vcharset_chinese_big5_1))
544     {
545       unsigned int I
546         = ((code_point >> 8) - 33) * (0xFF - 0xA1)
547         + ((code_point & 0xFF) - 33);
548       unsigned char b1 = I / (0xFF - 0xA1 + 0x7F - 0x40) + 0xA1;
549       unsigned char b2 = I % (0xFF - 0xA1 + 0x7F - 0x40);
550
551       b2 += b2 < 0x3F ? 0x40 : 0x62;
552       return DECODE_CHAR (Vcharset_chinese_big5, (b1 << 8) | b2);
553     }
554   else if (EQ (charset, Vcharset_chinese_big5_2))
555     {
556       unsigned int I
557         = ((code_point >> 8) - 33) * (0xFF - 0xA1)
558         + ((code_point & 0xFF) - 33);
559       unsigned char b1, b2;
560
561       I += (0xFF - 0xA1 + 0x7F - 0x40) * (0xC9 - 0xA1);
562       b1 = I / (0xFF - 0xA1 + 0x7F - 0x40) + 0xA1;
563       b2 = I % (0xFF - 0xA1 + 0x7F - 0x40);
564       b2 += b2 < 0x3F ? 0x40 : 0x62;
565       return DECODE_CHAR (Vcharset_chinese_big5, (b1 << 8) | b2);
566     }
567   return decode_builtin_char (charset, code_point);
568 }
569
570 /* Return a character whose charset is CHARSET and position-codes
571    are C1 and C2.  TYPE9N character ignores C2. */
572
573 INLINE_HEADER Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2);
574 INLINE_HEADER Emchar
575 MAKE_CHAR (Lisp_Object charset, int c1, int c2)
576 {
577   if (XCHARSET_DIMENSION (charset) == 1)
578     return DECODE_CHAR (charset, c1);
579   else
580     return DECODE_CHAR (charset, (c1 << 8) | c2);
581 }
582
583 extern Lisp_Object Vcharacter_attribute_table;
584
585 int encode_builtin_char_1 (Emchar c, Lisp_Object* charset);
586 int charset_code_point (Lisp_Object charset, Emchar ch);
587 int range_charset_code_point (Lisp_Object charset, Emchar ch);
588
589 extern Lisp_Object Vdefault_coded_charset_priority_list;
590 EXFUN (Ffind_charset, 1);
591
592 INLINE_HEADER int encode_char_1 (Emchar ch, Lisp_Object* charset);
593 INLINE_HEADER int
594 encode_char_1 (Emchar ch, Lisp_Object* charset)
595 {
596   Lisp_Object charsets = Vdefault_coded_charset_priority_list;
597
598   while (!NILP (charsets))
599     {
600       *charset = Ffind_charset (Fcar (charsets));
601       if (!NILP (*charset))
602         {
603           int code_point = charset_code_point (*charset, ch);
604
605           if (code_point >= 0)
606             return code_point;
607         }
608       charsets = Fcdr (charsets);             
609     }
610   
611   /* otherwise --- maybe for bootstrap */
612   return encode_builtin_char_1 (ch, charset);
613 }
614
615 #define ENCODE_CHAR(ch, charset)        encode_char_1 (ch, &(charset))
616
617 INLINE_HEADER void
618 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2);
619 INLINE_HEADER void
620 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
621 {
622   int code_point = encode_char_1 (c, charset);
623
624   if (code_point >= 0)
625     {
626       int dim = XCHARSET_DIMENSION (*charset);
627
628        if (dim == 1)
629          {
630            *c1 = code_point;
631            *c2 = 0;
632          }
633        else /* if (dim == 2) */
634          {
635            *c1 = code_point >> 8;
636            *c2 = code_point & 255;
637          }
638     }
639   else{
640     *c1 = *c2 = 0;
641   }
642 }
643
644 #define BREAKUP_CHAR(ch, charset, b1, b2) \
645   breakup_char_1 (ch, &(charset), &(b1), &(b2))
646
647 INLINE_HEADER Lisp_Object CHAR_CHARSET (Emchar ch);
648 INLINE_HEADER Lisp_Object
649 CHAR_CHARSET (Emchar ch)
650 {
651   Lisp_Object charset;
652  
653   ENCODE_CHAR (ch, charset);
654   return charset;
655 }
656
657 #define CHAR_CHARSET_ID(c)  (XCHARSET_ID(CHAR_CHARSET(c)))
658 #define CHAR_COLUMNS(c)     (CHARSET_COLUMNS(XCHARSET(CHAR_CHARSET(c))))
659
660
661 typedef struct Charc
662 {
663   Lisp_Object charset;
664   int code_point;
665 } Charc;
666
667 INLINE_HEADER Charc CHAR_TO_CHARC (Emchar ch);
668 INLINE_HEADER Charc
669 CHAR_TO_CHARC (Emchar ch)
670 {
671   Charc cc;
672
673   cc.code_point = encode_char_1 (ch, &cc.charset);
674   return cc;
675 }
676
677 \f
678 /************************************************************************/
679 /*                            Exported functions                        */
680 /************************************************************************/
681
682 EXFUN (Fget_charset, 1);
683
684 extern Lisp_Object Qucs;
685
686 extern Lisp_Object Vcharset_japanese_jisx0208;
687 extern Lisp_Object Vcharset_japanese_jisx0208_1990;
688 extern Lisp_Object Vcharset_japanese_jisx0212;
689
690 Lisp_Object put_char_ccs_code_point (Lisp_Object character,
691                                      Lisp_Object ccs, Lisp_Object value);
692 Lisp_Object remove_char_ccs (Lisp_Object character, Lisp_Object ccs);
693
694 #endif /* INCLUDED_char_ucs_h_ */