update.
[chise/libchise.git] / chise.c
diff --git a/chise.c b/chise.c
index 43c60e7..da12d1b 100644 (file)
--- a/chise.c
+++ b/chise.c
@@ -1,4 +1,7 @@
 #include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
 #endif
@@ -127,7 +130,7 @@ chise_ds_get_feature (CHISE_DS *ds, const unsigned char *feature)
   return ft;
 }
 
-CHISE_CCS_Table*
+CHISE_CCS
 chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *ccs)
 {
   CHISE_CCS_Table* ct;
@@ -244,6 +247,35 @@ chise_feature_setup_db (CHISE_Feature feature, int writable)
 }
 
 int
+chise_feature_sync (CHISE_Feature feature)
+{
+  int status;
+
+  if (feature->db == NULL)
+    status = 0;
+  else
+    status = CHISE_Attribute_Table_close (feature->db);
+  feature->db = NULL;
+  feature->access = 0;
+  return status;
+}
+
+int
+chise_char_set_feature_value (CHISE_Char_ID cid,
+                             CHISE_Feature feature,
+                             unsigned char *value)
+{
+  unsigned char key_buf[8];
+
+  if (feature == NULL)
+    return -1;
+  if (chise_feature_setup_db (feature, 1))
+    return -1;
+  chise_format_char_id (cid, key_buf, 8);
+  return chise_attribute_table_put (feature->db, key_buf, value);
+}
+
+int
 chise_char_load_feature_value (CHISE_Char_ID cid,
                               CHISE_Feature_Table *table,
                               CHISE_Value *valdatum)
@@ -391,6 +423,9 @@ chise_ccs_decode (CHISE_CCS ccs, int code_point)
   int status = 0;
   char key_buf[16];
 
+  if (ccs == NULL)
+    return -1;
+
   if (ccs->db == NULL)
     {
       CHISE_DS *ds = ccs->ds;
@@ -423,6 +458,9 @@ chise_ccs_set_decoded_char (CHISE_CCS ccs,
 {
   char key_buf[16], val_buf[8];
 
+  if (ccs == NULL)
+    return -1;
+
   if ((ccs->access & DB_CREATE) == 0)
     {
       if (ccs->db != NULL)
@@ -462,11 +500,15 @@ CHISE_Attribute_Table_open (const unsigned char *db_dir,
   int len, flen, i;
   int size;
   char *db_file_name, *sp;
+  struct stat statbuf;
 
   status = db_create (&dbase, NULL, 0);
   if (status)
     return NULL;
 
+  if ( (accessmask & DB_CREATE) && stat (db_dir, &statbuf) )
+    mkdir (db_dir, modemask);
+
   len = strlen (db_dir);
   flen = strlen (feature);
   size = len + strlen (encoding) + flen * 3 + 4;
@@ -478,6 +520,10 @@ CHISE_Attribute_Table_open (const unsigned char *db_dir,
       db_file_name[len] = '\0';
     }
   strcat (db_file_name, encoding);
+
+  if ( (accessmask & DB_CREATE) && stat (db_file_name, &statbuf) )
+    mkdir (db_file_name, modemask);
+
   strcat (db_file_name, "/");
   /* strcat (db_file_name, feature); */
   sp = &db_file_name[strlen (db_file_name)];