New files.
[chise/libchise.git] / sample.c
1 #include "chise.h"
2
3 #define xzero(lvalue) ((void) memset (&(lvalue), '\0', sizeof (lvalue)))
4
5 char db_dir[] = "/usr/local/lib/xemacs-21.4.10/i586-pc-linux/char-db";
6
7 int
8 main (int argc, char* argv[])
9 {
10   CHISE_DS ds;
11   CHISE_Decoding_Table *dt;
12   CHISE_Feature_Table *ft;
13   int modemask;
14   int accessmask = 0;
15   DBTYPE real_subtype;
16   int status;
17   CHISE_Char_ID char_id;
18   CHISE_Value value;
19   
20   status = chise_open_data_source (&ds, CHISE_DS_Berkeley_DB, db_dir);
21   if (status)
22     {
23       chise_close_data_source (&ds);
24       return -1;
25     }
26
27   modemask = 0755;              /* rwxr-xr-x */
28
29   real_subtype = DB_HASH;
30   accessmask = DB_RDONLY;
31
32   status = chise_open_decoding_table (&dt, &ds,
33                                       "ideograph-daikanwa",
34                                       real_subtype, accessmask, modemask);
35   if (status)
36     {
37       chise_close_decoding_table (dt);
38       chise_close_data_source (&ds);
39       return -1;
40     }
41
42   char_id = chise_dt_get_char (dt, 20);
43   chise_close_decoding_table (dt);
44       
45   status = chise_open_feature_table (&ft, &ds,
46                                      "ideographic-structure",
47                                      real_subtype, accessmask, modemask);
48   if (status)
49     {
50       chise_close_feature_table (ft);
51       chise_close_data_source (&ds);
52       return -1;
53     }
54
55   status = chise_ft_get_value (ft, char_id, &value);
56   if (!status)
57     printf ("#x%X => %s\n", char_id, chise_value_to_c_string(&value));
58   else
59     printf ("#x%X (%d)\n", char_id, status);
60
61   chise_close_feature_table (ft);
62   chise_close_data_source (&ds);
63 }