(struct CHISE_DS): Add new member `subtype' and `modemask'.
authortomo <tomo>
Thu, 2 Oct 2003 09:52:48 +0000 (09:52 +0000)
committertomo <tomo>
Thu, 2 Oct 2003 09:52:48 +0000 (09:52 +0000)
(chise_open_data_source): Add new arguments `subtype' and `modemask'.
(chise_ds_get_feature): Delete arguments `real_subtype', `accessmask',
`modemask'.
(chise_ds_get_ccs): Likewise.
(struct CHISE_Feature_Table): Add new member `name' and `access'.
(chise_ds_open_feature_table): Delete arguments `real_subtype',
`accessmask', `modemask'.
(chise_ft_close): Release `table->name'.
(chise_char_load_feature_value): Setup `table->db'.
(chise_char_gets_feature_value): Likewise.
(chise_char_feature_value_iterate): Return an integer value; setup
`feature->db'.
(struct CHISE_CCS_Table): Add new member `name' and `access'.
(chise_ds_open_ccs_table): Delete arguments `real_subtype',
`accessmask', `modemask'.
(chise_ccst_close): Release `table->name'.
(chise_ccs_sync): New function.
(chise_ccs_decode): Setup `ccs->db'.
(chise_ccs_set_decoded_char): Renamed from `chise_ccst_put_char';
setup `ccs->db'.

chise.c

diff --git a/chise.c b/chise.c
index 93d35b0..3da6fd3 100644 (file)
--- a/chise.c
+++ b/chise.c
@@ -21,6 +21,18 @@ strnlen (register const char *s, register int maxlen)
 #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*
@@ -244,10 +256,13 @@ struct CHISE_DS
   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);
@@ -256,6 +271,8 @@ chise_open_data_source (CHISE_DS_Type type, char *location)
     return NULL;
 
   ds->type = type;
+  ds->subtype = subtype;
+  ds->modemask = modemask;
   ds->location = (unsigned char*)malloc (len + 1);
   if (ds->location == NULL)
     {
@@ -295,9 +312,7 @@ chise_ds_close (CHISE_DS *ds)
 }
 
 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;
 
@@ -305,9 +320,7 @@ chise_ds_get_feature (CHISE_DS *ds, const unsigned char *feature,
   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;
 
@@ -320,9 +333,7 @@ chise_ds_get_feature (CHISE_DS *ds, const unsigned char *feature,
 }
 
 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;
 
@@ -330,9 +341,7 @@ chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *ccs,
   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;
 
@@ -348,15 +357,16 @@ chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *ccs,
 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;
@@ -366,15 +376,15 @@ chise_ds_open_feature_table (CHISE_DS *ds, const char *feature,
     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;
 }
 
@@ -390,6 +400,14 @@ chise_ft_close (CHISE_Feature_Table *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;
 }
@@ -401,6 +419,18 @@ chise_char_load_feature_value (CHISE_Char_ID cid,
 {
   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);
@@ -415,6 +445,18 @@ chise_char_gets_feature_value (CHISE_Char_ID cid,
   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);
@@ -427,7 +469,7 @@ chise_char_gets_feature_value (CHISE_Char_ID cid,
   return buf;
 }
 
-void
+int
 chise_char_feature_value_iterate (CHISE_Feature feature,
                                  int (*func) (CHISE_Char_ID cid,
                                               CHISE_Feature feature,
@@ -437,6 +479,19 @@ chise_char_feature_value_iterate (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);
 
@@ -454,21 +509,23 @@ chise_char_feature_value_iterate (CHISE_Feature feature,
        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;
@@ -478,15 +535,15 @@ chise_ds_open_ccs_table (CHISE_DS *ds, const char *ccs,
     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;
 }
 
@@ -499,13 +556,35 @@ chise_ccst_close (CHISE_CCS_Table *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)
 {
@@ -513,6 +592,19 @@ 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)
@@ -527,15 +619,37 @@ chise_ccs_decode (CHISE_CCS ccs, int code_point)
 }
 
 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);
 }