867bf02ab6da4f1cb070c0cf6d3a7ca357567974
[chise/libchise.git] / chise.h
1 /* Copyright (C) 2003,2004,2005 MORIOKA Tomohiko
2    This file is part of the CHISE Library.
3
4    The CHISE Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The CHISE Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the CHISE Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #ifndef _CHISE_H
20 #define _CHISE_H
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 #if 0
26 }
27 #endif
28
29 #include <concord.h>
30
31 extern const unsigned char chise_db_dir[];
32 extern const unsigned char chise_system_db_dir[];
33
34 typedef CONCORD_Backend_Type CHISE_DS_Type;
35 #define CHISE_DS_Berkeley_DB CONCORD_Backend_Berkeley_DB
36
37 typedef CONCORD_Genre_Table CHISE_DS;
38
39 CHISE_DS*
40 CHISE_DS_open (CHISE_DS_Type type, const unsigned char* location,
41                int subtype, int modemask);
42
43 int CHISE_DS_close (CHISE_DS* ds);
44
45 unsigned char* chise_ds_location (CHISE_DS* ds);
46
47 int
48 chise_ds_foreach_char_feature_name (CHISE_DS* ds,
49                                     int (*func) (CHISE_DS* ds,
50                                                  unsigned char* name));
51
52
53 typedef int CHISE_Char_ID;
54
55
56 typedef CONCORD_String_Tank CHISE_Value;
57 int chise_value_size (const CHISE_Value* s);
58 unsigned char* chise_value_data (const CHISE_Value* s);
59 unsigned char* chise_value_to_c_string (const CHISE_Value* s);
60
61
62 typedef CONCORD_Feature CHISE_Feature;
63
64 CHISE_Feature
65 chise_ds_get_feature (CHISE_DS* ds, const unsigned char* name);
66
67 static inline int
68 chise_ds_load_char_feature_value (CHISE_DS* ds,
69                                   CHISE_Char_ID cid,
70                                   const unsigned char* name,
71                                   CHISE_Value* valdatum);
72
73 int chise_feature_setup_db (CHISE_Feature feature, int writable);
74
75 int chise_feature_sync (CHISE_Feature feature);
76
77 int chise_char_set_feature_value (CHISE_Char_ID cid,
78                                   CHISE_Feature feature,
79                                   unsigned char* value);
80
81 int chise_char_load_feature_value (CHISE_Char_ID cid,
82                                    CHISE_Feature feature,
83                                    CHISE_Value* valdatum);
84
85 static inline int
86 chise_ds_load_char_feature_value (CHISE_DS* ds,
87                                   CHISE_Char_ID cid,
88                                   const unsigned char* name,
89                                   CHISE_Value* valdatum)
90 {
91   return
92     chise_char_load_feature_value (cid, chise_ds_get_feature (ds, name),
93                                    valdatum);
94 }
95
96 unsigned char*
97 chise_char_gets_feature_value (CHISE_Char_ID cid,
98                                CHISE_Feature feature,
99                                unsigned char* dst, size_t size);
100
101 int
102 chise_feature_foreach_char_with_value (CHISE_Feature feature,
103                                        int (*func) (CHISE_Char_ID cid,
104                                                     CHISE_Feature feature,
105                                                     CHISE_Value* valdatum));
106
107
108 typedef CONCORD_INDEX CHISE_CCS;
109
110 CHISE_CCS chise_ds_get_ccs (CHISE_DS* ds, const unsigned char* name);
111
112 static inline CHISE_Char_ID
113 chise_ds_decode_char (CHISE_DS* ds,
114                       const unsigned char* ccs, int code_point);
115
116 int chise_ccs_setup_db (CHISE_CCS ccs, int writable);
117
118 int chise_ccs_sync (CHISE_CCS ccs);
119
120 int chise_ccs_set_decoded_char (CHISE_CCS ccs,
121                                 int code_point, CHISE_Char_ID cid);
122
123 CHISE_Char_ID chise_ccs_decode (CHISE_CCS ccs, int code_point);
124
125 static inline CHISE_Char_ID
126 chise_ds_decode_char (CHISE_DS* ds,
127                       const unsigned char* name, int code_point)
128 {
129   return
130     chise_ccs_decode (chise_ds_get_ccs (ds, name), code_point);
131 }
132
133
134 typedef CONCORD_Feature CHISE_Property;
135
136 CHISE_Property
137 chise_ds_get_property (CHISE_DS* ds, const unsigned char* name);
138
139 int chise_property_setup_db (CHISE_Property property, int writable);
140
141 int chise_property_sync (CHISE_Property property);
142
143 int chise_feature_set_property_value (CHISE_Feature feature,
144                                       CHISE_Property property,
145                                       unsigned char* value);
146
147 int chise_feature_load_property_value (CHISE_Feature feature,
148                                        CHISE_Property property,
149                                        CHISE_Value* valdatum);
150
151 unsigned char*
152 chise_feature_gets_property_value (CHISE_Feature feature,
153                                    CHISE_Property property,
154                                    unsigned char* buf, size_t size);
155
156 #if 0
157 {
158 #endif
159 #ifdef __cplusplus
160 }
161 #endif
162
163 #endif /* !_CHISE_H */