#include "chise.h"
#include "chise-name.h"
+const unsigned char chise_db_dir[] = CHISE_DB_DIR;
CHISE_Feature_Table*
chise_ds_open_feature_table (CHISE_DS *ds, const char *feature);
};
CHISE_DS*
-CHISE_DS_open (CHISE_DS_Type type, char *location,
+CHISE_DS_open (CHISE_DS_Type type, const unsigned char *location,
DBTYPE subtype, int modemask)
{
CHISE_DS *ds = (CHISE_DS*)malloc (sizeof (CHISE_DS));
return status;
}
-static int
+int
chise_feature_setup_db (CHISE_Feature feature, int writable)
{
u_int32_t access;
+ if (feature == NULL)
+ return -1;
+
if (writable)
{
if ((feature->access & DB_CREATE) == 0)
}
int
+chise_ccs_setup_db (CHISE_CCS ccs, int writable)
+{
+ u_int32_t access;
+
+ if (ccs == NULL)
+ return -1;
+
+ if (writable)
+ {
+ if ((ccs->access & DB_CREATE) == 0)
+ {
+ if (ccs->db != NULL)
+ {
+ CHISE_Attribute_Table_close (ccs->db);
+ ccs->db = NULL;
+ }
+ ccs->access = 0;
+ }
+ access = DB_CREATE;
+ }
+ else
+ access = DB_RDONLY;
+
+ if (ccs->db == NULL)
+ {
+ CHISE_DS *ds = ccs->ds;
+
+ ccs->db
+ = CHISE_Attribute_Table_open (ds->location,
+ ccs->name, "system-char-id",
+ ds->subtype, access, ds->modemask);
+ if (ccs->db == NULL)
+ return -1;
+ ccs->access = access;
+ }
+ return 0;
+}
+
+int
chise_ccs_sync (CHISE_CCS ccs)
{
int status;
if (ccs == NULL)
return -1;
- if (ccs->db == NULL)
- {
- CHISE_DS *ds = ccs->ds;
-
- ccs->db = CHISE_Attribute_Table_open (ds->location,
- ccs->name, "system-char-id",
- ds->subtype,
- DB_RDONLY, ds->modemask);
- if (ccs->db == NULL)
- return -1;
- ccs->access = DB_RDONLY;
- }
+ if (chise_ccs_setup_db (ccs, 0))
+ return -1;
sprintf(key_buf, "%d", code_point);
status = chise_attribute_table_get (ccs->db, key_buf, &valdatum);
if (ccs == NULL)
return -1;
- if ((ccs->access & DB_CREATE) == 0)
- {
- if (ccs->db != NULL)
- {
- CHISE_Attribute_Table_close (ccs->db);
- ccs->db = NULL;
- }
- ccs->access = 0;
- }
- if (ccs->db == NULL)
- {
- CHISE_DS *ds = ccs->ds;
-
- ccs->db
- = CHISE_Attribute_Table_open (ds->location,
- ccs->name, "system-char-id",
- ds->subtype, DB_CREATE, ds->modemask);
- if (ccs->db == NULL)
- return -1;
- ccs->access = DB_CREATE;
- }
+ if (chise_ccs_setup_db (ccs, 1))
+ return -1;
sprintf(key_buf, "%d", code_point);
chise_format_char_id (cid, val_buf, 8);