(chise_ft_iterate): New function.
[chise/libchise.git] / sample.c
1 #include <chise.h>
2
3 char db_dir[] = "/usr/local/lib/chise/char-db";
4
5 int
6 main (int argc, char* argv[])
7 {
8   CHISE_DS ds;
9   CHISE_Decoding_Table *dt_daikanwa;
10   CHISE_Feature_Table *ft_ideographic_structure;
11   int modemask;
12   int accessmask = 0;
13   DBTYPE real_subtype;
14   int status;
15   CHISE_Char_ID char_id;
16   CHISE_Value value;
17   
18   /* open a data-source */
19   status = chise_open_data_source (&ds, CHISE_DS_Berkeley_DB, db_dir);
20   if (status)
21     {
22       chise_close_data_source (&ds);
23       return -1;
24     }
25
26
27   /*
28    * get a character corresponding with Daikanwa number 364
29    */
30
31   modemask = 0755;              /* rwxr-xr-x */
32   real_subtype = DB_HASH;
33   accessmask = DB_RDONLY;
34
35   /* setup a decoding-table */
36   status = chise_open_decoding_table (&dt_daikanwa, &ds,
37                                       "=daikanwa",
38                                       real_subtype,
39                                       accessmask, modemask);
40   if (status)
41     {
42       chise_close_decoding_table (dt_daikanwa);
43       chise_close_data_source (&ds);
44       return -1;
45     }
46   
47   /* get a character from the decoding-table */
48   char_id = chise_dt_get_char (dt_daikanwa, 364);
49
50   /* close the decoding-table */
51   chise_close_decoding_table (dt_daikanwa);
52
53
54   /*
55    * get a ideographic-structure feature of the character
56    */
57   
58   /* setup a feature-table */
59   status = chise_open_feature_table (&ft_ideographic_structure, &ds,
60                                      "ideographic-structure",
61                                      real_subtype, accessmask, modemask);
62   if (status)
63     {
64       chise_close_feature_table (ft_ideographic_structure);
65       chise_close_data_source (&ds);
66       return -1;
67     }
68   
69   /* get a feature-value of the character */
70   status = chise_ft_get_value (ft_ideographic_structure, char_id, &value);
71
72   if (!status)
73     printf ("#x%X => %s\n", char_id, chise_value_to_c_string(&value));
74   else
75     printf ("#x%X (%d)\n", char_id, status);
76
77   /* close the feature-table */
78   chise_close_feature_table (ft_ideographic_structure);
79
80
81   /* close the data-source */
82   chise_close_data_source (&ds);
83 }