(C2-274E): Add `ideographic-strokes'.
[chise/xemacs-chise.git] / src / mule-charset.c
index 2a0dea9..a72788d 100644 (file)
@@ -73,6 +73,7 @@ Lisp_Object Vcharset_latin_tcvn5712;
 Lisp_Object Vcharset_latin_viscii_lower;
 Lisp_Object Vcharset_latin_viscii_upper;
 Lisp_Object Vcharset_chinese_big5;
+Lisp_Object Vcharset_chinese_big5_cdp;
 Lisp_Object Vcharset_ideograph_gt;
 Lisp_Object Vcharset_ideograph_gt_pj_1;
 Lisp_Object Vcharset_ideograph_gt_pj_2;
@@ -342,6 +343,29 @@ uint8_byte_table_same_value_p (Lisp_Object obj)
   return -1;
 }
 
+static int
+map_over_uint8_byte_table (Lisp_Uint8_Byte_Table *ct,
+                          int (*fn) (Emchar c, Lisp_Object val, void *arg),
+                          void *arg, Emchar ofs, int place)
+{
+  int i, retval;
+  int unit = 1 << (8 * place);
+  Emchar c = ofs;
+  Emchar c1;
+
+  for (i = 0, retval = 0; i < 256 && retval == 0; i++)
+    {
+      if (ct->property[i] != BT_UINT8_unbound)
+       {
+         c1 = c + unit;
+         for (; c < c1 && retval == 0; c++)
+           retval = (fn) (c, UINT8_DECODE (ct->property[i]), arg);
+       }
+      else
+       c += unit;
+    }
+  return retval;
+}
 
 #define BT_UINT16_MIN          0
 #define BT_UINT16_MAX   (USHRT_MAX - 3)
@@ -536,6 +560,30 @@ uint16_byte_table_same_value_p (Lisp_Object obj)
   return -1;
 }
 
+static int
+map_over_uint16_byte_table (Lisp_Uint16_Byte_Table *ct,
+                           int (*fn) (Emchar c, Lisp_Object val, void *arg),
+                           void *arg, Emchar ofs, int place)
+{
+  int i, retval;
+  int unit = 1 << (8 * place);
+  Emchar c = ofs;
+  Emchar c1;
+
+  for (i = 0, retval = 0; i < 256 && retval == 0; i++)
+    {
+      if (ct->property[i] != BT_UINT16_unbound)
+       {
+         c1 = c + unit;
+         for (; c < c1 && retval == 0; c++)
+           retval = (fn) (c, UINT16_DECODE (ct->property[i]), arg);
+       }
+      else
+       c += unit;
+    }
+  return retval;
+}
+
 
 static Lisp_Object
 mark_byte_table (Lisp_Object obj)
@@ -651,6 +699,52 @@ byte_table_same_value_p (Lisp_Object obj)
   return -1;
 }
 
+static int
+map_over_byte_table (Lisp_Byte_Table *ct,
+                    int (*fn) (Emchar c, Lisp_Object val, void *arg),
+                    void *arg, Emchar ofs, int place)
+{
+  int i, retval;
+  Lisp_Object v;
+  int unit = 1 << (8 * place);
+  Emchar c = ofs;
+
+  for (i = 0, retval = 0; i < 256 && retval == 0; i++)
+    {
+      v = ct->property[i];
+      if (UINT8_BYTE_TABLE_P (v))
+       {
+         retval
+           = map_over_uint8_byte_table (XUINT8_BYTE_TABLE(v),
+                                        fn, arg, c, place - 1);
+         c += unit;
+       }
+      else if (UINT16_BYTE_TABLE_P (v))
+       {
+         retval
+           = map_over_uint16_byte_table (XUINT16_BYTE_TABLE(v),
+                                         fn, arg, c, place - 1);
+         c += unit;
+       }
+      else if (BYTE_TABLE_P (v))
+       {
+         retval = map_over_byte_table (XBYTE_TABLE(v),
+                                       fn, arg, c, place - 1);
+         c += unit;
+       }
+      else if (!UNBOUNDP (v))
+       {
+         Emchar c1 = c + unit;
+
+         for (; c < c1 && retval == 0; c++)
+           retval = (fn) (c, v, arg);
+       }
+      else
+       c += unit;
+    }
+  return retval;
+}
+
 
 Lisp_Object get_byte_table (Lisp_Object table, unsigned char idx);
 Lisp_Object put_byte_table (Lisp_Object table, unsigned char idx,
@@ -880,6 +974,55 @@ put_char_id_table (Emchar ch, Lisp_Object value, Lisp_Object table)
     = put_byte_table (table1, (unsigned char)(code >> 24), table2);
 }
 
+/* Map FN (with client data ARG) in char table CT.
+   Mapping stops the first time FN returns non-zero, and that value
+   becomes the return value of map_char_id_table(). */
+int
+map_char_id_table (Lisp_Char_ID_Table *ct,
+                  int (*fn) (Emchar c, Lisp_Object val, void *arg),
+                  void *arg);
+int
+map_char_id_table (Lisp_Char_ID_Table *ct,
+                  int (*fn) (Emchar c, Lisp_Object val, void *arg),
+                  void *arg)
+{
+  Lisp_Object v = ct->table;
+
+  if (UINT8_BYTE_TABLE_P (v))
+    return map_over_uint8_byte_table (XUINT8_BYTE_TABLE(v), fn, arg, 0, 3);
+  else if (UINT16_BYTE_TABLE_P (v))
+    return map_over_uint16_byte_table (XUINT16_BYTE_TABLE(v), fn, arg, 0, 3);
+  else if (BYTE_TABLE_P (v))
+    return map_over_byte_table (XBYTE_TABLE(v), fn, arg, 0, 3);
+  else if (!UNBOUNDP (v))
+    {
+      int unit = 1 << 24;
+      Emchar c = 0;
+      Emchar c1 = c + unit;
+      int retval;
+
+      for (retval = 0; c < c1 && retval == 0; c++)
+       retval = (fn) (c, v, arg);
+    }
+  return 0;
+}
+
+struct slow_map_char_id_table_arg
+{
+  Lisp_Object function;
+  Lisp_Object retval;
+};
+
+static int
+slow_map_char_id_table_fun (Emchar c, Lisp_Object val, void *arg)
+{
+  struct slow_map_char_id_table_arg *closure =
+    (struct slow_map_char_id_table_arg *) arg;
+
+  closure->retval = call2 (closure->function, make_char (c), val);
+  return !NILP (closure->retval);
+}
+
 
 Lisp_Object Vchar_attribute_hash_table;
 Lisp_Object Vcharacter_composition_table;
@@ -1295,6 +1438,45 @@ Remove CHARACTER's ATTRIBUTE.
   return Qnil;
 }
 
+DEFUN ("map-char-attribute", Fmap_char_attribute, 2, 2, 0, /*
+Map FUNCTION over entries in ATTRIBUTE, calling it with two args,
+each key and value in the table.
+*/
+       (function, attribute))
+{
+  Lisp_Object ccs;
+  Lisp_Char_ID_Table *ct;
+  struct slow_map_char_id_table_arg slarg;
+  struct gcpro gcpro1, gcpro2;
+
+  if (!NILP (ccs = Ffind_charset (attribute)))
+    {
+      Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (ccs);
+
+      if (CHAR_ID_TABLE_P (encoding_table))
+       ct = XCHAR_ID_TABLE (encoding_table);
+      else
+       return Qnil;
+    }
+  else
+    {
+      Lisp_Object table = Fgethash (attribute,
+                                   Vchar_attribute_hash_table,
+                                   Qunbound);
+      if (CHAR_ID_TABLE_P (table))
+       ct = XCHAR_ID_TABLE (table);
+      else
+       return Qnil;
+    }
+  slarg.function = function;
+  slarg.retval = Qnil;
+  GCPRO2 (slarg.function, slarg.retval);
+  map_char_id_table (ct, slow_map_char_id_table_fun, &slarg);
+  UNGCPRO;
+
+  return slarg.retval;
+}
+
 INLINE_HEADER int CHARSET_BYTE_SIZE (Lisp_Charset* cs);
 INLINE_HEADER int
 CHARSET_BYTE_SIZE (Lisp_Charset* cs)
@@ -1563,6 +1745,42 @@ Store character's ATTRIBUTES.
   return character;
 }
 
+DEFUN ("find-char", Ffind_char, 1, 1, 0, /*
+Retrieve the character of the given ATTRIBUTES.
+*/
+       (attributes))
+{
+  Lisp_Object rest = attributes;
+  Lisp_Object code;
+
+  while (CONSP (rest))
+    {
+      Lisp_Object cell = Fcar (rest);
+      Lisp_Object ccs;
+
+      if (!LISTP (cell))
+       signal_simple_error ("Invalid argument", attributes);
+      if (!NILP (ccs = Ffind_charset (Fcar (cell))))
+       {
+         cell = Fcdr (cell);
+         if (CONSP (cell))
+           return Fmake_char (ccs, Fcar (cell), Fcar (Fcdr (cell)));
+         else
+           return Fdecode_char (ccs, cell);
+       }
+      rest = Fcdr (rest);
+    }
+  if ( (!NILP (code = Fcdr (Fassq (Qto_ucs, attributes)))) ||
+       (!NILP (code = Fcdr (Fassq (Q_ucs, attributes)))) )
+    {
+      if (!INTP (code))
+       signal_simple_error ("Invalid argument", attributes);
+      else
+       return make_char (XINT (code) + 0x100000);
+    }
+  return Qnil;
+}
+
 Lisp_Object Vutf_2000_version;
 #endif
 
@@ -1613,6 +1831,7 @@ Lisp_Object Qascii,
   Qvietnamese_viscii_lower,
   Qvietnamese_viscii_upper,
   Qchinese_big5,
+  Qchinese_big5_cdp,
   Qideograph_gt,
   Qideograph_gt_pj_1,
   Qideograph_gt_pj_2,
@@ -3459,7 +3678,9 @@ syms_of_mule_charset (void)
   DEFSUBR (Fget_char_attribute);
   DEFSUBR (Fput_char_attribute);
   DEFSUBR (Fremove_char_attribute);
+  DEFSUBR (Fmap_char_attribute);
   DEFSUBR (Fdefine_char);
+  DEFSUBR (Ffind_char);
   DEFSUBR (Fchar_variants);
   DEFSUBR (Fget_composite_char);
   DEFSUBR (Fcharset_mapping_table);
@@ -3561,6 +3782,7 @@ syms_of_mule_charset (void)
   defsymbol (&Qideograph_gt_pj_11,     "ideograph-gt-pj-11");
   defsymbol (&Qideograph_daikanwa,     "ideograph-daikanwa");
   defsymbol (&Qchinese_big5,           "chinese-big5");
+  defsymbol (&Qchinese_big5_cdp,       "chinese-big5-cdp");
   defsymbol (&Qmojikyo,                        "mojikyo");
   defsymbol (&Qmojikyo_2022_1,         "mojikyo-2022-1");
   defsymbol (&Qmojikyo_pj_1,           "mojikyo-pj-1");
@@ -3980,6 +4202,15 @@ complex_vars_of_mule_charset (void)
                  build_string ("Big5 Chinese traditional"),
                  build_string ("big5"),
                  Qnil, 0, 0, 0, 0);
+  staticpro (&Vcharset_chinese_big5_cdp);
+  Vcharset_chinese_big5_cdp =
+    make_charset (LEADING_BYTE_CHINESE_BIG5_CDP, Qchinese_big5_cdp, 256, 2,
+                 2, 2, 0, CHARSET_LEFT_TO_RIGHT,
+                 build_string ("Big5-CDP"),
+                 build_string ("Big5 + CDP extension"),
+                 build_string ("Big5 with CDP extension"),
+                 build_string ("big5\\.cdp-0"),
+                 Qnil, 0, 0, 0, 0);
   staticpro (&Vcharset_ideograph_gt);
   Vcharset_ideograph_gt =
     make_charset (LEADING_BYTE_GT, Qideograph_gt, 256, 3,
@@ -3998,7 +4229,7 @@ complex_vars_of_mule_charset (void)
                  build_string ("GT (pseudo JIS encoding) part "#n),    \
                  build_string ("GT 2000 (pseudo JIS encoding) part "#n), \
                  build_string                                          \
-                 ("\\(GT2000PJ-"#n "\\|jisx0208\\.GT2000-"#n "\\)$"),  \
+                 ("\\(GTpj-"#n "\\|jisx0208\\.GT-"#n "\\)$"),  \
                  Qnil, 0, 0, 0, 33);
   DEF_GT_PJ (1);
   DEF_GT_PJ (2);