update.
[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_format_version[];
32 extern const unsigned char chise_db_dir[];
33 extern const unsigned char chise_system_db_dir[];
34
35 typedef CONCORD_Backend_Type CHISE_DS_Type;
36 #define CHISE_DS_Berkeley_DB CONCORD_Backend_Berkeley_DB
37
38 typedef CONCORD_Genre_Table CHISE_DS;
39
40 CHISE_DS*
41 CHISE_DS_open (CHISE_DS_Type type, const unsigned char* location,
42                int subtype, int modemask);
43
44 int CHISE_DS_close (CHISE_DS* ds);
45
46 unsigned char* chise_ds_location (CHISE_DS* ds);
47
48 int
49 chise_ds_foreach_char_feature_name (CHISE_DS* ds,
50                                     int (*func) (CHISE_DS* ds,
51                                                  unsigned char* name));
52
53
54 typedef int CHISE_Char_ID;
55
56
57 typedef CONCORD_String_Tank CHISE_Value;
58 int chise_value_size (const CHISE_Value* s);
59 unsigned char* chise_value_data (const CHISE_Value* s);
60 unsigned char* chise_value_to_c_string (const CHISE_Value* s);
61
62
63 typedef CONCORD_Feature CHISE_Feature;
64
65 CHISE_Feature
66 chise_ds_get_feature (CHISE_DS* ds, const unsigned char* name);
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 int chise_feature_setup_db (CHISE_Feature feature, int writable);
75
76 int chise_feature_sync (CHISE_Feature feature);
77
78 int chise_char_set_feature_value (CHISE_Char_ID cid,
79                                   CHISE_Feature feature,
80                                   unsigned char* value);
81
82 int chise_char_load_feature_value (CHISE_Char_ID cid,
83                                    CHISE_Feature feature,
84                                    CHISE_Value* valdatum);
85
86 static inline int
87 chise_ds_load_char_feature_value (CHISE_DS* ds,
88                                   CHISE_Char_ID cid,
89                                   const unsigned char* name,
90                                   CHISE_Value* valdatum)
91 {
92   return
93     chise_char_load_feature_value (cid, chise_ds_get_feature (ds, name),
94                                    valdatum);
95 }
96
97 unsigned char*
98 chise_char_gets_feature_value (CHISE_Char_ID cid,
99                                CHISE_Feature feature,
100                                unsigned char* dst, size_t size);
101
102 int
103 chise_feature_foreach_char_with_value (CHISE_Feature feature,
104                                        int (*func) (CHISE_Char_ID cid,
105                                                     CHISE_Feature feature,
106                                                     CHISE_Value* valdatum));
107
108
109 typedef CONCORD_INDEX CHISE_CCS;
110
111 CHISE_CCS chise_ds_get_ccs (CHISE_DS* ds, const unsigned char* name);
112
113 static inline CHISE_Char_ID
114 chise_ds_decode_char (CHISE_DS* ds,
115                       const unsigned char* ccs, int code_point);
116
117 int chise_ccs_setup_db (CHISE_CCS ccs, int writable);
118
119 int chise_ccs_sync (CHISE_CCS ccs);
120
121 int chise_ccs_set_decoded_char (CHISE_CCS ccs,
122                                 int code_point, CHISE_Char_ID cid);
123
124 CHISE_Char_ID chise_ccs_decode (CHISE_CCS ccs, int code_point);
125
126 static inline CHISE_Char_ID
127 chise_ds_decode_char (CHISE_DS* ds,
128                       const unsigned char* name, int code_point)
129 {
130   return
131     chise_ccs_decode (chise_ds_get_ccs (ds, name), code_point);
132 }
133
134
135 typedef CONCORD_Feature CHISE_Property;
136
137 CHISE_Property
138 chise_ds_get_property (CHISE_DS* ds, const unsigned char* name);
139
140 int chise_property_setup_db (CHISE_Property property, int writable);
141
142 int chise_property_sync (CHISE_Property property);
143
144 int chise_feature_set_property_value (CHISE_Feature feature,
145                                       CHISE_Property property,
146                                       unsigned char* value);
147
148 int chise_feature_load_property_value (CHISE_Feature feature,
149                                        CHISE_Property property,
150                                        CHISE_Value* valdatum);
151
152 unsigned char*
153 chise_feature_gets_property_value (CHISE_Feature feature,
154                                    CHISE_Property property,
155                                    unsigned char* buf, size_t size);
156
157 #if 0
158 {
159 #endif
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif /* !_CHISE_H */