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