(make_byte_table): Add new argument `older'.
[chise/xemacs-chise.git] / src / mule-charset.c
index 66e1b49..3badc13 100644 (file)
@@ -206,7 +206,7 @@ byte_table_hash (Lisp_Object obj, int depth)
 }
 
 static const struct lrecord_description byte_table_description[] = {
-  { XD_LISP_OBJECT, offsetof(Lisp_Byte_Table, property), 256 },
+  { XD_LISP_OBJECT_ARRAY, offsetof(Lisp_Byte_Table, property), 256 },
   { XD_END }
 };
 
@@ -219,12 +219,16 @@ DEFINE_LRECORD_IMPLEMENTATION ("byte-table", byte_table,
                               Lisp_Byte_Table);
 
 static Lisp_Object
-make_byte_table (Lisp_Object initval)
+make_byte_table (Lisp_Object initval, int older)
 {
   Lisp_Object obj;
   int i;
-  Lisp_Byte_Table *cte
-    = alloc_lcrecord_type (Lisp_Byte_Table, &lrecord_byte_table);
+  Lisp_Byte_Table *cte;
+
+  if (older)
+    cte = alloc_older_lcrecord_type (Lisp_Byte_Table, &lrecord_byte_table);
+  else
+    cte = alloc_lcrecord_type (Lisp_Byte_Table, &lrecord_byte_table);
 
   for (i = 0; i < 256; i++)
     cte->property[i] = initval;
@@ -282,7 +286,7 @@ char_id_table_hash (Lisp_Object obj, int depth)
 }
 
 static const struct lrecord_description char_id_table_description[] = {
-  { XD_LISP_OBJECT, offsetof(Lisp_Char_ID_Table, table), 1 },
+  { XD_LISP_OBJECT, offsetof(Lisp_Char_ID_Table, table) },
   { XD_END }
 };
 
@@ -295,18 +299,25 @@ DEFINE_LRECORD_IMPLEMENTATION ("char-id-table", char_id_table,
                               Lisp_Char_ID_Table);
 
 static Lisp_Object
-make_char_id_table (Lisp_Object initval)
+make_char_id_table (Lisp_Object initval, int older)
 {
   Lisp_Object obj;
-  Lisp_Char_ID_Table *cte
-    = alloc_lcrecord_type (Lisp_Char_ID_Table, &lrecord_char_id_table);
+  Lisp_Char_ID_Table *cte;
 
-  cte->table = make_byte_table (initval);
+  if (older)
+    cte = alloc_older_lcrecord_type (Lisp_Char_ID_Table,
+                                    &lrecord_char_id_table);
+  else
+    cte = alloc_lcrecord_type (Lisp_Char_ID_Table, &lrecord_char_id_table);
+
+  cte->table = make_byte_table (initval, older);
 
   XSETCHAR_ID_TABLE (obj, cte);
   return obj;
 }
 
+/* not used */
+#if 0
 static Lisp_Object
 copy_char_id_table (Lisp_Object entry)
 {
@@ -319,6 +330,7 @@ copy_char_id_table (Lisp_Object entry)
   XSETCHAR_ID_TABLE (obj, ctenew);
   return obj;
 }
+#endif
 
 
 Lisp_Object
@@ -375,17 +387,19 @@ put_char_id_table (Emchar ch, Lisp_Object value, Lisp_Object table)
            }
          else if (!EQ (ret, value))
            {
-             Lisp_Object cpt4 = make_byte_table (ret);
-             
+             Lisp_Object cpt4
+               = make_byte_table (ret, OLDER_RECORD_P (table));
+
              XBYTE_TABLE(cpt4)->property[(unsigned char)code] = value;
              cpt3->property[(unsigned char)(code >> 8)] = cpt4;
            }
        }
       else if (!EQ (ret, value))
        {
-         Lisp_Object cpt3 = make_byte_table (ret);
-         Lisp_Object cpt4 = make_byte_table (ret);
-         
+         int older = OLDER_RECORD_P (table);
+         Lisp_Object cpt3 = make_byte_table (ret, older);
+         Lisp_Object cpt4 = make_byte_table (ret, older);
+
          XBYTE_TABLE(cpt4)->property[(unsigned char)code] = value;
          XBYTE_TABLE(cpt3)->property[(unsigned char)(code >> 8)]
            = cpt4;
@@ -394,10 +408,11 @@ put_char_id_table (Emchar ch, Lisp_Object value, Lisp_Object table)
     }
   else if (!EQ (ret, value))
     {
-      Lisp_Object cpt2 = make_byte_table (ret);
-      Lisp_Object cpt3 = make_byte_table (ret);
-      Lisp_Object cpt4 = make_byte_table (ret);
-      
+      int older = OLDER_RECORD_P (table);
+      Lisp_Object cpt2 = make_byte_table (ret, older);
+      Lisp_Object cpt3 = make_byte_table (ret, older);
+      Lisp_Object cpt4 = make_byte_table (ret, older);
+
       XBYTE_TABLE(cpt4)->property[(unsigned char)code] = value;
       XBYTE_TABLE(cpt3)->property[(unsigned char)(code >>  8)] = cpt4;
       XBYTE_TABLE(cpt2)->property[(unsigned char)(code >> 16)] = cpt3;
@@ -532,18 +547,28 @@ Return the value of CHARACTER's ATTRIBUTE.
 */
        (character, attribute))
 {
-  Lisp_Object ret;
   Lisp_Object ccs;
 
   CHECK_CHAR (character);
-  ret = get_char_id_table (XCHAR (character), Vcharacter_attribute_table);
-  if (EQ (ret, Qnil))
-    return Qnil;
-
   if (!NILP (ccs = Ffind_charset (attribute)))
-    attribute = ccs;
+    {
+      Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (ccs);
 
-  return Fcdr (Fassq (attribute, ret));
+      if (CHAR_ID_TABLE_P (encoding_table))
+       return get_char_id_table (XCHAR (character), encoding_table);
+      else
+       return Qnil;
+    }
+  else
+    {
+      Lisp_Object ret
+       = get_char_id_table (XCHAR (character), Vcharacter_attribute_table);
+
+      if (EQ (ret, Qnil))
+       return Qnil;
+      else
+       return Fcdr (Fassq (attribute, ret));
+    }
 }
 
 Lisp_Object put_char_attribute (Lisp_Object character,
@@ -615,6 +640,8 @@ Store CHARACTER's ATTRIBUTE with VALUE.
   ccs = Ffind_charset (attribute);
   if (!NILP (ccs))
     {
+      Lisp_Object encoding_table;
+
       if (!EQ (XCHARSET_NAME (ccs), Qucs)
          || (XCHAR (character) != XINT (value)))
        {
@@ -695,7 +722,8 @@ Store CHARACTER's ATTRIBUTE with VALUE.
            }
          else
            {
-             XCHARSET_DECODING_TABLE (ccs) = v = make_vector (ccs_len, Qnil);
+             XCHARSET_DECODING_TABLE (ccs) = v
+               = make_older_vector (ccs_len, Qnil);
            }
 
          dim = XCHARSET_DIMENSION (ccs);
@@ -710,7 +738,8 @@ Store CHARACTER's ATTRIBUTE with VALUE.
              if (dim > 0)
                {
                  if (!VECTORP (nv))
-                   nv = (XVECTOR_DATA(v)[i] = make_vector (ccs_len, Qnil));
+                   nv = (XVECTOR_DATA(v)[i]
+                         = make_older_vector (ccs_len, Qnil));
                  v = nv;
                }
              else
@@ -720,6 +749,13 @@ Store CHARACTER's ATTRIBUTE with VALUE.
        }
       else
        attribute = ccs;
+      if (NILP (encoding_table = XCHARSET_ENCODING_TABLE (ccs)))
+       {
+         XCHARSET_ENCODING_TABLE (ccs) = encoding_table
+           = make_char_id_table (Qnil, -1);
+       }
+      put_char_id_table (XCHAR (character), value, encoding_table);
+      return Qt;
     }
   else if (EQ (attribute, Q_decomposition))
     {
@@ -750,7 +786,8 @@ Store CHARACTER's ATTRIBUTE with VALUE.
                  ntable = get_char_id_table (c, table);
                  if (!CHAR_ID_TABLE_P (ntable))
                    {
-                     ntable = make_char_id_table (Qnil);
+                     ntable
+                       = make_char_id_table (Qnil, OLDER_RECORD_P (table));
                      put_char_id_table (c, ntable, table);
                    }
                  table = ntable;
@@ -813,7 +850,8 @@ Remove CHARACTER's ATTRIBUTE.
       int ccs_len;
       int dim;
       int code_point;
-             
+      Lisp_Object encoding_table;
+
       /* ad-hoc method for `ascii' */
       if ((XCHARSET_CHARS (ccs) == 94) &&
          (XCHARSET_BYTE_OFFSET (ccs) != 33))
@@ -844,6 +882,11 @@ Remove CHARACTER's ATTRIBUTE.
              v = XCHARSET_DECODING_TABLE (ccs);
            }
        }
+      if (!NILP (encoding_table = XCHARSET_ENCODING_TABLE (ccs)))
+       {
+         put_char_id_table (XCHAR (character), Qnil, encoding_table);
+       }
+      return Qt;
     }
   return remove_char_attribute (character, attribute);
 }
@@ -1358,7 +1401,8 @@ mark_charset (Lisp_Object obj)
   mark_object (cs->registry);
   mark_object (cs->ccl_program);
 #ifdef UTF2000
-  mark_object (cs->decoding_table);
+  /* mark_object (cs->encoding_table); */
+  /* mark_object (cs->decoding_table); */
 #endif
   return cs->name;
 }
@@ -1405,6 +1449,7 @@ static const struct lrecord_description charset_description[] = {
   { XD_LISP_OBJECT, offsetof (Lisp_Charset, ccl_program) },
 #ifdef UTF2000
   { XD_LISP_OBJECT, offsetof (Lisp_Charset, decoding_table) },
+  { XD_LISP_OBJECT, offsetof (Lisp_Charset, encoding_table) },
 #endif
   { XD_END }
 };
@@ -1450,6 +1495,7 @@ make_charset (Charset_ID id, Lisp_Object name,
   CHARSET_REVERSE_DIRECTION_CHARSET (cs) = Qnil;
 #ifdef UTF2000
   CHARSET_DECODING_TABLE(cs) = Qnil;
+  CHARSET_ENCODING_TABLE(cs) = Qnil;
   CHARSET_UCS_MIN(cs) = ucs_min;
   CHARSET_UCS_MAX(cs) = ucs_max;
   CHARSET_CODE_OFFSET(cs) = code_offset;
@@ -2941,13 +2987,13 @@ Version number of UTF-2000.
 */ );
 
   staticpro (&Vcharacter_attribute_table);
-  Vcharacter_attribute_table = make_char_id_table (Qnil);
+  Vcharacter_attribute_table = make_char_id_table (Qnil, 0);
 
-  staticpro (&Vcharacter_composition_table);
-  Vcharacter_composition_table = make_char_id_table (Qnil);
+  /* staticpro (&Vcharacter_composition_table); */
+  Vcharacter_composition_table = make_char_id_table (Qnil, -1);
 
   staticpro (&Vcharacter_variant_table);
-  Vcharacter_variant_table = make_char_id_table (Qnil);
+  Vcharacter_variant_table = make_char_id_table (Qnil, 0);
 
   Vdefault_coded_charset_priority_list = Qnil;
   DEFVAR_LISP ("default-coded-charset-priority-list",