(Vcharset_ucs_smp): New variable.
[chise/xemacs-chise.git-] / src / char-ucs.h
index 0626bfc..5087c10 100644 (file)
@@ -1,5 +1,5 @@
 /* Header for UCS-4 character representation.
-   Copyright (C) 1999,2000 MORIOKA Tomohiko
+   Copyright (C) 1999,2000,2001 MORIOKA Tomohiko
 
 This file is part of XEmacs.
 
@@ -18,124 +18,145 @@ along with XEmacs; see the file COPYING.  If not, write to
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
-/* Rewritten by MORIOKA Tomohiko <tomo@m17n.org>. */
+#ifndef INCLUDED_char_ucs_h_
+#define INCLUDED_char_ucs_h_
 
-#ifndef _XEMACS_CHAR_UCS_H
-#define _XEMACS_CHAR_UCS_H
+#include "chartab.h"
+#include "elhash.h"
+
+extern Lisp_Object Vchar_attribute_hash_table;
 
 #define valid_char_p(ch) 1
 
 #define CHAR_ASCII_P(ch) ((ch) <= 0x7F)
 
-\f
-DECLARE_LRECORD (char_byte_table, struct Lisp_Char_Byte_Table);
-#define XCHAR_BYTE_TABLE(x) \
-  XRECORD (x, char_byte_table, struct Lisp_Char_Byte_Table)
-#define XSETCHAR_BYTE_TABLE(x, p) XSETRECORD (x, p, char_byte_table)
-#define CHAR_BYTE_TABLE_P(x) RECORDP (x, char_byte_table)
-#define GC_CHAR_BYTE_TABLE_P(x) GC_RECORDP (x, char_byte_table)
-/* #define CHECK_CHAR_BYTE_TABLE(x) CHECK_RECORD (x, char_byte_table)
-   char table entries should never escape to Lisp */
-
-struct Lisp_Char_Byte_Table
-{
-  struct lcrecord_header header;
-
-  Lisp_Object property[256];
-};
-
-
-DECLARE_LRECORD (char_code_table, struct Lisp_Char_Code_Table);
-#define XCHAR_CODE_TABLE(x) \
-  XRECORD (x, char_code_table, struct Lisp_Char_Code_Table)
-#define XSETCHAR_CODE_TABLE(x, p) XSETRECORD (x, p, char_code_table)
-#define CHAR_CODE_TABLE_P(x) RECORDP (x, char_code_table)
-#define GC_CHAR_CODE_TABLE_P(x) GC_RECORDP (x, char_code_table)
-/* #define CHECK_CHAR_CODE_TABLE(x) CHECK_RECORD (x, char_code_table)
-   char table entries should never escape to Lisp */
-
-struct Lisp_Char_Code_Table
-{
-  struct lcrecord_header header;
-
-  Lisp_Object table;
-};
-
-Lisp_Object get_char_code_table (Emchar ch, Lisp_Object table);
-
-
-extern Lisp_Object Vcharset_ucs_bmp;
+extern Lisp_Object Vcharset_mojikyo;
+extern Lisp_Object Vcharset_mojikyo_2022_1;
 extern Lisp_Object Vcharset_latin_jisx0201;
-extern Lisp_Object Vcharset_latin_iso8859_2;
-extern Lisp_Object Vcharset_latin_iso8859_3;
-extern Lisp_Object Vcharset_latin_iso8859_4;
-extern Lisp_Object Vcharset_latin_iso8859_9;
-extern Lisp_Object Vcharset_latin_viscii_lower;
-extern Lisp_Object Vcharset_latin_viscii_upper;
 
 \f
 /************************************************************************/
 /*                    Definition of leading bytes                       */
 /************************************************************************/
 
-typedef int Charset_ID;
+typedef short Charset_ID;
 
-#define MIN_LEADING_BYTE               -0x60
+#define MIN_LEADING_BYTE               -0x200
 #define CHARSET_ID_OFFSET              0x00
 
+/* ISO/IEC 10646 */
+#define LEADING_BYTE_UCS               (CHARSET_ID_OFFSET - 1)
+
 /* represent normal 80-9F */
-#define LEADING_BYTE_CONTROL_1         (CHARSET_ID_OFFSET - 1)
+#define LEADING_BYTE_CONTROL_1         (CHARSET_ID_OFFSET - 2)
 
 /* ISO/IEC 10646 BMP */
-#define LEADING_BYTE_UCS_BMP           (CHARSET_ID_OFFSET - 2)
+#define LEADING_BYTE_UCS_BMP           (CHARSET_ID_OFFSET - 3)
 
-/* VISCII 1.1 */
-#define LEADING_BYTE_LATIN_VISCII      (CHARSET_ID_OFFSET - 3)
+/* ISO/IEC 10646 SMP */
+#define LEADING_BYTE_UCS_SMP           (CHARSET_ID_OFFSET - 4)
 
-/* MULE VISCII-LOWER                   (CHARSET_ID_OFFSET_96 + '1') */
-#define LEADING_BYTE_LATIN_VISCII_LOWER        (CHARSET_ID_OFFSET - 4)
+/* ISO/IEC 10646 SIP */
+#define LEADING_BYTE_UCS_SIP           (CHARSET_ID_OFFSET - 5)
 
-/* MULE VISCII-UPPER                   (CHARSET_ID_OFFSET_96 + '2') */
-#define LEADING_BYTE_LATIN_VISCII_UPPER        (CHARSET_ID_OFFSET - 5)
+/* ISO/IEC 10646 for CNS */
+#define LEADING_BYTE_UCS_CNS           (CHARSET_ID_OFFSET - 6)
+
+/* ISO/IEC 10646 for JIS */
+#define LEADING_BYTE_UCS_JIS           (CHARSET_ID_OFFSET - 7)
+
+/* ISO/IEC 10646 for KS */
+#define LEADING_BYTE_UCS_KS            (CHARSET_ID_OFFSET - 8)
+
+/* ISO/IEC 10646 for Big5 */
+#define LEADING_BYTE_UCS_BIG5          (CHARSET_ID_OFFSET - 9)
+
+/* Japanese JIS X0208-1990     2/4 2/{(8),9,10,11} 4/2 (B) */
+#define LEADING_BYTE_JAPANESE_JISX0208_1990 (CHARSET_ID_OFFSET - 10)
+
+/* Chinese GB 12345-1990 */
+#define LEADING_BYTE_CHINESE_GB12345   (CHARSET_ID_OFFSET - 11)
+
+#define LEADING_BYTE_CHINESE_BIG5      (CHARSET_ID_OFFSET - 20)
 
 /* Big5 Level 1                        2/4 2/{(8),9,10,11} 4/0 '0' */
-#define LEADING_BYTE_CHINESE_BIG5_1    (CHARSET_ID_OFFSET - 6)
+#define LEADING_BYTE_CHINESE_BIG5_1    (CHARSET_ID_OFFSET - 21)
 
 /* Big5 Level 2                        2/4 2/{(8),9,10,11} 4/0 '1' */
-#define LEADING_BYTE_CHINESE_BIG5_2    (CHARSET_ID_OFFSET - 7)
+#define LEADING_BYTE_CHINESE_BIG5_2    (CHARSET_ID_OFFSET - 22)
 
-#define LEADING_BYTE_ETHIOPIC_UCS      (CHARSET_ID_OFFSET - 8)
+/* VISCII 1.1 */
+#define LEADING_BYTE_LATIN_VISCII      (CHARSET_ID_OFFSET - 24)
 
-#define LEADING_BYTE_DAIKANWA          (CHARSET_ID_OFFSET - 9)
+/* MULE VISCII-LOWER                   (CHARSET_ID_OFFSET_96 + '1') */
+#define LEADING_BYTE_LATIN_VISCII_LOWER        (CHARSET_ID_OFFSET - 25)
 
-/* Japanese JIS X0208-1990     2/4 2/{(8),9,10,11} 4/2 (B) */
-#define LEADING_BYTE_JAPANESE_JISX0208_1990 (CHARSET_ID_OFFSET - 10)
+/* MULE VISCII-UPPER                   (CHARSET_ID_OFFSET_96 + '2') */
+#define LEADING_BYTE_LATIN_VISCII_UPPER        (CHARSET_ID_OFFSET - 26)
+
+#define LEADING_BYTE_ETHIOPIC_UCS      (CHARSET_ID_OFFSET - 27)
+
+#define LEADING_BYTE_DAIKANWA          (CHARSET_ID_OFFSET - 28)
+#define LEADING_BYTE_DAIKANWA_EKANJI   (CHARSET_ID_OFFSET - 29)
+
+#define LEADING_BYTE_GT                        (CHARSET_ID_OFFSET - 30)
+#define LEADING_BYTE_GT_PJ_1           (CHARSET_ID_OFFSET - 31)
+#define LEADING_BYTE_GT_PJ_2           (CHARSET_ID_OFFSET - 32)
+#define LEADING_BYTE_GT_PJ_3           (CHARSET_ID_OFFSET - 33)
+#define LEADING_BYTE_GT_PJ_4           (CHARSET_ID_OFFSET - 34)
+#define LEADING_BYTE_GT_PJ_5           (CHARSET_ID_OFFSET - 35)
+#define LEADING_BYTE_GT_PJ_6           (CHARSET_ID_OFFSET - 36)
+#define LEADING_BYTE_GT_PJ_7           (CHARSET_ID_OFFSET - 37)
+#define LEADING_BYTE_GT_PJ_8           (CHARSET_ID_OFFSET - 38)
+#define LEADING_BYTE_GT_PJ_9           (CHARSET_ID_OFFSET - 39)
+#define LEADING_BYTE_GT_PJ_10          (CHARSET_ID_OFFSET - 40)
+#define LEADING_BYTE_GT_PJ_11          (CHARSET_ID_OFFSET - 41)
+
+#define LEADING_BYTE_MOJIKYO           (CHARSET_ID_OFFSET - 48)
+#define LEADING_BYTE_MOJIKYO_2022_1    (CHARSET_ID_OFFSET - 49)
+#define LEADING_BYTE_MOJIKYO_2022_2    (CHARSET_ID_OFFSET - 50)
 
 /* Konjaku-Mojikyo font (for pseudo-JIS X 0208 encoding) */
-#define LEADING_BYTE_MOJIKYO_PJ_1      (CHARSET_ID_OFFSET - 11)
-#define LEADING_BYTE_MOJIKYO_PJ_2      (CHARSET_ID_OFFSET - 12)
-#define LEADING_BYTE_MOJIKYO_PJ_3      (CHARSET_ID_OFFSET - 13)
-#define LEADING_BYTE_MOJIKYO_PJ_4      (CHARSET_ID_OFFSET - 14)
-#define LEADING_BYTE_MOJIKYO_PJ_5      (CHARSET_ID_OFFSET - 15)
-#define LEADING_BYTE_MOJIKYO_PJ_6      (CHARSET_ID_OFFSET - 16)
-#define LEADING_BYTE_MOJIKYO_PJ_7      (CHARSET_ID_OFFSET - 17)
-#define LEADING_BYTE_MOJIKYO_PJ_8      (CHARSET_ID_OFFSET - 18)
-#define LEADING_BYTE_MOJIKYO_PJ_9      (CHARSET_ID_OFFSET - 19)
-#define LEADING_BYTE_MOJIKYO_PJ_10     (CHARSET_ID_OFFSET - 20)
-#define LEADING_BYTE_MOJIKYO_PJ_11     (CHARSET_ID_OFFSET - 21)
-#define LEADING_BYTE_MOJIKYO_PJ_12     (CHARSET_ID_OFFSET - 22)
-#define LEADING_BYTE_MOJIKYO_PJ_13     (CHARSET_ID_OFFSET - 23)
-#define LEADING_BYTE_MOJIKYO_PJ_14     (CHARSET_ID_OFFSET - 24)
-#define LEADING_BYTE_MOJIKYO_PJ_15     (CHARSET_ID_OFFSET - 25)
-#define LEADING_BYTE_MOJIKYO_PJ_16     (CHARSET_ID_OFFSET - 26)
-#define LEADING_BYTE_MOJIKYO_PJ_17     (CHARSET_ID_OFFSET - 27)
-#define LEADING_BYTE_MOJIKYO_PJ_18     (CHARSET_ID_OFFSET - 28)
-#define LEADING_BYTE_MOJIKYO_PJ_19     (CHARSET_ID_OFFSET - 29)
-#define LEADING_BYTE_MOJIKYO_PJ_20     (CHARSET_ID_OFFSET - 30)
-#define LEADING_BYTE_MOJIKYO_PJ_21     (CHARSET_ID_OFFSET - 31)
+#define LEADING_BYTE_MOJIKYO_PJ_1      (CHARSET_ID_OFFSET - 51)
+#define LEADING_BYTE_MOJIKYO_PJ_2      (CHARSET_ID_OFFSET - 52)
+#define LEADING_BYTE_MOJIKYO_PJ_3      (CHARSET_ID_OFFSET - 53)
+#define LEADING_BYTE_MOJIKYO_PJ_4      (CHARSET_ID_OFFSET - 54)
+#define LEADING_BYTE_MOJIKYO_PJ_5      (CHARSET_ID_OFFSET - 55)
+#define LEADING_BYTE_MOJIKYO_PJ_6      (CHARSET_ID_OFFSET - 56)
+#define LEADING_BYTE_MOJIKYO_PJ_7      (CHARSET_ID_OFFSET - 57)
+#define LEADING_BYTE_MOJIKYO_PJ_8      (CHARSET_ID_OFFSET - 58)
+#define LEADING_BYTE_MOJIKYO_PJ_9      (CHARSET_ID_OFFSET - 59)
+#define LEADING_BYTE_MOJIKYO_PJ_10     (CHARSET_ID_OFFSET - 60)
+#define LEADING_BYTE_MOJIKYO_PJ_11     (CHARSET_ID_OFFSET - 61)
+#define LEADING_BYTE_MOJIKYO_PJ_12     (CHARSET_ID_OFFSET - 62)
+#define LEADING_BYTE_MOJIKYO_PJ_13     (CHARSET_ID_OFFSET - 63)
+#define LEADING_BYTE_MOJIKYO_PJ_14     (CHARSET_ID_OFFSET - 64)
+#define LEADING_BYTE_MOJIKYO_PJ_15     (CHARSET_ID_OFFSET - 65)
+#define LEADING_BYTE_MOJIKYO_PJ_16     (CHARSET_ID_OFFSET - 66)
+#define LEADING_BYTE_MOJIKYO_PJ_17     (CHARSET_ID_OFFSET - 67)
+#define LEADING_BYTE_MOJIKYO_PJ_18     (CHARSET_ID_OFFSET - 68)
+#define LEADING_BYTE_MOJIKYO_PJ_19     (CHARSET_ID_OFFSET - 69)
+#define LEADING_BYTE_MOJIKYO_PJ_20     (CHARSET_ID_OFFSET - 70)
+#define LEADING_BYTE_MOJIKYO_PJ_21     (CHARSET_ID_OFFSET - 71)
+
+#define LEADING_BYTE_CHINA3_JEF                (CHARSET_ID_OFFSET - 72)
+#define LEADING_BYTE_CBETA             (CHARSET_ID_OFFSET - 73)
+#define LEADING_BYTE_CHINESE_BIG5_CDP  (CHARSET_ID_OFFSET - 74)
+#define LEADING_BYTE_HANZIKU_1         (CHARSET_ID_OFFSET - 75)
+#define LEADING_BYTE_HANZIKU_2         (CHARSET_ID_OFFSET - 76)
+#define LEADING_BYTE_HANZIKU_3         (CHARSET_ID_OFFSET - 77)
+#define LEADING_BYTE_HANZIKU_4         (CHARSET_ID_OFFSET - 78)
+#define LEADING_BYTE_HANZIKU_5         (CHARSET_ID_OFFSET - 79)
+#define LEADING_BYTE_HANZIKU_6         (CHARSET_ID_OFFSET - 80)
+#define LEADING_BYTE_HANZIKU_7         (CHARSET_ID_OFFSET - 81)
+#define LEADING_BYTE_HANZIKU_8         (CHARSET_ID_OFFSET - 82)
+#define LEADING_BYTE_HANZIKU_9         (CHARSET_ID_OFFSET - 83)
+#define LEADING_BYTE_HANZIKU_10                (CHARSET_ID_OFFSET - 84)
+#define LEADING_BYTE_HANZIKU_11                (CHARSET_ID_OFFSET - 85)
+#define LEADING_BYTE_HANZIKU_12                (CHARSET_ID_OFFSET - 86)
 
 #define MIN_LEADING_BYTE_PRIVATE       MIN_LEADING_BYTE
-#define MAX_LEADING_BYTE_PRIVATE       (CHARSET_ID_OFFSET - 32)
+#define MAX_LEADING_BYTE_PRIVATE       (CHARSET_ID_OFFSET - 87)
 
 
 /* #define CHARSET_ID_OFFSET_94                (CHARSET_ID_OFFSET - '0') */
@@ -185,9 +206,11 @@ typedef int Charset_ID;
 /* TIS620-2533 */
 #define LEADING_BYTE_THAI_TIS620       166 /* (CHARSET_ID_OFFSET_96 + 'T') */
 
+/* Right-hand Part of the VSCII-2 (TCVN 5712:1983) */
+#define LEADING_BYTE_LATIN_TCVN5712    180 /* F = 5/10 0x5A `Z' */
 
-/* #define CHARSET_ID_OFFSET_94x94             (CHARSET_ID_OFFSET_96 + 80) */
 
+/* #define CHARSET_ID_OFFSET_94x94             (CHARSET_ID_OFFSET_96 + 80) */
 
 /* #define MIN_LEADING_BYTE_PRIVATE_2  ('0' + CHARSET_ID_OFFSET_94x94) */
 /* #define MAX_LEADING_BYTE_PRIVATE_2  ('?' + CHARSET_ID_OFFSET_94x94) */
@@ -248,7 +271,10 @@ struct Lisp_Charset
 
   int id;
   Lisp_Object name;
-  Lisp_Object doc_string, registry, short_name, long_name;
+  Lisp_Object doc_string;
+  Lisp_Object registry;
+  Lisp_Object short_name;
+  Lisp_Object long_name;
 
   Lisp_Object reverse_direction_charset;
 
@@ -264,19 +290,16 @@ struct Lisp_Charset
   /* Direction of this character set */
   unsigned int direction;
 
-  /* Type of this character set (94, 96, 94x94, 96x96) */
-  unsigned int type;
-
-  /* Number of bytes used in encoding of this character set (1 or 2) */
-  unsigned int dimension;
+  /* Number of bytes used in encoding of this character set (1 .. 4) */
+  unsigned short dimension;
 
-  /* Number of chars in each dimension (usually 94 or 96) */
-  unsigned int chars;
+  /* Number of chars in each dimension (94, 96, 128, 256) */
+  unsigned short chars;
 
   /* Which half of font to be used to display this character set */
   unsigned int graphic;
 
-  /* Byte->character mapping table */
+  /* Code-point->character mapping table */
   Lisp_Object decoding_table;
 
   /* Range of character code */
@@ -288,24 +311,16 @@ struct Lisp_Charset
   /* Offset for each byte */
   Emchar byte_offset;
 };
+typedef struct Lisp_Charset Lisp_Charset;
 
-DECLARE_LRECORD (charset, struct Lisp_Charset);
-#define XCHARSET(x) XRECORD (x, charset, struct Lisp_Charset)
+DECLARE_LRECORD (charset, Lisp_Charset);
+#define XCHARSET(x) XRECORD (x, charset, Lisp_Charset)
 #define XSETCHARSET(x, p) XSETRECORD (x, p, charset)
 #define CHARSETP(x) RECORDP (x, charset)
 #define GC_CHARSETP(x) GC_RECORDP (x, charset)
 #define CHECK_CHARSET(x) CHECK_RECORD (x, charset)
 #define CONCHECK_CHARSET(x) CONCHECK_RECORD (x, charset)
 
-#define CHARSET_TYPE_94      0 /* This charset includes 94      characters. */
-#define CHARSET_TYPE_94X94   1 /* This charset includes 94x94   characters. */
-#define CHARSET_TYPE_96      2 /* This charset includes 96      characters. */
-#define CHARSET_TYPE_96X96   3 /* This charset includes 96x96   characters. */
-#define CHARSET_TYPE_128     4 /* This charset includes 128     characters. */
-#define CHARSET_TYPE_128X128 5 /* This charset includes 128x128 characters. */
-#define CHARSET_TYPE_256     6 /* This charset includes 256     characters. */
-#define CHARSET_TYPE_256X256 7 /* This charset includes 256x256 characters. */
-
 #define CHARSET_LEFT_TO_RIGHT  0
 #define CHARSET_RIGHT_TO_LEFT  1
 
@@ -317,7 +332,6 @@ DECLARE_LRECORD (charset, struct Lisp_Charset);
 #define CHARSET_LONG_NAME(cs)   ((cs)->long_name)
 #define CHARSET_COLUMNS(cs)     ((cs)->columns)
 #define CHARSET_GRAPHIC(cs)     ((cs)->graphic)
-#define CHARSET_TYPE(cs)        ((cs)->type)
 #define CHARSET_DIRECTION(cs)   ((cs)->direction)
 #define CHARSET_FINAL(cs)       ((cs)->final)
 #define CHARSET_DOC_STRING(cs)  ((cs)->doc_string)
@@ -332,13 +346,20 @@ DECLARE_LRECORD (charset, struct Lisp_Charset);
 #define CHARSET_CODE_OFFSET(cs)         ((cs)->code_offset)
 #define CHARSET_BYTE_OFFSET(cs)         ((cs)->byte_offset)
 
+INLINE_HEADER Lisp_Object CHARSET_ENCODING_TABLE (Lisp_Charset* cs);
+INLINE_HEADER Lisp_Object
+CHARSET_ENCODING_TABLE (Lisp_Charset* cs)
+{
+  return Fgethash (CHARSET_NAME(cs),
+                  Vchar_attribute_hash_table,
+                  Qnil);
+}
 
 #define XCHARSET_ID(cs)                  CHARSET_ID           (XCHARSET (cs))
 #define XCHARSET_NAME(cs)        CHARSET_NAME         (XCHARSET (cs))
 #define XCHARSET_SHORT_NAME(cs)          CHARSET_SHORT_NAME   (XCHARSET (cs))
 #define XCHARSET_LONG_NAME(cs)   CHARSET_LONG_NAME    (XCHARSET (cs))
 #define XCHARSET_GRAPHIC(cs)      CHARSET_GRAPHIC      (XCHARSET (cs))
-#define XCHARSET_TYPE(cs)        CHARSET_TYPE         (XCHARSET (cs))
 #define XCHARSET_DIRECTION(cs)   CHARSET_DIRECTION    (XCHARSET (cs))
 #define XCHARSET_FINAL(cs)       CHARSET_FINAL        (XCHARSET (cs))
 #define XCHARSET_DOC_STRING(cs)          CHARSET_DOC_STRING   (XCHARSET (cs))
@@ -350,6 +371,7 @@ DECLARE_LRECORD (charset, struct Lisp_Charset);
 #define XCHARSET_REVERSE_DIRECTION_CHARSET(cs) \
   CHARSET_REVERSE_DIRECTION_CHARSET (XCHARSET (cs))
 #define XCHARSET_DECODING_TABLE(cs) CHARSET_DECODING_TABLE(XCHARSET(cs))
+#define XCHARSET_ENCODING_TABLE(cs) CHARSET_ENCODING_TABLE(XCHARSET(cs))
 #define XCHARSET_UCS_MIN(cs)     CHARSET_UCS_MIN(XCHARSET(cs))
 #define XCHARSET_UCS_MAX(cs)     CHARSET_UCS_MAX(XCHARSET(cs))
 #define XCHARSET_CODE_OFFSET(cs)  CHARSET_CODE_OFFSET(XCHARSET(cs))
@@ -361,6 +383,8 @@ struct charset_lookup {
   
   /* Table of charsets indexed by type/final-byte/direction. */
   Lisp_Object charset_by_attributes[4][128];
+
+  Charset_ID next_allocated_leading_byte;
 };
 
 extern struct charset_lookup *chlook;
@@ -369,8 +393,8 @@ extern struct charset_lookup *chlook;
 /* int not Bufbyte even though that is the actual type of a leading byte.
    This way, out-ot-range values will get caught rather than automatically
    truncated. */
-INLINE Lisp_Object CHARSET_BY_LEADING_BYTE (Charset_ID lb);
-INLINE Lisp_Object
+INLINE_HEADER Lisp_Object CHARSET_BY_LEADING_BYTE (Charset_ID lb);
+INLINE_HEADER Lisp_Object
 CHARSET_BY_LEADING_BYTE (Charset_ID lb)
 {
   assert (lb >= MIN_LEADING_BYTE &&
@@ -385,8 +409,22 @@ CHARSET_BY_LEADING_BYTE (Charset_ID lb)
 
 #endif
 
-#define CHARSET_BY_ATTRIBUTES(type, final, dir) \
-  (chlook->charset_by_attributes[type][final])
+INLINE_HEADER Lisp_Object
+CHARSET_BY_ATTRIBUTES (int chars, int dimension, int final, int dir);
+INLINE_HEADER Lisp_Object
+CHARSET_BY_ATTRIBUTES (int chars, int dimension, int final, int dir)
+{
+  int type;
+
+  if (chars == 94)
+    type = 0;
+  else if (chars == 96)
+    type = 1;
+  else
+    return Qnil;
+  type += dimension == 1 ? 0 : 2;
+  return chlook->charset_by_attributes[type][final];
+}
 
 \f
 /************************************************************************/
@@ -395,14 +433,10 @@ CHARSET_BY_LEADING_BYTE (Charset_ID lb)
 
 #define MAX_CHAR_BASIC_LATIN   0x007F
 
-#define MIN_CHAR_GREEK         0x0370
-#define MAX_CHAR_GREEK         0x03CF
-
-#define MIN_CHAR_CYRILLIC      0x0400
-#define MAX_CHAR_CYRILLIC      0x045F
-
+/*
 #define MIN_CHAR_HEBREW                0x0590
 #define MAX_CHAR_HEBREW                0x05EF
+*/
 
 #define MIN_CHAR_THAI          0x0E00
 #define MAX_CHAR_THAI          0x0E5F
@@ -420,10 +454,24 @@ CHARSET_BY_LEADING_BYTE (Charset_ID lb)
 
 #define MAX_CHAR_BMP           0x00FFFF
 
-#define MIN_CHAR_DAIKANWA      0xE00000
-#define MAX_CHAR_DAIKANWA      0xE0FFFF
+#define MIN_CHAR_SMP           0x010000
+#define MAX_CHAR_SMP           0x01FFFF
 
-#define MIN_CHAR_94            0xE90940
+#define MIN_CHAR_SIP           0x020000
+#define MAX_CHAR_SIP           0x02FFFF
+
+#define MIN_CHAR_DAIKANWA      0x00E00000
+#define MAX_CHAR_DAIKANWA      (MIN_CHAR_DAIKANWA + 50100) /* 0xE0FFFF */
+/*
+#define MIN_CHAR_MOJIKYO_0     MIN_CHAR_DAIKANWA
+#define MAX_CHAR_MOJIKYO_0     (MIN_CHAR_MOJIKYO_0 + 94 * 60 * 22)
+*/
+#define MIN_CHAR_CBETA         0x00E20000
+#define MAX_CHAR_CBETA         0x00E2FFFF
+#define MIN_CHAR_CHINA3_JEF    0x00E80000
+#define MAX_CHAR_CHINA3_JEF    0x00E8FFFF
+
+#define MIN_CHAR_94            0x00E90940
 #define MAX_CHAR_94            (MIN_CHAR_94 + 94 * 80 - 1)
 #define MIN_CHAR_96            (MIN_CHAR_94 + 94 * 80)
 #define MAX_CHAR_96            (MIN_CHAR_96 + 96 * 80 - 1)
@@ -435,124 +483,239 @@ CHARSET_BY_LEADING_BYTE (Charset_ID lb)
 #define MIN_CHAR_96x96         0xF4C000
 #define MAX_CHAR_96x96         (MIN_CHAR_96x96 + 96 * 96 * 80 - 1)
 
+#define MIN_CHAR_MOJIKYO       0x60000000
+#define MAX_CHAR_MOJIKYO       (MIN_CHAR_MOJIKYO + 94 * 60 * 22)
+#define MIN_CHAR_GT            0x61000000
+#define MAX_CHAR_GT            (MIN_CHAR_GT + 66773)
+#define MIN_CHAR_BIG5_CDP      0x62000000
+#define MAX_CHAR_BIG5_CDP      0x6200FFFF
+#define MIN_CHAR_HANZIKU_1     (0x62000000 + 65536 * 1)
+#define MAX_CHAR_HANZIKU_1     (0x62000000 + 65536 * 1 + 65535)
+#define MIN_CHAR_HANZIKU_2     (0x62000000 + 65536 * 2)
+#define MAX_CHAR_HANZIKU_2     (0x62000000 + 65536 * 2 + 65535)
+#define MIN_CHAR_HANZIKU_3     (0x62000000 + 65536 * 3)
+#define MAX_CHAR_HANZIKU_3     (0x62000000 + 65536 * 3 + 65535)
+#define MIN_CHAR_HANZIKU_4     (0x62000000 + 65536 * 4)
+#define MAX_CHAR_HANZIKU_4     (0x62000000 + 65536 * 4 + 65535)
+#define MIN_CHAR_HANZIKU_5     (0x62000000 + 65536 * 5)
+#define MAX_CHAR_HANZIKU_5     (0x62000000 + 65536 * 5 + 65535)
+#define MIN_CHAR_HANZIKU_6     (0x62000000 + 65536 * 6)
+#define MAX_CHAR_HANZIKU_6     (0x62000000 + 65536 * 6 + 65535)
+#define MIN_CHAR_HANZIKU_7     (0x62000000 + 65536 * 7)
+#define MAX_CHAR_HANZIKU_7     (0x62000000 + 65536 * 7 + 65535)
+#define MIN_CHAR_HANZIKU_8     (0x62000000 + 65536 * 8)
+#define MAX_CHAR_HANZIKU_8     (0x62000000 + 65536 * 8 + 65535)
+#define MIN_CHAR_HANZIKU_9     (0x62000000 + 65536 * 9)
+#define MAX_CHAR_HANZIKU_9     (0x62000000 + 65536 * 9 + 65535)
+#define MIN_CHAR_HANZIKU_10    (0x62000000 + 65536 * 10)
+#define MAX_CHAR_HANZIKU_10    (0x62000000 + 65536 * 10 + 65535)
+#define MIN_CHAR_HANZIKU_11    (0x62000000 + 65536 * 11)
+#define MAX_CHAR_HANZIKU_11    (0x62000000 + 65536 * 11 + 65535)
+#define MIN_CHAR_HANZIKU_12    (0x62000000 + 65536 * 12)
+#define MAX_CHAR_HANZIKU_12    (0x62000000 + 65536 * 12 + 65535)
+
+Emchar decode_builtin_char (Lisp_Object charset, int code_point);
+
+INLINE_HEADER int
+DECODE_MOJIKYO_2022 (unsigned char b1, unsigned char b2, unsigned char b3);
+INLINE_HEADER int
+DECODE_MOJIKYO_2022 (unsigned char b1, unsigned char b2, unsigned char b3)
+{
+  if (b2 < 16 + 32)
+    return 0;
+  else if (b2 < 16 + 32 + 30)
+    return
+      (b1 - 33) * (94 * 60)
+      + (b2 - (16 + 32)) * 94
+      + (b3 - 33)
+      + 1;
+  else if (b2 < 18 + 32 + 30)
+    return 0;
+  else if (b2 < 18 + 32 + 60)
+    return
+      (b1 - 33) * (94 * 60)
+      + (b2 - (18 + 32)) * 94
+      + (b3 - 33)
+      + 1;
+  else
+    return 0;
+}
 
-/* Return a character whose charset is CHARSET and position-codes
-   are C1 and C2.  TYPE9N character ignores C2. */
+extern Lisp_Object Vcharset_chinese_big5;
+extern Lisp_Object Vcharset_chinese_big5_1;
+extern Lisp_Object Vcharset_chinese_big5_2;
 
-INLINE Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2);
-INLINE Emchar
-MAKE_CHAR (Lisp_Object charset, int c1, int c2)
+INLINE_HEADER Emchar
+DECODE_DEFINED_CHAR (Lisp_Object charset, int code_point);
+INLINE_HEADER Emchar
+DECODE_DEFINED_CHAR (Lisp_Object charset, int code_point)
 {
+  int dim = XCHARSET_DIMENSION (charset);
   Lisp_Object decoding_table = XCHARSET_DECODING_TABLE (charset);
   int idx;
   Lisp_Object ch;
 
-  if (!EQ (decoding_table, Qnil)
-      && (0 <= (idx = c1 - XCHARSET_BYTE_OFFSET (charset)))
-      && (idx < XVECTOR_LENGTH (decoding_table))
-      && !EQ (ch = XVECTOR_DATA(decoding_table)[idx], Qnil))
+  while (dim > 0)
     {
-      if (VECTORP (ch))
+      dim--;
+      if ( VECTORP (decoding_table)
+          && ( 0 <= (idx = ((code_point >> (dim * 8))
+                            & 255) - XCHARSET_BYTE_OFFSET (charset)) )
+          && ( idx < XVECTOR_LENGTH (decoding_table) )
+          && !NILP (ch = XVECTOR_DATA(decoding_table)[idx]) )
        {
-         if ((0 <= (idx = c2 - XCHARSET_BYTE_OFFSET (charset)))
-             && (idx < XVECTOR_LENGTH (ch))
-             && !EQ (ch = XVECTOR_DATA(ch)[idx], Qnil))
+         if (CHARP (ch))
            return XCHAR (ch);
+         else
+           decoding_table = ch;
        }
       else
-       return XCHAR (ch);
+       break;
     }
-  if (XCHARSET_UCS_MAX (charset))
+  return -1;
+}
+
+INLINE_HEADER Emchar DECODE_CHAR (Lisp_Object charset, int code_point);
+INLINE_HEADER Emchar
+DECODE_CHAR (Lisp_Object charset, int code_point)
+{
+  Emchar char_id = DECODE_DEFINED_CHAR (charset, code_point);
+
+  if (char_id >= 0)
+    return char_id;
+  else if (XCHARSET_DIMENSION (charset) == 1)
+    return decode_builtin_char (charset, code_point);
+  else if (EQ (charset, Vcharset_chinese_big5_1))
     {
-      Emchar code
-       = (XCHARSET_DIMENSION (charset) == 1
-          ?
-          c1 - XCHARSET_BYTE_OFFSET (charset)
-          :
-          (c1 - XCHARSET_BYTE_OFFSET (charset)) * XCHARSET_CHARS (charset)
-          + c2  - XCHARSET_BYTE_OFFSET (charset))
-       - XCHARSET_CODE_OFFSET (charset) + XCHARSET_UCS_MIN (charset);
-      if ((code < XCHARSET_UCS_MIN (charset))
-         || (XCHARSET_UCS_MAX (charset) < code))
-       signal_simple_error ("Arguments makes invalid character",
-                            make_char (code));
-      return code;
+      unsigned int I
+       = ((code_point >> 8) - 33) * (0xFF - 0xA1)
+       + ((code_point & 0xFF) - 33);
+      unsigned char b1 = I / (0xFF - 0xA1 + 0x7F - 0x40) + 0xA1;
+      unsigned char b2 = I % (0xFF - 0xA1 + 0x7F - 0x40);
+
+      b2 += b2 < 0x3F ? 0x40 : 0x62;
+      return DECODE_CHAR (Vcharset_chinese_big5, (b1 << 8) | b2);
     }
-  else if (XCHARSET_DIMENSION (charset) == 1)
+  else if (EQ (charset, Vcharset_chinese_big5_2))
     {
-      switch (XCHARSET_CHARS (charset))
-       {
-       case 94:
-         return MIN_CHAR_94
-           + (XCHARSET_FINAL (charset) - '0') * 94 + (c1 - 33);
-       case 96:
-         return MIN_CHAR_96
-           + (XCHARSET_FINAL (charset) - '0') * 96 + (c1 - 32);
-       default:
-         abort ();
-       }
+      unsigned int I
+       = ((code_point >> 8) - 33) * (0xFF - 0xA1)
+       + ((code_point & 0xFF) - 33);
+      unsigned char b1, b2;
+
+      I += (0xFF - 0xA1 + 0x7F - 0x40) * (0xC9 - 0xA1);
+      b1 = I / (0xFF - 0xA1 + 0x7F - 0x40) + 0xA1;
+      b2 = I % (0xFF - 0xA1 + 0x7F - 0x40);
+      b2 += b2 < 0x3F ? 0x40 : 0x62;
+      return DECODE_CHAR (Vcharset_chinese_big5, (b1 << 8) | b2);
+    }
+  else if (EQ (charset, Vcharset_mojikyo_2022_1))
+    {
+      int m =
+       DECODE_MOJIKYO_2022
+       ((unsigned char)(code_point >> 16),
+        (unsigned char)(code_point >>  8),
+        (unsigned char) code_point);
+
+      if (m > 0)
+       return DECODE_CHAR (Vcharset_mojikyo, m);
+      else
+       return ' ';
     }
   else
     {
-      switch (XCHARSET_CHARS (charset))
+      int plane = LEADING_BYTE_MOJIKYO_PJ_1 - XCHARSET_ID (charset);
+
+      if ( (0 <= plane) && (plane < 21) )
        {
-       case 94:
-         return MIN_CHAR_94x94
-           + (XCHARSET_FINAL (charset) - '0') * 94 * 94
-           + (c1 - 33) * 94 + (c2 - 33);
-       case 96:
-         return MIN_CHAR_96x96
-           + (XCHARSET_FINAL (charset) - '0') * 96 * 96
-           + (c1 - 32) * 96 + (c2 - 32);
-       default:
-         abort ();
+         int m = DECODE_MOJIKYO_2022 (plane + 33,
+                                      code_point >> 8,
+                                      (unsigned char)code_point);
+         if (m > 0)
+           return DECODE_CHAR (Vcharset_mojikyo, m);
+         else
+           return ' ';
        }
+      else
+       return decode_builtin_char (charset, code_point);
     }
 }
 
+/* Return a character whose charset is CHARSET and position-codes
+   are C1 and C2.  TYPE9N character ignores C2. */
+
+INLINE_HEADER Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2);
+INLINE_HEADER Emchar
+MAKE_CHAR (Lisp_Object charset, int c1, int c2)
+{
+  if (XCHARSET_DIMENSION (charset) == 1)
+    return DECODE_CHAR (charset, c1);
+  else
+    return DECODE_CHAR (charset, (c1 << 8) | c2);
+}
+
 extern Lisp_Object Vcharacter_attribute_table;
 
 int encode_builtin_char_1 (Emchar c, Lisp_Object* charset);
 int range_charset_code_point (Lisp_Object charset, Emchar ch);
-int charset_code_point (Lisp_Object charset, Emchar ch);
+
+INLINE_HEADER int charset_code_point (Lisp_Object charset, Emchar ch);
+INLINE_HEADER int
+charset_code_point (Lisp_Object charset, Emchar ch)
+{
+  Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (charset);
+  Lisp_Object ret;
+
+  if ( CHAR_TABLEP (encoding_table)
+       && INTP (ret = get_char_id_table (XCHAR_TABLE(encoding_table),
+                                        ch)) )
+    return XINT (ret);
+  else
+    return range_charset_code_point (charset, ch);
+}
 
 extern Lisp_Object Vdefault_coded_charset_priority_list;
 EXFUN (Ffind_charset, 1);
 
-INLINE int encode_char_1 (Emchar c, Lisp_Object* charset);
-INLINE int
-encode_char_1 (Emchar c, Lisp_Object* charset)
+INLINE_HEADER int encode_char_1 (Emchar ch, Lisp_Object* charset);
+INLINE_HEADER int
+encode_char_1 (Emchar ch, Lisp_Object* charset)
 {
-  Lisp_Object cdef = get_char_code_table (c, Vcharacter_attribute_table);
+  Lisp_Object charsets = Vdefault_coded_charset_priority_list;
 
-  if (!EQ (cdef, Qnil))
+  while (!NILP (charsets))
     {
-      Lisp_Object charsets = Vdefault_coded_charset_priority_list;
-      Lisp_Object field;
-
-      while (!EQ (charsets, Qnil))
+      *charset = Ffind_charset (Fcar (charsets));
+      if (!NILP (*charset))
        {
-         int code_point;
-
-         *charset = Ffind_charset (Fcar (charsets));
-         if (!EQ (*charset, Qnil))
+         Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (*charset);
+         Lisp_Object ret;
+
+         if ( CHAR_TABLEP (encoding_table)
+              && INTP (ret
+                       = get_char_id_table (XCHAR_TABLE(encoding_table),
+                                            ch)) )
+           return XINT (ret);
+         else
            {
-             if (!NILP (field = Fassq (*charset, cdef)))
-               return XINT (Fcdr (field));
-             else if ((code_point
-                       = range_charset_code_point (*charset, c)) >= 0)
+             int code_point = range_charset_code_point (*charset, ch);
+
+             if (code_point >= 0)
                return code_point;
            }
-         charsets = Fcdr (charsets);         
        }
+      charsets = Fcdr (charsets);            
     }
   
   /* otherwise --- maybe for bootstrap */
-  return encode_builtin_char_1 (c, charset);
+  return encode_builtin_char_1 (ch, charset);
 }
 
-INLINE void breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2);
-INLINE void
+#define ENCODE_CHAR(ch, charset)       encode_char_1 (ch, &(charset))
+
+INLINE_HEADER void
+breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2);
+INLINE_HEADER void
 breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
 {
   int code_point = encode_char_1 (c, charset);
@@ -580,20 +743,52 @@ breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2)
 #define BREAKUP_CHAR(ch, charset, b1, b2) \
   breakup_char_1 (ch, &(charset), &(b1), &(b2))
 
-INLINE Lisp_Object CHAR_CHARSET (Emchar ch);
-INLINE Lisp_Object
+INLINE_HEADER Lisp_Object CHAR_CHARSET (Emchar ch);
+INLINE_HEADER Lisp_Object
 CHAR_CHARSET (Emchar ch)
 {
   Lisp_Object charset;
-  int b1, b2;
-
-  BREAKUP_CHAR(ch, charset, b1, b2);
+  ENCODE_CHAR (ch, charset);
   return charset;
 }
 
 #define CHAR_CHARSET_ID(c)  (XCHARSET_ID(CHAR_CHARSET(c)))
 #define CHAR_COLUMNS(c)     (CHARSET_COLUMNS(XCHARSET(CHAR_CHARSET(c))))
 
+
+typedef struct Charc
+{
+  Lisp_Object charset;
+  int code_point;
+} Charc;
+
+INLINE_HEADER Charc CHAR_TO_CHARC (Emchar ch);
+INLINE_HEADER Charc
+CHAR_TO_CHARC (Emchar ch)
+{
+  Charc cc;
+
+  cc.code_point = encode_char_1 (ch, &cc.charset);
+  if (EQ (cc.charset, Vcharset_mojikyo))
+    {
+      int plane, byte1, byte2;
+
+      cc.code_point--;
+      plane = cc.code_point / (94 * 60);
+      byte1 = (cc.code_point % (94 * 60)) / 94;
+      if (byte1 < 30)
+       byte1 += 16 + 32;
+      else
+       byte1 += 18 + 32;
+      byte2 = cc.code_point % 94 + 33;
+      cc.charset
+       = CHARSET_BY_LEADING_BYTE (LEADING_BYTE_MOJIKYO_PJ_1 - plane);
+      cc.code_point = (byte1 << 8) | byte2;
+    }
+  return cc;
+}
+
 \f
 /************************************************************************/
 /*                            Exported functions                        */
@@ -601,9 +796,14 @@ CHAR_CHARSET (Emchar ch)
 
 EXFUN (Fget_charset, 1);
 
-extern Lisp_Object Vcharset_chinese_big5_1;
-extern Lisp_Object Vcharset_chinese_big5_2;
+extern Lisp_Object Qucs;
+
 extern Lisp_Object Vcharset_japanese_jisx0208;
+extern Lisp_Object Vcharset_japanese_jisx0208_1990;
 extern Lisp_Object Vcharset_japanese_jisx0212;
 
-#endif /* _XEMACS_CHAR_UCS_H */
+Lisp_Object put_char_ccs_code_point (Lisp_Object character,
+                                    Lisp_Object ccs, Lisp_Object value);
+Lisp_Object remove_char_ccs (Lisp_Object character, Lisp_Object ccs);
+
+#endif /* INCLUDED_char_ucs_h_ */