}
}
-int
-chise_open_data_source (CHISE_DS *ds, CHISE_DS_Type type, char *location)
+CHISE_DS*
+chise_open_data_source (CHISE_DS_Type type, char *location)
{
+ CHISE_DS *ds = (CHISE_DS*)malloc (sizeof (CHISE_DS));
+ size_t len = strlen (location);
+
+ if (ds == NULL)
+ return NULL;
+
ds->type = type;
- ds->location = location;
- return 0;
+ ds->location = (unsigned char*)malloc (len + 1);
+ if (ds->location == NULL)
+ {
+ free (ds);
+ return NULL;
+ }
+ strcpy (ds->location, location);
+ return ds;
}
int
-chise_close_data_source (CHISE_DS *ds)
+chise_ds_close (CHISE_DS *ds)
{
- ds->type = CHISE_DS_NONE;
- ds->location = NULL;
+ if (ds->location != NULL)
+ free (ds->location);
+ free (ds);
return 0;
}
-int
-chise_open_decoding_table (CHISE_Decoding_Table *db,
- CHISE_DS *ds, const char *ccs,
- DBTYPE real_subtype,
- u_int32_t accessmask, int modemask)
+CHISE_Decoding_Table*
+chise_ds_open_decoding_table (CHISE_DS *ds, const char *ccs,
+ DBTYPE real_subtype,
+ u_int32_t accessmask, int modemask)
{
return
- chise_open_attribute_table (db, ds->location,
+ chise_open_attribute_table (ds,
ccs, "system-char-id",
real_subtype, accessmask, modemask);
}
int
-chise_close_decoding_table (CHISE_Decoding_Table *db)
+chise_dt_close (CHISE_Decoding_Table *table)
{
- if (db)
- return chise_close_attribute_table (db);
+ if (table)
+ return chise_close_attribute_table (table);
return -1;
}
CHISE_Char_ID
-chise_dt_get_char (CHISE_Decoding_Table *db, int code_point)
+chise_dt_get_char (CHISE_Decoding_Table *table, int code_point)
{
CHISE_Value valdatum;
int status = 0;
char key_buf[16];
sprintf(key_buf, "%d", code_point);
- status = chise_get_attribute_table (db, key_buf, &valdatum);
+ status = chise_get_attribute_table (table, key_buf, &valdatum);
if (!status)
{
unsigned char *str
}
int
-chise_dt_put_char (CHISE_Decoding_Table *db,
+chise_dt_put_char (CHISE_Decoding_Table *table,
int code_point, CHISE_Char_ID cid)
{
CHISE_Value valdatum;
sprintf(key_buf, "%d", code_point);
chise_format_char_id (cid, val_buf, 8);
- return chise_put_attribute_table (db, key_buf, val_buf);
+ return chise_put_attribute_table (table, key_buf, val_buf);
}
-int
-chise_open_feature_table (CHISE_Feature_Table *db,
- CHISE_DS *ds, const char *feature,
- DBTYPE real_subtype,
- u_int32_t accessmask, int modemask)
+CHISE_Feature_Table*
+chise_ds_open_feature_table (CHISE_DS *ds, const char *feature,
+ DBTYPE real_subtype,
+ u_int32_t accessmask, int modemask)
{
return
- chise_open_attribute_table (db, ds->location,
+ chise_open_attribute_table (ds,
"system-char-id", feature,
real_subtype, accessmask, modemask);
}
int
-chise_close_feature_table (CHISE_Feature_Table *db)
+chise_ft_close (CHISE_Feature_Table *table)
{
- if (db)
- return chise_close_attribute_table (db);
+ if (table)
+ return chise_close_attribute_table (table);
return -1;
}
int
-chise_ft_get_value (CHISE_Feature_Table *db,
+chise_ft_get_value (CHISE_Feature_Table *table,
CHISE_Char_ID cid, CHISE_Value *valdatum)
{
unsigned char key_buf[8];
chise_format_char_id (cid, key_buf, 8);
- return chise_get_attribute_table (db, key_buf, valdatum);
+ return chise_get_attribute_table (table, key_buf, valdatum);
}
void
-chise_ft_iterate (CHISE_Feature_Table *ft,
- int (*func) (CHISE_Feature_Table *ft,
+chise_ft_iterate (CHISE_Feature_Table *table,
+ int (*func) (CHISE_Feature_Table *table,
CHISE_Char_ID cid, CHISE_Value *valdatum))
{
DBT keydatum, valdatum;
xzero (keydatum);
xzero (valdatum);
- status = ft->dbp->cursor (ft->dbp, NULL, &dbcp, 0);
+ status = table->db->cursor (table->db, 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 (ft, key, &valdatum))
+ if (ret = func (table, key, &valdatum))
break;
}
dbcp->c_close (dbcp);
}
-int
-chise_open_attribute_table (CHISE_Attribute_Table *ft,
- const char *db_dir,
+CHISE_Attribute_Table*
+chise_open_attribute_table (CHISE_DS *ds,
const char *encoding, const char *feature,
DBTYPE real_subtype,
u_int32_t accessmask, int modemask)
{
+ CHISE_Attribute_Table* table;
+ char *db_dir;
DB* dbase;
int status;
int len, flen, i;
int size;
char *db_file_name, *sp;
+ if (ds == NULL)
+ return NULL;
+
+ table = (CHISE_Attribute_Table*)malloc (sizeof (CHISE_Attribute_Table));
+ if (table == NULL)
+ return NULL;
+
+ table->ds = ds;
+
status = db_create (&dbase, NULL, 0);
if (status)
- return -1;
+ {
+ free (table);
+ return NULL;
+ }
+ db_dir = ds->location;
len = strlen (db_dir);
flen = strlen (feature);
size = len + strlen (encoding) + flen * 3 + 4;
if (status)
{
dbase->close (dbase, 0);
- return -1;
+ free (table);
+ return NULL;
}
- ft->dbp = dbase;
- return 0;
+ table->db = dbase;
+ return table;
}
int
-chise_close_attribute_table (CHISE_Attribute_Table *ft)
+chise_close_attribute_table (CHISE_Attribute_Table *table)
{
- if (ft->dbp)
+ if (table->db)
{
- ft->dbp->sync (ft->dbp, 0);
- ft->dbp->close (ft->dbp, 0);
+ table->db->sync (table->db, 0);
+ table->db->close (table->db, 0);
}
+ free (table);
return 0;
}
int
-chise_get_attribute_table (CHISE_Attribute_Table *ft,
+chise_get_attribute_table (CHISE_Attribute_Table *table,
char *key, CHISE_Value *valdatum)
{
DBT keydatum;
keydatum.data = key;
keydatum.size = strlen (key);
- status = ft->dbp->get (ft->dbp, NULL, &keydatum, valdatum, 0);
+ status = table->db->get (table->db, NULL, &keydatum, valdatum, 0);
return status;
}
int
-chise_put_attribute_table (CHISE_Attribute_Table *ft,
+chise_put_attribute_table (CHISE_Attribute_Table *table,
char *key, char *value)
{
DBT keydatum, valdatum;
valdatum.data = value;
valdatum.size = strlen (value);
- status = ft->dbp->put (ft->dbp, NULL, &keydatum, &valdatum, 0);
+ status = table->db->put (table->db, NULL, &keydatum, &valdatum, 0);
return status;
}