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