From: tomo Date: Sun, 2 Nov 2003 12:39:12 +0000 (+0000) Subject: (test_map_func): Modify to display UCS code point and character name. X-Git-Tag: libchise-0_2_0~10 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=fdb8a10dc34f6c16d1e6aefb32dc41f26e09161c;p=chise%2Flibchise.git (test_map_func): Modify to display UCS code point and character name. (main): Use `chise_system_db_dir'; display `numeric-value' instead of `ascii'. --- diff --git a/sample.c b/sample.c index aba6940..b72c41d 100644 --- a/sample.c +++ b/sample.c @@ -1,7 +1,9 @@ +#include #include #include #include +CHISE_DS *ds; static int test_name_map_func (CHISE_DS *ds, unsigned char *name) @@ -15,51 +17,62 @@ test_map_func (CHISE_Char_ID cid, CHISE_Feature_Table *db, CHISE_Value *valdatum) { unsigned char buf[256]; + unsigned char name[256]; + int ucs = -1; + + 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 (" "); + + if ( chise_char_gets_feature_value + (cid, chise_ds_get_feature (ds, "name"), + name, sizeof (name)) != NULL ) + printf (" %s", name); - 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); + printf ("\t%s\n", buf); } else - printf ("#x%04X\t(%c)\t%s\n", - cid, cid, chise_value_to_c_string (valdatum)); + printf ("\t%s\n", + chise_value_to_c_string (valdatum)); return 0; } int main (int argc, char* argv[]) { - CHISE_DS *ds; #if 0 CHISE_CCS ccs_daikanwa; #endif CHISE_Feature ft_ideographic_structure; - CHISE_Feature ft_ascii; - int modemask = 0755; /* rwxr-xr-x */ - DBTYPE real_subtype = DB_HASH; + CHISE_Feature ft_numeric_value; CHISE_Char_ID char_id; unsigned char buf[1024]; - unsigned char *db_dir; - - printf("chise_db_dir = %s\n", chise_db_dir); - db_dir = (unsigned char*)alloca (strlen (chise_db_dir) + 4); - if (db_dir == NULL) - { - printf ("Can't open data source\n"); - return -1; - } - strcpy (db_dir, chise_db_dir); - strcat (db_dir, "db/"); - printf("db_dir = '%s'\n", db_dir); + printf("chise_system_db_dir = %s\n", chise_system_db_dir); /* open a data-source */ - ds = CHISE_DS_open (CHISE_DS_Berkeley_DB, db_dir, - real_subtype, modemask); + ds = CHISE_DS_open (CHISE_DS_Berkeley_DB, chise_system_db_dir, + 0 /* DB_HASH */, 0755 /* rwxr-xr-x */); if (ds == NULL) { printf ("Can't open data source\n"); @@ -99,8 +112,8 @@ main (int argc, char* argv[]) chise_ds_foreach_char_feature_name (ds, &test_name_map_func); - ft_ascii = chise_ds_get_feature (ds, "ascii"); - chise_feature_foreach_char_with_value (ft_ascii, &test_map_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 (ft_ideographic_structure, &test_map_func);