Sync with r21-2-44-utf-2000-0_18-m15.
[chise/xemacs-chise.git-] / src / chartab.c
index 0347c43..1a22127 100644 (file)
@@ -65,9 +65,10 @@ Lisp_Object Vword_combining_categories, Vword_separating_categories;
 \f
 #ifdef UTF2000
 
+EXFUN (Fmap_char_attribute, 3);
+
 #if defined(HAVE_DATABASE)
 EXFUN (Fload_char_attribute_table, 1);
-EXFUN (Fmap_char_attribute, 3);
 
 Lisp_Object Vchar_db_stingy_mode;
 #endif
@@ -1058,12 +1059,9 @@ make_char_id_table (Lisp_Object initval)
 }
 
 
-Lisp_Object Vcharacter_composition_table;
-Lisp_Object Vcharacter_variant_table;
-
-
 Lisp_Object Qsystem_char_id;
 
+Lisp_Object Qcomposition;
 Lisp_Object Q_decomposition;
 Lisp_Object Qto_ucs;
 Lisp_Object Q_ucs;
@@ -1135,33 +1133,25 @@ Return character corresponding with list.
 */
        (list))
 {
-  Lisp_Object table = Vcharacter_composition_table;
-  Lisp_Object rest = list;
+  Lisp_Object base, modifier;
+  Lisp_Object rest;
 
-  while (CONSP (rest))
+  if (!CONSP (list))
+    signal_simple_error ("Invalid value for composition", list);
+  base = Fcar (list);
+  rest = Fcdr (list);
+  while (!NILP (rest))
     {
-      Lisp_Object v = Fcar (rest);
-      Lisp_Object ret;
-      Emchar c = to_char_id (v, "Invalid value for composition", list);
-
-      ret = get_char_id_table (XCHAR_TABLE(table), c);
-
+      if (!CHARP (base))
+       return Qnil;
+      if (!CONSP (rest))
+       signal_simple_error ("Invalid value for composition", list);
+      modifier = Fcar (rest);
       rest = Fcdr (rest);
-      if (NILP (rest))
-       {
-         if (!CHAR_TABLEP (ret))
-           return ret;
-         else
-           return Qt;
-       }
-      else if (!CONSP (rest))
-       break;
-      else if (CHAR_TABLEP (ret))
-       table = ret;
-      else
-       signal_simple_error ("Invalid table is found with", list);
+      base = Fcdr (Fassq (modifier,
+                         Fget_char_attribute (base, Qcomposition, Qnil)));
     }
-  signal_simple_error ("Invalid value for composition", list);
+  return base;
 }
 
 DEFUN ("char-variants", Fchar_variants, 1, 1, 0, /*
@@ -1172,8 +1162,7 @@ Return variants of CHARACTER.
   Lisp_Object ret;
 
   CHECK_CHAR (character);
-  ret = get_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
-                          XCHAR(character));
+  ret = Fget_char_attribute (character, Q_ucs_variants, Qnil);
   if (CONSP (ret))
     return Fcopy_list (ret);
   else
@@ -3165,8 +3154,6 @@ Store CHARACTER's ATTRIBUTE with VALUE.
     }
   else if (EQ (attribute, Q_decomposition))
     {
-      Lisp_Object seq;
-
       CHECK_CHAR (character);
       if (!CONSP (value))
        signal_simple_error ("Invalid value for ->decomposition",
@@ -3174,42 +3161,31 @@ Store CHARACTER's ATTRIBUTE with VALUE.
 
       if (CONSP (Fcdr (value)))
        {
-         Lisp_Object rest = value;
-         Lisp_Object table = Vcharacter_composition_table;
-         size_t len;
-         int i = 0;
-
-         GET_EXTERNAL_LIST_LENGTH (rest, len);
-         seq = make_vector (len, Qnil);
-
-         while (CONSP (rest))
+         if (NILP (Fcdr (Fcdr (value))))
            {
-             Lisp_Object v = Fcar (rest);
-             Lisp_Object ntable;
-             Emchar c
-               = to_char_id (v, "Invalid value for ->decomposition", value);
+             Lisp_Object base = Fcar (value);
+             Lisp_Object modifier = Fcar (Fcdr (value));
 
-             if (c < 0)
-               XVECTOR_DATA(seq)[i++] = v;
-             else
-               XVECTOR_DATA(seq)[i++] = make_char (c);
-             rest = Fcdr (rest);
-             if (!CONSP (rest))
+             if (INTP (base))
                {
-                 put_char_id_table (XCHAR_TABLE(table),
-                                    make_char (c), character);
-                 break;
+                 base = make_char (XINT (base));
+                 Fsetcar (value, base);
                }
-             else
+             if (INTP (modifier))
+               {
+                 modifier = make_char (XINT (modifier));
+                 Fsetcar (Fcdr (value), modifier);
+               }
+             if (CHARP (base))
                {
-                 ntable = get_char_id_table (XCHAR_TABLE(table), c);
-                 if (!CHAR_TABLEP (ntable))
-                   {
-                     ntable = make_char_id_table (Qnil);
-                     put_char_id_table (XCHAR_TABLE(table),
-                                        make_char (c), ntable);
-                   }
-                 table = ntable;
+                 Lisp_Object alist = Fget_char_attribute (base, Qcomposition, Qnil);
+                 Lisp_Object ret = Fassq (modifier, alist);
+
+                 if (NILP (ret))
+                   Fput_char_attribute (base, Qcomposition,
+                                        Fcons (Fcons (modifier, character), alist));
+                 else
+                   Fsetcdr (ret, character);
                }
            }
        }
@@ -3221,23 +3197,20 @@ Store CHARACTER's ATTRIBUTE with VALUE.
            {
              Emchar c = XINT (v);
              Lisp_Object ret
-               = get_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
-                                    c);
+               = Fget_char_attribute (make_char (c), Q_ucs_variants, Qnil);
 
              if (!CONSP (ret))
                {
-                 put_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
-                                    make_char (c), Fcons (character, Qnil));
+                 Fput_char_attribute (make_char (c), Q_ucs_variants,
+                                      Fcons (character, Qnil));
                }
-             else if (NILP (Fmemq (v, ret)))
+             else if (NILP (Fmemq (character, ret)))
                {
-                 put_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
-                                    make_char (c), Fcons (character, ret));
+                 Fput_char_attribute (make_char (c), Q_ucs_variants,
+                                      Fcons (character, ret));
                }
            }
-         seq = make_vector (1, v);
        }
-      value = seq;
     }
   else if (EQ (attribute, Qto_ucs) || EQ (attribute, Q_ucs))
     {
@@ -3250,16 +3223,16 @@ Store CHARACTER's ATTRIBUTE with VALUE.
 
       c = XINT (value);
 
-      ret = get_char_id_table (XCHAR_TABLE(Vcharacter_variant_table), c);
+      ret = Fget_char_attribute (make_char (c), Q_ucs_variants, Qnil);
       if (!CONSP (ret))
        {
-         put_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
-                            make_char (c), Fcons (character, Qnil));
+         Fput_char_attribute (make_char (c), Q_ucs_variants,
+                              Fcons (character, Qnil));
        }
       else if (NILP (Fmemq (character, ret)))
        {
-         put_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
-                            make_char (c), Fcons (character, ret));
+         Fput_char_attribute (make_char (c), Q_ucs_variants,
+                              Fcons (character, ret));
        }
 #if 0
       if (EQ (attribute, Q_ucs))
@@ -3311,6 +3284,7 @@ Remove CHARACTER's ATTRIBUTE.
   return Qnil;
 }
 
+#ifdef HAVE_DATABASE
 Lisp_Object
 char_attribute_system_db_file (Lisp_Object key_type, Lisp_Object attribute,
                               int writing_mode)
@@ -3362,7 +3336,7 @@ char_attribute_system_db_file (Lisp_Object key_type, Lisp_Object attribute,
   return Fexpand_file_name (Fsymbol_name (attribute), db_dir);
 #endif
 }
-  
+
 DEFUN ("save-char-attribute-table", Fsave_char_attribute_table, 1, 1, 0, /*
 Save values of ATTRIBUTE into database file.
 */
@@ -3483,7 +3457,6 @@ Reset values of ATTRIBUTE with database file.
   return Qnil;
 }
 
-#ifdef HAVE_DATABASE
 Lisp_Object
 load_char_attribute_maybe (Lisp_Char_Table* cit, Emchar ch)
 {
@@ -3537,14 +3510,12 @@ For internal use.  Don't use it.
     put_char_id_table_0 (char_attribute_table_to_load, code, Fread (value));
   return Qnil;
 }
-#endif
 
 DEFUN ("load-char-attribute-table", Fload_char_attribute_table, 1, 1, 0, /*
 Load values of ATTRIBUTE into database file.
 */
        (attribute))
 {
-#ifdef HAVE_DATABASE
   Lisp_Object table = Fgethash (attribute,
                                Vchar_attribute_hash_table,
                                Qunbound);
@@ -3575,8 +3546,8 @@ Load values of ATTRIBUTE into database file.
        }
     }
   return Qnil;
-#endif
 }
+#endif
 
 DEFUN ("map-char-attribute", Fmap_char_attribute, 2, 3, 0, /*
 Map FUNCTION over entries in ATTRIBUTE, calling it with two args,
@@ -4077,6 +4048,7 @@ syms_of_chartab (void)
   defsymbol (&Qto_ucs,                 "=>ucs");
   defsymbol (&Q_ucs,                   "->ucs");
   defsymbol (&Q_ucs_variants,          "->ucs-variants");
+  defsymbol (&Qcomposition,            "composition");
   defsymbol (&Q_decomposition,         "->decomposition");
   defsymbol (&Qcompat,                 "compat");
   defsymbol (&Qisolated,               "isolated");
@@ -4099,16 +4071,16 @@ syms_of_chartab (void)
   DEFSUBR (Ffind_char_attribute_table);
   defsymbol (&Qput_char_table_map_function, "put-char-table-map-function");
   DEFSUBR (Fput_char_table_map_function);
+#ifdef HAVE_DATABASE
   DEFSUBR (Fsave_char_attribute_table);
   DEFSUBR (Fmount_char_attribute_table);
   DEFSUBR (Freset_char_attribute_table);
   DEFSUBR (Fclose_char_attribute_table);
-#ifdef HAVE_DATABASE
   defsymbol (&Qload_char_attribute_table_map_function,
             "load-char-attribute-table-map-function");
   DEFSUBR (Fload_char_attribute_table_map_function);
-#endif
   DEFSUBR (Fload_char_attribute_table);
+#endif
   DEFSUBR (Fchar_attribute_alist);
   DEFSUBR (Fget_char_attribute);
   DEFSUBR (Fput_char_attribute);
@@ -4168,12 +4140,6 @@ void
 vars_of_chartab (void)
 {
 #ifdef UTF2000
-  staticpro (&Vcharacter_composition_table);
-  Vcharacter_composition_table = make_char_id_table (Qnil);
-
-  staticpro (&Vcharacter_variant_table);
-  Vcharacter_variant_table = make_char_id_table (Qunbound);
-
 #ifdef HAVE_DATABASE
   DEFVAR_LISP ("char-db-stingy-mode", &Vchar_db_stingy_mode /*
 */ );
@@ -4203,11 +4169,6 @@ complex_vars_of_chartab (void)
   staticpro (&Vchar_attribute_hash_table);
   Vchar_attribute_hash_table
     = make_lisp_hash_table (16, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
-#ifdef HAVE_DATABASE
-  Fputhash (Q_ucs_variants, Vcharacter_variant_table,
-           Vchar_attribute_hash_table);
-  XCHAR_TABLE_NAME (Vcharacter_variant_table) = Q_ucs_variants;
-#endif /* HAVE_DATABASE */
 #endif /* UTF2000 */
 #ifdef MULE
   /* Set this now, so first buffer creation can refer to it. */