Include "chise-name.h".
authortomo <tomo>
Thu, 28 Aug 2003 16:33:44 +0000 (16:33 +0000)
committertomo <tomo>
Thu, 28 Aug 2003 16:33:44 +0000 (16:33 +0000)
(CHISE_DS): Add new members `feature_names' and `ccs_names'.
(chise_open_data_source): Setup ds->feature_names and ds->ccs_names.
(chise_ds_close): Release ds->feature_names and ds->ccs_names.
(chise_ds_get_feature): New function.
(chise_ds_get_ccs): New function.
(chise_char_load_feature_value): Renamed from `chise_ft_get_value';
modify interface.
(chise_char_gets_feature_value): New function.
(chise_char_feature_value_iterate): Renamed from `chise_ft_iterate';
modify interface.
(CHISE_CCS_Table): Renamed from `CHISE_Decoding_Table'.
(chise_ds_open_ccs_table): Renamed from
`chise_ds_open_decoding_table'.
(chise_ccst_close): Renamed from `chise_dt_close'.
(chise_ccs_decode): Renamed from `chise_dt_get_char'.
(chise_ccst_put_char): Renamed from `chise_dt_put_char'.

chise.c

diff --git a/chise.c b/chise.c
index e27d7bc..93d35b0 100644 (file)
--- a/chise.c
+++ b/chise.c
@@ -19,6 +19,7 @@ strnlen (register const char *s, register int maxlen)
 #endif
 
 #include "chise.h"
+#include "chise-name.h"
 
 typedef DB CHISE_Attribute_Table;
 
@@ -241,6 +242,8 @@ struct CHISE_DS
 {
   CHISE_DS_Type type;
   unsigned char *location;
+  CHISE_NAME_TABLE* feature_names;
+  CHISE_NAME_TABLE* ccs_names;
 };
 
 CHISE_DS*
@@ -260,6 +263,21 @@ chise_open_data_source (CHISE_DS_Type type, char *location)
       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;
 }
 
@@ -268,10 +286,64 @@ chise_ds_close (CHISE_DS *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
 {
@@ -323,8 +395,9 @@ chise_ft_close (CHISE_Feature_Table *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];
 
@@ -333,10 +406,32 @@ chise_ft_get_value (CHISE_Feature_Table *table,
                                    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;
@@ -345,7 +440,7 @@ chise_ft_iterate (CHISE_Feature_Table *table,
   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))
@@ -355,30 +450,30 @@ chise_ft_iterate (CHISE_Feature_Table *table,
       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;
 
@@ -396,7 +491,7 @@ chise_ds_open_decoding_table (CHISE_DS *ds, const char *ccs,
 }
 
 int
-chise_dt_close (CHISE_Decoding_Table *table)
+chise_ccst_close (CHISE_CCS_Table *table)
 {
   int status;
 
@@ -412,14 +507,14 @@ chise_dt_close (CHISE_Decoding_Table *table)
 }
 
 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
@@ -432,8 +527,8 @@ chise_dt_get_char (CHISE_Decoding_Table *table, int code_point)
 }
 
 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];