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