projects
/
chise
/
concord.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
(concord_object_get_feature_value): If `concord_current_env' is not
[chise/concord.git]
/
concord.c
diff --git
a/concord.c
b/concord.c
index
6ed7bb6
..
71d5d4d
100644
(file)
--- a/
concord.c
+++ b/
concord.c
@@
-1,4
+1,4
@@
-/* Copyright (C) 2003,2004,2005 MORIOKA Tomohiko
+/* Copyright (C) 2003, 2004, 2005, 2006, 2011, 2013 MORIOKA Tomohiko
This file is part of the CONCORD Library.
The CONCORD Library is free software; you can redistribute it and/or
This file is part of the CONCORD Library.
The CONCORD Library is free software; you can redistribute it and/or
@@
-21,11
+21,9
@@
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
#include "sysdep.h"
#include "concord.h"
#include "sysdep.h"
#include "concord.h"
+#include "cos-i.h"
#include "concord-name.h"
#include "concord-bdb.h"
#include "concord-name.h"
#include "concord-bdb.h"
@@
-42,35
+40,29
@@
CONCORD_String_data (const CONCORD_String s)
return s->data;
}
return s->data;
}
-CONCORD_Genre
-concord_ds_open_genre (CONCORD_DS ds, const unsigned char* name);
-
-int concord_close_genre (CONCORD_Genre genre);
+CONCORD_Genre concord_ds_open_genre (CONCORD_DS ds, const char* name);
CONCORD_Feature
CONCORD_Feature
-concord_genre_open_feature (CONCORD_Genre genre, const unsigned char* name);
-
-int concord_close_feature (CONCORD_Feature feature);
+concord_genre_open_feature (CONCORD_Genre genre, const char* name);
CONCORD_INDEX
CONCORD_INDEX
-concord_genre_open_index (CONCORD_Genre genre, const unsigned char* index);
+concord_genre_open_index (CONCORD_Genre genre, const char* index);
CONCORD_Feature
CONCORD_Feature
-concord_genre_get_feature_0 (CONCORD_Genre genre, const unsigned char* name);
-
-int concord_close_index (CONCORD_INDEX table);
+concord_genre_get_feature_0 (CONCORD_Genre genre, const char* name);
CONCORD_Object
concord_default_read_object (const unsigned char* string, size_t length);
CONCORD_Object
concord_default_read_object (const unsigned char* string, size_t length);
-struct CONCORD_DS_Table
+struct COS_DS_ent
{
{
+ COS_Object_Header header;
CONCORD_Backend_Type type;
CONCORD_Backend_Type type;
- unsigned char *location;
+ char *location;
CONCORD_NAME_TABLE* genre_names;
DBTYPE subtype;
int modemask;
CONCORD_NAME_TABLE* genre_names;
DBTYPE subtype;
int modemask;
@@
-86,16
+78,16
@@
concord_default_read_object (const unsigned char* str, size_t length)
if (buf == NULL)
return NULL;
if (buf == NULL)
return NULL;
- strncpy (buf, str, length);
+ strncpy ((char*)buf, (char*)str, length);
buf[length] = '\0';
buf[length] = '\0';
- return buf;
+ return (CONCORD_Object)buf;
}
CONCORD_DS
}
CONCORD_DS
-concord_open_ds (CONCORD_Backend_Type type, const unsigned char* location,
+concord_open_ds (CONCORD_Backend_Type type, const char* location,
int subtype, int modemask)
{
int subtype, int modemask)
{
- CONCORD_DS ds = (CONCORD_DS)malloc (sizeof (CONCORD_DS_Table));
+ CONCORD_DS ds = COS_ALLOCATE_OBJECT (DS);
size_t len = strlen (location);
if (ds == NULL)
size_t len = strlen (location);
if (ds == NULL)
@@
-104,7
+96,7
@@
concord_open_ds (CONCORD_Backend_Type type, const unsigned char* location,
ds->type = type;
ds->subtype = ( (subtype != 0) ? subtype : DB_HASH );
ds->modemask = modemask;
ds->type = type;
ds->subtype = ( (subtype != 0) ? subtype : DB_HASH );
ds->modemask = modemask;
- ds->location = (unsigned char*)malloc (len + 1);
+ ds->location = (char*)malloc (len + 1);
if (ds->location == NULL)
goto location_failure;
if (ds->location == NULL)
goto location_failure;
@@
-136,7
+128,7
@@
concord_close_ds (CONCORD_DS ds)
return 0;
}
return 0;
}
-unsigned char*
+char*
concord_ds_location (CONCORD_DS ds)
{
return ds->location;
concord_ds_location (CONCORD_DS ds)
{
return ds->location;
@@
-160,7
+152,7
@@
concord_ds_set_read_object_function (CONCORD_DS ds,
}
CONCORD_Genre
}
CONCORD_Genre
-concord_ds_get_genre (CONCORD_DS ds, const unsigned char* name)
+concord_ds_get_genre (CONCORD_DS ds, const char* name)
{
CONCORD_Genre genre;
{
CONCORD_Genre genre;
@@
-182,10
+174,9
@@
concord_ds_get_genre (CONCORD_DS ds, const unsigned char* name)
int
concord_ds_foreach_genre_name (CONCORD_DS ds,
int
concord_ds_foreach_genre_name (CONCORD_DS ds,
- int (*func) (CONCORD_DS ds,
- unsigned char* name))
+ int (*func) (CONCORD_DS ds, char* name))
{
{
- unsigned char* dname = ds->location;
+ char* dname = ds->location;
DIR *dir;
struct dirent *de;
DIR *dir;
struct dirent *de;
@@
-199,10
+190,10
@@
concord_ds_foreach_genre_name (CONCORD_DS ds,
{
int i, need_to_decode = 0;
unsigned char *cp;
{
int i, need_to_decode = 0;
unsigned char *cp;
- unsigned char *name;
+ char *name;
unsigned char *np;
unsigned char *np;
- for (cp = de->d_name, i = 0; *cp != '\0'; i++)
+ for (cp = (unsigned char*)de->d_name, i = 0; *cp != '\0'; i++)
{
if (*cp++ == '%')
need_to_decode = 1;
{
if (*cp++ == '%')
need_to_decode = 1;
@@
-213,9
+204,9
@@
concord_ds_foreach_genre_name (CONCORD_DS ds,
int ch, c[2];
int hex[2];
int ch, c[2];
int hex[2];
- name = (unsigned char *) alloca (i);
- cp = de->d_name;
- np = name;
+ name = (char*) alloca (i);
+ cp = (unsigned char*)de->d_name;
+ np = (unsigned char*)name;
while ( (ch = *cp++) != '\0')
{
while ( (ch = *cp++) != '\0')
{
@@
-271,16
+262,17
@@
concord_ds_foreach_genre_name (CONCORD_DS ds,
}
}
-struct CONCORD_Genre_Table
+struct COS_Genre_ent
{
{
+ COS_Object_Header header;
CONCORD_DS ds;
CONCORD_DS ds;
- unsigned char *name;
+ char *name;
CONCORD_NAME_TABLE* feature_names;
CONCORD_NAME_TABLE* index_names;
};
CONCORD_Genre
CONCORD_NAME_TABLE* feature_names;
CONCORD_NAME_TABLE* index_names;
};
CONCORD_Genre
-concord_ds_open_genre (CONCORD_DS ds, const unsigned char* name)
+concord_ds_open_genre (CONCORD_DS ds, const char* name)
{
CONCORD_Genre genre;
size_t len = strlen (name);
{
CONCORD_Genre genre;
size_t len = strlen (name);
@@
-288,12
+280,12
@@
concord_ds_open_genre (CONCORD_DS ds, const unsigned char* name)
if (ds == NULL)
return NULL;
if (ds == NULL)
return NULL;
- genre = (CONCORD_Genre)malloc (sizeof (CONCORD_Genre_Table));
+ genre = COS_ALLOCATE_OBJECT (Genre);
if (genre == NULL)
return NULL;
genre->ds = ds;
if (genre == NULL)
return NULL;
genre->ds = ds;
- genre->name = (unsigned char*)malloc (len + 1);
+ genre->name = (char*)malloc (len + 1);
if (genre->name == NULL)
{
free (genre);
if (genre->name == NULL)
{
free (genre);
@@
-346,7
+338,7
@@
concord_close_genre (CONCORD_Genre genre)
return status;
}
return status;
}
-unsigned char*
+char*
concord_genre_get_name (CONCORD_Genre genre)
{
return genre->name;
concord_genre_get_name (CONCORD_Genre genre)
{
return genre->name;
@@
-361,9
+353,9
@@
concord_genre_get_data_source (CONCORD_Genre genre)
int
concord_genre_foreach_feature_name (CONCORD_Genre genre,
int (*func) (CONCORD_Genre genre,
int
concord_genre_foreach_feature_name (CONCORD_Genre genre,
int (*func) (CONCORD_Genre genre,
- unsigned char* name))
+ char* name))
{
{
- unsigned char *dname
+ char *dname
= alloca (strlen (genre->ds->location)
+ 1 + strlen (genre->name) + sizeof ("/feature") + 1);
DIR *dir;
= alloca (strlen (genre->ds->location)
+ 1 + strlen (genre->name) + sizeof ("/feature") + 1);
DIR *dir;
@@
-384,10
+376,10
@@
concord_genre_foreach_feature_name (CONCORD_Genre genre,
{
int i, need_to_decode = 0;
unsigned char *cp;
{
int i, need_to_decode = 0;
unsigned char *cp;
- unsigned char *name;
+ char *name;
unsigned char *np;
unsigned char *np;
- for (cp = de->d_name, i = 0; *cp != '\0'; i++)
+ for (cp = (unsigned char*)de->d_name, i = 0; *cp != '\0'; i++)
{
if (*cp++ == '%')
need_to_decode = 1;
{
if (*cp++ == '%')
need_to_decode = 1;
@@
-398,9
+390,9
@@
concord_genre_foreach_feature_name (CONCORD_Genre genre,
int ch, c[2];
int hex[2];
int ch, c[2];
int hex[2];
- name = (unsigned char *) alloca (i);
- cp = de->d_name;
- np = name;
+ name = (char*) alloca (i);
+ cp = (unsigned char*)de->d_name;
+ np = (unsigned char*)name;
while ( (ch = *cp++) != '\0')
{
while ( (ch = *cp++) != '\0')
{
@@
-456,7
+448,7
@@
concord_genre_foreach_feature_name (CONCORD_Genre genre,
}
CONCORD_Feature
}
CONCORD_Feature
-concord_genre_get_feature_0 (CONCORD_Genre genre, const unsigned char* name)
+concord_genre_get_feature_0 (CONCORD_Genre genre, const char* name)
{
CONCORD_Feature feature;
{
CONCORD_Feature feature;
@@
-477,7
+469,7
@@
concord_genre_get_feature_0 (CONCORD_Genre genre, const unsigned char* name)
}
CONCORD_Feature
}
CONCORD_Feature
-concord_genre_get_feature (CONCORD_Genre genre, const unsigned char* name)
+concord_genre_get_feature (CONCORD_Genre genre, const char* name)
{
CONCORD_Genre g_feature
= concord_ds_get_genre (genre->ds, "feature");
{
CONCORD_Genre g_feature
= concord_ds_get_genre (genre->ds, "feature");
@@
-496,7
+488,7
@@
concord_genre_get_feature (CONCORD_Genre genre, const unsigned char* name)
&s_true_name);
if (status == 0)
{
&s_true_name);
if (status == 0)
{
- unsigned char* t_name = alloca (s_true_name.size + 1);
+ 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';
strncpy (t_name, s_true_name.data, s_true_name.size);
t_name[s_true_name.size] = '\0';
@@
-508,7
+500,7
@@
concord_genre_get_feature (CONCORD_Genre genre, const unsigned char* name)
}
CONCORD_INDEX
}
CONCORD_INDEX
-concord_genre_get_index (CONCORD_Genre genre, const unsigned char* name)
+concord_genre_get_index (CONCORD_Genre genre, const char* name)
{
CONCORD_INDEX index;
{
CONCORD_INDEX index;
@@
-529,16
+521,17
@@
concord_genre_get_index (CONCORD_Genre genre, const unsigned char* name)
}
}
-struct CONCORD_Feature_Table
+struct COS_Feature_ent
{
{
+ COS_Object_Header header;
CONCORD_Genre genre;
CONCORD_Genre genre;
- unsigned char* name;
+ char* name;
DB* db;
u_int32_t access;
};
CONCORD_Feature
DB* db;
u_int32_t access;
};
CONCORD_Feature
-concord_genre_open_feature (CONCORD_Genre genre, const unsigned char* feature)
+concord_genre_open_feature (CONCORD_Genre genre, const char* feature)
{
CONCORD_Feature table;
size_t len = strlen (feature);
{
CONCORD_Feature table;
size_t len = strlen (feature);
@@
-546,14
+539,14
@@
concord_genre_open_feature (CONCORD_Genre genre, const unsigned char* feature)
if (genre == NULL)
return NULL;
if (genre == NULL)
return NULL;
- table = (CONCORD_Feature)malloc (sizeof (CONCORD_Feature_Table));
+ table = COS_ALLOCATE_OBJECT (Feature);
if (table == NULL)
return NULL;
table->genre = genre;
table->db = NULL;
table->access = 0;
if (table == NULL)
return NULL;
table->genre = genre;
table->db = NULL;
table->access = 0;
- table->name = (unsigned char*)malloc (len + 1);
+ table->name = (char*)malloc (len + 1);
if (table->name == NULL)
{
free (table);
if (table->name == NULL)
{
free (table);
@@
-587,7
+580,7
@@
concord_close_feature (CONCORD_Feature feature)
return status;
}
return status;
}
-unsigned char*
+char*
concord_feature_get_name (CONCORD_Feature feature)
{
return feature->name;
concord_feature_get_name (CONCORD_Feature feature)
{
return feature->name;
@@
-654,7
+647,7
@@
concord_feature_sync (CONCORD_Feature feature)
}
int
}
int
-concord_obj_put_feature_value_str (const unsigned char* object_id,
+concord_obj_put_feature_value_str (const char* object_id,
CONCORD_Feature feature,
unsigned char* value)
{
CONCORD_Feature feature,
unsigned char* value)
{
@@
-666,7
+659,7
@@
concord_obj_put_feature_value_str (const unsigned char* object_id,
}
int
}
int
-concord_obj_get_feature_value_string (const unsigned char* object_id,
+concord_obj_get_feature_value_string (const char* object_id,
CONCORD_Feature feature,
CONCORD_String value)
{
CONCORD_Feature feature,
CONCORD_String value)
{
@@
-679,7
+672,7
@@
concord_obj_get_feature_value_string (const unsigned char* object_id,
}
CONCORD_Object
}
CONCORD_Object
-concord_obj_get_feature_value (const unsigned char* object_id,
+concord_obj_get_feature_value (const char* object_id,
CONCORD_Feature feature)
{
DBT valdatum;
CONCORD_Feature feature)
{
DBT valdatum;
@@
-694,7
+687,7
@@
concord_obj_get_feature_value (const unsigned char* object_id,
}
unsigned char*
}
unsigned char*
-concord_obj_gets_feature_value (const unsigned char* object_id,
+concord_obj_gets_feature_value (const char* object_id,
CONCORD_Feature feature,
unsigned char* dst, size_t size)
{
CONCORD_Feature feature,
unsigned char* dst, size_t size)
{
@@
-708,7
+701,7
@@
concord_obj_gets_feature_value (const unsigned char* object_id,
return NULL;
if (size < valdatum.size)
return NULL;
return NULL;
if (size < valdatum.size)
return NULL;
- strncpy (dst, valdatum.data, valdatum.size);
+ strncpy ((char*)dst, valdatum.data, valdatum.size);
dst[valdatum.size] = '\0';
return dst;
}
dst[valdatum.size] = '\0';
return dst;
}
@@
-743,16
+736,17
@@
concord_feature_foreach_obj_string (CONCORD_Feature feature,
}
}
-struct CONCORD_INDEX_Table
+struct COS_Feature_INDEX_ent
{
{
+ COS_Object_Header header;
CONCORD_Genre genre;
CONCORD_Genre genre;
- unsigned char *name;
+ char *name;
DB* db;
u_int32_t access;
};
CONCORD_INDEX
DB* db;
u_int32_t access;
};
CONCORD_INDEX
-concord_genre_open_index (CONCORD_Genre genre, const unsigned char* index)
+concord_genre_open_index (CONCORD_Genre genre, const char* index)
{
CONCORD_INDEX table;
size_t len = strlen (index);
{
CONCORD_INDEX table;
size_t len = strlen (index);
@@
-760,14
+754,14
@@
concord_genre_open_index (CONCORD_Genre genre, const unsigned char* index)
if (genre == NULL)
return NULL;
if (genre == NULL)
return NULL;
- table = (CONCORD_INDEX)malloc (sizeof (CONCORD_INDEX_Table));
+ table = COS_ALLOCATE_OBJECT (Feature_INDEX);
if (table == NULL)
return NULL;
table->genre = genre;
table->db = NULL;
table->access = 0;
if (table == NULL)
return NULL;
table->genre = genre;
table->db = NULL;
table->access = 0;
- table->name = (unsigned char*)malloc (len + 1);
+ table->name = (char*)malloc (len + 1);
if (table->name == NULL)
{
free (table);
if (table->name == NULL)
{
free (table);
@@
-801,6
+795,18
@@
concord_close_index (CONCORD_INDEX table)
return status;
}
return status;
}
+char*
+concord_index_get_name (CONCORD_INDEX index)
+{
+ return index->name;
+}
+
+CONCORD_Genre
+concord_index_get_genre (CONCORD_INDEX index)
+{
+ return index->genre;
+}
+
int
concord_index_setup_db (CONCORD_INDEX index, int writable)
{
int
concord_index_setup_db (CONCORD_INDEX index, int writable)
{
@@
-857,8
+863,7
@@
concord_index_sync (CONCORD_INDEX index)
int
concord_index_strid_put_obj (CONCORD_INDEX index,
int
concord_index_strid_put_obj (CONCORD_INDEX index,
- const unsigned char* strid,
- unsigned char* object_id)
+ const char* strid, char* object_id)
{
if (index == NULL)
return -1;
{
if (index == NULL)
return -1;
@@
-866,12
+871,12
@@
concord_index_strid_put_obj (CONCORD_INDEX index,
if (concord_index_setup_db (index, 1))
return -1;
if (concord_index_setup_db (index, 1))
return -1;
- return CONCORD_BDB_put (index->db, strid, object_id);
+ return CONCORD_BDB_put (index->db, strid, (unsigned char*)object_id);
}
int
concord_index_strid_get_obj_string (CONCORD_INDEX index,
}
int
concord_index_strid_get_obj_string (CONCORD_INDEX index,
- const unsigned char* strid,
+ const char* strid,
CONCORD_String object_id)
{
if (index == NULL)
CONCORD_String object_id)
{
if (index == NULL)