(chise_feature_sync): New prototype.
[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_sync (CHISE_Feature feature);
59
60 int chise_char_set_feature_value (CHISE_Char_ID cid,
61                                   CHISE_Feature feature,
62                                   unsigned char *value);
63
64 int chise_char_load_feature_value (CHISE_Char_ID cid,
65                                    CHISE_Feature feature,
66                                    CHISE_Value *valdatum);
67
68 static inline int
69 chise_ds_load_char_feature_value (CHISE_DS *ds,
70                                   CHISE_Char_ID cid,
71                                   const unsigned char *name,
72                                   CHISE_Value *valdatum)
73 {
74   return
75     chise_char_load_feature_value (cid, chise_ds_get_feature (ds, name),
76                                    valdatum);
77 }
78
79 unsigned char*
80 chise_char_gets_feature_value (CHISE_Char_ID cid,
81                                CHISE_Feature feature,
82                                unsigned char *dst, size_t size);
83
84 int
85 chise_char_feature_value_iterate (CHISE_Feature feature,
86                                   int (*func) (CHISE_Char_ID cid,
87                                                CHISE_Feature feature,
88                                                CHISE_Value *valdatum));
89
90 #if 0
91 int
92 chise_char_feature_str_iterate (CHISE_Feature feature,
93                                 int (*func) (CHISE_Char_ID cid,
94                                              CHISE_Feature feature,
95                                              unsigned char *str));
96 #endif
97
98
99 typedef struct CHISE_CCS_Table CHISE_CCS_Table;
100 typedef CHISE_CCS_Table* CHISE_CCS;
101
102 CHISE_CCS
103 chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *name);
104
105 static inline CHISE_Char_ID
106 chise_ds_decode_char (CHISE_DS *ds,
107                       const unsigned char *ccs, int code_point);
108
109 int chise_ccs_set_decoded_char (CHISE_CCS ccs,
110                                 int code_point, CHISE_Char_ID cid);
111
112 int chise_ccs_sync (CHISE_CCS ccs);
113
114 CHISE_Char_ID chise_ccs_decode (CHISE_CCS ccs, int code_point);
115
116 static inline CHISE_Char_ID
117 chise_ds_decode_char (CHISE_DS *ds,
118                       const unsigned char *name, int code_point)
119 {
120   return
121     chise_ccs_decode (chise_ds_get_ccs (ds, name), code_point);
122 }
123
124 #endif /* !_CHISE_H */