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