}
int
+chise_format_char_id (CHISE_Char_ID cid, unsigned char *dest, int len)
+{
+ int i = 0;
+
+ dest[i++] = '?';
+ if (cid == '\t')
+ {
+ dest[i++] = '\\';
+ dest[i++] = 't';
+ dest[i] = '\0';
+ return i;
+ }
+ else if (cid == '\n')
+ {
+ dest[i++] = '\\';
+ dest[i++] = 'n';
+ dest[i] = '\0';
+ return i;
+ }
+ else if (cid == '\r')
+ {
+ dest[i++] = '\\';
+ dest[i++] = 'r';
+ dest[i] = '\0';
+ return i;
+ }
+ else if (cid == 0x1C)
+ {
+ dest[i++] = '\\';
+ dest[i++] = '^';
+ dest[i++] = '\\';
+ dest[i++] = '\\';
+ dest[i] = '\0';
+ return i;
+ }
+ else if (cid <= 0x1F)
+ {
+ dest[i++] = '\\';
+ dest[i++] = '^';
+ dest[i++] = '@' + cid;
+ dest[i] = '\0';
+ return i;
+ }
+ else if ( (cid == ' ') || (cid == '"') ||
+ (cid == '#') || (cid == '\'') ||
+ (cid == '(') || (cid == ')') ||
+ (cid == ',') || (cid == '.') ||
+ (cid == ';') || (cid == '?') ||
+ (cid == '[') || (cid == '\\') ||
+ (cid == ']') || (cid == '`') )
+ {
+ dest[i++] = '\\';
+ dest[i++] = cid;
+ dest[i] = '\0';
+ return i;
+ }
+ else if (cid <= 0x7E)
+ {
+ dest[i++] = cid;
+ dest[i] = '\0';
+ return i;
+ }
+ else if (cid == 0x7F)
+ {
+ dest[i++] = '\\';
+ dest[i++] = '^';
+ dest[i++] = '?';
+ dest[i] = '\0';
+ return i;
+ }
+ else if (cid <= 0x9F)
+ {
+ dest[i++] = '\\';
+ dest[i++] = '^';
+ dest[i++] = ((cid + '@') >> 6) | 0xC0;
+ dest[i++] = ((cid + '@') & 0x3F) | 0x80;
+ dest[i] = '\0';
+ return i;
+ }
+ else if (cid <= 0x7FF)
+ {
+ dest[i++] = (cid >> 6) | 0xC0;
+ dest[i++] = (cid & 0x3F) | 0x80;
+ dest[i] = '\0';
+ return i;
+ }
+ else if (cid <= 0xFFFF)
+ {
+ dest[i++] = (cid >> 12) | 0xE0;
+ dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
+ dest[i++]= (cid & 0x3F) | 0x80;
+ dest[i] = '\0';
+ return i;
+ }
+ else if (cid <= 0x1FFFFF)
+ {
+ dest[i++]= (cid >> 18) | 0xF0;
+ dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
+ dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
+ dest[i++]= (cid & 0x3F) | 0x80;
+ dest[i] = '\0';
+ return i;
+ }
+ else if (cid <= 0x3FFFFFF)
+ {
+ dest[i++]= (cid >> 24) | 0xF8;
+ dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
+ dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
+ dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
+ dest[i++]= (cid & 0x3F) | 0x80;
+ dest[i] = '\0';
+ return i;
+ }
+ else
+ {
+ dest[i++]= (cid >> 30) | 0xFC;
+ dest[i++]= ((cid >> 24) & 0x3F) | 0x80;
+ dest[i++]= ((cid >> 18) & 0x3F) | 0x80;
+ dest[i++]= ((cid >> 12) & 0x3F) | 0x80;
+ dest[i++]= ((cid >> 6) & 0x3F) | 0x80;
+ dest[i++]= (cid & 0x3F) | 0x80;
+ dest[i] = '\0';
+ return i;
+ }
+}
+
+int
chise_open_data_source (CHISE_DS *ds, CHISE_DS_Type type, char *location)
{
ds->type = type;
int
-chise_open_decoding_table (CHISE_Decoding_Table **db,
+chise_open_decoding_table (CHISE_Decoding_Table *db,
CHISE_DS *ds, const char *ccs,
DBTYPE real_subtype,
u_int32_t accessmask, int modemask)
return -1;
}
+int
+chise_dt_put_char (CHISE_Decoding_Table *db,
+ int code_point, CHISE_Char_ID cid)
+{
+ CHISE_Value valdatum;
+ char key_buf[16], val_buf[8];
+
+ sprintf(key_buf, "%d", code_point);
+ chise_format_char_id (cid, val_buf, 8);
+ return chise_put_attribute_table (db, key_buf, val_buf);
+}
+
int
-chise_open_feature_table (CHISE_Feature_Table **db,
+chise_open_feature_table (CHISE_Feature_Table *db,
CHISE_DS *ds, const char *feature,
DBTYPE real_subtype,
u_int32_t accessmask, int modemask)
return -1;
}
-int chise_ft_get_value (CHISE_Feature_Table *db,
- CHISE_Char_ID cid, CHISE_Value *valdatum)
+int
+chise_ft_get_value (CHISE_Feature_Table *db,
+ CHISE_Char_ID cid, CHISE_Value *valdatum)
{
unsigned char key_buf[8];
- key_buf[0] = '?';
- if (cid == '\t')
- {
- key_buf[1] = '\\';
- key_buf[2] = 't';
- key_buf[3] = '\0';
- }
- else if (cid == '\n')
- {
- key_buf[1] = '\\';
- key_buf[2] = 'n';
- key_buf[3] = '\0';
- }
- else if (cid == '\r')
- {
- key_buf[1] = '\\';
- key_buf[2] = 'r';
- key_buf[3] = '\0';
- }
- else if (cid == 0x1C)
- {
- key_buf[1] = '\\';
- key_buf[2] = '^';
- key_buf[3] = '\\';
- key_buf[4] = '\\';
- key_buf[5] = '\0';
- }
- else if (cid <= 0x1F)
- {
- key_buf[1] = '\\';
- key_buf[2] = '^';
- key_buf[3] = '@' + cid;
- key_buf[4] = '\0';
- }
- else if ( (cid == ' ') || (cid == '"') ||
- (cid == '#') || (cid == '\'') ||
- (cid == '(') || (cid == ')') ||
- (cid == ',') || (cid == '.') ||
- (cid == ';') || (cid == '?') ||
- (cid == '[') || (cid == '\\') ||
- (cid == ']') || (cid == '`') )
- {
- key_buf[1] = '\\';
- key_buf[2] = cid;
- key_buf[3] = '\0';
- }
- else if (cid <= 0x7E)
- {
- key_buf[1] = cid;
- key_buf[2] = '\0';
- }
- else if (cid == 0x7F)
- {
- key_buf[1] = '\\';
- key_buf[2] = '^';
- key_buf[3] = '?';
- key_buf[4] = '\0';
- }
- else if (cid <= 0x9F)
- {
- key_buf[1] = '\\';
- key_buf[2] = '^';
- key_buf[3] = ((cid + '@') >> 6) | 0xC0;
- key_buf[4] = ((cid + '@') & 0x3F) | 0x80;
- key_buf[5] = '\0';
-
- }
- else if (cid <= 0x7FF)
- {
- key_buf[1] = (cid >> 6) | 0xC0;
- key_buf[2] = (cid & 0x3F) | 0x80;
- key_buf[3] = '\0';
- }
- else if (cid <= 0xFFFF)
- {
- key_buf[1] = (cid >> 12) | 0xE0;
- key_buf[2]= ((cid >> 6) & 0x3F) | 0x80;
- key_buf[3]= (cid & 0x3F) | 0x80;
- key_buf[4] = '\0';
- }
- else if (cid <= 0x1FFFFF)
- {
- key_buf[1]= (cid >> 18) | 0xF0;
- key_buf[2]= ((cid >> 12) & 0x3F) | 0x80;
- key_buf[3]= ((cid >> 6) & 0x3F) | 0x80;
- key_buf[4]= (cid & 0x3F) | 0x80;
- key_buf[5] = '\0';
- }
- else if (cid <= 0x3FFFFFF)
- {
- key_buf[1]= (cid >> 24) | 0xF8;
- key_buf[2]= ((cid >> 18) & 0x3F) | 0x80;
- key_buf[3]= ((cid >> 12) & 0x3F) | 0x80;
- key_buf[4]= ((cid >> 6) & 0x3F) | 0x80;
- key_buf[5]= (cid & 0x3F) | 0x80;
- key_buf[6] = '\0';
- }
- else
- {
- key_buf[1]= (cid >> 30) | 0xFC;
- key_buf[2]= ((cid >> 24) & 0x3F) | 0x80;
- key_buf[3]= ((cid >> 18) & 0x3F) | 0x80;
- key_buf[4]= ((cid >> 12) & 0x3F) | 0x80;
- key_buf[5]= ((cid >> 6) & 0x3F) | 0x80;
- key_buf[6]= (cid & 0x3F) | 0x80;
- key_buf[7] = '\0';
- }
- return
- chise_get_attribute_table (db, key_buf, valdatum);
+ chise_format_char_id (cid, key_buf, 8);
+ return chise_get_attribute_table (db, key_buf, valdatum);
}
void
-chise_ft_iterate (CHISE_Feature_Table *dbp,
- int (*func) (CHISE_Feature_Table *db,
+chise_ft_iterate (CHISE_Feature_Table *ft,
+ int (*func) (CHISE_Feature_Table *ft,
CHISE_Char_ID cid, CHISE_Value *valdatum))
{
DBT keydatum, valdatum;
xzero (keydatum);
xzero (valdatum);
- status = dbp->cursor (dbp, NULL, &dbcp, 0);
+ status = ft->dbp->cursor (ft->dbp, NULL, &dbcp, 0);
for (status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_FIRST);
status == 0;
status = dbcp->c_get (dbcp, &keydatum, &valdatum, DB_NEXT))
CHISE_Char_ID key = chise_char_id_parse_c_string (key_str, key_len);
int ret;
- if (ret = func (dbp, key, &valdatum))
+ if (ret = func (ft, key, &valdatum))
break;
}
dbcp->c_close (dbcp);
}
int
-chise_open_attribute_table (CHISE_Attribute_Table **db,
+chise_open_attribute_table (CHISE_Attribute_Table *ft,
const char *db_dir,
const char *encoding, const char *feature,
DBTYPE real_subtype,
dbase->close (dbase, 0);
return -1;
}
- *db = dbase;
+ ft->dbp = dbase;
return 0;
}
int
-chise_close_attribute_table (CHISE_Attribute_Table *db)
+chise_close_attribute_table (CHISE_Attribute_Table *ft)
{
- if (db)
+ if (ft->dbp)
{
- db->sync (db, 0);
- db->close (db, 0);
+ ft->dbp->sync (ft->dbp, 0);
+ ft->dbp->close (ft->dbp, 0);
}
return 0;
}
int
-chise_get_attribute_table (CHISE_Attribute_Table *db,
+chise_get_attribute_table (CHISE_Attribute_Table *ft,
char *key, CHISE_Value *valdatum)
{
DBT keydatum;
keydatum.data = key;
keydatum.size = strlen (key);
- status = db->get (db, NULL, &keydatum, valdatum, 0);
+ status = ft->dbp->get (ft->dbp, NULL, &keydatum, valdatum, 0);
+ return status;
+}
+
+int
+chise_put_attribute_table (CHISE_Attribute_Table *ft,
+ char *key, char *value)
+{
+ DBT keydatum, valdatum;
+ int status = 0;
+
+ /* DB Version 2 requires DBT's to be zeroed before use. */
+ xzero (keydatum);
+ xzero (valdatum);
+
+ keydatum.data = key;
+ keydatum.size = strlen (key);
+
+ valdatum.data = value;
+ valdatum.size = strlen (value);
+
+ status = ft->dbp->put (ft->dbp, NULL, &keydatum, &valdatum, 0);
return status;
}