6b903d1f977020f4096276eb97596f5fb6c3152b
[chise/libchise.git] / chise.h
1 /* Copyright (C) 2003 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 #include <db.h>
23 #include <errno.h>
24
25 extern const unsigned char chise_db_dir[];
26 extern const unsigned char chise_system_db_dir[];
27
28 typedef enum CHISE_DS_Type
29 {
30   CHISE_DS_NONE,
31   CHISE_DS_Berkeley_DB
32 } CHISE_DS_Type;
33
34 typedef struct CHISE_DS CHISE_DS;
35
36 CHISE_DS*
37 CHISE_DS_open (CHISE_DS_Type type, const unsigned char *location,
38                int subtype, int modemask);
39
40 int CHISE_DS_close (CHISE_DS *ds);
41
42 unsigned char* chise_ds_location (CHISE_DS *ds);
43
44 int
45 chise_ds_foreach_char_feature_name (CHISE_DS *ds,
46                                     int (*func) (CHISE_DS *ds,
47                                                  unsigned char *name));
48
49
50 typedef int CHISE_Char_ID;
51
52
53 typedef DBT CHISE_Value;
54
55 static inline int
56 chise_value_size (const CHISE_Value *s)
57 {
58   return s->size;
59 }
60
61 static inline char *
62 chise_value_data (const CHISE_Value *s)
63 {
64   return s->data;
65 }
66
67 static inline char *
68 chise_value_to_c_string (const CHISE_Value *s)
69 {
70   return s->data;
71 }
72
73
74 typedef struct CHISE_Feature_Table CHISE_Feature_Table;
75 typedef CHISE_Feature_Table* CHISE_Feature;
76
77 CHISE_Feature
78 chise_ds_get_feature (CHISE_DS *ds, const unsigned char *name);
79
80 static inline int
81 chise_ds_load_char_feature_value (CHISE_DS *ds,
82                                   CHISE_Char_ID cid,
83                                   const unsigned char *name,
84                                   CHISE_Value *valdatum);
85
86 int chise_feature_setup_db (CHISE_Feature feature, int writable);
87
88 int chise_feature_sync (CHISE_Feature feature);
89
90 int chise_char_set_feature_value (CHISE_Char_ID cid,
91                                   CHISE_Feature feature,
92                                   unsigned char *value);
93
94 int chise_char_load_feature_value (CHISE_Char_ID cid,
95                                    CHISE_Feature feature,
96                                    CHISE_Value *valdatum);
97
98 static inline int
99 chise_ds_load_char_feature_value (CHISE_DS *ds,
100                                   CHISE_Char_ID cid,
101                                   const unsigned char *name,
102                                   CHISE_Value *valdatum)
103 {
104   return
105     chise_char_load_feature_value (cid, chise_ds_get_feature (ds, name),
106                                    valdatum);
107 }
108
109 unsigned char*
110 chise_char_gets_feature_value (CHISE_Char_ID cid,
111                                CHISE_Feature feature,
112                                unsigned char *dst, size_t size);
113
114 int
115 chise_feature_foreach_char_with_value (CHISE_Feature feature,
116                                        int (*func) (CHISE_Char_ID cid,
117                                                     CHISE_Feature feature,
118                                                     CHISE_Value *valdatum));
119
120 #if 0
121 int
122 chise_feature_foreach_char_with_str (CHISE_Feature feature,
123                                      int (*func) (CHISE_Char_ID cid,
124                                                   CHISE_Feature feature,
125                                                   unsigned char *str));
126 #endif
127
128
129 typedef struct CHISE_CCS_Table CHISE_CCS_Table;
130 typedef CHISE_CCS_Table* CHISE_CCS;
131
132 CHISE_CCS
133 chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *name);
134
135 static inline CHISE_Char_ID
136 chise_ds_decode_char (CHISE_DS *ds,
137                       const unsigned char *ccs, int code_point);
138
139 int chise_ccs_setup_db (CHISE_CCS ccs, int writable);
140
141 int chise_ccs_sync (CHISE_CCS ccs);
142
143 int chise_ccs_set_decoded_char (CHISE_CCS ccs,
144                                 int code_point, CHISE_Char_ID cid);
145
146 CHISE_Char_ID chise_ccs_decode (CHISE_CCS ccs, int code_point);
147
148 static inline CHISE_Char_ID
149 chise_ds_decode_char (CHISE_DS *ds,
150                       const unsigned char *name, int code_point)
151 {
152   return
153     chise_ccs_decode (chise_ds_get_ccs (ds, name), code_point);
154 }
155
156
157 typedef struct CHISE_Property_Table CHISE_Property_Table;
158 typedef CHISE_Property_Table* CHISE_Property;
159
160 CHISE_Property_Table*
161 chise_ds_get_property (CHISE_DS *ds, const unsigned char *property);
162
163 int chise_property_setup_db (CHISE_Property property, int writable);
164
165 int chise_property_sync (CHISE_Property property);
166
167 int chise_feature_set_property_value (CHISE_Feature feature,
168                                       CHISE_Property property,
169                                       unsigned char *value);
170
171 int chise_feature_load_property_value (CHISE_Feature feature,
172                                        CHISE_Property_Table *table,
173                                        CHISE_Value *valdatum);
174
175 unsigned char*
176 chise_feature_gets_property_value (CHISE_Feature feature,
177                                    CHISE_Property_Table *table,
178                                    unsigned char *buf, size_t size);
179
180 #endif /* !_CHISE_H */