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)))
27 chise_open_data_source (CHISE_DS *ds, CHISE_DS_Type type, char *location)
30 ds->location = location;
35 chise_close_data_source (CHISE_DS *ds)
37 ds->type = CHISE_DS_NONE;
44 chise_open_decoding_table (CHISE_Decoding_Table **db,
45 CHISE_DS *ds, const char *ccs,
47 u_int32_t accessmask, int modemask)
50 chise_open_attribute_table (db, ds->location,
51 ccs, "system-char-id",
52 real_subtype, accessmask, modemask);
56 chise_close_decoding_table (CHISE_Decoding_Table *db)
59 return chise_close_attribute_table (db);
64 chise_dt_get_char (CHISE_Decoding_Table *db, int code_point)
70 sprintf(key_buf, "%d", code_point);
71 status = chise_get_attribute_table (db, key_buf, &valdatum);
75 = (unsigned char *)chise_value_data (&valdatum);
76 int len = strnlen (str, chise_value_size (&valdatum));
79 if ( (len >= 2) && (str[i++] == '?') )
81 unsigned char c = str[i++];
98 return c & (0x80 | 0x1F);
132 if (counter + 2 <= len)
136 for (j = 0; j < counter; j++)
137 cid = (cid << 6) | (str[j + i] & 0x3F);
148 chise_open_feature_table (CHISE_Feature_Table **db,
149 CHISE_DS *ds, const char *feature,
151 u_int32_t accessmask, int modemask)
154 chise_open_attribute_table (db, ds->location,
155 "system-char-id", feature,
156 real_subtype, accessmask, modemask);
160 chise_close_feature_table (CHISE_Feature_Table *db)
163 return chise_close_attribute_table (db);
167 int chise_ft_get_value (CHISE_Feature_Table *db,
168 CHISE_Char_ID cid, CHISE_Value *valdatum)
170 unsigned char key_buf[8];
179 else if (cid == '\n')
185 else if (cid == '\r')
191 else if (cid == 0x1C)
199 else if (cid <= 0x1F)
203 key_buf[3] = '@' + cid;
206 else if ( (cid == ' ') || (cid == '"') ||
207 (cid == '#') || (cid == '\'') ||
208 (cid == '(') || (cid == ')') ||
209 (cid == ',') || (cid == '.') ||
210 (cid == ';') || (cid == '?') ||
211 (cid == '[') || (cid == '\\') ||
212 (cid == ']') || (cid == '`') )
218 else if (cid <= 0x7E)
223 else if (cid == 0x7F)
230 else if (cid <= 0x9F)
234 key_buf[3] = ((cid + '@') >> 6) | 0xC0;
235 key_buf[4] = ((cid + '@') & 0x3F) | 0x80;
239 else if (cid <= 0x7FF)
241 key_buf[1] = (cid >> 6) | 0xC0;
242 key_buf[2] = (cid & 0x3F) | 0x80;
245 else if (cid <= 0xFFFF)
247 key_buf[1] = (cid >> 12) | 0xE0;
248 key_buf[2]= ((cid >> 6) & 0x3F) | 0x80;
249 key_buf[3]= (cid & 0x3F) | 0x80;
252 else if (cid <= 0x1FFFFF)
254 key_buf[1]= (cid >> 18) | 0xF0;
255 key_buf[2]= ((cid >> 12) & 0x3F) | 0x80;
256 key_buf[3]= ((cid >> 6) & 0x3F) | 0x80;
257 key_buf[4]= (cid & 0x3F) | 0x80;
260 else if (cid <= 0x3FFFFFF)
262 key_buf[1]= (cid >> 24) | 0xF8;
263 key_buf[2]= ((cid >> 18) & 0x3F) | 0x80;
264 key_buf[3]= ((cid >> 12) & 0x3F) | 0x80;
265 key_buf[4]= ((cid >> 6) & 0x3F) | 0x80;
266 key_buf[5]= (cid & 0x3F) | 0x80;
271 key_buf[1]= (cid >> 30) | 0xFC;
272 key_buf[2]= ((cid >> 24) & 0x3F) | 0x80;
273 key_buf[3]= ((cid >> 18) & 0x3F) | 0x80;
274 key_buf[4]= ((cid >> 12) & 0x3F) | 0x80;
275 key_buf[5]= ((cid >> 6) & 0x3F) | 0x80;
276 key_buf[6]= (cid & 0x3F) | 0x80;
280 chise_get_attribute_table (db, key_buf, valdatum);
285 chise_open_attribute_table (CHISE_Attribute_Table **db,
287 const char *encoding, const char *feature,
289 u_int32_t accessmask, int modemask)
295 char *db_file_name, *sp;
297 status = db_create (&dbase, NULL, 0);
301 len = strlen (db_dir);
302 flen = strlen (feature);
303 size = len + strlen (encoding) + flen * 3 + 4;
304 db_file_name = alloca (size);
305 strcpy (db_file_name, db_dir);
306 if (db_file_name[len - 1] != '/')
308 db_file_name[len++] = '/';
309 db_file_name[len] = '\0';
311 strcat (db_file_name, encoding);
312 strcat (db_file_name, "/");
313 /* strcat (db_file_name, feature); */
314 sp = &db_file_name[strlen (db_file_name)];
315 for (i = 0; i < flen; i++)
319 if ( (c == '/') || (c == '%') )
321 sprintf (sp, "%%%02X", c);
328 status = dbase->open (dbase, db_file_name, NULL,
329 real_subtype, accessmask, modemask);
332 dbase->close (dbase, 0);
340 chise_close_attribute_table (CHISE_Attribute_Table *db)
351 chise_get_attribute_table (CHISE_Attribute_Table *db,
352 char *key, CHISE_Value *valdatum)
357 /* DB Version 2 requires DBT's to be zeroed before use. */
362 keydatum.size = strlen (key);
364 status = db->get (db, NULL, &keydatum, valdatum, 0);