From 673f0d0218f209da7a73b2e252c3ac964dfb860a Mon Sep 17 00:00:00 2001 From: tomo Date: Sun, 17 Aug 2003 18:25:34 +0000 Subject: [PATCH] (CHISE_Attribute_Table): Use instead of . (chise_put_attribute_table): New prototype. (struct CHISE_Decoding_Table): Use instead of as the type of member `db'. (chise_ds_open_decoding_table): New implementation. (chise_dt_close): Likewise. (chise_dt_get_char): Modify for new implementation of . (chise_dt_put_char): Likewise. (struct CHISE_Feature_Table): Use instead of as the type of member `db'. (chise_ds_open_feature_table): New implementation. (chise_ft_close): Likewise. (chise_ft_get_value): Modify for new implementation of . (chise_open_attribute_table): Use db_dir instead of ds as the first argument; modify for new implementation of . (chise_close_attribute_table): Modify for new implementation of . (chise_get_attribute_table): Likewise. (chise_put_attribute_table): Likewise. --- chise.c | 146 +++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 86 insertions(+), 60 deletions(-) diff --git a/chise.c b/chise.c index 7ddb79b..45cd601 100644 --- a/chise.c +++ b/chise.c @@ -20,23 +20,22 @@ strnlen (register const char *s, register int maxlen) #include "chise.h" -typedef struct CHISE_Attribute_Table -{ - CHISE_DS *ds; - DB *db; -} CHISE_Attribute_Table; +typedef DB CHISE_Attribute_Table; CHISE_Attribute_Table* -chise_open_attribute_table (CHISE_DS *ds, +chise_open_attribute_table (const unsigned char *db_dir, const char *encoding, const char *feature, DBTYPE real_subtype, u_int32_t accessmask, int modemask); -int chise_close_attribute_table (CHISE_Attribute_Table *at); +int chise_close_attribute_table (CHISE_Attribute_Table *db); -int chise_get_attribute_table (CHISE_Attribute_Table *at, +int chise_get_attribute_table (CHISE_Attribute_Table *db, char *key, CHISE_Value *valdatum); +int chise_put_attribute_table (CHISE_Attribute_Table *db, + char *key, unsigned char *value); + #define xzero(lvalue) ((void) memset (&(lvalue), '\0', sizeof (lvalue))) @@ -277,7 +276,7 @@ chise_ds_close (CHISE_DS *ds) struct CHISE_Decoding_Table { CHISE_DS *ds; - DB *db; + CHISE_Attribute_Table *db; }; CHISE_Decoding_Table* @@ -285,19 +284,42 @@ chise_ds_open_decoding_table (CHISE_DS *ds, const char *ccs, DBTYPE real_subtype, u_int32_t accessmask, int modemask) { - return - (CHISE_Decoding_Table*) - chise_open_attribute_table (ds, - ccs, "system-char-id", - real_subtype, accessmask, modemask); + CHISE_Decoding_Table* table; + + if (ds == NULL) + return NULL; + + table = (CHISE_Decoding_Table*)malloc (sizeof (CHISE_Decoding_Table)); + if (table == NULL) + 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) + { + free (table); + return NULL; + } + return table; } int chise_dt_close (CHISE_Decoding_Table *table) { - if (table) - return chise_close_attribute_table ((CHISE_Attribute_Table*)table); - return -1; + int status; + + if (table == NULL) + return -1; + + if (table->db == NULL) + status = -1; + else + status = chise_close_attribute_table (table->db); + free (table); + return status; } CHISE_Char_ID @@ -308,8 +330,7 @@ chise_dt_get_char (CHISE_Decoding_Table *table, int code_point) char key_buf[16]; sprintf(key_buf, "%d", code_point); - status = chise_get_attribute_table ((CHISE_Attribute_Table*)table, - key_buf, &valdatum); + status = chise_get_attribute_table (table->db, key_buf, &valdatum); if (!status) { unsigned char *str @@ -330,14 +351,14 @@ chise_dt_put_char (CHISE_Decoding_Table *table, sprintf(key_buf, "%d", code_point); chise_format_char_id (cid, val_buf, 8); - return chise_put_attribute_table (table, key_buf, val_buf); + return chise_put_attribute_table (table->db, key_buf, val_buf); } struct CHISE_Feature_Table { CHISE_DS *ds; - DB *db; + CHISE_Attribute_Table *db; }; CHISE_Feature_Table* @@ -345,19 +366,42 @@ chise_ds_open_feature_table (CHISE_DS *ds, const char *feature, DBTYPE real_subtype, u_int32_t accessmask, int modemask) { - return - (CHISE_Feature_Table*) - chise_open_attribute_table (ds, - "system-char-id", feature, - real_subtype, accessmask, modemask); + CHISE_Feature_Table* table; + + if (ds == NULL) + return NULL; + + table = (CHISE_Feature_Table*)malloc (sizeof (CHISE_Feature_Table)); + if (table == NULL) + 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) + { + free (table); + return NULL; + } + return table; } int chise_ft_close (CHISE_Feature_Table *table) { - if (table) - return chise_close_attribute_table ((CHISE_Attribute_Table*)table); - return -1; + int status; + + if (table == NULL) + return -1; + + if (table->db == NULL) + status = -1; + else + status = chise_close_attribute_table (table->db); + free (table); + return status; } int @@ -367,7 +411,7 @@ chise_ft_get_value (CHISE_Feature_Table *table, unsigned char key_buf[8]; chise_format_char_id (cid, key_buf, 8); - return chise_get_attribute_table ((CHISE_Attribute_Table*)table, + return chise_get_attribute_table (table->db, key_buf, valdatum); } @@ -400,36 +444,21 @@ chise_ft_iterate (CHISE_Feature_Table *table, } CHISE_Attribute_Table* -chise_open_attribute_table (CHISE_DS *ds, +chise_open_attribute_table (const unsigned char *db_dir, const char *encoding, const char *feature, DBTYPE real_subtype, u_int32_t accessmask, int modemask) { - CHISE_Attribute_Table* table; - char *db_dir; DB* dbase; int status; int len, flen, i; int size; char *db_file_name, *sp; - if (ds == NULL) - return NULL; - - table = (CHISE_Attribute_Table*)malloc (sizeof (CHISE_Attribute_Table)); - if (table == NULL) - return NULL; - - table->ds = ds; - status = db_create (&dbase, NULL, 0); if (status) - { - free (table); - return NULL; - } + return NULL; - db_dir = ds->location; len = strlen (db_dir); flen = strlen (feature); size = len + strlen (encoding) + flen * 3 + 4; @@ -462,27 +491,24 @@ chise_open_attribute_table (CHISE_DS *ds, if (status) { dbase->close (dbase, 0); - free (table); return NULL; } - table->db = dbase; - return table; + return dbase; } int -chise_close_attribute_table (CHISE_Attribute_Table *table) +chise_close_attribute_table (CHISE_Attribute_Table *db) { - if (table->db) + if (db) { - table->db->sync (table->db, 0); - table->db->close (table->db, 0); + db->sync (db, 0); + db->close (db, 0); } - free (table); return 0; } int -chise_get_attribute_table (CHISE_Attribute_Table *table, +chise_get_attribute_table (CHISE_Attribute_Table *db, char *key, CHISE_Value *valdatum) { DBT keydatum; @@ -495,13 +521,13 @@ chise_get_attribute_table (CHISE_Attribute_Table *table, keydatum.data = key; keydatum.size = strlen (key); - status = table->db->get (table->db, NULL, &keydatum, valdatum, 0); + status = db->get (db, NULL, &keydatum, valdatum, 0); return status; } int -chise_put_attribute_table (CHISE_Attribute_Table *table, - char *key, char *value) +chise_put_attribute_table (CHISE_Attribute_Table *db, + char *key, unsigned char *value) { DBT keydatum, valdatum; int status = 0; @@ -516,6 +542,6 @@ chise_put_attribute_table (CHISE_Attribute_Table *table, valdatum.data = value; valdatum.size = strlen (value); - status = table->db->put (table->db, NULL, &keydatum, &valdatum, 0); + status = db->put (db, NULL, &keydatum, &valdatum, 0); return status; } -- 1.7.10.4