update.
[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 Lisp_Object get_char_code_table (Emchar ch, Lisp_Object table);
49
50
51 extern Lisp_Object Vcharset_ucs_bmp;
52 extern Lisp_Object Vcharset_latin_jisx0201;
53 extern Lisp_Object Vcharset_latin_iso8859_2;
54 extern Lisp_Object Vcharset_latin_iso8859_3;
55 extern Lisp_Object Vcharset_latin_iso8859_4;
56 extern Lisp_Object Vcharset_latin_iso8859_9;
57 extern Lisp_Object Vcharset_latin_viscii_lower;
58 extern Lisp_Object Vcharset_latin_viscii_upper;
59
60 \f
61 /************************************************************************/
62 /*                    Definition of leading bytes                       */
63 /************************************************************************/
64
65 typedef int Charset_ID;
66
67 #define MIN_LEADING_BYTE                0x80
68
69 #define LEADING_BYTE_UCS_BMP            0x80
70 #define LEADING_BYTE_CONTROL_1          0x81 /* represent normal 80-9F */
71 #define LEADING_BYTE_HIRAGANA_JISX0208  0x82
72 #define LEADING_BYTE_KATAKANA_JISX0208  0x83
73 #define LEADING_BYTE_LATIN_VISCII       0x84
74
75 #define CHARSET_ID_OFFSET_94            0x55
76
77 #define MIN_CHARSET_ID_PRIVATE_94       (CHARSET_ID_OFFSET_94 + '0')
78 #define MAX_CHARSET_ID_PRIVATE_94       (CHARSET_ID_OFFSET_94 + '?')
79
80 /* ISO 646 IRV */
81 #define LEADING_BYTE_ASCII              (CHARSET_ID_OFFSET_94 + 'B')
82
83 /* Right half of JIS X0201-1976 */
84 #define LEADING_BYTE_KATAKANA_JISX0201  (CHARSET_ID_OFFSET_94 + 'I')
85
86 /* Left  half of JIS X0201-1976 */
87 #define LEADING_BYTE_LATIN_JISX0201     (CHARSET_ID_OFFSET_94 + 'J')
88
89
90 #define CHARSET_ID_OFFSET_96            0x70
91
92 #define LEADING_BYTE_LATIN_VISCII_LOWER (CHARSET_ID_OFFSET_96 + '1')
93 #define LEADING_BYTE_LATIN_VISCII_UPPER (CHARSET_ID_OFFSET_96 + '2')
94
95 /* Right half of ISO 8859-1 */
96 #define LEADING_BYTE_LATIN_ISO8859_1    (CHARSET_ID_OFFSET_96 + 'A')
97
98 /* Right half of ISO 8859-2 */
99 #define LEADING_BYTE_LATIN_ISO8859_2    (CHARSET_ID_OFFSET_96 + 'B')
100
101 /* Right half of ISO 8859-3 */
102 #define LEADING_BYTE_LATIN_ISO8859_3    (CHARSET_ID_OFFSET_96 + 'C')
103
104 /* Right half of ISO 8859-4 */
105 #define LEADING_BYTE_LATIN_ISO8859_4    (CHARSET_ID_OFFSET_96 + 'D')
106
107 /* Right half of ISO 8859-7 */
108 #define LEADING_BYTE_GREEK_ISO8859_7    (CHARSET_ID_OFFSET_96 + 'F')
109
110 /* Right half of ISO 8859-6 */
111 #define LEADING_BYTE_ARABIC_ISO8859_6   (CHARSET_ID_OFFSET_96 + 'G')
112
113 /* Right half of ISO 8859-8 */
114 #define LEADING_BYTE_HEBREW_ISO8859_8   (CHARSET_ID_OFFSET_96 + 'H')
115
116 /* Right half of ISO 8859-5 */
117 #define LEADING_BYTE_CYRILLIC_ISO8859_5 (CHARSET_ID_OFFSET_96 + 'L')
118
119 /* Right half of ISO 8859-9 */
120 #define LEADING_BYTE_LATIN_ISO8859_9    (CHARSET_ID_OFFSET_96 + 'M')
121
122 /* TIS620-2533 */
123 #define LEADING_BYTE_THAI_TIS620        (CHARSET_ID_OFFSET_96 + 'T')
124
125
126 #define MIN_LEADING_BYTE_PRIVATE_1      0xD0
127 #define MAX_LEADING_BYTE_PRIVATE_1      0xDF
128
129
130 #define CHARSET_ID_OFFSET_94x94         0xB0
131
132 /* Big5 Level 1 */
133 #define LEADING_BYTE_CHINESE_BIG5_1     ('0' + CHARSET_ID_OFFSET_94x94)
134
135 /* Big5 Level 2 */
136 #define LEADING_BYTE_CHINESE_BIG5_2     ('1' + CHARSET_ID_OFFSET_94x94)
137
138 #define MIN_LEADING_BYTE_PRIVATE_2      ('0' + CHARSET_ID_OFFSET_94x94)
139 #define MAX_LEADING_BYTE_PRIVATE_2      ('?' + CHARSET_ID_OFFSET_94x94)
140
141 /* Japanese JIS X0208-1978 */
142 #define LEADING_BYTE_JAPANESE_JISX0208_1978 \
143                                         ('@' + CHARSET_ID_OFFSET_94x94)
144
145 /* Chinese Hanzi GB2312-1980 */
146 #define LEADING_BYTE_CHINESE_GB2312     ('A' + CHARSET_ID_OFFSET_94x94)
147
148 /* Japanese JIS X0208-1983 */
149 #define LEADING_BYTE_JAPANESE_JISX0208  ('B' + CHARSET_ID_OFFSET_94x94)
150
151 /* Hangul KS C5601-1987 */
152 #define LEADING_BYTE_KOREAN_KSC5601     ('C' + CHARSET_ID_OFFSET_94x94)
153
154 /* Japanese JIS X0212-1990 */
155 #define LEADING_BYTE_JAPANESE_JISX0212  ('D' + CHARSET_ID_OFFSET_94x94)
156
157 /* CCITT Extended GB */
158 #define LEADING_BYTE_CHINESE_CCITT_GB   ('E' + CHARSET_ID_OFFSET_94x94)
159
160 /* Chinese CNS11643 Set 1 */
161 #define LEADING_BYTE_CHINESE_CNS11643_1 ('G' + CHARSET_ID_OFFSET_94x94)
162
163 /* Chinese CNS11643 Set 2 */
164 #define LEADING_BYTE_CHINESE_CNS11643_2 ('H' + CHARSET_ID_OFFSET_94x94)
165
166 /* Chinese CNS11643 Set 3 */
167 #define LEADING_BYTE_CHINESE_CNS11643_3 ('I' + CHARSET_ID_OFFSET_94x94)
168
169 /* Chinese CNS11643 Set 4 */
170 #define LEADING_BYTE_CHINESE_CNS11643_4 ('J' + CHARSET_ID_OFFSET_94x94)
171
172 /* Chinese CNS11643 Set 5 */
173 #define LEADING_BYTE_CHINESE_CNS11643_5 ('K' + CHARSET_ID_OFFSET_94x94)
174
175 /* Chinese CNS11643 Set 6 */
176 #define LEADING_BYTE_CHINESE_CNS11643_6 ('L' + CHARSET_ID_OFFSET_94x94)
177
178 /* Chinese CNS11643 Set 7 */
179 #define LEADING_BYTE_CHINESE_CNS11643_7 ('M' + CHARSET_ID_OFFSET_94x94)
180
181 /* DPRK Hangul KPS 9566-1997 */
182 #define LEADING_BYTE_KOREAN_KPS9566     ('N' + CHARSET_ID_OFFSET_94x94)
183
184 #define MIN_LEADING_BYTE_OFFICIAL_2     LEADING_BYTE_JAPANESE_JISX0208_1978
185 #define MAX_LEADING_BYTE_OFFICIAL_2     LEADING_BYTE_KOREAN_KPS9566
186
187 #define NUM_LEADING_BYTES 256
188
189 \f
190 /************************************************************************/
191 /*            Information about a particular character set              */
192 /************************************************************************/
193
194 struct Lisp_Charset
195 {
196   struct lcrecord_header header;
197
198   int id;
199   Lisp_Object name;
200   Lisp_Object doc_string, registry, short_name, long_name;
201
202   Lisp_Object reverse_direction_charset;
203
204   Lisp_Object ccl_program;
205
206   /* Final byte of this character set in ISO2022 designating escape sequence */
207   Bufbyte final;
208
209   /* Number of columns a character in this charset takes up, on TTY
210      devices.  Not used for X devices. */
211   unsigned int columns;
212
213   /* Direction of this character set */
214   unsigned int direction;
215
216   /* Type of this character set (94, 96, 94x94, 96x96) */
217   unsigned int type;
218
219   /* Number of bytes used in encoding of this character set (1 or 2) */
220   unsigned int dimension;
221
222   /* Number of chars in each dimension (usually 94 or 96) */
223   unsigned int chars;
224
225   /* Which half of font to be used to display this character set */
226   unsigned int graphic;
227
228   /* Byte->character mapping table */
229   Lisp_Object decoding_table;
230
231   /* Character->byte mapping table */
232   Lisp_Object encoding_table;
233
234   /* Range of character code */
235   Emchar ucs_min, ucs_max;
236
237   /* Offset for external code */
238   Emchar code_offset;
239
240   /* Offset for each byte */
241   Emchar byte_offset;
242 };
243
244 DECLARE_LRECORD (charset, struct Lisp_Charset);
245 #define XCHARSET(x) XRECORD (x, charset, struct Lisp_Charset)
246 #define XSETCHARSET(x, p) XSETRECORD (x, p, charset)
247 #define CHARSETP(x) RECORDP (x, charset)
248 #define GC_CHARSETP(x) GC_RECORDP (x, charset)
249 #define CHECK_CHARSET(x) CHECK_RECORD (x, charset)
250 #define CONCHECK_CHARSET(x) CONCHECK_RECORD (x, charset)
251
252 #define CHARSET_TYPE_94      0 /* This charset includes 94      characters. */
253 #define CHARSET_TYPE_94X94   1 /* This charset includes 94x94   characters. */
254 #define CHARSET_TYPE_96      2 /* This charset includes 96      characters. */
255 #define CHARSET_TYPE_96X96   3 /* This charset includes 96x96   characters. */
256 #define CHARSET_TYPE_128     4 /* This charset includes 128     characters. */
257 #define CHARSET_TYPE_128X128 5 /* This charset includes 128x128 characters. */
258 #define CHARSET_TYPE_256     6 /* This charset includes 256     characters. */
259 #define CHARSET_TYPE_256X256 7 /* This charset includes 256x256 characters. */
260
261 #define CHARSET_LEFT_TO_RIGHT   0
262 #define CHARSET_RIGHT_TO_LEFT   1
263
264 /* Leading byte and id have been regrouped. -- OG */
265 #define CHARSET_ID(cs)           ((cs)->id)
266 #define CHARSET_LEADING_BYTE(cs) ((Bufbyte)(CHARSET_ID(cs)))
267 #define CHARSET_NAME(cs)         ((cs)->name)
268 #define CHARSET_SHORT_NAME(cs)   ((cs)->short_name)
269 #define CHARSET_LONG_NAME(cs)    ((cs)->long_name)
270 #define CHARSET_COLUMNS(cs)      ((cs)->columns)
271 #define CHARSET_GRAPHIC(cs)      ((cs)->graphic)
272 #define CHARSET_TYPE(cs)         ((cs)->type)
273 #define CHARSET_DIRECTION(cs)    ((cs)->direction)
274 #define CHARSET_FINAL(cs)        ((cs)->final)
275 #define CHARSET_DOC_STRING(cs)   ((cs)->doc_string)
276 #define CHARSET_REGISTRY(cs)     ((cs)->registry)
277 #define CHARSET_CCL_PROGRAM(cs)  ((cs)->ccl_program)
278 #define CHARSET_DIMENSION(cs)    ((cs)->dimension)
279 #define CHARSET_CHARS(cs)        ((cs)->chars)
280 #define CHARSET_REVERSE_DIRECTION_CHARSET(cs) ((cs)->reverse_direction_charset)
281 #define CHARSET_DECODING_TABLE(cs) ((cs)->decoding_table)
282 #define CHARSET_ENCODING_TABLE(cs) ((cs)->encoding_table)
283 #define CHARSET_UCS_MIN(cs)      ((cs)->ucs_min)
284 #define CHARSET_UCS_MAX(cs)      ((cs)->ucs_max)
285 #define CHARSET_CODE_OFFSET(cs)  ((cs)->code_offset)
286 #define CHARSET_BYTE_OFFSET(cs)  ((cs)->byte_offset)
287
288
289 #define XCHARSET_ID(cs)           CHARSET_ID           (XCHARSET (cs))
290 #define XCHARSET_NAME(cs)         CHARSET_NAME         (XCHARSET (cs))
291 #define XCHARSET_SHORT_NAME(cs)   CHARSET_SHORT_NAME   (XCHARSET (cs))
292 #define XCHARSET_LONG_NAME(cs)    CHARSET_LONG_NAME    (XCHARSET (cs))
293 #define XCHARSET_GRAPHIC(cs)      CHARSET_GRAPHIC      (XCHARSET (cs))
294 #define XCHARSET_TYPE(cs)         CHARSET_TYPE         (XCHARSET (cs))
295 #define XCHARSET_DIRECTION(cs)    CHARSET_DIRECTION    (XCHARSET (cs))
296 #define XCHARSET_FINAL(cs)        CHARSET_FINAL        (XCHARSET (cs))
297 #define XCHARSET_DOC_STRING(cs)   CHARSET_DOC_STRING   (XCHARSET (cs))
298 #define XCHARSET_REGISTRY(cs)     CHARSET_REGISTRY     (XCHARSET (cs))
299 #define XCHARSET_LEADING_BYTE(cs) CHARSET_LEADING_BYTE (XCHARSET (cs))
300 #define XCHARSET_CCL_PROGRAM(cs)  CHARSET_CCL_PROGRAM  (XCHARSET (cs))
301 #define XCHARSET_DIMENSION(cs)    CHARSET_DIMENSION    (XCHARSET (cs))
302 #define XCHARSET_CHARS(cs)        CHARSET_CHARS        (XCHARSET (cs))
303 #define XCHARSET_REVERSE_DIRECTION_CHARSET(cs) \
304   CHARSET_REVERSE_DIRECTION_CHARSET (XCHARSET (cs))
305 #define XCHARSET_DECODING_TABLE(cs) CHARSET_DECODING_TABLE(XCHARSET(cs))
306 #define XCHARSET_ENCODING_TABLE(cs) CHARSET_ENCODING_TABLE(XCHARSET(cs))
307 #define XCHARSET_UCS_MIN(cs)      CHARSET_UCS_MIN(XCHARSET(cs))
308 #define XCHARSET_UCS_MAX(cs)      CHARSET_UCS_MAX(XCHARSET(cs))
309 #define XCHARSET_CODE_OFFSET(cs)  CHARSET_CODE_OFFSET(XCHARSET(cs))
310 #define XCHARSET_BYTE_OFFSET(cs)  CHARSET_BYTE_OFFSET(XCHARSET(cs))
311
312 /* Table of charsets indexed by (leading byte - 128). */
313 extern Lisp_Object charset_by_leading_byte[NUM_LEADING_BYTES];
314
315 /* Table of charsets indexed by type/final-byte. */
316 extern Lisp_Object charset_by_attributes[4][128];
317
318 #ifdef ERROR_CHECK_TYPECHECK
319 /* int not Bufbyte even though that is the actual type of a leading byte.
320    This way, out-ot-range values will get caught rather than automatically
321    truncated. */
322 INLINE Lisp_Object CHARSET_BY_LEADING_BYTE (Charset_ID lb);
323 INLINE Lisp_Object
324 CHARSET_BY_LEADING_BYTE (Charset_ID lb)
325 {
326   assert (lb >= MIN_LEADING_BYTE &&
327           lb < (MIN_LEADING_BYTE + NUM_LEADING_BYTES));
328   return charset_by_leading_byte[lb - MIN_LEADING_BYTE];
329 }
330
331 #else
332
333 #define CHARSET_BY_LEADING_BYTE(lb) \
334   (charset_by_leading_byte[(lb) - MIN_LEADING_BYTE])
335
336 #endif
337
338 #define CHARSET_BY_ATTRIBUTES(type, final, dir) \
339   (charset_by_attributes[type][final])
340
341 \f
342 /************************************************************************/
343 /*                        Dealing with characters                       */
344 /************************************************************************/
345
346 #define MAX_CHAR_BASIC_LATIN    0x007F
347
348 #define MIN_CHAR_GREEK          0x0370
349 #define MAX_CHAR_GREEK          0x03CF
350
351 #define MIN_CHAR_CYRILLIC       0x0400
352 #define MAX_CHAR_CYRILLIC       0x045F
353
354 #define MIN_CHAR_HEBREW         0x0590
355 #define MAX_CHAR_HEBREW         0x05EF
356
357 #define MIN_CHAR_THAI           0x0E00
358 #define MAX_CHAR_THAI           0x0E5F
359
360 #define MIN_CHAR_HIRAGANA       0x3041
361 #define MAX_CHAR_HIRAGANA       0x3093
362
363 #define MIN_CHAR_KATAKANA       0x30A1
364 #define MAX_CHAR_KATAKANA       0x30F6
365
366 #define MIN_CHAR_HALFWIDTH_KATAKANA     0xFF61
367 #define MAX_CHAR_HALFWIDTH_KATAKANA     0xFF9F
368
369 #define MIN_CHAR_OBS_94x94      0xE00000
370 #define MAX_CHAR_OBS_94x94      (0xE00000 + 94 * 94 * 14 - 1)
371
372 #define MIN_CHAR_94             0xE90940
373 #define MAX_CHAR_94             (MIN_CHAR_94 + 94 * 80 - 1)
374 #define MIN_CHAR_96             (MIN_CHAR_94 + 94 * 80)
375 #define MAX_CHAR_96             (MIN_CHAR_96 + 96 * 80 - 1)
376
377 #define MIN_CHAR_94x94          0xE9F6C0
378 #define MAX_CHAR_94x94          (MIN_CHAR_94x94 + 94 * 94 * 80 - 1)
379 #define MIN_CHAR_96x96          0xF4C000
380 #define MAX_CHAR_96x96          (MIN_CHAR_96x96 + 96 * 96 * 80 - 1)
381
382
383 /* Return a character whose charset is CHARSET and position-codes
384    are C1 and C2.  TYPE9N character ignores C2. */
385
386 INLINE Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2);
387 INLINE Emchar
388 MAKE_CHAR (Lisp_Object charset, int c1, int c2)
389 {
390   Lisp_Object decoding_table = XCHARSET_DECODING_TABLE (charset);
391   int idx;
392   Lisp_Object ch;
393
394   if (!EQ (decoding_table, Qnil)
395       && (0 <= (idx = c1 - XCHARSET_BYTE_OFFSET (charset)))
396       && (idx < XVECTOR_LENGTH (decoding_table))
397       && !EQ (ch = XVECTOR_DATA(decoding_table)[idx], Qnil))
398     {
399       if (VECTORP (ch))
400         {
401           if ((0 <= (idx = c2 - XCHARSET_BYTE_OFFSET (charset)))
402               && (idx < XVECTOR_LENGTH (ch))
403               && !EQ (ch = XVECTOR_DATA(ch)[idx], Qnil))
404             return XCHAR (ch);
405         }
406       else
407         return XCHAR (ch);
408     }
409   if (EQ (charset, Vcharset_katakana_jisx0201))
410     if (c1 < 0x60)
411       return c1 + MIN_CHAR_HALFWIDTH_KATAKANA - 33;
412     else
413       /* return MIN_CHAR_94 + ('I' - '0') * 94 + (c1 - 33); */
414       return ' ';
415   else if (XCHARSET_UCS_MAX (charset))
416     {
417       Emchar code
418         = (XCHARSET_DIMENSION (charset) == 1
419            ?
420            c1 - XCHARSET_BYTE_OFFSET (charset)
421            :
422            (c1 - XCHARSET_BYTE_OFFSET (charset)) * XCHARSET_CHARS (charset)
423            + c2  - XCHARSET_BYTE_OFFSET (charset))
424         - XCHARSET_CODE_OFFSET (charset) + XCHARSET_UCS_MIN (charset);
425       if ((code < XCHARSET_UCS_MIN (charset))
426           || (XCHARSET_UCS_MAX (charset) < code))
427         signal_simple_error ("Arguments makes invalid character",
428                              make_char (code));
429       return code;
430     }
431   else if (XCHARSET_DIMENSION (charset) == 1)
432     {
433       switch (XCHARSET_CHARS (charset))
434         {
435         case 94:
436           return MIN_CHAR_94
437             + (XCHARSET_FINAL (charset) - '0') * 94 + (c1 - 33);
438         case 96:
439           return MIN_CHAR_96
440             + (XCHARSET_FINAL (charset) - '0') * 96 + (c1 - 32);
441         default:
442           abort ();
443         }
444     }
445   else
446     {
447       switch (XCHARSET_CHARS (charset))
448         {
449         case 94:
450           return MIN_CHAR_94x94
451             + (XCHARSET_FINAL (charset) - '0') * 94 * 94
452             + (c1 - 33) * 94 + (c2 - 33);
453         case 96:
454           return MIN_CHAR_96x96
455             + (XCHARSET_FINAL (charset) - '0') * 96 * 96
456             + (c1 - 32) * 96 + (c2 - 32);
457         default:
458           abort ();
459         }
460     }
461 }
462
463 unsigned char charset_get_byte1 (Lisp_Object charset, Emchar ch);
464 unsigned char charset_get_byte2 (Lisp_Object charset, Emchar ch);
465
466 extern Lisp_Object Vdefault_coded_charset_priority_list;
467 EXFUN (Ffind_charset, 1);
468
469 INLINE void breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2);
470 INLINE void
471 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
472 {
473   if (c < MIN_CHAR_OBS_94x94)
474     {
475       Lisp_Object charsets = Vdefault_coded_charset_priority_list;
476       while (!EQ (charsets, Qnil))
477         {
478           *charset = Ffind_charset (Fcar (charsets));
479           if (!EQ (*charset, Qnil)
480               && (*c1 = charset_get_byte1 (*charset, c)) )
481             {
482               *c2 = charset_get_byte2 (*charset, c);
483               return;
484             }
485           charsets = Fcdr (charsets);         
486         }
487       /* otherwise --- maybe for bootstrap */
488       if (c <= MAX_CHAR_BASIC_LATIN)
489         {
490           *charset = Vcharset_ascii;
491           *c1 = charset_get_byte1 (*charset, c);
492           *c2 = charset_get_byte2 (*charset, c);
493         }
494       else if (c < 0xA0)
495         {
496           *charset = Vcharset_control_1;
497           *c1 = charset_get_byte1 (*charset, c);
498           *c2 = charset_get_byte2 (*charset, c);
499         }
500       else if (c <= 0xff)
501         {
502           *charset = Vcharset_latin_iso8859_1;
503           *c1 = charset_get_byte1 (*charset, c);
504           *c2 = charset_get_byte2 (*charset, c);
505         }
506       else if ((MIN_CHAR_GREEK <= c) && (c <= MAX_CHAR_GREEK))
507         {
508           *charset = Vcharset_greek_iso8859_7;
509           *c1 = c - MIN_CHAR_GREEK + 0x20;
510           *c2 = 0;
511         }
512       else if ((MIN_CHAR_CYRILLIC <= c) && (c <= MAX_CHAR_CYRILLIC))
513         {
514           *charset = Vcharset_cyrillic_iso8859_5;
515           *c1 = c - MIN_CHAR_CYRILLIC + 0x20;
516           *c2 = 0;
517         }
518       else if ((MIN_CHAR_HEBREW <= c) && (c <= MAX_CHAR_HEBREW))
519         {
520           *charset = Vcharset_hebrew_iso8859_8;
521           *c1 = c - MIN_CHAR_HEBREW + 0x20;
522           *c2 = 0;
523         }
524       else if ((MIN_CHAR_THAI <= c) && (c <= MAX_CHAR_THAI))
525         {
526           *charset = Vcharset_thai_tis620;
527           *c1 = c - MIN_CHAR_THAI + 0x20;
528           *c2 = 0;
529         }
530       else if ((MIN_CHAR_HALFWIDTH_KATAKANA <= c)
531                && (c <= MAX_CHAR_HALFWIDTH_KATAKANA))
532         {
533           *charset = Vcharset_katakana_jisx0201;
534           *c1 = c - MIN_CHAR_HALFWIDTH_KATAKANA + 33;
535           *c2 = 0;
536         }
537       else
538         {
539           *charset = Vcharset_ucs_bmp;
540           *c1 = c >> 8;
541           *c2 = c & 0xff;
542         }
543     }
544   else if (c <= MAX_CHAR_OBS_94x94)
545     {
546       *charset
547         = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_94X94,
548                                  ((c - MIN_CHAR_OBS_94x94) / (94 * 94)) + '@',
549                                  CHARSET_LEFT_TO_RIGHT);
550       *c1 = (((c - MIN_CHAR_OBS_94x94) / 94) % 94) + 33;
551       *c2 = ((c - MIN_CHAR_OBS_94x94) % 94) + 33;
552     }
553   else if (c <= MAX_CHAR_94)
554     {
555       *charset
556         = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_94,
557                                  ((c - MIN_CHAR_94) / 94) + '0',
558                                  CHARSET_LEFT_TO_RIGHT);
559       *c1 = ((c - MIN_CHAR_94) % 94) + 33;
560       *c2 = 0;
561     }
562   else if (c <= MAX_CHAR_96)
563     {
564       *charset
565         = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_96,
566                                  ((c - MIN_CHAR_96) / 96) + '0',
567                                  CHARSET_LEFT_TO_RIGHT);
568       *c1 = ((c - MIN_CHAR_96) % 96) + 32;
569       *c2 = 0;
570     }
571   else if (c <= MAX_CHAR_94x94)
572     {
573       *charset
574         = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_94X94,
575                                  ((c - MIN_CHAR_94x94) / (94 * 94)) + '0',
576                                  CHARSET_LEFT_TO_RIGHT);
577       *c1 = (((c - MIN_CHAR_94x94) / 94) % 94) + 33;
578       *c2 = ((c - MIN_CHAR_94x94) % 94) + 33;
579     }
580   else if (c <= MAX_CHAR_96x96)
581     {
582       *charset
583         = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_96X96,
584                                  ((c - MIN_CHAR_96x96) / (96 * 96)) + '0',
585                                  CHARSET_LEFT_TO_RIGHT);
586       *c1 = (((c - MIN_CHAR_96x96) / 96) % 96) + 32;
587       *c2 = ((c - MIN_CHAR_96x96) % 96) + 32;
588     }
589   else
590     {
591       printf("u+%x", c);
592       abort();
593     }
594 }
595
596 #define BREAKUP_CHAR(ch, charset, b1, b2) \
597   breakup_char_1 (ch, &(charset), &(b1), &(b2))
598
599 INLINE Lisp_Object CHAR_CHARSET (Emchar ch);
600 INLINE Lisp_Object
601 CHAR_CHARSET (Emchar ch)
602 {
603   Lisp_Object charset;
604   int b1, b2;
605
606   BREAKUP_CHAR(ch, charset, b1, b2);
607   return charset;
608 }
609
610 #define CHAR_LEADING_BYTE(c) (XCHARSET_LEADING_BYTE(CHAR_CHARSET(c)))
611
612 #define CHAR_COLUMNS(c)     (CHARSET_COLUMNS(XCHARSET(CHAR_CHARSET(c))))
613
614 \f
615 /************************************************************************/
616 /*                            Exported functions                        */
617 /************************************************************************/
618
619 EXFUN (Fget_charset, 1);
620
621 extern Lisp_Object Vcharset_chinese_big5_1;
622 extern Lisp_Object Vcharset_chinese_big5_2;
623 extern Lisp_Object Vcharset_japanese_jisx0208;
624 extern Lisp_Object Vcharset_japanese_jisx0212;
625
626 #endif /* _XEMACS_CHAR_UCS_H */