X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=sample.c;h=af4f92d8767fd884542f5adb710c4c23ff9d1a4e;hb=d9e7b9fb3e5ad9fa105e1c94df9aff0fb02dfc71;hp=b72c41d5f32ab255d1e94921bcbf822ee544a283;hpb=fdb8a10dc34f6c16d1e6aefb32dc41f26e09161c;p=chise%2Flibchise.git diff --git a/sample.c b/sample.c index b72c41d..af4f92d 100644 --- a/sample.c +++ b/sample.c @@ -13,7 +13,7 @@ test_name_map_func (CHISE_DS *ds, unsigned char *name) } static int -test_map_func (CHISE_Char_ID cid, CHISE_Feature_Table *db, +test_map_func (CHISE_Char_ID cid, CHISE_Feature db, CHISE_Value *valdatum) { unsigned char buf[256]; @@ -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 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]; @@ -79,6 +126,8 @@ main (int argc, char* argv[]) return -1; } + printf("data source location = %s\n", chise_ds_location(ds)); + /* * get a character corresponding with Daikanwa number 364 @@ -112,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