(test_radical_func): New function.
authortomo <tomo>
Wed, 2 Mar 2005 07:01:48 +0000 (07:01 +0000)
committertomo <tomo>
Wed, 2 Mar 2005 07:01:48 +0000 (07:01 +0000)
(main): Add sample code about `ideographic-radical'.

sample.c

index 03abec7..e65e39d 100644 (file)
--- a/sample.c
+++ b/sample.c
@@ -57,6 +57,52 @@ test_map_func (CHISE_Char_ID cid, CHISE_Feature_Table *db,
   return 0;
 }
 
+static int
+test_radical_func (CHISE_Char_ID cid, CHISE_Feature_Table *db,
+                  CHISE_Value *valdatum)
+{
+  unsigned char buf[256];
+  unsigned char name[256];
+  int ucs = -1;
+
+  if (chise_value_size (valdatum) < 256)
+    {
+      strncpy (buf, chise_value_data (valdatum),
+              chise_value_size (valdatum));
+      buf[chise_value_size (valdatum)] = '\0';
+      printf ("%s\t", buf);
+    }
+  else
+    printf ("%s\t",
+           chise_value_to_c_string (valdatum));
+
+  if (strcmp (buf, "75") == 0) /* Tree */
+    {
+      printf ("#x%08X ", cid);
+      if ( chise_char_gets_feature_value
+          (cid, chise_ds_get_feature (ds, "=ucs"),
+           buf, sizeof (buf)) != NULL )
+       {
+         ucs = atoi (buf);
+         printf ("[U-%08X]", ucs);
+       }
+      else if ( chise_char_gets_feature_value
+               (cid, chise_ds_get_feature (ds, "=>ucs"),
+                buf, sizeof (buf)) != NULL )
+       {
+         ucs = atoi (buf);
+         printf ("(U-%08X)", ucs);
+       }
+      else
+       printf ("            ");
+
+      printf ("\n");
+    }
+  else
+    printf ("\n");
+  return 0;
+}
+
 int
 main (int argc, char* argv[])
 {
@@ -65,6 +111,7 @@ main (int argc, char* argv[])
 #endif
   CHISE_Feature ft_ideographic_structure;
   CHISE_Feature ft_numeric_value;
+  CHISE_Feature ft_radicals;
   CHISE_Char_ID char_id;
   unsigned char buf[1024];
 
@@ -114,6 +161,9 @@ main (int argc, char* argv[])
 
   chise_ds_foreach_char_feature_name (ds, &test_name_map_func);
 
+  ft_radicals = chise_ds_get_feature (ds, "ideographic-radical");
+  chise_feature_foreach_char_with_value (ft_radicals, &test_radical_func);
+
   ft_numeric_value = chise_ds_get_feature (ds, "numeric-value");
   chise_feature_foreach_char_with_value (ft_numeric_value, &test_map_func);
   chise_feature_foreach_char_with_value