#include "chise.h"
#include "chise-name.h"
+
+CHISE_Feature_Table*
+chise_ds_open_feature_table (CHISE_DS *ds, const char *feature);
+
+int chise_ft_close (CHISE_Feature_Table *table);
+
+CHISE_CCS_Table*
+chise_ds_open_ccs_table (CHISE_DS *ds, const char *ccs);
+
+int chise_ccst_close (CHISE_CCS_Table *table);
+
+
typedef DB CHISE_Attribute_Table;
CHISE_Attribute_Table*
unsigned char *location;
CHISE_NAME_TABLE* feature_names;
CHISE_NAME_TABLE* ccs_names;
+ DBTYPE subtype;
+ int modemask;
};
CHISE_DS*
-chise_open_data_source (CHISE_DS_Type type, char *location)
+chise_open_data_source (CHISE_DS_Type type, char *location,
+ DBTYPE subtype, int modemask)
{
CHISE_DS *ds = (CHISE_DS*)malloc (sizeof (CHISE_DS));
size_t len = strlen (location);
return NULL;
ds->type = type;
+ ds->subtype = subtype;
+ ds->modemask = modemask;
ds->location = (unsigned char*)malloc (len + 1);
if (ds->location == NULL)
{
}
CHISE_Feature_Table*
-chise_ds_get_feature (CHISE_DS *ds, const unsigned char *feature,
- DBTYPE real_subtype,
- u_int32_t accessmask, int modemask)
+chise_ds_get_feature (CHISE_DS *ds, const unsigned char *feature)
{
CHISE_Feature_Table* ft;
if (ft != NULL)
return ft;
- ft = chise_ds_open_feature_table (ds, feature,
- real_subtype,
- accessmask, modemask);
+ ft = chise_ds_open_feature_table (ds, feature);
if (ft == NULL)
return NULL;
}
CHISE_CCS_Table*
-chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *ccs,
- DBTYPE real_subtype,
- u_int32_t accessmask, int modemask)
+chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *ccs)
{
CHISE_CCS_Table* ct;
if (ct != NULL)
return ct;
- ct = chise_ds_open_ccs_table (ds, ccs,
- real_subtype,
- accessmask, modemask);
+ ct = chise_ds_open_ccs_table (ds, ccs);
if (ct == NULL)
return NULL;
struct CHISE_Feature_Table
{
CHISE_DS *ds;
+ unsigned char *name;
CHISE_Attribute_Table *db;
+ u_int32_t access;
};
CHISE_Feature_Table*
-chise_ds_open_feature_table (CHISE_DS *ds, const char *feature,
- DBTYPE real_subtype,
- u_int32_t accessmask, int modemask)
+chise_ds_open_feature_table (CHISE_DS *ds, const char *feature)
{
CHISE_Feature_Table* table;
+ size_t len = strlen (feature);
if (ds == NULL)
return NULL;
return NULL;
table->ds = ds;
- table->db = chise_open_attribute_table (ds->location,
- "system-char-id", feature,
- real_subtype,
- accessmask, modemask);
- if (table->db == NULL)
+ table->db = NULL;
+ table->access = 0;
+ table->name = (unsigned char*)malloc (len + 1);
+ if (table->name == NULL)
{
free (table);
return NULL;
}
+ strcpy (table->name, feature);
return table;
}
status = -1;
else
status = chise_close_attribute_table (table->db);
+
+ if (table->name == NULL)
+ status = -1;
+ else
+ {
+ free (table->name);
+ status = 0;
+ }
free (table);
return status;
}
{
unsigned char key_buf[8];
+ if (table->db == NULL)
+ {
+ CHISE_DS *ds = table->ds;
+
+ table->db = chise_open_attribute_table (ds->location,
+ "system-char-id", table->name,
+ ds->subtype,
+ DB_RDONLY, ds->modemask);
+ if (table->db == NULL)
+ return -1;
+ table->access = DB_RDONLY;
+ }
chise_format_char_id (cid, key_buf, 8);
return chise_get_attribute_table (table->db,
key_buf, valdatum);
unsigned char key_buf[8];
int status;
+ if (table->db == NULL)
+ {
+ CHISE_DS *ds = table->ds;
+
+ table->db = chise_open_attribute_table (ds->location,
+ "system-char-id", table->name,
+ ds->subtype,
+ DB_RDONLY, ds->modemask);
+ if (table->db == NULL)
+ return NULL;
+ table->access = DB_RDONLY;
+ }
chise_format_char_id (cid, key_buf, 8);
status = chise_get_attribute_table (table->db,
key_buf, &valdatum);
return buf;
}
-void
+int
chise_char_feature_value_iterate (CHISE_Feature feature,
int (*func) (CHISE_Char_ID cid,
CHISE_Feature feature,
DBC *dbcp;
int status;
+ if (feature->db == NULL)
+ {
+ CHISE_DS *ds = feature->ds;
+
+ feature->db
+ = chise_open_attribute_table (ds->location,
+ "system-char-id", feature->name,
+ ds->subtype,
+ DB_RDONLY, ds->modemask);
+ if (feature->db == NULL)
+ return -1;
+ feature->access = DB_RDONLY;
+ }
xzero (keydatum);
xzero (valdatum);
break;
}
dbcp->c_close (dbcp);
+ return 0;
}
struct CHISE_CCS_Table
{
CHISE_DS *ds;
+ unsigned char *name;
CHISE_Attribute_Table *db;
+ u_int32_t access;
};
CHISE_CCS_Table*
-chise_ds_open_ccs_table (CHISE_DS *ds, const char *ccs,
- DBTYPE real_subtype,
- u_int32_t accessmask, int modemask)
+chise_ds_open_ccs_table (CHISE_DS *ds, const char *ccs)
{
CHISE_CCS_Table* table;
+ size_t len = strlen (ccs);
if (ds == NULL)
return NULL;
return NULL;
table->ds = ds;
- table->db = chise_open_attribute_table (ds->location,
- ccs, "system-char-id",
- real_subtype,
- accessmask, modemask);
- if (table->db == NULL)
+ table->db = NULL;
+ table->access = 0;
+ table->name = (unsigned char*)malloc (len + 1);
+ if (table->name == NULL)
{
free (table);
return NULL;
}
+ strcpy (table->name, ccs);
return table;
}
return -1;
if (table->db == NULL)
- status = -1;
+ status = 0;
else
status = chise_close_attribute_table (table->db);
+
+ if (table->name == NULL)
+ status = -1;
+ else
+ {
+ free (table->name);
+ status = 0;
+ }
free (table);
return status;
}
+int
+chise_ccs_sync (CHISE_CCS ccs)
+{
+ int status;
+
+ if (ccs->db == NULL)
+ status = 0;
+ else
+ status = chise_close_attribute_table (ccs->db);
+ ccs->db = NULL;
+ ccs->access = 0;
+ return status;
+}
+
CHISE_Char_ID
chise_ccs_decode (CHISE_CCS ccs, int code_point)
{
int status = 0;
char key_buf[16];
+ if (ccs->db == NULL)
+ {
+ CHISE_DS *ds = ccs->ds;
+
+ ccs->db = chise_open_attribute_table (ds->location,
+ ccs->name, "system-char-id",
+ ds->subtype,
+ DB_RDONLY, ds->modemask);
+ if (ccs->db == NULL)
+ return -1;
+ ccs->access = DB_RDONLY;
+ }
+
sprintf(key_buf, "%d", code_point);
status = chise_get_attribute_table (ccs->db, key_buf, &valdatum);
if (!status)
}
int
-chise_ccst_put_char (CHISE_CCS_Table *table,
- int code_point, CHISE_Char_ID cid)
+chise_ccs_set_decoded_char (CHISE_CCS ccs,
+ int code_point, CHISE_Char_ID cid)
{
CHISE_Value valdatum;
char key_buf[16], val_buf[8];
+ if ((ccs->access & DB_CREATE) == 0)
+ {
+ if (ccs->db != NULL)
+ {
+ chise_close_attribute_table (ccs->db);
+ ccs->db = NULL;
+ }
+ ccs->access = 0;
+ }
+ if (ccs->db == NULL)
+ {
+ CHISE_DS *ds = ccs->ds;
+
+ ccs->db = chise_open_attribute_table (ds->location,
+ ccs->name, "system-char-id",
+ ds->subtype,
+ DB_CREATE, ds->modemask);
+ if (ccs->db == NULL)
+ return -1;
+ ccs->access = DB_CREATE;
+ }
+
sprintf(key_buf, "%d", code_point);
chise_format_char_id (cid, val_buf, 8);
- return chise_put_attribute_table (table->db, key_buf, val_buf);
+ return chise_put_attribute_table (ccs->db, key_buf, val_buf);
}