6 /* original in mysql, strings/strnlen.c.
7 uint strnlen(register const char *s, register uint maxlen)
9 const char *end= (const char *)memchr(s, '\0', maxlen);
10 return end ? (uint) (end - s) : maxlen;
14 strnlen (register const char *s, register int maxlen)
16 const char *end= (const char *)memchr(s, '\0', maxlen);
17 return end ? (int) (end - s) : maxlen;
23 #define xzero(lvalue) ((void) memset (&(lvalue), '\0', sizeof (lvalue)))
26 chise_char_id_parse_c_string (unsigned char *str, int len)
30 if ( (len >= 2) && (str[i++] == '?') )
32 unsigned char c = str[i++];
49 return c & (0x80 | 0x1F);
83 if (counter + 2 <= len)
87 for (j = 0; j < counter; j++)
88 cid = (cid << 6) | (str[j + i] & 0x3F);
96 chise_open_data_source (CHISE_DS *ds, CHISE_DS_Type type, char *location)
99 ds->location = location;
104 chise_close_data_source (CHISE_DS *ds)
106 ds->type = CHISE_DS_NONE;
113 chise_open_decoding_table (CHISE_Decoding_Table **db,
114 CHISE_DS *ds, const char *ccs,
116 u_int32_t accessmask, int modemask)
119 chise_open_attribute_table (db, ds->location,
120 ccs, "system-char-id",
121 real_subtype, accessmask, modemask);
125 chise_close_decoding_table (CHISE_Decoding_Table *db)
128 return chise_close_attribute_table (db);
133 chise_dt_get_char (CHISE_Decoding_Table *db, int code_point)
135 CHISE_Value valdatum;
139 sprintf(key_buf, "%d", code_point);
140 status = chise_get_attribute_table (db, key_buf, &valdatum);
144 = (unsigned char *)chise_value_data (&valdatum);
145 int len = strnlen (str, chise_value_size (&valdatum));
147 return chise_char_id_parse_c_string (str, len);
155 chise_open_feature_table (CHISE_Feature_Table **db,
156 CHISE_DS *ds, const char *feature,
158 u_int32_t accessmask, int modemask)
161 chise_open_attribute_table (db, ds->location,
162 "system-char-id", feature,
163 real_subtype, accessmask, modemask);
167 chise_close_feature_table (CHISE_Feature_Table *db)
170 return chise_close_attribute_table (db);
174 int chise_ft_get_value (CHISE_Feature_Table *db,
175 CHISE_Char_ID cid, CHISE_Value *valdatum)
177 unsigned char key_buf[8];
186 else if (cid == '\n')
192 else if (cid == '\r')
198 else if (cid == 0x1C)
206 else if (cid <= 0x1F)
210 key_buf[3] = '@' + cid;
213 else if ( (cid == ' ') || (cid == '"') ||
214 (cid == '#') || (cid == '\'') ||
215 (cid == '(') || (cid == ')') ||
216 (cid == ',') || (cid == '.') ||
217 (cid == ';') || (cid == '?') ||
218 (cid == '[') || (cid == '\\') ||
219 (cid == ']') || (cid == '`') )
225 else if (cid <= 0x7E)
230 else if (cid == 0x7F)
237 else if (cid <= 0x9F)
241 key_buf[3] = ((cid + '@') >> 6) | 0xC0;
242 key_buf[4] = ((cid + '@') & 0x3F) | 0x80;
246 else if (cid <= 0x7FF)
248 key_buf[1] = (cid >> 6) | 0xC0;
249 key_buf[2] = (cid & 0x3F) | 0x80;
252 else if (cid <= 0xFFFF)
254 key_buf[1] = (cid >> 12) | 0xE0;
255 key_buf[2]= ((cid >> 6) & 0x3F) | 0x80;
256 key_buf[3]= (cid & 0x3F) | 0x80;
259 else if (cid <= 0x1FFFFF)
261 key_buf[1]= (cid >> 18) | 0xF0;
262 key_buf[2]= ((cid >> 12) & 0x3F) | 0x80;
263 key_buf[3]= ((cid >> 6) & 0x3F) | 0x80;
264 key_buf[4]= (cid & 0x3F) | 0x80;
267 else if (cid <= 0x3FFFFFF)
269 key_buf[1]= (cid >> 24) | 0xF8;
270 key_buf[2]= ((cid >> 18) & 0x3F) | 0x80;
271 key_buf[3]= ((cid >> 12) & 0x3F) | 0x80;
272 key_buf[4]= ((cid >> 6) & 0x3F) | 0x80;
273 key_buf[5]= (cid & 0x3F) | 0x80;
278 key_buf[1]= (cid >> 30) | 0xFC;
279 key_buf[2]= ((cid >> 24) & 0x3F) | 0x80;
280 key_buf[3]= ((cid >> 18) & 0x3F) | 0x80;
281 key_buf[4]= ((cid >> 12) & 0x3F) | 0x80;
282 key_buf[5]= ((cid >> 6) & 0x3F) | 0x80;
283 key_buf[6]= (cid & 0x3F) | 0x80;
287 chise_get_attribute_table (db, key_buf, valdatum);
291 chise_ft_iterate (CHISE_Feature_Table *dbp,
292 int (*func) (CHISE_Feature_Table *db,
293 CHISE_Char_ID cid, CHISE_Value *valdatum))
295 DBT keydatum, valdatum;
302 status = dbp->cursor (dbp, NULL, &dbcp, 0);
303 for (status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_FIRST);
305 status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_NEXT))
307 unsigned char *key_str = (unsigned char *)keydatum.data;
308 int key_len = strnlen (key_str, keydatum.size);
309 CHISE_Char_ID key = chise_char_id_parse_c_string (key_str, key_len);
312 if (ret = func (dbp, key, &valdatum))
315 dbcp->c_close (dbcp);
319 chise_open_attribute_table (CHISE_Attribute_Table **db,
321 const char *encoding, const char *feature,
323 u_int32_t accessmask, int modemask)
329 char *db_file_name, *sp;
331 status = db_create (&dbase, NULL, 0);
335 len = strlen (db_dir);
336 flen = strlen (feature);
337 size = len + strlen (encoding) + flen * 3 + 4;
338 db_file_name = alloca (size);
339 strcpy (db_file_name, db_dir);
340 if (db_file_name[len - 1] != '/')
342 db_file_name[len++] = '/';
343 db_file_name[len] = '\0';
345 strcat (db_file_name, encoding);
346 strcat (db_file_name, "/");
347 /* strcat (db_file_name, feature); */
348 sp = &db_file_name[strlen (db_file_name)];
349 for (i = 0; i < flen; i++)
353 if ( (c == '/') || (c == '%') )
355 sprintf (sp, "%%%02X", c);
362 status = dbase->open (dbase, db_file_name, NULL,
363 real_subtype, accessmask, modemask);
366 dbase->close (dbase, 0);
374 chise_close_attribute_table (CHISE_Attribute_Table *db)
385 chise_get_attribute_table (CHISE_Attribute_Table *db,
386 char *key, CHISE_Value *valdatum)
391 /* DB Version 2 requires DBT's to be zeroed before use. */
396 keydatum.size = strlen (key);
398 status = db->get (db, NULL, &keydatum, valdatum, 0);