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