X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=sample.c;h=179c021964724883497a204abbc13614c49b8fdc;hb=7b810cb668950e7f3e6b0ff4de0861b725712eea;hp=c544fcd1e761b60506920e41312c6fd77d0fa5ac;hpb=6f45c841989f186d3552d956a56c881b973226fc;p=chise%2Flibchise.git diff --git a/sample.c b/sample.c index c544fcd..179c021 100644 --- a/sample.c +++ b/sample.c @@ -3,23 +3,45 @@ char db_dir[] = "/usr/local/lib/chise/char-db"; int +test_map_func (CHISE_Char_ID cid, CHISE_Feature_Table *db, + CHISE_Value *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; +} + +int main (int argc, char* argv[]) { - CHISE_DS ds; - CHISE_Decoding_Table *dt_daikanwa; - CHISE_Feature_Table *ft_ideographic_structure; - int modemask; - int accessmask = 0; - DBTYPE real_subtype; + CHISE_DS *ds; + CHISE_CCS ccs_daikanwa; + CHISE_Feature ft_ideographic_structure; + CHISE_Feature ft_ascii; + int modemask = 0755; /* rwxr-xr-x */ + DBTYPE real_subtype = DB_HASH; int status; CHISE_Char_ID char_id; CHISE_Value value; - + unsigned char buf[1024]; + /* open a data-source */ - status = chise_open_data_source (&ds, CHISE_DS_Berkeley_DB, db_dir); - if (status) + ds = chise_open_data_source (CHISE_DS_Berkeley_DB, db_dir, + real_subtype, modemask); + if (ds == NULL) { - chise_close_data_source (&ds); + printf ("Can't open data source\n"); return -1; } @@ -28,56 +50,33 @@ main (int argc, char* argv[]) * get a character corresponding with Daikanwa number 364 */ - modemask = 0755; /* rwxr-xr-x */ - real_subtype = DB_HASH; - accessmask = DB_RDONLY; - /* setup a decoding-table */ - status = chise_open_decoding_table (&dt_daikanwa, &ds, - "ideograph-daikanwa", - real_subtype, - accessmask, modemask); - if (status) + ccs_daikanwa + = chise_ds_get_ccs (ds, "=daikanwa"); + if (ccs_daikanwa == NULL) { - chise_close_decoding_table (dt_daikanwa); - chise_close_data_source (&ds); + 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); + char_id = chise_ccs_decode (ccs_daikanwa, 364); - /* close the decoding-table */ - chise_close_decoding_table (dt_daikanwa); - - /* - * get a ideographic-structure feature of the character - */ - - /* setup a feature-table */ - status = chise_open_feature_table (&ft_ideographic_structure, &ds, - "ideographic-structure", - real_subtype, accessmask, modemask); - if (status) - { - chise_close_feature_table (ft_ideographic_structure); - chise_close_data_source (&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"); + 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); - - /* close the feature-table */ - chise_close_feature_table (ft_ideographic_structure); + printf ("#x%X\n", char_id); + ft_ascii = chise_ds_get_feature (ds, "ascii"); + 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_close_data_source (&ds); + chise_ds_close (ds); }