New file.
[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 int
43 chise_ds_foreach_char_feature_name (CHISE_DS *ds,
44                                     int (*func) (CHISE_DS *ds,
45                                                  unsigned char *name));
46
47
48 typedef int CHISE_Char_ID;
49
50
51 typedef DBT CHISE_Value;
52
53 static inline int
54 chise_value_size (const CHISE_Value *s)
55 {
56   return s->size;
57 }
58
59 static inline char *
60 chise_value_data (const CHISE_Value *s)
61 {
62   return s->data;
63 }
64
65 static inline char *
66 chise_value_to_c_string (const CHISE_Value *s)
67 {
68   return s->data;
69 }
70
71
72 typedef struct CHISE_Feature_Table CHISE_Feature_Table;
73 typedef CHISE_Feature_Table* CHISE_Feature;
74
75 CHISE_Feature
76 chise_ds_get_feature (CHISE_DS *ds, const unsigned char *name);
77
78 static inline int
79 chise_ds_load_char_feature_value (CHISE_DS *ds,
80                                   CHISE_Char_ID cid,
81                                   const unsigned char *name,
82                                   CHISE_Value *valdatum);
83
84 int chise_feature_setup_db (CHISE_Feature feature, int writable);
85
86 int chise_feature_sync (CHISE_Feature feature);
87
88 int chise_char_set_feature_value (CHISE_Char_ID cid,
89                                   CHISE_Feature feature,
90                                   unsigned char *value);
91
92 int chise_char_load_feature_value (CHISE_Char_ID cid,
93                                    CHISE_Feature feature,
94                                    CHISE_Value *valdatum);
95
96 static inline int
97 chise_ds_load_char_feature_value (CHISE_DS *ds,
98                                   CHISE_Char_ID cid,
99                                   const unsigned char *name,
100                                   CHISE_Value *valdatum)
101 {
102   return
103     chise_char_load_feature_value (cid, chise_ds_get_feature (ds, name),
104                                    valdatum);
105 }
106
107 unsigned char*
108 chise_char_gets_feature_value (CHISE_Char_ID cid,
109                                CHISE_Feature feature,
110                                unsigned char *dst, size_t size);
111
112 int
113 chise_feature_foreach_char_with_value (CHISE_Feature feature,
114                                        int (*func) (CHISE_Char_ID cid,
115                                                     CHISE_Feature feature,
116                                                     CHISE_Value *valdatum));
117
118 #if 0
119 int
120 chise_feature_foreach_char_with_str (CHISE_Feature feature,
121                                      int (*func) (CHISE_Char_ID cid,
122                                                   CHISE_Feature feature,
123                                                   unsigned char *str));
124 #endif
125
126
127 typedef struct CHISE_CCS_Table CHISE_CCS_Table;
128 typedef CHISE_CCS_Table* CHISE_CCS;
129
130 CHISE_CCS
131 chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *name);
132
133 static inline CHISE_Char_ID
134 chise_ds_decode_char (CHISE_DS *ds,
135                       const unsigned char *ccs, int code_point);
136
137 int chise_ccs_setup_db (CHISE_CCS ccs, int writable);
138
139 int chise_ccs_sync (CHISE_CCS ccs);
140
141 int chise_ccs_set_decoded_char (CHISE_CCS ccs,
142                                 int code_point, CHISE_Char_ID cid);
143
144 CHISE_Char_ID chise_ccs_decode (CHISE_CCS ccs, int code_point);
145
146 static inline CHISE_Char_ID
147 chise_ds_decode_char (CHISE_DS *ds,
148                       const unsigned char *name, int code_point)
149 {
150   return
151     chise_ccs_decode (chise_ds_get_ccs (ds, name), code_point);
152 }
153
154 #endif /* !_CHISE_H */