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];
178 else if (cid <= 0x7ff)
180 key_buf[1] = (cid >> 6) | 0xc0;
181 key_buf[2] = (cid & 0x3f) | 0x80;
184 else if (cid <= 0xffff)
186 key_buf[1] = (cid >> 12) | 0xe0;
187 key_buf[2]= ((cid >> 6) & 0x3f) | 0x80;
188 key_buf[3]= (cid & 0x3f) | 0x80;
191 else if (cid <= 0x1fffff)
193 key_buf[1]= (cid >> 18) | 0xf0;
194 key_buf[2]= ((cid >> 12) & 0x3f) | 0x80;
195 key_buf[3]= ((cid >> 6) & 0x3f) | 0x80;
196 key_buf[4]= (cid & 0x3f) | 0x80;
199 else if (cid <= 0x3ffffff)
201 key_buf[1]= (cid >> 24) | 0xf8;
202 key_buf[2]= ((cid >> 18) & 0x3f) | 0x80;
203 key_buf[3]= ((cid >> 12) & 0x3f) | 0x80;
204 key_buf[4]= ((cid >> 6) & 0x3f) | 0x80;
205 key_buf[5]= (cid & 0x3f) | 0x80;
210 key_buf[1]= (cid >> 30) | 0xfc;
211 key_buf[2]= ((cid >> 24) & 0x3f) | 0x80;
212 key_buf[3]= ((cid >> 18) & 0x3f) | 0x80;
213 key_buf[4]= ((cid >> 12) & 0x3f) | 0x80;
214 key_buf[5]= ((cid >> 6) & 0x3f) | 0x80;
215 key_buf[6]= (cid & 0x3f) | 0x80;
219 chise_get_attribute_table (db, key_buf, valdatum);
224 chise_open_attribute_table (CHISE_Attribute_Table **db,
226 const char *encoding, const char *feature,
228 u_int32_t accessmask, int modemask)
234 char *db_file_name, *sp;
236 status = db_create (&dbase, NULL, 0);
240 len = strlen (db_dir);
241 flen = strlen (feature);
242 size = len + strlen (encoding) + flen * 3 + 4;
243 db_file_name = alloca (size);
244 strcpy (db_file_name, db_dir);
245 if (db_file_name[len - 1] != '/')
247 db_file_name[len++] = '/';
248 db_file_name[len] = '\0';
250 strcat (db_file_name, encoding);
251 strcat (db_file_name, "/");
252 /* strcat (db_file_name, feature); */
253 sp = &db_file_name[strlen (db_file_name)];
254 for (i = 0; i < flen; i++)
258 if ( (c == '/') || (c == '%') )
260 sprintf (sp, "%%%02X", c);
267 status = dbase->open (dbase, db_file_name, NULL,
268 real_subtype, accessmask, modemask);
271 dbase->close (dbase, 0);
279 chise_close_attribute_table (CHISE_Attribute_Table *db)
290 chise_get_attribute_table (CHISE_Attribute_Table *db,
291 char *key, CHISE_Value *valdatum)
296 /* DB Version 2 requires DBT's to be zeroed before use. */
301 keydatum.size = strlen (key);
303 status = db->get (db, NULL, &keydatum, valdatum, 0);