1 /* Copyright (C) 2003,2004,2005 MORIOKA Tomohiko
2 This file is part of the CHISE Library.
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.
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.
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
20 #include <sys/types.h>
30 const unsigned char chise_db_format_version[] = CHISE_DB_FORMAT_VERSION;
31 const unsigned char chise_db_dir[] = CHISE_DB_DIR;
32 const unsigned char chise_system_db_dir[] = CHISE_SI_DB_DIR;
35 #define xzero(lvalue) ((void) memset (&(lvalue), '\0', sizeof (lvalue)))
39 chise_value_size (const CHISE_Value* s)
45 chise_value_data (const CHISE_Value* s)
51 chise_value_to_c_string (const CHISE_Value* s)
58 chise_char_id_parse_c_string (unsigned char *str, size_t len);
61 chise_format_char_id (CHISE_Char_ID cid, unsigned char *dest, size_t len);
65 CHISE_DS_open (CHISE_DS_Type type, const unsigned char* location,
66 int subtype, int modemask)
68 CONCORD_DS ds = concord_open_ds (type, location, subtype, modemask);
73 return concord_ds_get_genre (ds, "character");
77 CHISE_DS_close (CHISE_DS* ds)
79 return concord_close_ds (concord_genre_get_data_source (ds));
83 chise_ds_location (CHISE_DS* ds)
85 return concord_ds_location (concord_genre_get_data_source (ds));
89 chise_ds_get_feature (CHISE_DS* ds, const unsigned char* name)
91 return concord_genre_get_feature (ds, name);
95 chise_ds_get_ccs (CHISE_DS* ds, const unsigned char* name)
97 return concord_genre_get_index (ds, name);
101 chise_ds_get_property (CHISE_DS* ds, const unsigned char* name)
104 = concord_ds_get_genre (concord_genre_get_data_source (ds),
110 return concord_genre_get_feature (genre, name);
114 chise_ds_foreach_char_feature_name (CHISE_DS* ds,
115 int (*func) (CHISE_DS* ds,
116 unsigned char* name))
118 return concord_genre_foreach_feature_name (ds, func);
122 chise_feature_setup_db (CHISE_Feature feature, int writable)
124 return concord_feature_setup_db (feature, writable);
128 chise_feature_sync (CHISE_Feature feature)
130 return concord_feature_sync (feature);
134 chise_char_set_feature_value (CHISE_Char_ID cid,
135 CHISE_Feature feature,
136 unsigned char* value)
138 unsigned char key_buf[8];
140 chise_format_char_id (cid, key_buf, 8);
141 return concord_obj_put_feature_value_str (key_buf, feature, value);
145 chise_char_load_feature_value (CHISE_Char_ID cid,
146 CHISE_Feature feature,
147 CHISE_Value* valdatum)
149 unsigned char key_buf[8];
151 chise_format_char_id (cid, key_buf, 8);
152 return concord_obj_get_feature_value_string (key_buf, feature, valdatum);
156 chise_char_gets_feature_value (CHISE_Char_ID cid,
157 CHISE_Feature feature,
158 unsigned char* dst, size_t size)
160 unsigned char key_buf[8];
162 chise_format_char_id (cid, key_buf, 8);
163 return concord_obj_gets_feature_value (key_buf, feature, dst, size);
167 (*chise_feature_for_a_char_with_value_func) (CHISE_Char_ID cid,
168 CHISE_Feature feature,
169 CHISE_Value* valdatum);
172 chise_feature_foreach_char_with_value_wrapper (CONCORD_String object_id,
173 CONCORD_Feature feature,
174 CONCORD_String value);
176 chise_feature_foreach_char_with_value_wrapper (CONCORD_String object_id,
177 CONCORD_Feature feature,
178 CONCORD_String value)
180 unsigned char* cid_str = CONCORD_String_data (object_id);
181 int cid_len = strnlen (cid_str, CONCORD_String_size (object_id));
182 CHISE_Char_ID cid = chise_char_id_parse_c_string (cid_str, cid_len);
184 return chise_feature_for_a_char_with_value_func (cid, feature, value);
188 chise_feature_foreach_char_with_value (CHISE_Feature feature,
189 int (*func) (CHISE_Char_ID cid,
190 CHISE_Feature feature,
191 CHISE_Value* valdatum))
193 chise_feature_for_a_char_with_value_func = func;
195 concord_feature_foreach_obj_string
196 (feature, &chise_feature_foreach_char_with_value_wrapper);
201 chise_ccs_setup_db (CHISE_CCS ccs, int writable)
203 return concord_index_setup_db (ccs, writable);
207 chise_ccs_sync (CHISE_CCS ccs)
209 return concord_index_sync (ccs);
213 chise_ccs_decode (CHISE_CCS ccs, int code_point)
216 CONCORD_String_Tank value;
219 sprintf(key_buf, "%d", code_point);
220 status = concord_index_strid_get_obj_string (ccs, key_buf, &value);
224 = (unsigned char *)CONCORD_String_data (&value);
225 int len = strnlen (str, CONCORD_String_size (&value));
227 return chise_char_id_parse_c_string (str, len);
233 chise_ccs_set_decoded_char (CHISE_CCS ccs,
234 int code_point, CHISE_Char_ID cid)
236 char key_buf[16], val_buf[8];
238 sprintf(key_buf, "%d", code_point);
239 chise_format_char_id (cid, val_buf, 8);
240 return concord_index_strid_put_obj (ccs, key_buf, val_buf);
245 chise_property_setup_db (CHISE_Property property, int writable)
247 return concord_feature_setup_db (property, writable);
251 chise_property_sync (CHISE_Property property)
253 return concord_feature_sync (property);
257 chise_feature_set_property_value (CHISE_Feature feature,
258 CHISE_Property property,
259 unsigned char* value)
262 concord_obj_put_feature_value_str
263 (concord_feature_get_name (feature), property, value);
267 chise_feature_load_property_value (CHISE_Feature feature,
268 CHISE_Property property,
269 CHISE_Value* valdatum)
272 concord_obj_get_feature_value_string
273 (concord_feature_get_name (feature), property, valdatum);
277 chise_feature_gets_property_value (CHISE_Feature feature,
278 CHISE_Property property,
279 unsigned char* buf, size_t size)
282 concord_obj_gets_feature_value (concord_feature_get_name (feature),
283 property, buf, size);
288 chise_char_id_parse_c_string (unsigned char *str, size_t len)
292 if ( (len >= 2) && (str[i++] == '?') )
294 unsigned char c = str[i++];
311 return c & (0x80 | 0x1F);
345 if (counter + 2 <= len)
349 for (j = 0; j < counter; j++)
350 cid = (cid << 6) | (str[j + i] & 0x3F);
358 chise_format_char_id (CHISE_Char_ID cid, unsigned char *dest, size_t len)
370 else if (cid == '\n')
377 else if (cid == '\r')
384 else if (cid == 0x1C)
393 else if (cid <= 0x1F)
397 dest[i++] = '@' + cid;
401 else if ( (cid == ' ') || (cid == '"') ||
402 (cid == '#') || (cid == '\'') ||
403 (cid == '(') || (cid == ')') ||
404 (cid == ',') || (cid == '.') ||
405 (cid == ';') || (cid == '?') ||
406 (cid == '[') || (cid == '\\') ||
407 (cid == ']') || (cid == '`') )
414 else if (cid <= 0x7E)
420 else if (cid == 0x7F)
428 else if (cid <= 0x9F)
432 dest[i++] = ((cid + '@') >> 6) | 0xC0;
433 dest[i++] = ((cid + '@') & 0x3F) | 0x80;
437 else if (cid <= 0x7FF)
439 dest[i++] = (cid >> 6) | 0xC0;
440 dest[i++] = (cid & 0x3F) | 0x80;
444 else if (cid <= 0xFFFF)
446 dest[i++] = (cid >> 12) | 0xE0;
447 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
448 dest[i++]= (cid & 0x3F) | 0x80;
452 else if (cid <= 0x1FFFFF)
454 dest[i++]= (cid >> 18) | 0xF0;
455 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
456 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
457 dest[i++]= (cid & 0x3F) | 0x80;
461 else if (cid <= 0x3FFFFFF)
463 dest[i++]= (cid >> 24) | 0xF8;
464 dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
465 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
466 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
467 dest[i++]= (cid & 0x3F) | 0x80;
473 dest[i++]= (cid >> 30) | 0xFC;
474 dest[i++]= ((cid >> 24) & 0x3F) | 0x80;
475 dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
476 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
477 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
478 dest[i++]= (cid & 0x3F) | 0x80;