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