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_dir[] = CHISE_DB_DIR;
31 const unsigned char chise_system_db_dir[] = CHISE_SI_DB_DIR;
34 #define xzero(lvalue) ((void) memset (&(lvalue), '\0', sizeof (lvalue)))
38 chise_value_size (const CHISE_Value* s)
44 chise_value_data (const CHISE_Value* s)
50 chise_value_to_c_string (const CHISE_Value* s)
57 chise_char_id_parse_c_string (unsigned char *str, size_t len);
60 chise_format_char_id (CHISE_Char_ID cid, unsigned char *dest, size_t len);
64 CHISE_DS_open (CHISE_DS_Type type, const unsigned char* location,
65 int subtype, int modemask)
67 CONCORD_DS ds = concord_open_ds (type, location, subtype, modemask);
72 return concord_ds_get_genre (ds, "character");
76 CHISE_DS_close (CHISE_DS* ds)
78 return CONCORD_DS_close (concord_genre_get_data_source (ds));
82 chise_ds_location (CHISE_DS* ds)
84 return concord_ds_location (concord_genre_get_data_source (ds));
88 chise_ds_get_feature (CHISE_DS* ds, const unsigned char* name)
90 return concord_genre_get_feature (ds, name);
94 chise_ds_get_ccs (CHISE_DS* ds, const unsigned char* name)
96 return concord_genre_get_index (ds, name);
100 chise_ds_get_property (CHISE_DS* ds, const unsigned char* name)
103 = concord_ds_get_genre (concord_genre_get_data_source (ds),
109 return concord_genre_get_feature (genre, name);
113 chise_ds_foreach_char_feature_name (CHISE_DS* ds,
114 int (*func) (CHISE_DS* ds,
115 unsigned char* name))
117 return concord_genre_foreach_feature_name (ds, func);
121 chise_feature_setup_db (CHISE_Feature feature, int writable)
123 return concord_feature_setup_db (feature, writable);
127 chise_feature_sync (CHISE_Feature feature)
129 return concord_feature_sync (feature);
133 chise_char_set_feature_value (CHISE_Char_ID cid,
134 CHISE_Feature feature,
135 unsigned char* value)
137 unsigned char key_buf[8];
139 chise_format_char_id (cid, key_buf, 8);
140 return concord_stroid_set_feature_str (key_buf, feature, value);
144 chise_char_load_feature_value (CHISE_Char_ID cid,
145 CHISE_Feature feature,
146 CHISE_Value* valdatum)
148 unsigned char key_buf[8];
150 chise_format_char_id (cid, key_buf, 8);
151 return concord_stroid_get_feature_string (key_buf, feature, valdatum);
155 chise_char_gets_feature_value (CHISE_Char_ID cid,
156 CHISE_Feature feature,
157 unsigned char* dst, size_t size)
159 unsigned char key_buf[8];
161 chise_format_char_id (cid, key_buf, 8);
162 return concord_stroid_gets_feature (key_buf, feature, dst, size);
166 (*chise_feature_for_a_char_with_value_func) (CHISE_Char_ID cid,
167 CHISE_Feature feature,
168 CHISE_Value* valdatum);
171 chise_feature_foreach_char_with_value_wrapper (CONCORD_String object_id,
172 CONCORD_Feature feature,
173 CONCORD_String value);
175 chise_feature_foreach_char_with_value_wrapper (CONCORD_String object_id,
176 CONCORD_Feature feature,
177 CONCORD_String value)
179 unsigned char* cid_str = CONCORD_String_data (object_id);
180 int cid_len = strnlen (cid_str, CONCORD_String_size (object_id));
181 CHISE_Char_ID cid = chise_char_id_parse_c_string (cid_str, cid_len);
183 return chise_feature_for_a_char_with_value_func (cid, feature, value);
187 chise_feature_foreach_char_with_value (CHISE_Feature feature,
188 int (*func) (CHISE_Char_ID cid,
189 CHISE_Feature feature,
190 CHISE_Value* valdatum))
192 chise_feature_for_a_char_with_value_func = func;
194 concord_feature_foreach_object_string
195 (feature, &chise_feature_foreach_char_with_value_wrapper);
200 chise_ccs_setup_db (CHISE_CCS ccs, int writable)
202 return concord_index_setup_db (ccs, writable);
206 chise_ccs_sync (CHISE_CCS ccs)
208 return concord_index_sync (ccs);
212 chise_ccs_decode (CHISE_CCS ccs, int code_point)
215 CONCORD_String_Tank value;
218 sprintf(key_buf, "%d", code_point);
219 status = concord_index_strid_get_object_string (ccs, key_buf, &value);
223 = (unsigned char *)CONCORD_String_data (&value);
224 int len = strnlen (str, CONCORD_String_size (&value));
226 return chise_char_id_parse_c_string (str, len);
232 chise_ccs_set_decoded_char (CHISE_CCS ccs,
233 int code_point, CHISE_Char_ID cid)
235 char key_buf[16], val_buf[8];
237 sprintf(key_buf, "%d", code_point);
238 chise_format_char_id (cid, val_buf, 8);
239 return concord_index_strid_set_object_str (ccs, key_buf, val_buf);
244 chise_property_setup_db (CHISE_Property property, int writable)
246 return concord_feature_setup_db (property, writable);
250 chise_property_sync (CHISE_Property property)
252 return concord_feature_sync (property);
256 chise_feature_set_property_value (CHISE_Feature feature,
257 CHISE_Property property,
258 unsigned char* value)
261 concord_stroid_set_feature_str (concord_feature_get_name (feature),
266 chise_feature_load_property_value (CHISE_Feature feature,
267 CHISE_Property property,
268 CHISE_Value* valdatum)
271 concord_stroid_get_feature_string (concord_feature_get_name (feature),
276 chise_feature_gets_property_value (CHISE_Feature feature,
277 CHISE_Property property,
278 unsigned char* buf, size_t size)
281 concord_stroid_gets_feature (concord_feature_get_name (feature),
282 property, buf, size);
287 chise_char_id_parse_c_string (unsigned char *str, size_t len)
291 if ( (len >= 2) && (str[i++] == '?') )
293 unsigned char c = str[i++];
310 return c & (0x80 | 0x1F);
344 if (counter + 2 <= len)
348 for (j = 0; j < counter; j++)
349 cid = (cid << 6) | (str[j + i] & 0x3F);
357 chise_format_char_id (CHISE_Char_ID cid, unsigned char *dest, size_t len)
369 else if (cid == '\n')
376 else if (cid == '\r')
383 else if (cid == 0x1C)
392 else if (cid <= 0x1F)
396 dest[i++] = '@' + cid;
400 else if ( (cid == ' ') || (cid == '"') ||
401 (cid == '#') || (cid == '\'') ||
402 (cid == '(') || (cid == ')') ||
403 (cid == ',') || (cid == '.') ||
404 (cid == ';') || (cid == '?') ||
405 (cid == '[') || (cid == '\\') ||
406 (cid == ']') || (cid == '`') )
413 else if (cid <= 0x7E)
419 else if (cid == 0x7F)
427 else if (cid <= 0x9F)
431 dest[i++] = ((cid + '@') >> 6) | 0xC0;
432 dest[i++] = ((cid + '@') & 0x3F) | 0x80;
436 else if (cid <= 0x7FF)
438 dest[i++] = (cid >> 6) | 0xC0;
439 dest[i++] = (cid & 0x3F) | 0x80;
443 else if (cid <= 0xFFFF)
445 dest[i++] = (cid >> 12) | 0xE0;
446 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
447 dest[i++]= (cid & 0x3F) | 0x80;
451 else if (cid <= 0x1FFFFF)
453 dest[i++]= (cid >> 18) | 0xF0;
454 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
455 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
456 dest[i++]= (cid & 0x3F) | 0x80;
460 else if (cid <= 0x3FFFFFF)
462 dest[i++]= (cid >> 24) | 0xF8;
463 dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
464 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
465 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
466 dest[i++]= (cid & 0x3F) | 0x80;
472 dest[i++]= (cid >> 30) | 0xFC;
473 dest[i++]= ((cid >> 24) & 0x3F) | 0x80;
474 dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
475 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
476 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
477 dest[i++]= (cid & 0x3F) | 0x80;