#endif
#include "chise.h"
+#include "chise-name.h"
typedef DB CHISE_Attribute_Table;
{
CHISE_DS_Type type;
unsigned char *location;
+ CHISE_NAME_TABLE* feature_names;
+ CHISE_NAME_TABLE* ccs_names;
};
CHISE_DS*
return NULL;
}
strcpy (ds->location, location);
+
+ ds->feature_names = chise_make_name_table ();
+ if (ds->feature_names == NULL)
+ {
+ free (ds->location);
+ free (ds);
+ }
+
+ ds->ccs_names = chise_make_name_table ();
+ if (ds->ccs_names == NULL)
+ {
+ free (ds->feature_names);
+ free (ds->location);
+ free (ds);
+ }
return ds;
}
{
if (ds->location != NULL)
free (ds->location);
+ if (ds->feature_names != NULL)
+ free (ds->feature_names);
+ if (ds->ccs_names != NULL)
+ free (ds->ccs_names);
free (ds);
return 0;
}
+CHISE_Feature_Table*
+chise_ds_get_feature (CHISE_DS *ds, const unsigned char *feature,
+ DBTYPE real_subtype,
+ u_int32_t accessmask, int modemask)
+{
+ CHISE_Feature_Table* ft;
+
+ ft = chise_name_table_get (ds->feature_names, feature);
+ if (ft != NULL)
+ return ft;
+
+ ft = chise_ds_open_feature_table (ds, feature,
+ real_subtype,
+ accessmask, modemask);
+ if (ft == NULL)
+ return NULL;
+
+ if (chise_name_table_put (ds->feature_names, feature, ft))
+ {
+ chise_ft_close (ft);
+ return NULL;
+ }
+ return ft;
+}
+
+CHISE_CCS_Table*
+chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *ccs,
+ DBTYPE real_subtype,
+ u_int32_t accessmask, int modemask)
+{
+ CHISE_CCS_Table* ct;
+
+ ct = chise_name_table_get (ds->ccs_names, ccs);
+ if (ct != NULL)
+ return ct;
+
+ ct = chise_ds_open_ccs_table (ds, ccs,
+ real_subtype,
+ accessmask, modemask);
+ if (ct == NULL)
+ return NULL;
+
+ if (chise_name_table_put (ds->ccs_names, ccs, ct))
+ {
+ chise_ccst_close (ct);
+ return NULL;
+ }
+ return ct;
+}
+
struct CHISE_Feature_Table
{
}
int
-chise_ft_get_value (CHISE_Feature_Table *table,
- CHISE_Char_ID cid, CHISE_Value *valdatum)
+chise_char_load_feature_value (CHISE_Char_ID cid,
+ CHISE_Feature_Table *table,
+ CHISE_Value *valdatum)
{
unsigned char key_buf[8];
key_buf, valdatum);
}
+unsigned char*
+chise_char_gets_feature_value (CHISE_Char_ID cid,
+ CHISE_Feature_Table *table,
+ unsigned char *buf, size_t size)
+{
+ CHISE_Value valdatum;
+ unsigned char key_buf[8];
+ int status;
+
+ chise_format_char_id (cid, key_buf, 8);
+ status = chise_get_attribute_table (table->db,
+ key_buf, &valdatum);
+ if (status)
+ return NULL;
+ if (size < valdatum.size)
+ return NULL;
+ strncpy (buf, valdatum.data, valdatum.size);
+ buf[valdatum.size] = '\0';
+ return buf;
+}
+
void
-chise_ft_iterate (CHISE_Feature_Table *table,
- int (*func) (CHISE_Feature_Table *table,
- CHISE_Char_ID cid, CHISE_Value *valdatum))
+chise_char_feature_value_iterate (CHISE_Feature feature,
+ int (*func) (CHISE_Char_ID cid,
+ CHISE_Feature feature,
+ CHISE_Value *valdatum))
{
DBT keydatum, valdatum;
DBC *dbcp;
xzero (keydatum);
xzero (valdatum);
- status = table->db->cursor (table->db, NULL, &dbcp, 0);
+ status = feature->db->cursor (feature->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 (table, key, &valdatum))
+ if (ret = func (key, feature, &valdatum))
break;
}
dbcp->c_close (dbcp);
}
-struct CHISE_Decoding_Table
+struct CHISE_CCS_Table
{
CHISE_DS *ds;
CHISE_Attribute_Table *db;
};
-CHISE_Decoding_Table*
-chise_ds_open_decoding_table (CHISE_DS *ds, const char *ccs,
- DBTYPE real_subtype,
- u_int32_t accessmask, int modemask)
+CHISE_CCS_Table*
+chise_ds_open_ccs_table (CHISE_DS *ds, const char *ccs,
+ DBTYPE real_subtype,
+ u_int32_t accessmask, int modemask)
{
- CHISE_Decoding_Table* table;
+ CHISE_CCS_Table* table;
if (ds == NULL)
return NULL;
- table = (CHISE_Decoding_Table*)malloc (sizeof (CHISE_Decoding_Table));
+ table = (CHISE_CCS_Table*)malloc (sizeof (CHISE_CCS_Table));
if (table == NULL)
return NULL;
}
int
-chise_dt_close (CHISE_Decoding_Table *table)
+chise_ccst_close (CHISE_CCS_Table *table)
{
int status;
}
CHISE_Char_ID
-chise_dt_get_char (CHISE_Decoding_Table *table, int code_point)
+chise_ccs_decode (CHISE_CCS ccs, int code_point)
{
CHISE_Value valdatum;
int status = 0;
char key_buf[16];
sprintf(key_buf, "%d", code_point);
- status = chise_get_attribute_table (table->db, key_buf, &valdatum);
+ status = chise_get_attribute_table (ccs->db, key_buf, &valdatum);
if (!status)
{
unsigned char *str
}
int
-chise_dt_put_char (CHISE_Decoding_Table *table,
- int code_point, CHISE_Char_ID cid)
+chise_ccst_put_char (CHISE_CCS_Table *table,
+ int code_point, CHISE_Char_ID cid)
{
CHISE_Value valdatum;
char key_buf[16], val_buf[8];