Merge b1-r0_2_0-pre10.
[chise/libchise.git] / chise.h
1 #ifndef _CHISE_H
2 #define _CHISE_H
3
4 #include <db.h>
5 #include <errno.h>
6
7 extern const unsigned char chise_db_dir[];
8 extern const unsigned char chise_system_db_dir[];
9
10 typedef enum CHISE_DS_Type
11 {
12   CHISE_DS_NONE,
13   CHISE_DS_Berkeley_DB
14 } CHISE_DS_Type;
15
16 typedef struct CHISE_DS CHISE_DS;
17
18 CHISE_DS*
19 CHISE_DS_open (CHISE_DS_Type type, const unsigned char *location,
20                int subtype, int modemask);
21
22 int CHISE_DS_close (CHISE_DS *ds);
23
24 int
25 chise_ds_foreach_char_feature_name (CHISE_DS *ds,
26                                     int (*func) (CHISE_DS *ds,
27                                                  unsigned char *name));
28
29
30 typedef int CHISE_Char_ID;
31
32
33 typedef DBT CHISE_Value;
34
35 static inline int
36 chise_value_size (const CHISE_Value *s)
37 {
38   return s->size;
39 }
40
41 static inline char *
42 chise_value_data (const CHISE_Value *s)
43 {
44   return s->data;
45 }
46
47 static inline char *
48 chise_value_to_c_string (const CHISE_Value *s)
49 {
50   return s->data;
51 }
52
53
54 typedef struct CHISE_Feature_Table CHISE_Feature_Table;
55 typedef CHISE_Feature_Table* CHISE_Feature;
56
57 CHISE_Feature
58 chise_ds_get_feature (CHISE_DS *ds, const unsigned char *name);
59
60 static inline int
61 chise_ds_load_char_feature_value (CHISE_DS *ds,
62                                   CHISE_Char_ID cid,
63                                   const unsigned char *name,
64                                   CHISE_Value *valdatum);
65
66 int chise_feature_setup_db (CHISE_Feature feature, int writable);
67
68 int chise_feature_sync (CHISE_Feature feature);
69
70 int chise_char_set_feature_value (CHISE_Char_ID cid,
71                                   CHISE_Feature feature,
72                                   unsigned char *value);
73
74 int chise_char_load_feature_value (CHISE_Char_ID cid,
75                                    CHISE_Feature feature,
76                                    CHISE_Value *valdatum);
77
78 static inline int
79 chise_ds_load_char_feature_value (CHISE_DS *ds,
80                                   CHISE_Char_ID cid,
81                                   const unsigned char *name,
82                                   CHISE_Value *valdatum)
83 {
84   return
85     chise_char_load_feature_value (cid, chise_ds_get_feature (ds, name),
86                                    valdatum);
87 }
88
89 unsigned char*
90 chise_char_gets_feature_value (CHISE_Char_ID cid,
91                                CHISE_Feature feature,
92                                unsigned char *dst, size_t size);
93
94 int
95 chise_feature_foreach_char_with_value (CHISE_Feature feature,
96                                        int (*func) (CHISE_Char_ID cid,
97                                                     CHISE_Feature feature,
98                                                     CHISE_Value *valdatum));
99
100 #if 0
101 int
102 chise_feature_foreach_char_with_str (CHISE_Feature feature,
103                                      int (*func) (CHISE_Char_ID cid,
104                                                   CHISE_Feature feature,
105                                                   unsigned char *str));
106 #endif
107
108
109 typedef struct CHISE_CCS_Table CHISE_CCS_Table;
110 typedef CHISE_CCS_Table* CHISE_CCS;
111
112 CHISE_CCS
113 chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *name);
114
115 static inline CHISE_Char_ID
116 chise_ds_decode_char (CHISE_DS *ds,
117                       const unsigned char *ccs, int code_point);
118
119 int chise_ccs_setup_db (CHISE_CCS ccs, int writable);
120
121 int chise_ccs_sync (CHISE_CCS ccs);
122
123 int chise_ccs_set_decoded_char (CHISE_CCS ccs,
124                                 int code_point, CHISE_Char_ID cid);
125
126 CHISE_Char_ID chise_ccs_decode (CHISE_CCS ccs, int code_point);
127
128 static inline CHISE_Char_ID
129 chise_ds_decode_char (CHISE_DS *ds,
130                       const unsigned char *name, int code_point)
131 {
132   return
133     chise_ccs_decode (chise_ds_get_ccs (ds, name), code_point);
134 }
135
136 #endif /* !_CHISE_H */