From: MORIOKA Tomohiko Date: Mon, 1 Apr 2013 05:28:36 +0000 (+0900) Subject: - Move code to include "config.h" into sysdep.h. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=b789ce503b76cde11d5b8d4539684ed95978eb74;p=chise%2Fconcord.git - Move code to include "config.h" into sysdep.h. - Include "cos-i.h". (concord_close_genre): Move prototype into cos-i.h. (concord_close_feature): Likewise. (concord_close_index): Likewise. (struct CONCORD_Object_Header): Renamed to `COS_Object_Header'; moved to cos-i.h; add new member `reference_count'. (CONCORD_OBJECT_TYPE_NULL): Renamed to `COS_Object_Type_NULL'; moved to cos-i.h; use `enum COS_Object_Type'. (CONCORD_OBJECT_TYPE_C_STRING): Renamed to `COS_Object_Type_C_String'; moved to cos-i.h; use `enum COS_Object_Type'. (CONCORD_OBJECT_TYPE_INT): Renamed to `COS_Object_Type_int'; moved to cos-i.h; use `enum COS_Object_Type'. (CONCORD_OBJECT_TYPE_DS): Renamed to `COS_Object_Type_DS'; moved to cos-i.h; use `enum COS_Object_Type'. (CONCORD_OBJECT_TYPE_GENRE): Renamed to `COS_Object_Type_Genre'; moved to cos-i.h; use `enum COS_Object_Type'. (CONCORD_OBJECT_TYPE_FEATURE): Renamed to `COS_Object_Type_Feature'; moved to cos-i.h; use `enum COS_Object_Type'. (CONCORD_OBJECT_TYPE_INDEX): Renamed to `COS_Object_Type_Feature_INDEX'; moved to cos-i.h; use `enum COS_Object_Type'. (CONCORD_OBJECT_TYPE_OBJECT): Renamed to `COS_Object_Type_DB_Object'; moved to cos-i.h; use `enum COS_Object_Type'. (struct CONCORD_DS_Table): Renamed to `struct COS_DS_ent'; add new member `symbol_names'. (concord_open_ds): Use `COS_ALLOCATE_OBJECT'; initialize `ds->symbol_names'. (concord_close_ds): Destroy `ds->symbol_names'. (struct CONCORD_Genre_Table): Renamed to `struct COS_Genre_ent'. (concord_ds_open_genre): Use `COS_ALLOCATE_OBJECT'. (struct CONCORD_Feature_Table): Renamed to `struct COS_Feature_ent'. (concord_genre_open_feature): Use `COS_ALLOCATE_OBJECT'. (struct CONCORD_INDEX_Table): Renamed to `struct COS_Feature_INDEX_ent'. (concord_genre_open_index): Use `COS_ALLOCATE_OBJECT'. (concord_index_get_name): New function. (concord_index_get_genre): New function. --- diff --git a/concord.c b/concord.c index 2bac1df..83bb97f 100644 --- a/concord.c +++ b/concord.c @@ -21,11 +21,9 @@ #include #include #include -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif #include "sysdep.h" #include "concord.h" +#include "cos-i.h" #include "concord-name.h" #include "concord-bdb.h" @@ -44,14 +42,10 @@ CONCORD_String_data (const CONCORD_String s) CONCORD_Genre concord_ds_open_genre (CONCORD_DS ds, const char* name); -int concord_close_genre (CONCORD_Genre genre); - CONCORD_Feature concord_genre_open_feature (CONCORD_Genre genre, const char* name); -int concord_close_feature (CONCORD_Feature feature); - CONCORD_INDEX concord_genre_open_index (CONCORD_Genre genre, const char* index); @@ -59,32 +53,14 @@ concord_genre_open_index (CONCORD_Genre genre, const char* index); CONCORD_Feature concord_genre_get_feature_0 (CONCORD_Genre genre, const char* name); -int concord_close_index (CONCORD_INDEX table); - CONCORD_Object concord_default_read_object (const unsigned char* string, size_t length); -typedef struct CONCORD_Object_Header -{ - unsigned char prefix; - unsigned char type; -} CONCORD_Object_Header; - -#define CONCORD_OBJECT_TYPE_NULL 0 -#define CONCORD_OBJECT_TYPE_C_STRING 1 -#define CONCORD_OBJECT_TYPE_INT 2 -#define CONCORD_OBJECT_TYPE_DS 16 -#define CONCORD_OBJECT_TYPE_GENRE 17 -#define CONCORD_OBJECT_TYPE_FEATURE 18 -#define CONCORD_OBJECT_TYPE_INDEX 19 -#define CONCORD_OBJECT_TYPE_OBJECT 128 - - -struct CONCORD_DS_Table +struct COS_DS_ent { - CONCORD_Object_Header header; + COS_Object_Header header; CONCORD_Backend_Type type; char *location; CONCORD_NAME_TABLE* genre_names; @@ -93,6 +69,7 @@ struct CONCORD_DS_Table CONCORD_Object object_nil; CONCORD_Object (*read_object) (const unsigned char* str, size_t length); + CONCORD_NAME_TABLE* symbol_names; }; CONCORD_Object @@ -104,21 +81,30 @@ concord_default_read_object (const unsigned char* str, size_t length) return NULL; strncpy ((char*)buf, (char*)str, length); buf[length] = '\0'; - return buf; + return (CONCORD_Object)buf; } CONCORD_DS concord_open_ds (CONCORD_Backend_Type type, const char* location, int subtype, int modemask) { - CONCORD_DS ds = (CONCORD_DS)malloc (sizeof (CONCORD_DS_Table)); +#if 0 + CONCORD_DS ds = (CONCORD_DS)malloc (sizeof (CONCORD_DS_ent)); size_t len = strlen (location); if (ds == NULL) return NULL; ds->header.prefix = 0xff; - ds->header.type = CONCORD_OBJECT_TYPE_DS; + ds->header.type = CONCORD_Object_Type_DS; +#else + CONCORD_DS ds = COS_ALLOCATE_OBJECT (DS); + size_t len = strlen (location); + + if (ds == NULL) + return NULL; +#endif + ds->type = type; ds->subtype = ( (subtype != 0) ? subtype : DB_HASH ); ds->modemask = modemask; @@ -137,6 +123,15 @@ concord_open_ds (CONCORD_Backend_Type type, const char* location, return NULL; } + ds->symbol_names = concord_make_name_table (); + if (ds->symbol_names == NULL) + { + concord_destroy_name_table (ds->genre_names); + free (ds->location); + free (ds); + return NULL; + } + ds->object_nil = NULL; ds->read_object = &concord_default_read_object; @@ -150,6 +145,8 @@ concord_close_ds (CONCORD_DS ds) free (ds->location); if (ds->genre_names != NULL) concord_destroy_name_table (ds->genre_names); + if (ds->symbol_names != NULL) + concord_destroy_name_table (ds->symbol_names); free (ds); return 0; } @@ -288,9 +285,9 @@ concord_ds_foreach_genre_name (CONCORD_DS ds, } -struct CONCORD_Genre_Table +struct COS_Genre_ent { - CONCORD_Object_Header header; + COS_Object_Header header; CONCORD_DS ds; char *name; CONCORD_NAME_TABLE* feature_names; @@ -306,12 +303,19 @@ concord_ds_open_genre (CONCORD_DS ds, const char* name) if (ds == NULL) return NULL; - genre = (CONCORD_Genre)malloc (sizeof (CONCORD_Genre_Table)); +#if 0 + genre = (CONCORD_Genre)malloc (sizeof (CONCORD_Genre_ent)); if (genre == NULL) return NULL; genre->header.prefix = 0xff; - genre->header.type = CONCORD_OBJECT_TYPE_GENRE; + genre->header.type = CONCORD_Object_Type_Genre; +#else + genre = COS_ALLOCATE_OBJECT (Genre); + if (genre == NULL) + return NULL; +#endif + genre->ds = ds; genre->name = (char*)malloc (len + 1); if (genre->name == NULL) @@ -549,9 +553,9 @@ concord_genre_get_index (CONCORD_Genre genre, const char* name) } -struct CONCORD_Feature_Table +struct COS_Feature_ent { - CONCORD_Object_Header header; + COS_Object_Header header; CONCORD_Genre genre; char* name; DB* db; @@ -567,12 +571,19 @@ concord_genre_open_feature (CONCORD_Genre genre, const char* feature) if (genre == NULL) return NULL; - table = (CONCORD_Feature)malloc (sizeof (CONCORD_Feature_Table)); +#if 0 + table = (CONCORD_Feature)malloc (sizeof (CONCORD_Feature_ent)); if (table == NULL) return NULL; table->header.prefix = 0xff; - table->header.type = CONCORD_OBJECT_TYPE_FEATURE; + table->header.type = CONCORD_Object_Type_Feature; +#else + table = COS_ALLOCATE_OBJECT (Feature); + if (table == NULL) + return NULL; +#endif + table->genre = genre; table->db = NULL; table->access = 0; @@ -766,9 +777,9 @@ concord_feature_foreach_obj_string (CONCORD_Feature feature, } -struct CONCORD_INDEX_Table +struct COS_Feature_INDEX_ent { - CONCORD_Object_Header header; + COS_Object_Header header; CONCORD_Genre genre; char *name; DB* db; @@ -784,12 +795,19 @@ concord_genre_open_index (CONCORD_Genre genre, const char* index) if (genre == NULL) return NULL; - table = (CONCORD_INDEX)malloc (sizeof (CONCORD_INDEX_Table)); +#if 0 + table = (CONCORD_INDEX)malloc (sizeof (CONCORD_INDEX_ent)); if (table == NULL) return NULL; table->header.prefix = 0xff; - table->header.type = CONCORD_OBJECT_TYPE_INDEX; + table->header.type = CONCORD_Object_Type_INDEX; +#else + table = COS_ALLOCATE_OBJECT (Feature_INDEX); + if (table == NULL) + return NULL; +#endif + table->genre = genre; table->db = NULL; table->access = 0; @@ -827,6 +845,18 @@ concord_close_index (CONCORD_INDEX table) 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) {