(concord_genre_get_name): New function.
[chise/concord.git] / concord.c
index 38583e8..6ed7bb6 100644 (file)
--- a/concord.c
+++ b/concord.c
@@ -57,6 +57,9 @@ int concord_close_feature (CONCORD_Feature feature);
 CONCORD_INDEX
 concord_genre_open_index (CONCORD_Genre genre, const unsigned char* index);
 
+CONCORD_Feature
+concord_genre_get_feature_0 (CONCORD_Genre genre, const unsigned char* name);
+
 int concord_close_index (CONCORD_INDEX table);
 
 
@@ -123,7 +126,7 @@ concord_open_ds (CONCORD_Backend_Type type, const unsigned char* location,
 }
 
 int
-CONCORD_DS_close (CONCORD_DS ds)
+concord_close_ds (CONCORD_DS ds)
 {
   if (ds->location != NULL)
     free (ds->location);
@@ -140,7 +143,7 @@ concord_ds_location (CONCORD_DS ds)
 }
 
 int
-concord_ds_set_object_nil (CONCORD_DS ds, CONCORD_Object object_nil)
+concord_ds_set_object_failure (CONCORD_DS ds, CONCORD_Object object_nil)
 {
   ds->object_nil = object_nil;
   return 0;
@@ -343,6 +346,12 @@ concord_close_genre (CONCORD_Genre genre)
   return status;
 }
 
+unsigned char*
+concord_genre_get_name (CONCORD_Genre genre)
+{
+  return genre->name;
+}
+
 CONCORD_DS
 concord_genre_get_data_source (CONCORD_Genre genre)
 {
@@ -447,7 +456,7 @@ concord_genre_foreach_feature_name (CONCORD_Genre genre,
 }
 
 CONCORD_Feature
-concord_genre_get_feature (CONCORD_Genre genre, const unsigned char* name)
+concord_genre_get_feature_0 (CONCORD_Genre genre, const unsigned char* name)
 {
   CONCORD_Feature feature;
 
@@ -467,6 +476,37 @@ concord_genre_get_feature (CONCORD_Genre genre, const unsigned char* name)
   return feature;
 }
 
+CONCORD_Feature
+concord_genre_get_feature (CONCORD_Genre genre, const unsigned char* name)
+{
+  CONCORD_Genre g_feature
+    = concord_ds_get_genre (genre->ds, "feature");
+
+  if (g_feature != NULL)
+    {
+      CONCORD_Feature p_true_name
+       = concord_genre_get_feature_0 (g_feature, "true-name");
+
+      if (g_feature != NULL)
+       {
+         CONCORD_String_Tank s_true_name;
+         int status
+           = concord_obj_get_feature_value_string (name,
+                                                   p_true_name,
+                                                   &s_true_name);
+         if (status == 0)
+           {
+             unsigned char* t_name = alloca (s_true_name.size + 1);
+
+             strncpy (t_name, s_true_name.data, s_true_name.size);
+             t_name[s_true_name.size] = '\0';
+             return concord_genre_get_feature_0 (genre, t_name);
+           }
+       }
+    }
+  return concord_genre_get_feature_0 (genre, name);
+}
+
 CONCORD_INDEX
 concord_genre_get_index (CONCORD_Genre genre, const unsigned char* name)
 {
@@ -553,6 +593,12 @@ concord_feature_get_name (CONCORD_Feature feature)
   return feature->name;
 }
 
+CONCORD_Genre
+concord_feature_get_genre (CONCORD_Feature feature)
+{
+  return feature->genre;
+}
+
 int
 concord_feature_setup_db (CONCORD_Feature feature, int writable)
 {
@@ -608,9 +654,9 @@ concord_feature_sync (CONCORD_Feature feature)
 }
 
 int
-concord_stroid_set_feature_str (const unsigned char* object_id,
-                               CONCORD_Feature feature,
-                               unsigned char* value)
+concord_obj_put_feature_value_str (const unsigned char* object_id,
+                                  CONCORD_Feature feature,
+                                  unsigned char* value)
 {
   if (feature == NULL)
     return -1;
@@ -620,9 +666,9 @@ concord_stroid_set_feature_str (const unsigned char* object_id,
 }
 
 int
-concord_stroid_get_feature_string (const unsigned char* object_id,
-                                  CONCORD_Feature feature,
-                                  CONCORD_String value)
+concord_obj_get_feature_value_string (const unsigned char* object_id,
+                                     CONCORD_Feature feature,
+                                     CONCORD_String value)
 {
   int status;
 
@@ -633,8 +679,8 @@ concord_stroid_get_feature_string (const unsigned char* object_id,
 }
 
 CONCORD_Object
-concord_stroid_get_feature_object (const unsigned char* object_id,
-                                  CONCORD_Feature feature)
+concord_obj_get_feature_value (const unsigned char* object_id,
+                              CONCORD_Feature feature)
 {
   DBT valdatum;
   int status;
@@ -648,9 +694,9 @@ concord_stroid_get_feature_object (const unsigned char* object_id,
 }
 
 unsigned char*
-concord_stroid_gets_feature (const unsigned char* object_id,
-                            CONCORD_Feature feature,
-                            unsigned char* dst, size_t size)
+concord_obj_gets_feature_value (const unsigned char* object_id,
+                               CONCORD_Feature feature,
+                               unsigned char* dst, size_t size)
 {
   DBT valdatum;
   int status;
@@ -668,10 +714,10 @@ concord_stroid_gets_feature (const unsigned char* object_id,
 }
 
 int
-concord_feature_foreach_object_string (CONCORD_Feature feature,
-                                      int (*func)(CONCORD_String object_id,
-                                                  CONCORD_Feature feature,
-                                                  CONCORD_String value))
+concord_feature_foreach_obj_string (CONCORD_Feature feature,
+                                   int (*func)(CONCORD_String object_id,
+                                               CONCORD_Feature feature,
+                                               CONCORD_String value))
 {
   CONCORD_String_Tank key, value;
   DBC *dbcp;
@@ -810,29 +856,29 @@ concord_index_sync (CONCORD_INDEX index)
 }
 
 int
-concord_index_strid_get_object_string (CONCORD_INDEX index,
-                                      const unsigned char* strid,
-                                      CONCORD_String object_id)
+concord_index_strid_put_obj (CONCORD_INDEX index,
+                            const unsigned char* strid,
+                            unsigned char* object_id)
 {
   if (index == NULL)
     return -1;
 
-  if (concord_index_setup_db (index, 0))
+  if (concord_index_setup_db (index, 1))
     return -1;  
 
-  return CONCORD_BDB_get (index->db, strid, object_id);
+  return CONCORD_BDB_put (index->db, strid, object_id);
 }
 
 int
-concord_index_strid_set_object_str (CONCORD_INDEX index,
+concord_index_strid_get_obj_string (CONCORD_INDEX index,
                                    const unsigned char* strid,
-                                   unsigned char* object_id)
+                                   CONCORD_String object_id)
 {
   if (index == NULL)
     return -1;
 
-  if (concord_index_setup_db (index, 1))
+  if (concord_index_setup_db (index, 0))
     return -1;  
 
-  return CONCORD_BDB_put (index->db, strid, object_id);
+  return CONCORD_BDB_get (index->db, strid, object_id);
 }