(CFLAGS): Refer @CFLAGS@.
[chise/libchise.git] / chise.h
1 #ifndef _CHISE_H
2
3 #include <db.h>
4 #include <errno.h>
5
6 #ifndef HAVE_STRNLEN
7
8 /* original in mysql, strings/strnlen.c.
9 uint strnlen(register const char *s, register uint maxlen)
10 {
11   const char *end= (const char *)memchr(s, '\0', maxlen);
12   return end ? (uint) (end - s) : maxlen;
13 }
14 */
15
16 static inline int
17 strnlen (register const char *s, register int maxlen)
18 {
19   const char *end= (const char *)memchr(s, '\0', maxlen);
20   return end ? (int) (end - s) : maxlen;
21 }
22
23 #endif
24
25
26 typedef enum CHISE_DS_Type
27 {
28   CHISE_DS_NONE,
29   CHISE_DS_Berkeley_DB
30 } CHISE_DS_Type;
31
32 typedef struct CHISE_DS
33 {
34   CHISE_DS_Type type;
35   char *location;
36 } CHISE_DS;
37
38 int chise_open_data_source (CHISE_DS *ds, CHISE_DS_Type type,
39                             char *location);
40
41 int chise_close_data_source (CHISE_DS *ds);
42
43
44 typedef int CHISE_Char_ID;
45
46
47 typedef DBT CHISE_Value;
48
49 static inline int
50 chise_value_size (const CHISE_Value *s)
51 {
52   return s->size;
53 }
54
55 static inline char *
56 chise_value_data (const CHISE_Value *s)
57 {
58   return s->data;
59 }
60
61 static inline char *
62 chise_value_to_c_string (const CHISE_Value *s)
63 {
64   return s->data;
65 }
66
67
68 typedef DB CHISE_Attribute_Table;
69
70
71 typedef CHISE_Attribute_Table CHISE_Decoding_Table;
72
73 int chise_open_decoding_table (CHISE_Decoding_Table **db,
74                                CHISE_DS *ds, const char *ccs,
75                                DBTYPE real_subtype,
76                                u_int32_t accessmask, int modemask);
77
78 int chise_close_decoding_table (CHISE_Decoding_Table *db);
79
80 CHISE_Char_ID chise_dt_get_char (CHISE_Decoding_Table *db, int code_point);
81
82
83 typedef CHISE_Attribute_Table CHISE_Feature_Table;
84
85 int chise_open_feature_table (CHISE_Feature_Table **db,
86                               CHISE_DS *ds, const char *feature,
87                               DBTYPE real_subtype,
88                               u_int32_t accessmask, int modemask);
89
90 int chise_close_feature_table (CHISE_Feature_Table *db);
91
92 int chise_ft_get_value (CHISE_Feature_Table *db,
93                         CHISE_Char_ID cid, CHISE_Value *valdatum);
94
95
96
97 CHISE_Char_ID chise_decode_char (CHISE_DS *ds, char *ccs, int code_point);
98
99 int chise_get_feature (CHISE_DS *ds, CHISE_Char_ID cid,
100                        char *key, CHISE_Value *valdatum);
101
102
103 int chise_open_attribute_table (CHISE_Attribute_Table **db,
104                                 const char *db_dir,
105                                 const char *encoding, const char *feature,
106                                 DBTYPE real_subtype,
107                                 u_int32_t accessmask, int modemask);
108
109 int chise_close_attribute_table (CHISE_Attribute_Table *db);
110
111 int chise_get_attribute_table (CHISE_Attribute_Table *db,
112                                char *key, CHISE_Value *valdatum);
113
114 #endif /* !_CHISE_H */