(MAKE_CHAR): Delete builtin support for `Vcharset_katakana_jisx0201'.
[chise/xemacs-chise.git] / src / char-ucs.h
1 /* Header for UCS-4 character representation.
2    Copyright (C) 1999 Electrotechnical Laboratory, JAPAN.
3    Licensed to the Free Software Foundation.
4
5 This file is part of XEmacs.
6
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
11
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING.  If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 /* Rewritten by MORIOKA Tomohiko <tomo@m17n.org>. */
23
24 #ifndef _XEMACS_CHAR_UCS_H
25 #define _XEMACS_CHAR_UCS_H
26
27 #define valid_char_p(ch) 1
28
29 #define CHAR_ASCII_P(ch) ((ch) <= 0x7F)
30
31 \f
32 DECLARE_LRECORD (char_byte_table, struct Lisp_Char_Byte_Table);
33 #define XCHAR_BYTE_TABLE(x) \
34   XRECORD (x, char_byte_table, struct Lisp_Char_Byte_Table)
35 #define XSETCHAR_BYTE_TABLE(x, p) XSETRECORD (x, p, char_byte_table)
36 #define CHAR_BYTE_TABLE_P(x) RECORDP (x, char_byte_table)
37 #define GC_CHAR_BYTE_TABLE_P(x) GC_RECORDP (x, char_byte_table)
38 /* #define CHECK_CHAR_BYTE_TABLE(x) CHECK_RECORD (x, char_byte_table)
39    char table entries should never escape to Lisp */
40
41 struct Lisp_Char_Byte_Table
42 {
43   struct lcrecord_header header;
44
45   Lisp_Object property[256];
46 };
47
48
49 DECLARE_LRECORD (char_code_table, struct Lisp_Char_Code_Table);
50 #define XCHAR_CODE_TABLE(x) \
51   XRECORD (x, char_code_table, struct Lisp_Char_Code_Table)
52 #define XSETCHAR_CODE_TABLE(x, p) XSETRECORD (x, p, char_code_table)
53 #define CHAR_CODE_TABLE_P(x) RECORDP (x, char_code_table)
54 #define GC_CHAR_CODE_TABLE_P(x) GC_RECORDP (x, char_code_table)
55 /* #define CHECK_CHAR_CODE_TABLE(x) CHECK_RECORD (x, char_code_table)
56    char table entries should never escape to Lisp */
57
58 struct Lisp_Char_Code_Table
59 {
60   struct lcrecord_header header;
61
62   Lisp_Object table;
63 };
64
65 Lisp_Object get_char_code_table (Emchar ch, Lisp_Object table);
66
67
68 extern Lisp_Object Vcharset_ucs_bmp;
69 extern Lisp_Object Vcharset_latin_jisx0201;
70 extern Lisp_Object Vcharset_latin_iso8859_2;
71 extern Lisp_Object Vcharset_latin_iso8859_3;
72 extern Lisp_Object Vcharset_latin_iso8859_4;
73 extern Lisp_Object Vcharset_latin_iso8859_9;
74 extern Lisp_Object Vcharset_latin_viscii_lower;
75 extern Lisp_Object Vcharset_latin_viscii_upper;
76
77 \f
78 /************************************************************************/
79 /*                    Definition of leading bytes                       */
80 /************************************************************************/
81
82 typedef int Charset_ID;
83
84 #define MIN_LEADING_BYTE                -0x60
85 #define CHARSET_ID_OFFSET               0x00
86
87 /* represent normal 80-9F */
88 #define LEADING_BYTE_CONTROL_1          (CHARSET_ID_OFFSET - 1)
89
90 /* ISO/IEC 10646 BMP */
91 #define LEADING_BYTE_UCS_BMP            (CHARSET_ID_OFFSET - 2)
92
93 /* VISCII 1.1 */
94 #define LEADING_BYTE_LATIN_VISCII       (CHARSET_ID_OFFSET - 3)
95
96 /* MULE VISCII-LOWER                    (CHARSET_ID_OFFSET_96 + '1') */
97 #define LEADING_BYTE_LATIN_VISCII_LOWER (CHARSET_ID_OFFSET - 4)
98
99 /* MULE VISCII-UPPER                    (CHARSET_ID_OFFSET_96 + '2') */
100 #define LEADING_BYTE_LATIN_VISCII_UPPER (CHARSET_ID_OFFSET - 5)
101
102 /* Big5 Level 1                 2/4 2/{(8),9,10,11} 4/0 '0' */
103 #define LEADING_BYTE_CHINESE_BIG5_1     (CHARSET_ID_OFFSET - 6)
104
105 /* Big5 Level 2                 2/4 2/{(8),9,10,11} 4/0 '1' */
106 #define LEADING_BYTE_CHINESE_BIG5_2     (CHARSET_ID_OFFSET - 7)
107
108 #define LEADING_BYTE_ETHIOPIC_UCS       (CHARSET_ID_OFFSET - 8)
109
110 #define LEADING_BYTE_DAIKANWA           (CHARSET_ID_OFFSET - 9)
111
112 /* Japanese JIS X0208-1990      2/4 2/{(8),9,10,11} 4/2 (B) */
113 #define LEADING_BYTE_JAPANESE_JISX0208_1990 (CHARSET_ID_OFFSET - 10)
114
115 /* Konjaku-Mojikyo font (for pseudo-JIS X 0208 encoding) */
116 #define LEADING_BYTE_MOJIKYO_PJ_1       (CHARSET_ID_OFFSET - 11)
117 #define LEADING_BYTE_MOJIKYO_PJ_2       (CHARSET_ID_OFFSET - 12)
118 #define LEADING_BYTE_MOJIKYO_PJ_3       (CHARSET_ID_OFFSET - 13)
119 #define LEADING_BYTE_MOJIKYO_PJ_4       (CHARSET_ID_OFFSET - 14)
120 #define LEADING_BYTE_MOJIKYO_PJ_5       (CHARSET_ID_OFFSET - 15)
121 #define LEADING_BYTE_MOJIKYO_PJ_6       (CHARSET_ID_OFFSET - 16)
122 #define LEADING_BYTE_MOJIKYO_PJ_7       (CHARSET_ID_OFFSET - 17)
123 #define LEADING_BYTE_MOJIKYO_PJ_8       (CHARSET_ID_OFFSET - 18)
124 #define LEADING_BYTE_MOJIKYO_PJ_9       (CHARSET_ID_OFFSET - 19)
125 #define LEADING_BYTE_MOJIKYO_PJ_10      (CHARSET_ID_OFFSET - 20)
126 #define LEADING_BYTE_MOJIKYO_PJ_11      (CHARSET_ID_OFFSET - 21)
127 #define LEADING_BYTE_MOJIKYO_PJ_12      (CHARSET_ID_OFFSET - 22)
128 #define LEADING_BYTE_MOJIKYO_PJ_13      (CHARSET_ID_OFFSET - 23)
129 #define LEADING_BYTE_MOJIKYO_PJ_14      (CHARSET_ID_OFFSET - 24)
130 #define LEADING_BYTE_MOJIKYO_PJ_15      (CHARSET_ID_OFFSET - 25)
131 #define LEADING_BYTE_MOJIKYO_PJ_16      (CHARSET_ID_OFFSET - 26)
132 #define LEADING_BYTE_MOJIKYO_PJ_17      (CHARSET_ID_OFFSET - 27)
133 #define LEADING_BYTE_MOJIKYO_PJ_18      (CHARSET_ID_OFFSET - 28)
134 #define LEADING_BYTE_MOJIKYO_PJ_19      (CHARSET_ID_OFFSET - 29)
135 #define LEADING_BYTE_MOJIKYO_PJ_20      (CHARSET_ID_OFFSET - 30)
136 #define LEADING_BYTE_MOJIKYO_PJ_21      (CHARSET_ID_OFFSET - 31)
137
138 #define MIN_LEADING_BYTE_PRIVATE        MIN_LEADING_BYTE
139 #define MAX_LEADING_BYTE_PRIVATE        (CHARSET_ID_OFFSET - 32)
140
141
142 /* #define CHARSET_ID_OFFSET_94         (CHARSET_ID_OFFSET - '0') */
143
144 /* #define MIN_CHARSET_ID_PRIVATE_94    (CHARSET_ID_OFFSET_94 + '0') */
145 /* #define MAX_CHARSET_ID_PRIVATE_94    (CHARSET_ID_OFFSET_94 + '?') */
146
147 /* ISO 646 IRV */
148 #define LEADING_BYTE_ASCII                6 /* (CHARSET_ID_OFFSET_94 + 'B') */
149
150 /* Right half of JIS X0201-1976 */
151 #define LEADING_BYTE_KATAKANA_JISX0201   13 /* (CHARSET_ID_OFFSET_94 + 'I') */
152
153 /* Left  half of JIS X0201-1976 */
154 #define LEADING_BYTE_LATIN_JISX0201      14 /* (CHARSET_ID_OFFSET_94 + 'J') */
155
156
157 /* #define CHARSET_ID_OFFSET_96         (CHARSET_ID_OFFSET_94 + 80) */
158
159 /* Right half of ISO 8859-1 */
160 #define LEADING_BYTE_LATIN_ISO8859_1    100 /* (CHARSET_ID_OFFSET_96 + 'A') */
161
162 /* Right half of ISO 8859-2 */
163 #define LEADING_BYTE_LATIN_ISO8859_2    101 /* (CHARSET_ID_OFFSET_96 + 'B') */
164
165 /* Right half of ISO 8859-3 */
166 #define LEADING_BYTE_LATIN_ISO8859_3    109 /* (CHARSET_ID_OFFSET_96 + 'C') */
167
168 /* Right half of ISO 8859-4 */
169 #define LEADING_BYTE_LATIN_ISO8859_4    110 /* (CHARSET_ID_OFFSET_96 + 'D') */
170
171 /* Right half of ISO 8859-7 */
172 #define LEADING_BYTE_GREEK_ISO8859_7    126 /* (CHARSET_ID_OFFSET_96 + 'F') */
173
174 /* Right half of ISO 8859-6 */
175 #define LEADING_BYTE_ARABIC_ISO8859_6   127 /* (CHARSET_ID_OFFSET_96 + 'G') */
176
177 /* Right half of ISO 8859-8 */
178 #define LEADING_BYTE_HEBREW_ISO8859_8   138 /* (CHARSET_ID_OFFSET_96 + 'H') */
179
180 /* Right half of ISO 8859-5 */
181 #define LEADING_BYTE_CYRILLIC_ISO8859_5 144 /* (CHARSET_ID_OFFSET_96 + 'L') */
182
183 /* Right half of ISO 8859-9 */
184 #define LEADING_BYTE_LATIN_ISO8859_9    148 /* (CHARSET_ID_OFFSET_96 + 'M') */
185
186 /* TIS620-2533 */
187 #define LEADING_BYTE_THAI_TIS620        166 /* (CHARSET_ID_OFFSET_96 + 'T') */
188
189
190 /* #define CHARSET_ID_OFFSET_94x94              (CHARSET_ID_OFFSET_96 + 80) */
191
192
193 /* #define MIN_LEADING_BYTE_PRIVATE_2   ('0' + CHARSET_ID_OFFSET_94x94) */
194 /* #define MAX_LEADING_BYTE_PRIVATE_2   ('?' + CHARSET_ID_OFFSET_94x94) */
195
196 /* Japanese JIS X0208-1978      2/4 2/{(8),9,10,11} 4/0 (@) */
197 #define LEADING_BYTE_JAPANESE_JISX0208_1978      42
198
199 /* Chinese Hanzi GB2312-1980    2/4 2/{(8),9,10,11} 4/1 (A) */
200 #define LEADING_BYTE_CHINESE_GB2312              58
201
202 /* Japanese JIS X0208-1983      2/4 2/{(8),9,10,11} 4/2 (B) */
203 #define LEADING_BYTE_JAPANESE_JISX0208           87
204
205 /* Hangul KS C5601-1987         2/4 2/{8,9,10,11} 4/3 (C) */
206 #define LEADING_BYTE_KOREAN_KSC5601             149
207
208 /* Japanese JIS X0212-1990      2/4 2/{8,9,10,11} 4/4 (D) */
209 #define LEADING_BYTE_JAPANESE_JISX0212          159
210
211 /* CCITT Extended GB            2/4 2/{8,9,10,11} 4/5 (E) */
212 #define LEADING_BYTE_CHINESE_CCITT_GB           165
213
214 /* Chinese CNS11643 Set 1       2/4 2/{8,9,10,11} 4/7 (G) */
215 #define LEADING_BYTE_CHINESE_CNS11643_1         171
216
217 /* Chinese CNS11643 Set 2       2/4 2/{8,9,10,11} 4/8 (H) */
218 #define LEADING_BYTE_CHINESE_CNS11643_2         172
219
220 /* Chinese CNS11643 Set 3       2/4 2/{8,9,10,11} 4/9 (I) */
221 #define LEADING_BYTE_CHINESE_CNS11643_3         183
222
223 /* Chinese CNS11643 Set 4       2/4 2/{8,9,10,11} 4/10 (J) */
224 #define LEADING_BYTE_CHINESE_CNS11643_4         184
225
226 /* Chinese CNS11643 Set 5       2/4 2/{8,9,10,11} 4/11 (K) */
227 #define LEADING_BYTE_CHINESE_CNS11643_5         185
228
229 /* Chinese CNS11643 Set 6       2/4 2/{8,9,10,11} 4/12 (L) */
230 #define LEADING_BYTE_CHINESE_CNS11643_6         186
231
232 /* Chinese CNS11643 Set 7       2/4 2/{8,9,10,11} 4/13 (M) */
233 #define LEADING_BYTE_CHINESE_CNS11643_7         187
234
235 /* DPRK Hangul KPS 9566-1997    2/4 2/{8,9,10,11} 4/14 (N) */
236 #define LEADING_BYTE_KOREAN_KPS9566             202
237
238
239 #define NUM_LEADING_BYTES       (80 * 3 - MIN_LEADING_BYTE)
240
241 \f
242 /************************************************************************/
243 /*            Information about a particular character set              */
244 /************************************************************************/
245
246 struct Lisp_Charset
247 {
248   struct lcrecord_header header;
249
250   int id;
251   Lisp_Object name;
252   Lisp_Object doc_string, registry, short_name, long_name;
253
254   Lisp_Object reverse_direction_charset;
255
256   Lisp_Object ccl_program;
257
258   /* Final byte of this character set in ISO2022 designating escape sequence */
259   Bufbyte final;
260
261   /* Number of columns a character in this charset takes up, on TTY
262      devices.  Not used for X devices. */
263   unsigned int columns;
264
265   /* Direction of this character set */
266   unsigned int direction;
267
268   /* Type of this character set (94, 96, 94x94, 96x96) */
269   unsigned int type;
270
271   /* Number of bytes used in encoding of this character set (1 or 2) */
272   unsigned int dimension;
273
274   /* Number of chars in each dimension (usually 94 or 96) */
275   unsigned int chars;
276
277   /* Which half of font to be used to display this character set */
278   unsigned int graphic;
279
280   /* Byte->character mapping table */
281   Lisp_Object decoding_table;
282
283   /* Range of character code */
284   Emchar ucs_min, ucs_max;
285
286   /* Offset for external code */
287   Emchar code_offset;
288
289   /* Offset for each byte */
290   Emchar byte_offset;
291 };
292
293 DECLARE_LRECORD (charset, struct Lisp_Charset);
294 #define XCHARSET(x) XRECORD (x, charset, struct Lisp_Charset)
295 #define XSETCHARSET(x, p) XSETRECORD (x, p, charset)
296 #define CHARSETP(x) RECORDP (x, charset)
297 #define GC_CHARSETP(x) GC_RECORDP (x, charset)
298 #define CHECK_CHARSET(x) CHECK_RECORD (x, charset)
299 #define CONCHECK_CHARSET(x) CONCHECK_RECORD (x, charset)
300
301 #define CHARSET_TYPE_94      0 /* This charset includes 94      characters. */
302 #define CHARSET_TYPE_94X94   1 /* This charset includes 94x94   characters. */
303 #define CHARSET_TYPE_96      2 /* This charset includes 96      characters. */
304 #define CHARSET_TYPE_96X96   3 /* This charset includes 96x96   characters. */
305 #define CHARSET_TYPE_128     4 /* This charset includes 128     characters. */
306 #define CHARSET_TYPE_128X128 5 /* This charset includes 128x128 characters. */
307 #define CHARSET_TYPE_256     6 /* This charset includes 256     characters. */
308 #define CHARSET_TYPE_256X256 7 /* This charset includes 256x256 characters. */
309
310 #define CHARSET_LEFT_TO_RIGHT   0
311 #define CHARSET_RIGHT_TO_LEFT   1
312
313 /* Leading byte and id have been regrouped. -- OG */
314 #define CHARSET_ID(cs)           ((cs)->id)
315 #define CHARSET_LEADING_BYTE(cs) (CHARSET_ID(cs))
316 #define CHARSET_NAME(cs)         ((cs)->name)
317 #define CHARSET_SHORT_NAME(cs)   ((cs)->short_name)
318 #define CHARSET_LONG_NAME(cs)    ((cs)->long_name)
319 #define CHARSET_COLUMNS(cs)      ((cs)->columns)
320 #define CHARSET_GRAPHIC(cs)      ((cs)->graphic)
321 #define CHARSET_TYPE(cs)         ((cs)->type)
322 #define CHARSET_DIRECTION(cs)    ((cs)->direction)
323 #define CHARSET_FINAL(cs)        ((cs)->final)
324 #define CHARSET_DOC_STRING(cs)   ((cs)->doc_string)
325 #define CHARSET_REGISTRY(cs)     ((cs)->registry)
326 #define CHARSET_CCL_PROGRAM(cs)  ((cs)->ccl_program)
327 #define CHARSET_DIMENSION(cs)    ((cs)->dimension)
328 #define CHARSET_CHARS(cs)        ((cs)->chars)
329 #define CHARSET_REVERSE_DIRECTION_CHARSET(cs) ((cs)->reverse_direction_charset)
330 #define CHARSET_DECODING_TABLE(cs) ((cs)->decoding_table)
331 #define CHARSET_UCS_MIN(cs)      ((cs)->ucs_min)
332 #define CHARSET_UCS_MAX(cs)      ((cs)->ucs_max)
333 #define CHARSET_CODE_OFFSET(cs)  ((cs)->code_offset)
334 #define CHARSET_BYTE_OFFSET(cs)  ((cs)->byte_offset)
335
336
337 #define XCHARSET_ID(cs)           CHARSET_ID           (XCHARSET (cs))
338 #define XCHARSET_NAME(cs)         CHARSET_NAME         (XCHARSET (cs))
339 #define XCHARSET_SHORT_NAME(cs)   CHARSET_SHORT_NAME   (XCHARSET (cs))
340 #define XCHARSET_LONG_NAME(cs)    CHARSET_LONG_NAME    (XCHARSET (cs))
341 #define XCHARSET_GRAPHIC(cs)      CHARSET_GRAPHIC      (XCHARSET (cs))
342 #define XCHARSET_TYPE(cs)         CHARSET_TYPE         (XCHARSET (cs))
343 #define XCHARSET_DIRECTION(cs)    CHARSET_DIRECTION    (XCHARSET (cs))
344 #define XCHARSET_FINAL(cs)        CHARSET_FINAL        (XCHARSET (cs))
345 #define XCHARSET_DOC_STRING(cs)   CHARSET_DOC_STRING   (XCHARSET (cs))
346 #define XCHARSET_REGISTRY(cs)     CHARSET_REGISTRY     (XCHARSET (cs))
347 #define XCHARSET_LEADING_BYTE(cs) CHARSET_LEADING_BYTE (XCHARSET (cs))
348 #define XCHARSET_CCL_PROGRAM(cs)  CHARSET_CCL_PROGRAM  (XCHARSET (cs))
349 #define XCHARSET_DIMENSION(cs)    CHARSET_DIMENSION    (XCHARSET (cs))
350 #define XCHARSET_CHARS(cs)        CHARSET_CHARS        (XCHARSET (cs))
351 #define XCHARSET_REVERSE_DIRECTION_CHARSET(cs) \
352   CHARSET_REVERSE_DIRECTION_CHARSET (XCHARSET (cs))
353 #define XCHARSET_DECODING_TABLE(cs) CHARSET_DECODING_TABLE(XCHARSET(cs))
354 #define XCHARSET_UCS_MIN(cs)      CHARSET_UCS_MIN(XCHARSET(cs))
355 #define XCHARSET_UCS_MAX(cs)      CHARSET_UCS_MAX(XCHARSET(cs))
356 #define XCHARSET_CODE_OFFSET(cs)  CHARSET_CODE_OFFSET(XCHARSET(cs))
357 #define XCHARSET_BYTE_OFFSET(cs)  CHARSET_BYTE_OFFSET(XCHARSET(cs))
358
359 /* Table of charsets indexed by (leading byte - 128). */
360 extern Lisp_Object charset_by_leading_byte[NUM_LEADING_BYTES];
361
362 /* Table of charsets indexed by type/final-byte. */
363 extern Lisp_Object charset_by_attributes[4][128];
364
365 #ifdef ERROR_CHECK_TYPECHECK
366 /* int not Bufbyte even though that is the actual type of a leading byte.
367    This way, out-ot-range values will get caught rather than automatically
368    truncated. */
369 INLINE Lisp_Object CHARSET_BY_LEADING_BYTE (Charset_ID lb);
370 INLINE Lisp_Object
371 CHARSET_BY_LEADING_BYTE (Charset_ID lb)
372 {
373   assert (lb >= MIN_LEADING_BYTE &&
374           lb < (MIN_LEADING_BYTE + NUM_LEADING_BYTES));
375   return charset_by_leading_byte[lb - MIN_LEADING_BYTE];
376 }
377
378 #else
379
380 #define CHARSET_BY_LEADING_BYTE(lb) \
381   (charset_by_leading_byte[(lb) - MIN_LEADING_BYTE])
382
383 #endif
384
385 #define CHARSET_BY_ATTRIBUTES(type, final, dir) \
386   (charset_by_attributes[type][final])
387
388 \f
389 /************************************************************************/
390 /*                        Dealing with characters                       */
391 /************************************************************************/
392
393 #define MAX_CHAR_BASIC_LATIN    0x007F
394
395 #define MIN_CHAR_GREEK          0x0370
396 #define MAX_CHAR_GREEK          0x03CF
397
398 #define MIN_CHAR_CYRILLIC       0x0400
399 #define MAX_CHAR_CYRILLIC       0x045F
400
401 #define MIN_CHAR_HEBREW         0x0590
402 #define MAX_CHAR_HEBREW         0x05EF
403
404 #define MIN_CHAR_THAI           0x0E00
405 #define MAX_CHAR_THAI           0x0E5F
406
407 #define MIN_CHAR_HIRAGANA       0x3041
408 #define MAX_CHAR_HIRAGANA       0x3093
409
410 #define MIN_CHAR_KATAKANA       0x30A1
411 #define MAX_CHAR_KATAKANA       0x30F6
412
413 #define MIN_CHAR_HALFWIDTH_KATAKANA     0xFF61
414 #define MAX_CHAR_HALFWIDTH_KATAKANA     0xFF9F
415
416 #define MIN_CHAR_OBS_94x94      0xE00000
417 #define MIN_CHAR_JIS_X0208_1990 0xE04508
418 #define MAX_CHAR_JIS_X0208_1990 0XE0678B
419 #define MAX_CHAR_OBS_94x94      0XE1E337
420
421 #define MIN_CHAR_DAIKANWA       0xE50000
422 #define MAX_CHAR_DAIKANWA       0xE5FFFF
423
424 #define MIN_CHAR_94             0xE90940
425 #define MAX_CHAR_94             (MIN_CHAR_94 + 94 * 80 - 1)
426 #define MIN_CHAR_96             (MIN_CHAR_94 + 94 * 80)
427 #define MAX_CHAR_96             (MIN_CHAR_96 + 96 * 80 - 1)
428
429 #define MIN_CHAR_94x94          0xE9F6C0
430 #define MAX_CHAR_94x94          (MIN_CHAR_94x94 + 94 * 94 * 80 - 1)
431 #define MIN_CHAR_96x96          0xF4C000
432 #define MAX_CHAR_96x96          (MIN_CHAR_96x96 + 96 * 96 * 80 - 1)
433
434
435 /* Return a character whose charset is CHARSET and position-codes
436    are C1 and C2.  TYPE9N character ignores C2. */
437
438 INLINE Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2);
439 INLINE Emchar
440 MAKE_CHAR (Lisp_Object charset, int c1, int c2)
441 {
442   Lisp_Object decoding_table = XCHARSET_DECODING_TABLE (charset);
443   int idx;
444   Lisp_Object ch;
445
446   if (!EQ (decoding_table, Qnil)
447       && (0 <= (idx = c1 - XCHARSET_BYTE_OFFSET (charset)))
448       && (idx < XVECTOR_LENGTH (decoding_table))
449       && !EQ (ch = XVECTOR_DATA(decoding_table)[idx], Qnil))
450     {
451       if (VECTORP (ch))
452         {
453           if ((0 <= (idx = c2 - XCHARSET_BYTE_OFFSET (charset)))
454               && (idx < XVECTOR_LENGTH (ch))
455               && !EQ (ch = XVECTOR_DATA(ch)[idx], Qnil))
456             return XCHAR (ch);
457         }
458       else
459         return XCHAR (ch);
460     }
461   if (XCHARSET_UCS_MAX (charset))
462     {
463       Emchar code
464         = (XCHARSET_DIMENSION (charset) == 1
465            ?
466            c1 - XCHARSET_BYTE_OFFSET (charset)
467            :
468            (c1 - XCHARSET_BYTE_OFFSET (charset)) * XCHARSET_CHARS (charset)
469            + c2  - XCHARSET_BYTE_OFFSET (charset))
470         - XCHARSET_CODE_OFFSET (charset) + XCHARSET_UCS_MIN (charset);
471       if ((code < XCHARSET_UCS_MIN (charset))
472           || (XCHARSET_UCS_MAX (charset) < code))
473         signal_simple_error ("Arguments makes invalid character",
474                              make_char (code));
475       return code;
476     }
477   else if (XCHARSET_DIMENSION (charset) == 1)
478     {
479       switch (XCHARSET_CHARS (charset))
480         {
481         case 94:
482           return MIN_CHAR_94
483             + (XCHARSET_FINAL (charset) - '0') * 94 + (c1 - 33);
484         case 96:
485           return MIN_CHAR_96
486             + (XCHARSET_FINAL (charset) - '0') * 96 + (c1 - 32);
487         default:
488           abort ();
489         }
490     }
491   else
492     {
493       switch (XCHARSET_CHARS (charset))
494         {
495         case 94:
496           return MIN_CHAR_94x94
497             + (XCHARSET_FINAL (charset) - '0') * 94 * 94
498             + (c1 - 33) * 94 + (c2 - 33);
499         case 96:
500           return MIN_CHAR_96x96
501             + (XCHARSET_FINAL (charset) - '0') * 96 * 96
502             + (c1 - 32) * 96 + (c2 - 32);
503         default:
504           abort ();
505         }
506     }
507 }
508
509 extern Lisp_Object Vcharacter_attribute_table;
510
511 Lisp_Object split_builtin_char (Emchar c);
512 Lisp_Object range_charset_code_point (Lisp_Object charset, Emchar ch);
513 Lisp_Object charset_code_point (Lisp_Object charset, Emchar ch);
514
515 extern Lisp_Object Vdefault_coded_charset_priority_list;
516 EXFUN (Ffind_charset, 1);
517
518 INLINE Lisp_Object SPLIT_CHAR (Emchar c);
519 INLINE Lisp_Object
520 SPLIT_CHAR (Emchar c)
521 {
522   Lisp_Object cdef = get_char_code_table (c, Vcharacter_attribute_table);
523
524   if (!EQ (cdef, Qnil))
525     {
526       Lisp_Object charsets = Vdefault_coded_charset_priority_list;
527       Lisp_Object field;
528
529       while (!EQ (charsets, Qnil))
530         {
531           Lisp_Object charset = Ffind_charset (Fcar (charsets));
532
533           if (!EQ (charset, Qnil))
534             {
535               if (!NILP (field = Fassq (charset, cdef)))
536                 return field;
537               else if (!NILP (field = range_charset_code_point (charset, c)))
538                 return Fcons (charset, field);
539             }
540           charsets = Fcdr (charsets);         
541         }
542     }
543   
544   /* otherwise --- maybe for bootstrap */
545   return split_builtin_char (c);
546 }
547
548 INLINE void breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2);
549 INLINE void
550 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
551 {
552   Lisp_Object ret = SPLIT_CHAR (c);
553
554   *charset = Fcar (ret);
555   ret = Fcdr (ret);
556   if (INTP (Fcar (ret)))
557     {
558       *c1 = XINT (Fcar (ret));
559       ret = Fcdr (ret);
560       if (INTP (Fcar (ret)))
561         *c2 = XINT (Fcar (ret));
562       else
563         *c2 = 0;
564     }
565   else
566     {
567       *c1 = *c2 = 0;
568     }
569 }
570
571 #define BREAKUP_CHAR(ch, charset, b1, b2) \
572   breakup_char_1 (ch, &(charset), &(b1), &(b2))
573
574 INLINE Lisp_Object CHAR_CHARSET (Emchar ch);
575 INLINE Lisp_Object
576 CHAR_CHARSET (Emchar ch)
577 {
578   Lisp_Object charset;
579   int b1, b2;
580
581   BREAKUP_CHAR(ch, charset, b1, b2);
582   return charset;
583 }
584
585 #define CHAR_CHARSET_ID(c)  (XCHARSET_ID(CHAR_CHARSET(c)))
586 #define CHAR_COLUMNS(c)     (CHARSET_COLUMNS(XCHARSET(CHAR_CHARSET(c))))
587
588 \f
589 /************************************************************************/
590 /*                            Exported functions                        */
591 /************************************************************************/
592
593 EXFUN (Fget_charset, 1);
594
595 extern Lisp_Object Vcharset_chinese_big5_1;
596 extern Lisp_Object Vcharset_chinese_big5_2;
597 extern Lisp_Object Vcharset_japanese_jisx0208;
598 extern Lisp_Object Vcharset_japanese_jisx0212;
599
600 #endif /* _XEMACS_CHAR_UCS_H */