13251afdcdd7df197c434f17483831a1a613a53c
[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;
10   CHISE_Feature_Table *ft;
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   status = chise_open_data_source (&ds, CHISE_DS_Berkeley_DB, db_dir);
19   if (status)
20     {
21       chise_close_data_source (&ds);
22       return -1;
23     }
24
25   modemask = 0755;              /* rwxr-xr-x */
26
27   real_subtype = DB_HASH;
28   accessmask = DB_RDONLY;
29
30   status = chise_open_decoding_table (&dt, &ds,
31                                       "ideograph-daikanwa",
32                                       real_subtype, accessmask, modemask);
33   if (status)
34     {
35       chise_close_decoding_table (dt);
36       chise_close_data_source (&ds);
37       return -1;
38     }
39
40   char_id = chise_dt_get_char (dt, 20);
41   chise_close_decoding_table (dt);
42       
43   status = chise_open_feature_table (&ft, &ds,
44                                      "ideographic-structure",
45                                      real_subtype, accessmask, modemask);
46   if (status)
47     {
48       chise_close_feature_table (ft);
49       chise_close_data_source (&ds);
50       return -1;
51     }
52
53   status = chise_ft_get_value (ft, char_id, &value);
54   if (!status)
55     printf ("#x%X => %s\n", char_id, chise_value_to_c_string(&value));
56   else
57     printf ("#x%X (%d)\n", char_id, status);
58
59   chise_close_feature_table (ft);
60   chise_close_data_source (&ds);
61 }