(test_map_func): Modify for chise_char_feature_value_iterate.
authortomo <tomo>
Sun, 31 Aug 2003 02:23:10 +0000 (02:23 +0000)
committertomo <tomo>
Sun, 31 Aug 2003 02:23:10 +0000 (02:23 +0000)
(main): Rename `dt_*' to `ccs_*'; use `chise_ds_get_ccs' instead of
`chise_ds_open_decoding_table'; use `chise_ccs_decode' instead of
`chise_dt_get_char'; don't use `chise_dt_close'; use `use
`chise_ds_get_feature' instead of `chise_ds_open_feature_table'; use
`chise_char_gets_feature_value' instead of `chise_ft_get_value'; use
`chise_char_feature_value_iterate' instead of `chise_ft_iterate';
don't use `chise_ft_close'.

sample.c

index b72940c..05093db 100644 (file)
--- a/sample.c
+++ b/sample.c
@@ -3,11 +3,22 @@
 char db_dir[] = "/usr/local/lib/chise/char-db";
 
 int
-test_map_func (CHISE_Feature_Table *db,
-              CHISE_Char_ID cid, CHISE_Value *valdatum)
+test_map_func (CHISE_Char_ID cid, CHISE_Feature_Table *db,
+              CHISE_Value *valdatum)
 {
-  printf ("#x%04X\t(%c)\t%s\n",
-         cid, cid, chise_value_to_c_string (valdatum));
+  unsigned char buf[256];
+
+  printf ("(flags = %x)\n", valdatum->flags);
+  if (chise_value_size (valdatum) < 256)
+    {
+      strncpy (buf, chise_value_data (valdatum),
+              chise_value_size (valdatum));
+      buf[chise_value_size (valdatum)] = '\0';
+      printf ("#x%04X\t(%c)\t%s\n", cid, cid, buf);
+    }
+  else
+    printf ("#x%04X\t(%c)\t%s\n",
+           cid, cid, chise_value_to_c_string (valdatum));
   return 0;
 }
 
@@ -15,7 +26,7 @@ int
 main (int argc, char* argv[])
 {
   CHISE_DS *ds;
-  CHISE_Decoding_Table *dt_daikanwa;
+  CHISE_CCS ccs_daikanwa;
   CHISE_Feature_Table *ft_ideographic_structure;
   CHISE_Feature_Table *ft_ascii;
   int modemask;
@@ -24,11 +35,13 @@ main (int argc, char* argv[])
   int status;
   CHISE_Char_ID char_id;
   CHISE_Value value;
-  
+  unsigned char buf[1024];
+
   /* open a data-source */
   ds = chise_open_data_source (CHISE_DS_Berkeley_DB, db_dir);
   if (ds == NULL)
     {
+      printf ("Can't open data source\n");
       return -1;
     }
 
@@ -42,59 +55,34 @@ main (int argc, char* argv[])
   accessmask = DB_RDONLY;
 
   /* setup a decoding-table */
-  dt_daikanwa
-    = chise_ds_open_decoding_table (ds, "=daikanwa",
-                                   real_subtype, accessmask, modemask);
-  if (dt_daikanwa == NULL)
+  ccs_daikanwa
+    = chise_ds_get_ccs (ds, "=daikanwa",
+                       real_subtype, accessmask, modemask);
+  if (ccs_daikanwa == NULL)
     {
+      printf ("Can't open CCS =daikanwa\n");
       chise_ds_close (ds);
       return -1;
     }
   
   /* get a character from the decoding-table */
-  char_id = chise_dt_get_char (dt_daikanwa, 364);
-
-  /* close the decoding-table */
-  chise_dt_close (dt_daikanwa);
+  char_id = chise_ccs_decode (ccs_daikanwa, 364);
 
 
-  /*
-   * get a ideographic-structure feature of the character
-   */
-  
-  /* setup a feature-table */
-  ft_ideographic_structure
-    = chise_ds_open_feature_table (ds, "ideographic-structure",
-                                  real_subtype, accessmask, modemask);
-  if (ft_ideographic_structure == NULL)
-    {
-      chise_ds_close (ds);
-      return -1;
-    }
-  
-  /* setup a feature-table */
-  ft_ascii = chise_ds_open_feature_table (ds, "ascii",
-                                         real_subtype, accessmask, modemask);
-  if (ft_ascii == NULL)
-    {
-      chise_ds_close (ds);
-      return -1;
-    }
-  
   /* get a feature-value of the character */
-  status = chise_ft_get_value (ft_ideographic_structure, char_id, &value);
-
-  if (!status)
-    printf ("#x%X => %s\n", char_id, chise_value_to_c_string(&value));
+  ft_ideographic_structure
+    = chise_ds_get_feature (ds, "ideographic-structure",
+                           real_subtype, accessmask, modemask);
+  if (chise_char_gets_feature_value
+      (char_id, ft_ideographic_structure, buf, sizeof (buf)) != NULL)
+    printf ("#x%X => %s\n", char_id, buf);
   else
-    printf ("#x%X (%d)\n", char_id, status);
-
-  chise_ft_iterate (ft_ascii, &test_map_func);
-  chise_ft_iterate (ft_ideographic_structure, &test_map_func);
+    printf ("#x%X\n", char_id);
 
-  /* close the feature-table */
-  chise_ft_close (ft_ideographic_structure);
-  chise_ft_close (ft_ascii);
+  ft_ascii = chise_ds_get_feature (ds, "ascii",
+                                  real_subtype, accessmask, modemask);
+  chise_char_feature_value_iterate (ft_ascii, &test_map_func);
+  chise_char_feature_value_iterate (ft_ideographic_structure, &test_map_func);
 
   /* close the data-source */
   chise_ds_close (ds);