Rename `vietnamese-viscii-*' to `latin-viscii-*'.
[chise/xemacs-chise.git-] / src / mule-charset.c
index 4740373..db6b2b8 100644 (file)
@@ -58,11 +58,11 @@ Lisp_Object Vcharset_japanese_jisx0212;
 Lisp_Object Vcharset_chinese_cns11643_1;
 Lisp_Object Vcharset_chinese_cns11643_2;
 #ifdef UTF2000
-Lisp_Object Vcharset_chinese_cns11643_3;
-Lisp_Object Vcharset_chinese_cns11643_4;
-Lisp_Object Vcharset_chinese_cns11643_5;
-Lisp_Object Vcharset_chinese_cns11643_6;
-Lisp_Object Vcharset_chinese_cns11643_7;
+Lisp_Object Vcharset_ucs_bmp;
+Lisp_Object Vcharset_latin_viscii_lower;
+Lisp_Object Vcharset_latin_viscii_upper;
+Lisp_Object Vcharset_hiragana_jisx0208;
+Lisp_Object Vcharset_katakana_jisx0208;
 #endif
 Lisp_Object Vcharset_chinese_big5_1;
 Lisp_Object Vcharset_chinese_big5_2;
@@ -85,7 +85,11 @@ static int composite_char_col_next;
 Lisp_Object charset_by_leading_byte[NUM_LEADING_BYTES];
 
 /* Table of charsets indexed by type/final-byte/direction. */
+#ifdef UTF2000
+Lisp_Object charset_by_attributes[4][128];
+#else
 Lisp_Object charset_by_attributes[4][128][2];
+#endif
 
 #ifndef UTF2000
 /* Table of number of bytes in the string representation of a character
@@ -119,9 +123,85 @@ Bytecount rep_bytes_by_first_byte[0xA0] =
 };
 #endif
 
+#ifdef UTF2000
+Emchar_to_byte_table*
+make_byte_from_character_table ()
+{
+  Emchar_to_byte_table* table
+    = (Emchar_to_byte_table*) xmalloc (sizeof (Emchar_to_byte_table));
+
+  table->base = NULL;
+  return table;
+}
+
+#define destroy_byte_from_character_table(table)  xfree(table)
+
+void
+put_byte_from_character_table (Emchar ch, unsigned char val,
+                              Emchar_to_byte_table* table)
+{
+  if (table->base == NULL)
+    {
+      table->base = xmalloc (256);
+      table->offset = ch - (ch % 256);
+      table->size = 256;
+      table->base[ch - table->offset] = val;
+    }
+  else
+    {
+      int i = ch - table->offset;
+
+      if (i < 0)
+       {
+         size_t new_size = table->size - i;
+         size_t j;
+
+         new_size += 256 - (new_size % 256);
+         table->base = xrealloc (table->base, new_size);
+         memmove (table->base + (new_size - table->size), table->base,
+                  table->size);
+         for (j = 0; j < (new_size - table->size); j++)
+           table->base[j] = 0;
+         table->offset -= (new_size - table->size);
+         table->base[ch - table->offset] = val;
+         table->size = new_size;
+       }
+      else if (i >= table->size)
+       {
+         size_t new_size = i + 1;
+         size_t j;
+
+         new_size += 256 - (new_size % 256);
+         table->base = xrealloc (table->base, new_size);
+         for (j = table->size; j < new_size; j++)
+           table->base[j] = 0;
+         table->base[i] = val;
+         table->size = new_size;
+       }
+      else
+       {
+         table->base[i] = val;
+       }
+    }
+}
+
+unsigned char
+get_byte_from_character_table (Emchar ch, Emchar_to_byte_table* table)
+{
+  size_t i = ch - table->offset;
+  if (i < table->size)
+    return table->base[i];
+  else
+    return 0;
+}
+
+
 Lisp_Object Vutf_2000_version;
+#endif
 
+#ifndef UTF2000
 int leading_code_private_11;
+#endif
 
 Lisp_Object Qcharsetp;
 
@@ -154,11 +234,13 @@ Lisp_Object Qascii,
   Qchinese_cns11643_1,
   Qchinese_cns11643_2,
 #ifdef UTF2000
-  Qchinese_cns11643_3,
-  Qchinese_cns11643_4,
-  Qchinese_cns11643_5,
-  Qchinese_cns11643_6,
-  Qchinese_cns11643_7,
+  Qucs_bmp,
+  Qlatin_viscii_lower,
+  Qlatin_viscii_upper,
+  Qvietnamese_viscii_lower,
+  Qvietnamese_viscii_upper,
+  Qhiragana_jisx0208,
+  Qkatakana_jisx0208,
 #endif
   Qchinese_big5_1,
   Qchinese_big5_2,
@@ -168,8 +250,8 @@ Lisp_Object Ql2r, Qr2l;
 
 Lisp_Object Vcharset_hash_table;
 
-static Bufbyte next_allocated_1_byte_leading_byte;
-static Bufbyte next_allocated_2_byte_leading_byte;
+static Charset_ID next_allocated_1_byte_leading_byte;
+static Charset_ID next_allocated_2_byte_leading_byte;
 
 /* Composite characters are characters constructed by overstriking two
    or more regular characters.
@@ -215,7 +297,7 @@ non_ascii_set_charptr_emchar (Bufbyte *str, Emchar c)
 {
   Bufbyte *p;
 #ifndef UTF2000
-  Bufbyte lb;
+  Charset_ID lb;
   int c1, c2;
   Lisp_Object charset;
 #endif
@@ -531,6 +613,9 @@ mark_charset (Lisp_Object obj, void (*markobj) (Lisp_Object))
   markobj (cs->doc_string);
   markobj (cs->registry);
   markobj (cs->ccl_program);
+#ifdef UTF2000
+  markobj (cs->decoding_table);
+#endif
   return cs->name;
 }
 
@@ -574,16 +659,20 @@ static const struct lrecord_description charset_description[] = {
 };
 
 DEFINE_LRECORD_IMPLEMENTATION ("charset", charset,
-                               mark_charset, print_charset, 0, 0, 0, charset_description,
+                               mark_charset, print_charset, 0, 0, 0,
+                              charset_description,
                               struct Lisp_Charset);
 /* Make a new charset. */
 
 static Lisp_Object
-make_charset (int id, Lisp_Object name, unsigned char rep_bytes,
+make_charset (Charset_ID id, Lisp_Object name,
              unsigned char type, unsigned char columns, unsigned char graphic,
-             Bufbyte final, unsigned char direction,  Lisp_Object short_name,
+             Bufbyte final, unsigned char direction, Lisp_Object short_name,
              Lisp_Object long_name, Lisp_Object doc,
-             Lisp_Object reg)
+             Lisp_Object reg,
+             Lisp_Object decoding_table,
+             Emchar ucs_min, Emchar ucs_max,
+             Emchar code_offset, unsigned char byte_offset)
 {
   Lisp_Object obj;
   struct Lisp_Charset *cs =
@@ -594,7 +683,6 @@ make_charset (int id, Lisp_Object name, unsigned char rep_bytes,
   CHARSET_NAME         (cs) = name;
   CHARSET_SHORT_NAME   (cs) = short_name;
   CHARSET_LONG_NAME    (cs) = long_name;
-  CHARSET_REP_BYTES    (cs) = rep_bytes;
   CHARSET_DIRECTION    (cs) = direction;
   CHARSET_TYPE         (cs) = type;
   CHARSET_COLUMNS      (cs) = columns;
@@ -604,19 +692,120 @@ make_charset (int id, Lisp_Object name, unsigned char rep_bytes,
   CHARSET_REGISTRY     (cs) = reg;
   CHARSET_CCL_PROGRAM  (cs) = Qnil;
   CHARSET_REVERSE_DIRECTION_CHARSET (cs) = Qnil;
+#ifdef UTF2000
+  CHARSET_DECODING_TABLE(cs) = decoding_table;
+  CHARSET_UCS_MIN(cs) = ucs_min;
+  CHARSET_UCS_MAX(cs) = ucs_max;
+  CHARSET_CODE_OFFSET(cs) = code_offset;
+  CHARSET_BYTE_OFFSET(cs) = byte_offset;
+#endif
+  
+  switch ( CHARSET_TYPE (cs) )
+    {
+    case CHARSET_TYPE_94:
+      CHARSET_DIMENSION (cs) = 1;
+      CHARSET_CHARS (cs) = 94;
+#ifdef UTF2000
+      if (!EQ (decoding_table, Qnil))
+       {
+         size_t i;
+         CHARSET_TO_BYTE1_TABLE(cs) = make_byte_from_character_table();
+         for (i = 0; i < 94; i++)
+           {
+             Lisp_Object c = XVECTOR_DATA(decoding_table)[i];
+
+             if (!EQ (c, Qnil))
+               put_byte_from_character_table (XCHAR (c), i + 33,
+                                              CHARSET_TO_BYTE1_TABLE(cs));
+           }
+       }
+      else
+       CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+      CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+#endif
+      break;
+    case CHARSET_TYPE_96:
+      CHARSET_DIMENSION (cs) = 1;
+      CHARSET_CHARS (cs) = 96;
+#ifdef UTF2000
+      if (!EQ (decoding_table, Qnil))
+       {
+         size_t i;
+         CHARSET_TO_BYTE1_TABLE(cs) = make_byte_from_character_table();
+         for (i = 0; i < 96; i++)
+           {
+             Lisp_Object c = XVECTOR_DATA(decoding_table)[i];
+
+             if (!EQ (c, Qnil))
+               put_byte_from_character_table (XCHAR (c), i + 32,
+                                              CHARSET_TO_BYTE1_TABLE(cs));
+           }
+       }
+      else
+       CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+      CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+#endif
+      break;
+    case CHARSET_TYPE_94X94:
+      CHARSET_DIMENSION (cs) = 2;
+      CHARSET_CHARS (cs) = 94;
+#ifdef UTF2000
+      CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+      CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+#endif
+      break;
+    case CHARSET_TYPE_96X96:
+      CHARSET_DIMENSION (cs) = 2;
+      CHARSET_CHARS (cs) = 96;
+#ifdef UTF2000
+      CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+      CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+#endif
+      break;
+#ifdef UTF2000
+    case CHARSET_TYPE_128X128:
+      CHARSET_DIMENSION (cs) = 2;
+      CHARSET_CHARS (cs) = 128;
+#ifdef UTF2000
+      CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+      CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+#endif
+      break;
+    case CHARSET_TYPE_256X256:
+      CHARSET_DIMENSION (cs) = 2;
+      CHARSET_CHARS (cs) = 256;
+#ifdef UTF2000
+      CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+      CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+#endif
+      break;
+#endif
+    }
 
-  CHARSET_DIMENSION     (cs) = (CHARSET_TYPE (cs) == CHARSET_TYPE_94 ||
-                               CHARSET_TYPE (cs) == CHARSET_TYPE_96) ? 1 : 2;
-  CHARSET_CHARS         (cs) = (CHARSET_TYPE (cs) == CHARSET_TYPE_94 ||
-                               CHARSET_TYPE (cs) == CHARSET_TYPE_94X94) ? 94 : 96;
-
+#ifndef UTF2000
+  if (id == LEADING_BYTE_ASCII)
+    CHARSET_REP_BYTES (cs) = 1;
+  else if (id < 0xA0)
+    CHARSET_REP_BYTES (cs) = CHARSET_DIMENSION (cs) + 1;
+  else
+    CHARSET_REP_BYTES (cs) = CHARSET_DIMENSION (cs) + 2;
+#endif
+  
   if (final)
     {
       /* some charsets do not have final characters.  This includes
         ASCII, Control-1, Composite, and the two faux private
         charsets. */
+#if UTF2000
+      if (code_offset == 0)
+       {
+         assert (NILP (charset_by_attributes[type][final]));
+         charset_by_attributes[type][final] = obj;
+       }
+#else
       assert (NILP (charset_by_attributes[type][final][direction]));
       charset_by_attributes[type][final][direction] = obj;
+#endif
     }
 
   assert (NILP (charset_by_leading_byte[id - MIN_LEADING_BYTE]));
@@ -624,7 +813,7 @@ make_charset (int id, Lisp_Object name, unsigned char rep_bytes,
 #ifndef UTF2000
   if (id < 0xA0)
     /* official leading byte */
-    rep_bytes_by_first_byte[id] = rep_bytes;
+    rep_bytes_by_first_byte[id] = CHARSET_REP_BYTES (cs);
 #endif
 
   /* Some charsets are "faux" and don't have names or really exist at
@@ -637,7 +826,7 @@ make_charset (int id, Lisp_Object name, unsigned char rep_bytes,
 static int
 get_unallocated_leading_byte (int dimension)
 {
-  int lb;
+  Charset_ID lb;
 
   if (dimension == 1)
     {
@@ -662,6 +851,117 @@ get_unallocated_leading_byte (int dimension)
   return lb;
 }
 
+#ifdef UTF2000
+unsigned char
+charset_get_byte1 (Lisp_Object charset, Emchar ch)
+{
+  Emchar_to_byte_table* table;
+  int d;
+
+  if ((table = XCHARSET_TO_BYTE1_TABLE (charset)) != NULL)
+    return get_byte_from_character_table (ch, table);
+  else if ((XCHARSET_UCS_MIN (charset) <= ch)
+          && (ch <= XCHARSET_UCS_MAX (charset)))
+    return (ch - XCHARSET_UCS_MIN (charset)
+           + XCHARSET_CODE_OFFSET (charset))
+      / (XCHARSET_DIMENSION (charset) == 1 ?
+        1
+        :
+        XCHARSET_DIMENSION (charset) == 2 ?
+        XCHARSET_CHARS (charset)
+        :
+        XCHARSET_DIMENSION (charset) == 3 ?
+        XCHARSET_CHARS (charset) * XCHARSET_CHARS (charset)
+        :
+        XCHARSET_CHARS (charset)
+        * XCHARSET_CHARS (charset) * XCHARSET_CHARS (charset))
+      + XCHARSET_BYTE_OFFSET (charset);
+  else if (XCHARSET_CODE_OFFSET (charset) == 0)
+    {
+      if (XCHARSET_DIMENSION (charset) == 1)
+       {
+         if (XCHARSET_CHARS (charset) == 94)
+           {
+             if (((d = ch - (MIN_CHAR_94
+                             + (XCHARSET_FINAL (charset) - '0') * 94)) >= 0)
+                 && (d < 94))
+               return d + 33;
+           }
+         else if (XCHARSET_CHARS (charset) == 96)
+           {
+             if (((d = ch - (MIN_CHAR_96
+                             + (XCHARSET_FINAL (charset) - '0') * 96)) >= 0)
+                 && (d < 96))
+               return d + 32;
+           }
+         else
+           return 0;
+       }
+      else if (XCHARSET_DIMENSION (charset) == 2)
+       {
+         if (XCHARSET_CHARS (charset) == 94)
+           {
+             if (((d = ch - (MIN_CHAR_94x94
+                             + (XCHARSET_FINAL (charset) - '0') * 94 * 94))
+                  >= 0)
+                 && (d < 94 * 94))
+               return (d / 94) + 33;
+           }
+         else if (XCHARSET_CHARS (charset) == 96)
+           {
+             if (((d = ch - (MIN_CHAR_96x96
+                             + (XCHARSET_FINAL (charset) - '0') * 96 * 96))
+                  >= 0)
+                 && (d < 96 * 96))
+               return (d / 96) + 32;
+           }
+       }
+    }
+  return 0;
+}
+
+unsigned char
+charset_get_byte2 (Lisp_Object charset, Emchar ch)
+{
+  if (XCHARSET_DIMENSION (charset) == 1)
+    return 0;
+  else
+    {
+      Emchar_to_byte_table* table;
+
+      if ((table = XCHARSET_TO_BYTE2_TABLE (charset)) != NULL)
+       return get_byte_from_character_table (ch, table);
+      else if ((XCHARSET_UCS_MIN (charset) <= ch)
+              && (ch <= XCHARSET_UCS_MAX (charset)))
+       return ((ch - XCHARSET_UCS_MIN (charset)
+                + XCHARSET_CODE_OFFSET (charset))
+               / (XCHARSET_DIMENSION (charset) == 2 ?
+                  1
+                  :
+                  XCHARSET_DIMENSION (charset) == 3 ?
+                  XCHARSET_CHARS (charset)
+                  :
+                  XCHARSET_CHARS (charset) * XCHARSET_CHARS (charset)))
+         % XCHARSET_CHARS (charset)
+         + XCHARSET_BYTE_OFFSET (charset);
+      else if (XCHARSET_CHARS (charset) == 94)
+       return (MIN_CHAR_94x94
+               + (XCHARSET_FINAL (charset) - '0') * 94 * 94 <= ch)
+         && (ch < MIN_CHAR_94x94
+             + (XCHARSET_FINAL (charset) - '0' + 1) * 94 * 94) ?
+         ((ch - MIN_CHAR_94x94) % 94) + 33 : 0;
+      else /* if (XCHARSET_CHARS (charset) == 96) */
+       return (MIN_CHAR_96x96
+               + (XCHARSET_FINAL (charset) - '0') * 96 * 96 <= ch)
+         && (ch < MIN_CHAR_96x96
+             + (XCHARSET_FINAL (charset) - '0' + 1) * 96 * 96) ?
+         ((ch - MIN_CHAR_96x96) % 96) + 32 : 0;
+    }
+}
+
+Lisp_Object Vdefault_coded_charset_priority_list;
+#endif
+
 \f
 /************************************************************************/
 /*                      Basic charset Lisp functions                    */
@@ -914,7 +1214,45 @@ character set.  Recognized properties are:
     error
       ("Character set already defined for this DIMENSION/CHARS/FINAL combo");
 
+#ifdef UTF2000
+  if (dimension == 1)
+    {
+      if (chars == 94)
+       {
+         /* id = CHARSET_ID_OFFSET_94 + final; */
+         id = get_unallocated_leading_byte (dimension);
+       }
+      else if (chars == 96)
+       {
+         id = get_unallocated_leading_byte (dimension);
+       }
+      else
+       {
+         abort ();
+       }
+    }
+  else if (dimension == 2)
+    {
+      if (chars == 94)
+       {
+         id = get_unallocated_leading_byte (dimension);
+       }
+      else if (chars == 96)
+       {
+         id = get_unallocated_leading_byte (dimension);
+       }
+      else
+       {
+         abort ();
+       }
+    }
+  else
+    {
+      abort ();
+    }
+#else
   id = get_unallocated_leading_byte (dimension);
+#endif
 
   if (NILP (doc_string))
     doc_string = build_string ("");
@@ -930,8 +1268,10 @@ character set.  Recognized properties are:
 
   if (columns == -1)
     columns = dimension;
-  charset = make_charset (id, name, dimension + 2, type, columns, graphic,
-                         final, direction, short_name, long_name, doc_string, registry);
+  charset = make_charset (id, name, type, columns, graphic,
+                         final, direction, short_name, long_name,
+                         doc_string, registry,
+                         Qnil, 0, 0, 0, 0);
   if (!NILP (ccl_program))
     XCHARSET_CCL_PROGRAM (charset) = ccl_program;
   return charset;
@@ -976,9 +1316,19 @@ NEW-NAME is the name of the new charset.  Return the new charset.
   long_name = CHARSET_LONG_NAME (cs);
   registry = CHARSET_REGISTRY (cs);
 
-  new_charset = make_charset (id, new_name, dimension + 2, type, columns,
+  new_charset = make_charset (id, new_name, type, columns,
                              graphic, final, direction, short_name, long_name,
-                             doc_string, registry);
+                             doc_string, registry,
+#ifdef UTF2000
+                             CHARSET_DECODING_TABLE(cs),
+                             CHARSET_UCS_MIN(cs),
+                             CHARSET_UCS_MAX(cs),
+                             CHARSET_CODE_OFFSET(cs),
+                             CHARSET_BYTE_OFFSET(cs)
+#else
+                             Qnil, 0, 0, 0, 0
+#endif
+);
 
   CHARSET_REVERSE_DIRECTION_CHARSET (cs) = new_charset;
   XCHARSET_REVERSE_DIRECTION_CHARSET (new_charset) = charset;
@@ -986,6 +1336,16 @@ NEW-NAME is the name of the new charset.  Return the new charset.
   return new_charset;
 }
 
+DEFUN ("define-charset-alias", Fdefine_charset_alias, 2, 2, 0, /*
+Define symbol ALIAS as an alias for CHARSET.
+*/
+       (alias, charset))
+{
+  CHECK_SYMBOL (alias);
+  charset = Fget_charset (charset);
+  return Fputhash (alias, charset, Vcharset_hash_table);
+}
+
 /* #### Reverse direction charsets not yet implemented.  */
 #if 0
 DEFUN ("charset-reverse-direction-charset", Fcharset_reverse_direction_charset,
@@ -1164,7 +1524,6 @@ invalidate_charset_font_caches (Lisp_Object charset)
     }
 }
 
-/* Japanese folks may want to (set-charset-registry 'ascii "jisx0201") */
 DEFUN ("set-charset-registry", Fset_charset_registry, 2, 2, 0, /*
 Set the 'registry property of CHARSET to REGISTRY.
 */
@@ -1178,6 +1537,133 @@ Set the 'registry property of CHARSET to REGISTRY.
   return Qnil;
 }
 
+#ifdef UTF2000
+DEFUN ("charset-mapping-table", Fcharset_mapping_table, 1, 1, 0, /*
+Return mapping-table of CHARSET.
+*/
+       (charset))
+{
+  return XCHARSET_DECODING_TABLE (Fget_charset (charset));
+}
+
+DEFUN ("set-charset-mapping-table", Fset_charset_mapping_table, 2, 2, 0, /*
+Set mapping-table of CHARSET to TABLE.
+*/
+       (charset, table))
+{
+  struct Lisp_Charset *cs;
+  Emchar_to_byte_table* old_byte1_table;
+  Emchar_to_byte_table* old_byte2_table;
+
+  charset = Fget_charset (charset);
+  CHECK_VECTOR (table);
+  
+  cs = XCHARSET (charset);
+  CHARSET_DECODING_TABLE(cs) = table;
+  old_byte1_table = CHARSET_TO_BYTE1_TABLE(cs);
+  old_byte2_table = CHARSET_TO_BYTE2_TABLE(cs);
+  switch (CHARSET_TYPE (cs))
+    {
+    case CHARSET_TYPE_94:
+      if (!EQ (table, Qnil))
+       {
+         size_t i;
+         CHARSET_TO_BYTE1_TABLE(cs) = make_byte_from_character_table();
+         for (i = 0; i < 94; i++)
+           {
+             Lisp_Object c = XVECTOR_DATA(table)[i];
+
+             if (!EQ (c, Qnil))
+               put_byte_from_character_table (XCHAR (c), i + 33,
+                                              CHARSET_TO_BYTE1_TABLE(cs));
+           }
+       }
+      else
+       CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+      CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+      break;
+    case CHARSET_TYPE_96:
+      if (!EQ (table, Qnil))
+       {
+         size_t i;
+         CHARSET_TO_BYTE1_TABLE(cs) = make_byte_from_character_table();
+         for (i = 0; i < 96; i++)
+           {
+             Lisp_Object c = XVECTOR_DATA(table)[i];
+
+             if (!EQ (c, Qnil))
+               put_byte_from_character_table (XCHAR (c), i + 32,
+                                              CHARSET_TO_BYTE1_TABLE(cs));
+           }
+       }
+      else
+       CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+      CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+      break;
+    case CHARSET_TYPE_94X94:
+      if (!EQ (table, Qnil))
+       {
+         size_t i;
+
+         CHARSET_TO_BYTE1_TABLE(cs) = make_byte_from_character_table();
+         CHARSET_TO_BYTE2_TABLE(cs) = make_byte_from_character_table();
+         for (i = 0; i < XVECTOR_LENGTH (table); i++)
+           {
+             Lisp_Object v = XVECTOR_DATA(table)[i];
+
+             if (VECTORP (v))
+               {
+                 size_t j;
+
+                 for (j = 0; j < XVECTOR_LENGTH (v); j++)
+                   {
+                     Lisp_Object c = XVECTOR_DATA(v)[j];
+
+                     if (!EQ (c, Qnil))
+                       {
+                         put_byte_from_character_table
+                           (XCHAR (c), i + 33, CHARSET_TO_BYTE1_TABLE(cs));
+                         put_byte_from_character_table
+                           (XCHAR (c), j + 33, CHARSET_TO_BYTE2_TABLE(cs));
+                       }
+                   }
+               }
+             else if (CHARP (v))
+               put_byte_from_character_table
+                 (XCHAR (v), i + 33, CHARSET_TO_BYTE1_TABLE(cs));
+           }
+       }
+      else
+       {
+         CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+         CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+       }
+      break;
+    case CHARSET_TYPE_96X96:
+      CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+      CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+      break;
+    case CHARSET_TYPE_128X128:
+      CHARSET_DIMENSION (cs) = 2;
+      CHARSET_CHARS (cs) = 128;
+      CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+      CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+      break;
+    case CHARSET_TYPE_256X256:
+      CHARSET_DIMENSION (cs) = 2;
+      CHARSET_CHARS (cs) = 256;
+      CHARSET_TO_BYTE1_TABLE(cs) = NULL;
+      CHARSET_TO_BYTE2_TABLE(cs) = NULL;
+      break;
+    }
+  if (old_byte1_table != NULL)
+    destroy_byte_from_character_table (old_byte1_table);
+  if (old_byte2_table != NULL)
+    destroy_byte_from_character_table (old_byte2_table);
+  return table;
+}
+#endif
+
 \f
 /************************************************************************/
 /*              Lisp primitives for working with characters             */
@@ -1200,6 +1686,9 @@ character s with caron.
 
   if      (EQ (charset, Vcharset_ascii))     lowlim =  0, highlim = 127;
   else if (EQ (charset, Vcharset_control_1)) lowlim =  0, highlim =  31;
+#ifdef UTF2000
+  else if (CHARSET_CHARS (cs) == 256)        lowlim =  0, highlim = 255;
+#endif
   else if (CHARSET_CHARS (cs) == 94)         lowlim = 33, highlim = 126;
   else /* CHARSET_CHARS (cs) == 96) */      lowlim = 32, highlim = 127;
 
@@ -1208,7 +1697,13 @@ character s with caron.
      the 8th bit off ARG1 and ARG2 becaue it allows programmers to
      write (make-char 'latin-iso8859-2 CODE) where code is the actual
      Latin 2 code of the character.  */
-  a1 = XINT (arg1) & 0x7f;
+#ifdef UTF2000
+  a1 = XINT (arg1);
+  if (highlim < 128)
+    a1 &= 0x7f;
+#else
+  a1 = XINT (arg1);
+#endif
   if (a1 < lowlim || a1 > highlim)
     args_out_of_range_3 (arg1, make_int (lowlim), make_int (highlim));
 
@@ -1221,7 +1716,13 @@ character s with caron.
     }
 
   CHECK_INT (arg2);
+#ifdef UTF2000
+  a2 = XINT (arg2);
+  if (highlim < 128)
+    a2 &= 0x7f;
+#else
   a2 = XINT (arg2) & 0x7f;
+#endif
   if (a2 < lowlim || a2 > highlim)
     args_out_of_range_3 (arg2, make_int (lowlim), make_int (highlim));
 
@@ -1235,8 +1736,7 @@ Return the character set of char CH.
 {
   CHECK_CHAR_COERCE_INT (ch);
 
-  return XCHARSET_NAME (CHARSET_BY_LEADING_BYTE
-                       (CHAR_LEADING_BYTE (XCHAR (ch))));
+  return XCHARSET_NAME (CHAR_CHARSET (XCHAR (ch)));
 }
 
 DEFUN ("split-char", Fsplit_char, 1, 1, 0, /*
@@ -1358,6 +1858,7 @@ syms_of_mule_charset (void)
   DEFSUBR (Fmake_charset);
   DEFSUBR (Fmake_reverse_direction_charset);
   /*  DEFSUBR (Freverse_direction_charset); */
+  DEFSUBR (Fdefine_charset_alias);
   DEFSUBR (Fcharset_from_attributes);
   DEFSUBR (Fcharset_short_name);
   DEFSUBR (Fcharset_long_name);
@@ -1367,6 +1868,10 @@ syms_of_mule_charset (void)
   DEFSUBR (Fcharset_id);
   DEFSUBR (Fset_charset_ccl_program);
   DEFSUBR (Fset_charset_registry);
+#ifdef UTF2000
+  DEFSUBR (Fcharset_mapping_table);
+  DEFSUBR (Fset_charset_mapping_table);
+#endif
 
   DEFSUBR (Fmake_char);
   DEFSUBR (Fchar_charset);
@@ -1413,39 +1918,44 @@ syms_of_mule_charset (void)
   defsymbol (&Qchinese_cns11643_1,     "chinese-cns11643-1");
   defsymbol (&Qchinese_cns11643_2,     "chinese-cns11643-2");
 #ifdef UTF2000
-  defsymbol (&Qchinese_cns11643_3,     "chinese-cns11643-3");
-  defsymbol (&Qchinese_cns11643_4,     "chinese-cns11643-4");
-  defsymbol (&Qchinese_cns11643_5,     "chinese-cns11643-5");
-  defsymbol (&Qchinese_cns11643_6,     "chinese-cns11643-6");
-  defsymbol (&Qchinese_cns11643_7,     "chinese-cns11643-7");
+  defsymbol (&Qucs_bmp,                        "ucs-bmp");
+  defsymbol (&Qlatin_viscii_lower,     "latin-viscii-lower");
+  defsymbol (&Qlatin_viscii_upper,     "latin-viscii-upper");
+  defsymbol (&Qvietnamese_viscii_lower,        "vietnamese-viscii-lower");
+  defsymbol (&Qvietnamese_viscii_upper,        "vietnamese-viscii-upper");
+  defsymbol (&Qhiragana_jisx0208,      "hiragana-jisx0208");
+  defsymbol (&Qkatakana_jisx0208,      "katakana-jisx0208");
 #endif
   defsymbol (&Qchinese_big5_1,         "chinese-big5-1");
   defsymbol (&Qchinese_big5_2,         "chinese-big5-2");
 
   defsymbol (&Qcomposite,              "composite");
-
-#ifdef UTF2000
-  Vutf_2000_version = build_string("0.4 (Shin-Imamiya)");
-  DEFVAR_LISP ("utf-2000-version", &Vutf_2000_version /*
-Version number of UTF-2000.
-*/ );
-#endif
 }
 
 void
 vars_of_mule_charset (void)
 {
-  int i, j, k;
+  int i, j;
+#ifndef UTF2000
+  int k;
+#endif
 
   /* Table of charsets indexed by leading byte. */
   for (i = 0; i < countof (charset_by_leading_byte); i++)
     charset_by_leading_byte[i] = Qnil;
 
+#ifdef UTF2000
+  /* Table of charsets indexed by type/final-byte. */
+  for (i = 0; i < countof (charset_by_attributes); i++)
+    for (j = 0; j < countof (charset_by_attributes[0]); j++)
+       charset_by_attributes[i][j] = Qnil;
+#else
   /* Table of charsets indexed by type/final-byte/direction. */
   for (i = 0; i < countof (charset_by_attributes); i++)
     for (j = 0; j < countof (charset_by_attributes[0]); j++)
       for (k = 0; k < countof (charset_by_attributes[0][0]); k++)
        charset_by_attributes[i][j][k] = Qnil;
+#endif
 
   next_allocated_1_byte_leading_byte = MIN_LEADING_BYTE_PRIVATE_1;
 #ifdef UTF2000
@@ -1454,11 +1964,26 @@ vars_of_mule_charset (void)
   next_allocated_2_byte_leading_byte = MIN_LEADING_BYTE_PRIVATE_2;
 #endif
 
+#ifndef UTF2000
   leading_code_private_11 = PRE_LEADING_BYTE_PRIVATE_1;
   DEFVAR_INT ("leading-code-private-11", &leading_code_private_11 /*
 Leading-code of private TYPE9N charset of column-width 1.
 */ );
   leading_code_private_11 = PRE_LEADING_BYTE_PRIVATE_1;
+#endif
+
+#ifdef UTF2000
+  Vutf_2000_version = build_string("0.8 (Kami)");
+  DEFVAR_LISP ("utf-2000-version", &Vutf_2000_version /*
+Version number of UTF-2000.
+*/ );
+
+  Vdefault_coded_charset_priority_list = Qnil;
+  DEFVAR_LISP ("default-coded-charset-priority-list",
+              &Vdefault_coded_charset_priority_list /*
+Default order of preferred coded-character-set.
+*/ );
+#endif
 }
 
 void
@@ -1471,252 +1996,291 @@ complex_vars_of_mule_charset (void)
   /* Predefined character sets.  We store them into variables for
      ease of access. */
 
+#ifdef UTF2000
+  Vcharset_ucs_bmp =
+    make_charset (LEADING_BYTE_UCS_BMP, Qucs_bmp,
+                 CHARSET_TYPE_256X256, 1, 0, 0,
+                 CHARSET_LEFT_TO_RIGHT,
+                 build_string ("BMP"),
+                 build_string ("BMP"),
+                 build_string ("BMP"),
+                 build_string (""),
+                 Qnil, 0, 0xFFFF, 0, 0);
+#else
+# define MIN_CHAR_THAI 0
+# define MAX_CHAR_THAI 0
+# define MIN_CHAR_GREEK 0
+# define MAX_CHAR_GREEK 0
+# define MIN_CHAR_HEBREW 0
+# define MAX_CHAR_HEBREW 0
+# define MIN_CHAR_HALFWIDTH_KATAKANA 0
+# define MAX_CHAR_HALFWIDTH_KATAKANA 0
+# define MIN_CHAR_CYRILLIC 0
+# define MAX_CHAR_CYRILLIC 0
+#endif
   Vcharset_ascii =
-    make_charset (LEADING_BYTE_ASCII, Qascii, 1,
+    make_charset (LEADING_BYTE_ASCII, Qascii,
                  CHARSET_TYPE_94, 1, 0, 'B',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("ASCII"),
                  build_string ("ASCII)"),
                  build_string ("ASCII (ISO646 IRV)"),
-                 build_string ("\\(iso8859-[0-9]*\\|-ascii\\)"));
+                 build_string ("\\(iso8859-[0-9]*\\|-ascii\\)"),
+                 Qnil, 0, 0x7F, 0, 0);
   Vcharset_control_1 =
-    make_charset (LEADING_BYTE_CONTROL_1, Qcontrol_1, 2,
+    make_charset (LEADING_BYTE_CONTROL_1, Qcontrol_1,
                  CHARSET_TYPE_94, 1, 1, 0,
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("C1"),
                  build_string ("Control characters"),
                  build_string ("Control characters 128-191"),
-                 build_string (""));
+                 build_string (""),
+                 Qnil, 0x80, 0x9F, 0, 0);
   Vcharset_latin_iso8859_1 =
-    make_charset (LEADING_BYTE_LATIN_ISO8859_1, Qlatin_iso8859_1, 2,
+    make_charset (LEADING_BYTE_LATIN_ISO8859_1, Qlatin_iso8859_1,
                  CHARSET_TYPE_96, 1, 1, 'A',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("Latin-1"),
                  build_string ("ISO8859-1 (Latin-1)"),
                  build_string ("ISO8859-1 (Latin-1)"),
-                 build_string ("iso8859-1"));
+                 build_string ("iso8859-1"),
+                 Qnil, 0xA0, 0xFF, 0, 32);
   Vcharset_latin_iso8859_2 =
-    make_charset (LEADING_BYTE_LATIN_ISO8859_2, Qlatin_iso8859_2, 2,
+    make_charset (LEADING_BYTE_LATIN_ISO8859_2, Qlatin_iso8859_2,
                  CHARSET_TYPE_96, 1, 1, 'B',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("Latin-2"),
                  build_string ("ISO8859-2 (Latin-2)"),
                  build_string ("ISO8859-2 (Latin-2)"),
-                 build_string ("iso8859-2"));
+                 build_string ("iso8859-2"),
+                 Qnil, 0, 0, 0, 32);
   Vcharset_latin_iso8859_3 =
-    make_charset (LEADING_BYTE_LATIN_ISO8859_3, Qlatin_iso8859_3, 2,
+    make_charset (LEADING_BYTE_LATIN_ISO8859_3, Qlatin_iso8859_3,
                  CHARSET_TYPE_96, 1, 1, 'C',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("Latin-3"),
                  build_string ("ISO8859-3 (Latin-3)"),
                  build_string ("ISO8859-3 (Latin-3)"),
-                 build_string ("iso8859-3"));
+                 build_string ("iso8859-3"),
+                 Qnil, 0, 0, 0, 32);
   Vcharset_latin_iso8859_4 =
-    make_charset (LEADING_BYTE_LATIN_ISO8859_4, Qlatin_iso8859_4, 2,
+    make_charset (LEADING_BYTE_LATIN_ISO8859_4, Qlatin_iso8859_4,
                  CHARSET_TYPE_96, 1, 1, 'D',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("Latin-4"),
                  build_string ("ISO8859-4 (Latin-4)"),
                  build_string ("ISO8859-4 (Latin-4)"),
-                 build_string ("iso8859-4"));
+                 build_string ("iso8859-4"),
+                 Qnil, 0, 0, 0, 32);
   Vcharset_thai_tis620 =
-    make_charset (LEADING_BYTE_THAI_TIS620, Qthai_tis620, 2,
+    make_charset (LEADING_BYTE_THAI_TIS620, Qthai_tis620,
                  CHARSET_TYPE_96, 1, 1, 'T',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("TIS620"),
                  build_string ("TIS620 (Thai)"),
                  build_string ("TIS620.2529 (Thai)"),
-                 build_string ("tis620"));
+                 build_string ("tis620"),
+                 Qnil, MIN_CHAR_THAI, MAX_CHAR_THAI, 0, 32);
   Vcharset_greek_iso8859_7 =
-    make_charset (LEADING_BYTE_GREEK_ISO8859_7, Qgreek_iso8859_7, 2,
+    make_charset (LEADING_BYTE_GREEK_ISO8859_7, Qgreek_iso8859_7,
                  CHARSET_TYPE_96, 1, 1, 'F',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("ISO8859-7"),
                  build_string ("ISO8859-7 (Greek)"),
                  build_string ("ISO8859-7 (Greek)"),
-                 build_string ("iso8859-7"));
+                 build_string ("iso8859-7"),
+                 Qnil, MIN_CHAR_GREEK, MAX_CHAR_GREEK, 0, 32);
   Vcharset_arabic_iso8859_6 =
-    make_charset (LEADING_BYTE_ARABIC_ISO8859_6, Qarabic_iso8859_6, 2,
+    make_charset (LEADING_BYTE_ARABIC_ISO8859_6, Qarabic_iso8859_6,
                  CHARSET_TYPE_96, 1, 1, 'G',
                  CHARSET_RIGHT_TO_LEFT,
                  build_string ("ISO8859-6"),
                  build_string ("ISO8859-6 (Arabic)"),
                  build_string ("ISO8859-6 (Arabic)"),
-                 build_string ("iso8859-6"));
+                 build_string ("iso8859-6"),
+                 Qnil, 0, 0, 0, 32);
   Vcharset_hebrew_iso8859_8 =
-    make_charset (LEADING_BYTE_HEBREW_ISO8859_8, Qhebrew_iso8859_8, 2,
+    make_charset (LEADING_BYTE_HEBREW_ISO8859_8, Qhebrew_iso8859_8,
                  CHARSET_TYPE_96, 1, 1, 'H',
                  CHARSET_RIGHT_TO_LEFT,
                  build_string ("ISO8859-8"),
                  build_string ("ISO8859-8 (Hebrew)"),
                  build_string ("ISO8859-8 (Hebrew)"),
-                 build_string ("iso8859-8"));
+                 build_string ("iso8859-8"),
+                 Qnil, MIN_CHAR_HEBREW, MAX_CHAR_HEBREW, 0, 32);
   Vcharset_katakana_jisx0201 =
-    make_charset (LEADING_BYTE_KATAKANA_JISX0201, Qkatakana_jisx0201, 2,
+    make_charset (LEADING_BYTE_KATAKANA_JISX0201, Qkatakana_jisx0201,
                  CHARSET_TYPE_94, 1, 1, 'I',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("JISX0201 Kana"),
                  build_string ("JISX0201.1976 (Japanese Kana)"),
                  build_string ("JISX0201.1976 Japanese Kana"),
-                 build_string ("jisx0201.1976"));
+                 build_string ("jisx0201\\.1976"),
+                 Qnil,
+                 MIN_CHAR_HALFWIDTH_KATAKANA,
+                 MAX_CHAR_HALFWIDTH_KATAKANA, 0, 33);
   Vcharset_latin_jisx0201 =
-    make_charset (LEADING_BYTE_LATIN_JISX0201, Qlatin_jisx0201, 2,
+    make_charset (LEADING_BYTE_LATIN_JISX0201, Qlatin_jisx0201,
                  CHARSET_TYPE_94, 1, 0, 'J',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("JISX0201 Roman"),
                  build_string ("JISX0201.1976 (Japanese Roman)"),
                  build_string ("JISX0201.1976 Japanese Roman"),
-                 build_string ("jisx0201.1976"));
+                 build_string ("jisx0201\\.1976"),
+                 Qnil, 0, 0, 0, 33);
   Vcharset_cyrillic_iso8859_5 =
-    make_charset (LEADING_BYTE_CYRILLIC_ISO8859_5, Qcyrillic_iso8859_5, 2,
+    make_charset (LEADING_BYTE_CYRILLIC_ISO8859_5, Qcyrillic_iso8859_5,
                  CHARSET_TYPE_96, 1, 1, 'L',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("ISO8859-5"),
                  build_string ("ISO8859-5 (Cyrillic)"),
                  build_string ("ISO8859-5 (Cyrillic)"),
-                 build_string ("iso8859-5"));
+                 build_string ("iso8859-5"),
+                 Qnil, MIN_CHAR_CYRILLIC, MAX_CHAR_CYRILLIC, 0, 32);
   Vcharset_latin_iso8859_9 =
-    make_charset (LEADING_BYTE_LATIN_ISO8859_9, Qlatin_iso8859_9, 2,
+    make_charset (LEADING_BYTE_LATIN_ISO8859_9, Qlatin_iso8859_9,
                  CHARSET_TYPE_96, 1, 1, 'M',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("Latin-5"),
                  build_string ("ISO8859-9 (Latin-5)"),
                  build_string ("ISO8859-9 (Latin-5)"),
-                 build_string ("iso8859-9"));
+                 build_string ("iso8859-9"),
+                 Qnil, 0, 0, 0, 32);
   Vcharset_japanese_jisx0208_1978 =
-    make_charset (LEADING_BYTE_JAPANESE_JISX0208_1978, Qjapanese_jisx0208_1978, 3,
+    make_charset (LEADING_BYTE_JAPANESE_JISX0208_1978, Qjapanese_jisx0208_1978,
                  CHARSET_TYPE_94X94, 2, 0, '@',
                  CHARSET_LEFT_TO_RIGHT,
-                 build_string ("JISX0208.1978"),
-                 build_string ("JISX0208.1978 (Japanese)"),
+                 build_string ("JIS X0208:1978"),
+                 build_string ("JIS X0208:1978 (Japanese)"),
                  build_string
-                 ("JISX0208.1978 Japanese Kanji (so called \"old JIS\")"),
-                 build_string ("\\(jisx0208\\|jisc6226\\)\\.1978"));
+                 ("JIS X0208:1978 Japanese Kanji (so called \"old JIS\")"),
+                 build_string ("\\(jisx0208\\|jisc6226\\)\\.1978"),
+                 Qnil, 0, 0, 0, 33);
   Vcharset_chinese_gb2312 =
-    make_charset (LEADING_BYTE_CHINESE_GB2312, Qchinese_gb2312, 3,
+    make_charset (LEADING_BYTE_CHINESE_GB2312, Qchinese_gb2312,
                  CHARSET_TYPE_94X94, 2, 0, 'A',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("GB2312"),
                  build_string ("GB2312)"),
                  build_string ("GB2312 Chinese simplified"),
-                 build_string ("gb2312"));
+                 build_string ("gb2312"),
+                 Qnil, 0, 0, 0, 33);
   Vcharset_japanese_jisx0208 =
-    make_charset (LEADING_BYTE_JAPANESE_JISX0208, Qjapanese_jisx0208, 3,
+    make_charset (LEADING_BYTE_JAPANESE_JISX0208, Qjapanese_jisx0208,
                  CHARSET_TYPE_94X94, 2, 0, 'B',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("JISX0208"),
-                 build_string ("JISX0208.1983/1990 (Japanese)"),
-                 build_string ("JISX0208.1983/1990 Japanese Kanji"),
-                 build_string ("jisx0208.19\\(83\\|90\\)"));
+                 build_string ("JIS X0208:1983 (Japanese)"),
+                 build_string ("JIS X0208:1983 Japanese Kanji"),
+                 build_string ("jisx0208\\.1983"),
+                 Qnil, 0, 0, 0, 33);
   Vcharset_korean_ksc5601 =
-    make_charset (LEADING_BYTE_KOREAN_KSC5601, Qkorean_ksc5601, 3,
+    make_charset (LEADING_BYTE_KOREAN_KSC5601, Qkorean_ksc5601,
                  CHARSET_TYPE_94X94, 2, 0, 'C',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("KSC5601"),
                  build_string ("KSC5601 (Korean"),
                  build_string ("KSC5601 Korean Hangul and Hanja"),
-                 build_string ("ksc5601"));
+                 build_string ("ksc5601"),
+                 Qnil, 0, 0, 0, 33);
   Vcharset_japanese_jisx0212 =
-    make_charset (LEADING_BYTE_JAPANESE_JISX0212, Qjapanese_jisx0212, 3,
+    make_charset (LEADING_BYTE_JAPANESE_JISX0212, Qjapanese_jisx0212,
                  CHARSET_TYPE_94X94, 2, 0, 'D',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("JISX0212"),
                  build_string ("JISX0212 (Japanese)"),
                  build_string ("JISX0212 Japanese Supplement"),
-                 build_string ("jisx0212"));
+                 build_string ("jisx0212"),
+                 Qnil, 0, 0, 0, 33);
 
 #define CHINESE_CNS_PLANE_RE(n) "cns11643[.-]\\(.*[.-]\\)?" n "$"
   Vcharset_chinese_cns11643_1 =
-    make_charset (LEADING_BYTE_CHINESE_CNS11643_1, Qchinese_cns11643_1, 3,
+    make_charset (LEADING_BYTE_CHINESE_CNS11643_1, Qchinese_cns11643_1,
                  CHARSET_TYPE_94X94, 2, 0, 'G',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("CNS11643-1"),
                  build_string ("CNS11643-1 (Chinese traditional)"),
                  build_string
                  ("CNS 11643 Plane 1 Chinese traditional"),
-                 build_string (CHINESE_CNS_PLANE_RE("1")));
+                 build_string (CHINESE_CNS_PLANE_RE("1")),
+                 Qnil, 0, 0, 0, 33);
   Vcharset_chinese_cns11643_2 =
-    make_charset (LEADING_BYTE_CHINESE_CNS11643_2, Qchinese_cns11643_2, 3,
+    make_charset (LEADING_BYTE_CHINESE_CNS11643_2, Qchinese_cns11643_2,
                  CHARSET_TYPE_94X94, 2, 0, 'H',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("CNS11643-2"),
                  build_string ("CNS11643-2 (Chinese traditional)"),
                  build_string
                  ("CNS 11643 Plane 2 Chinese traditional"),
-                 build_string (CHINESE_CNS_PLANE_RE("2")));
+                 build_string (CHINESE_CNS_PLANE_RE("2")),
+                 Qnil, 0, 0, 0, 33);
 #ifdef UTF2000
-  Vcharset_chinese_cns11643_3 =
-    make_charset (LEADING_BYTE_CHINESE_CNS11643_3, Qchinese_cns11643_3, 3,
-                 CHARSET_TYPE_94X94, 2, 0, 'I',
+  Vcharset_latin_viscii_lower =
+    make_charset (LEADING_BYTE_LATIN_VISCII_LOWER, Qlatin_viscii_lower,
+                 CHARSET_TYPE_96, 1, 1, '1',
                  CHARSET_LEFT_TO_RIGHT,
-                 build_string ("CNS11643-3"),
-                 build_string ("CNS11643-3 (Chinese traditional)"),
-                 build_string
-                 ("CNS 11643 Plane 3 Chinese traditional"),
-                 build_string (CHINESE_CNS_PLANE_RE("3")));
-  Vcharset_chinese_cns11643_4 =
-    make_charset (LEADING_BYTE_CHINESE_CNS11643_4, Qchinese_cns11643_4, 3,
-                 CHARSET_TYPE_94X94, 2, 0, 'J',
-                 CHARSET_LEFT_TO_RIGHT,
-                 build_string ("CNS11643-4"),
-                 build_string ("CNS11643-4 (Chinese traditional)"),
-                 build_string
-                 ("CNS 11643 Plane 4 Chinese traditional"),
-                 build_string (CHINESE_CNS_PLANE_RE("4")));
-  Vcharset_chinese_cns11643_5 =
-    make_charset (LEADING_BYTE_CHINESE_CNS11643_5, Qchinese_cns11643_5, 3,
-                 CHARSET_TYPE_94X94, 2, 0, 'K',
+                 build_string ("VISCII lower"),
+                 build_string ("VISCII lower (Vietnamese)"),
+                 build_string ("VISCII lower (Vietnamese)"),
+                 build_string ("VISCII1\\.1"),
+                 Qnil, 0, 0, 0, 32);
+  Vcharset_latin_viscii_upper =
+    make_charset (LEADING_BYTE_LATIN_VISCII_UPPER, Qlatin_viscii_upper,
+                 CHARSET_TYPE_96, 1, 1, '2',
                  CHARSET_LEFT_TO_RIGHT,
-                 build_string ("CNS11643-5"),
-                 build_string ("CNS11643-5 (Chinese traditional)"),
-                 build_string
-                 ("CNS 11643 Plane 5 Chinese traditional"),
-                 build_string (CHINESE_CNS_PLANE_RE("5")));
-  Vcharset_chinese_cns11643_6 =
-    make_charset (LEADING_BYTE_CHINESE_CNS11643_6, Qchinese_cns11643_6, 3,
-                 CHARSET_TYPE_94X94, 2, 0, 'L',
+                 build_string ("VISCII upper"),
+                 build_string ("VISCII upper (Vietnamese)"),
+                 build_string ("VISCII upper (Vietnamese)"),
+                 build_string ("VISCII1\\.1"),
+                 Qnil, 0, 0, 0, 32);
+  Vcharset_hiragana_jisx0208 =
+    make_charset (LEADING_BYTE_HIRAGANA_JISX0208, Qhiragana_jisx0208,
+                 CHARSET_TYPE_94X94, 2, 0, 'B',
                  CHARSET_LEFT_TO_RIGHT,
-                 build_string ("CNS11643-6"),
-                 build_string ("CNS11643-6 (Chinese traditional)"),
-                 build_string
-                 ("CNS 11643 Plane 6 Chinese traditional"),
-                 build_string (CHINESE_CNS_PLANE_RE("6")));
-  Vcharset_chinese_cns11643_7 =
-    make_charset (LEADING_BYTE_CHINESE_CNS11643_7, Qchinese_cns11643_7, 3,
-                 CHARSET_TYPE_94X94, 2, 0, 'M',
+                 build_string ("Hiragana"),
+                 build_string ("Hiragana of JIS X0208"),
+                 build_string ("Japanese Hiragana of JIS X0208"),
+                 build_string ("jisx0208\\.19\\(78\\|83\\|90\\)"),
+                 Qnil, MIN_CHAR_HIRAGANA, MAX_CHAR_HIRAGANA,
+                 (0x24 - 33) * 94 + (0x21 - 33), 33);
+  Vcharset_katakana_jisx0208 =
+    make_charset (LEADING_BYTE_KATAKANA_JISX0208, Qkatakana_jisx0208,
+                 CHARSET_TYPE_94X94, 2, 0, 'B',
                  CHARSET_LEFT_TO_RIGHT,
-                 build_string ("CNS11643-7"),
-                 build_string ("CNS11643-7 (Chinese traditional)"),
-                 build_string
-                 ("CNS 11643 Plane 7 Chinese traditional"),
-                 build_string (CHINESE_CNS_PLANE_RE("7")));
+                 build_string ("Katakana"),
+                 build_string ("Katakana of JIS X0208"),
+                 build_string ("Japanese Katakana of JIS X0208"),
+                 build_string ("jisx0208\\.19\\(78\\|83\\|90\\)"),
+                 Qnil, MIN_CHAR_KATAKANA, MAX_CHAR_KATAKANA,
+                 (0x25 - 33) * 94 + (0x21 - 33), 33);
 #endif
   Vcharset_chinese_big5_1 =
-    make_charset (LEADING_BYTE_CHINESE_BIG5_1, Qchinese_big5_1, 3,
+    make_charset (LEADING_BYTE_CHINESE_BIG5_1, Qchinese_big5_1,
                  CHARSET_TYPE_94X94, 2, 0, '0',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("Big5"),
                  build_string ("Big5 (Level-1)"),
                  build_string
                  ("Big5 Level-1 Chinese traditional"),
-                 build_string ("big5"));
+                 build_string ("big5"),
+                 Qnil, 0, 0, 0, 33);
   Vcharset_chinese_big5_2 =
-    make_charset (LEADING_BYTE_CHINESE_BIG5_2, Qchinese_big5_2, 3,
+    make_charset (LEADING_BYTE_CHINESE_BIG5_2, Qchinese_big5_2,
                  CHARSET_TYPE_94X94, 2, 0, '1',
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("Big5"),
                  build_string ("Big5 (Level-2)"),
                  build_string
                  ("Big5 Level-2 Chinese traditional"),
-                 build_string ("big5"));
-
+                 build_string ("big5"),
+                 Qnil, 0, 0, 0, 33);
 
 #ifdef ENABLE_COMPOSITE_CHARS
   /* #### For simplicity, we put composite chars into a 96x96 charset.
      This is going to lead to problems because you can run out of
      room, esp. as we don't yet recycle numbers. */
   Vcharset_composite =
-    make_charset (LEADING_BYTE_COMPOSITE, Qcomposite, 3,
+    make_charset (LEADING_BYTE_COMPOSITE, Qcomposite,
                  CHARSET_TYPE_96X96, 2, 0, 0,
                  CHARSET_LEFT_TO_RIGHT,
                  build_string ("Composite"),