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_format_char_id (CHISE_Char_ID cid, unsigned char *dest, int len)
108 else if (cid == '\n')
115 else if (cid == '\r')
122 else if (cid == 0x1C)
131 else if (cid <= 0x1F)
135 dest[i++] = '@' + cid;
139 else if ( (cid == ' ') || (cid == '"') ||
140 (cid == '#') || (cid == '\'') ||
141 (cid == '(') || (cid == ')') ||
142 (cid == ',') || (cid == '.') ||
143 (cid == ';') || (cid == '?') ||
144 (cid == '[') || (cid == '\\') ||
145 (cid == ']') || (cid == '`') )
152 else if (cid <= 0x7E)
158 else if (cid == 0x7F)
166 else if (cid <= 0x9F)
170 dest[i++] = ((cid + '@') >> 6) | 0xC0;
171 dest[i++] = ((cid + '@') & 0x3F) | 0x80;
175 else if (cid <= 0x7FF)
177 dest[i++] = (cid >> 6) | 0xC0;
178 dest[i++] = (cid & 0x3F) | 0x80;
182 else if (cid <= 0xFFFF)
184 dest[i++] = (cid >> 12) | 0xE0;
185 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
186 dest[i++]= (cid & 0x3F) | 0x80;
190 else if (cid <= 0x1FFFFF)
192 dest[i++]= (cid >> 18) | 0xF0;
193 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
194 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
195 dest[i++]= (cid & 0x3F) | 0x80;
199 else if (cid <= 0x3FFFFFF)
201 dest[i++]= (cid >> 24) | 0xF8;
202 dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
203 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
204 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
205 dest[i++]= (cid & 0x3F) | 0x80;
211 dest[i++]= (cid >> 30) | 0xFC;
212 dest[i++]= ((cid >> 24) & 0x3F) | 0x80;
213 dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
214 dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
215 dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
216 dest[i++]= (cid & 0x3F) | 0x80;
223 chise_open_data_source (CHISE_DS *ds, CHISE_DS_Type type, char *location)
226 ds->location = location;
231 chise_close_data_source (CHISE_DS *ds)
233 ds->type = CHISE_DS_NONE;
240 chise_open_decoding_table (CHISE_Decoding_Table **db,
241 CHISE_DS *ds, const char *ccs,
243 u_int32_t accessmask, int modemask)
246 chise_open_attribute_table (db, ds->location,
247 ccs, "system-char-id",
248 real_subtype, accessmask, modemask);
252 chise_close_decoding_table (CHISE_Decoding_Table *db)
255 return chise_close_attribute_table (db);
260 chise_dt_get_char (CHISE_Decoding_Table *db, int code_point)
262 CHISE_Value valdatum;
266 sprintf(key_buf, "%d", code_point);
267 status = chise_get_attribute_table (db, key_buf, &valdatum);
271 = (unsigned char *)chise_value_data (&valdatum);
272 int len = strnlen (str, chise_value_size (&valdatum));
274 return chise_char_id_parse_c_string (str, len);
282 chise_open_feature_table (CHISE_Feature_Table **db,
283 CHISE_DS *ds, const char *feature,
285 u_int32_t accessmask, int modemask)
288 chise_open_attribute_table (db, ds->location,
289 "system-char-id", feature,
290 real_subtype, accessmask, modemask);
294 chise_close_feature_table (CHISE_Feature_Table *db)
297 return chise_close_attribute_table (db);
302 chise_ft_get_value (CHISE_Feature_Table *db,
303 CHISE_Char_ID cid, CHISE_Value *valdatum)
305 unsigned char key_buf[8];
307 chise_format_char_id (cid, key_buf, 8);
308 return chise_get_attribute_table (db, key_buf, valdatum);
312 chise_ft_iterate (CHISE_Feature_Table *dbp,
313 int (*func) (CHISE_Feature_Table *db,
314 CHISE_Char_ID cid, CHISE_Value *valdatum))
316 DBT keydatum, valdatum;
323 status = dbp->cursor (dbp, NULL, &dbcp, 0);
324 for (status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_FIRST);
326 status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_NEXT))
328 unsigned char *key_str = (unsigned char *)keydatum.data;
329 int key_len = strnlen (key_str, keydatum.size);
330 CHISE_Char_ID key = chise_char_id_parse_c_string (key_str, key_len);
333 if (ret = func (dbp, key, &valdatum))
336 dbcp->c_close (dbcp);
340 chise_open_attribute_table (CHISE_Attribute_Table **db,
342 const char *encoding, const char *feature,
344 u_int32_t accessmask, int modemask)
350 char *db_file_name, *sp;
352 status = db_create (&dbase, NULL, 0);
356 len = strlen (db_dir);
357 flen = strlen (feature);
358 size = len + strlen (encoding) + flen * 3 + 4;
359 db_file_name = alloca (size);
360 strcpy (db_file_name, db_dir);
361 if (db_file_name[len - 1] != '/')
363 db_file_name[len++] = '/';
364 db_file_name[len] = '\0';
366 strcat (db_file_name, encoding);
367 strcat (db_file_name, "/");
368 /* strcat (db_file_name, feature); */
369 sp = &db_file_name[strlen (db_file_name)];
370 for (i = 0; i < flen; i++)
374 if ( (c == '/') || (c == '%') )
376 sprintf (sp, "%%%02X", c);
383 status = dbase->open (dbase, db_file_name, NULL,
384 real_subtype, accessmask, modemask);
387 dbase->close (dbase, 0);
395 chise_close_attribute_table (CHISE_Attribute_Table *db)
406 chise_get_attribute_table (CHISE_Attribute_Table *db,
407 char *key, CHISE_Value *valdatum)
412 /* DB Version 2 requires DBT's to be zeroed before use. */
417 keydatum.size = strlen (key);
419 status = db->get (db, NULL, &keydatum, valdatum, 0);