From 46b45085c6c357fe33a22aa7f7f7b12d4e9437ea Mon Sep 17 00:00:00 2001 From: tomo Date: Wed, 20 Aug 2003 18:17:12 +0000 Subject: [PATCH] Rearrangement. --- chise.c | 147 ++++++++++++++++++++++++++++++++------------------------------- chise.h | 30 ++++++------- 2 files changed, 89 insertions(+), 88 deletions(-) diff --git a/chise.c b/chise.c index 45cd601..e27d7bc 100644 --- a/chise.c +++ b/chise.c @@ -273,29 +273,29 @@ chise_ds_close (CHISE_DS *ds) } -struct CHISE_Decoding_Table +struct CHISE_Feature_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_Feature_Table* +chise_ds_open_feature_table (CHISE_DS *ds, const char *feature, + DBTYPE real_subtype, + u_int32_t accessmask, int modemask) { - CHISE_Decoding_Table* table; + CHISE_Feature_Table* table; if (ds == NULL) return NULL; - table = (CHISE_Decoding_Table*)malloc (sizeof (CHISE_Decoding_Table)); + 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, - ccs, "system-char-id", + "system-char-id", feature, real_subtype, accessmask, modemask); if (table->db == NULL) @@ -307,7 +307,7 @@ chise_ds_open_decoding_table (CHISE_DS *ds, const char *ccs, } int -chise_dt_close (CHISE_Decoding_Table *table) +chise_ft_close (CHISE_Feature_Table *table) { int status; @@ -322,62 +322,69 @@ chise_dt_close (CHISE_Decoding_Table *table) return status; } -CHISE_Char_ID -chise_dt_get_char (CHISE_Decoding_Table *table, int code_point) +int +chise_ft_get_value (CHISE_Feature_Table *table, + CHISE_Char_ID cid, CHISE_Value *valdatum) { - 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); - if (!status) - { - unsigned char *str - = (unsigned char *)chise_value_data (&valdatum); - int len = strnlen (str, chise_value_size (&valdatum)); + unsigned char key_buf[8]; - return chise_char_id_parse_c_string (str, len); - } - return -1; + chise_format_char_id (cid, key_buf, 8); + return chise_get_attribute_table (table->db, + key_buf, valdatum); } -int -chise_dt_put_char (CHISE_Decoding_Table *table, - int code_point, CHISE_Char_ID cid) +void +chise_ft_iterate (CHISE_Feature_Table *table, + int (*func) (CHISE_Feature_Table *table, + CHISE_Char_ID cid, CHISE_Value *valdatum)) { - CHISE_Value valdatum; - char key_buf[16], val_buf[8]; + DBT keydatum, valdatum; + DBC *dbcp; + int status; - sprintf(key_buf, "%d", code_point); - chise_format_char_id (cid, val_buf, 8); - return chise_put_attribute_table (table->db, key_buf, val_buf); + xzero (keydatum); + xzero (valdatum); + + status = table->db->cursor (table->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)) + { + unsigned char *key_str = (unsigned char *)keydatum.data; + int key_len = strnlen (key_str, keydatum.size); + CHISE_Char_ID key = chise_char_id_parse_c_string (key_str, key_len); + int ret; + + if (ret = func (table, key, &valdatum)) + break; + } + dbcp->c_close (dbcp); } -struct CHISE_Feature_Table +struct CHISE_Decoding_Table { CHISE_DS *ds; CHISE_Attribute_Table *db; }; -CHISE_Feature_Table* -chise_ds_open_feature_table (CHISE_DS *ds, const char *feature, - DBTYPE real_subtype, - u_int32_t accessmask, int modemask) +CHISE_Decoding_Table* +chise_ds_open_decoding_table (CHISE_DS *ds, const char *ccs, + DBTYPE real_subtype, + u_int32_t accessmask, int modemask) { - CHISE_Feature_Table* table; + CHISE_Decoding_Table* table; if (ds == NULL) return NULL; - table = (CHISE_Feature_Table*)malloc (sizeof (CHISE_Feature_Table)); + 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, - "system-char-id", feature, + ccs, "system-char-id", real_subtype, accessmask, modemask); if (table->db == NULL) @@ -389,7 +396,7 @@ chise_ds_open_feature_table (CHISE_DS *ds, const char *feature, } int -chise_ft_close (CHISE_Feature_Table *table) +chise_dt_close (CHISE_Decoding_Table *table) { int status; @@ -404,45 +411,39 @@ chise_ft_close (CHISE_Feature_Table *table) return status; } -int -chise_ft_get_value (CHISE_Feature_Table *table, - CHISE_Char_ID cid, CHISE_Value *valdatum) +CHISE_Char_ID +chise_dt_get_char (CHISE_Decoding_Table *table, int code_point) { - unsigned char key_buf[8]; + CHISE_Value valdatum; + int status = 0; + char key_buf[16]; - chise_format_char_id (cid, key_buf, 8); - return chise_get_attribute_table (table->db, - key_buf, valdatum); + sprintf(key_buf, "%d", code_point); + status = chise_get_attribute_table (table->db, key_buf, &valdatum); + if (!status) + { + unsigned char *str + = (unsigned char *)chise_value_data (&valdatum); + int len = strnlen (str, chise_value_size (&valdatum)); + + return chise_char_id_parse_c_string (str, len); + } + return -1; } -void -chise_ft_iterate (CHISE_Feature_Table *table, - int (*func) (CHISE_Feature_Table *table, - CHISE_Char_ID cid, CHISE_Value *valdatum)) +int +chise_dt_put_char (CHISE_Decoding_Table *table, + int code_point, CHISE_Char_ID cid) { - DBT keydatum, valdatum; - DBC *dbcp; - int status; - - xzero (keydatum); - xzero (valdatum); - - status = table->db->cursor (table->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)) - { - unsigned char *key_str = (unsigned char *)keydatum.data; - int key_len = strnlen (key_str, keydatum.size); - CHISE_Char_ID key = chise_char_id_parse_c_string (key_str, key_len); - int ret; + CHISE_Value valdatum; + char key_buf[16], val_buf[8]; - if (ret = func (table, key, &valdatum)) - break; - } - dbcp->c_close (dbcp); + sprintf(key_buf, "%d", code_point); + chise_format_char_id (cid, val_buf, 8); + return chise_put_attribute_table (table->db, key_buf, val_buf); } + CHISE_Attribute_Table* chise_open_attribute_table (const unsigned char *db_dir, const char *encoding, const char *feature, diff --git a/chise.h b/chise.h index 7657a4e..fd1f771 100644 --- a/chise.h +++ b/chise.h @@ -41,21 +41,6 @@ chise_value_to_c_string (const CHISE_Value *s) } -typedef struct CHISE_Decoding_Table CHISE_Decoding_Table; - -CHISE_Decoding_Table* -chise_ds_open_decoding_table (CHISE_DS *ds, const char *ccs, - DBTYPE real_subtype, - u_int32_t accessmask, int modemask); - -int chise_dt_close (CHISE_Decoding_Table *table); - -CHISE_Char_ID 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); - - typedef struct CHISE_Feature_Table CHISE_Feature_Table; CHISE_Feature_Table* @@ -74,6 +59,21 @@ chise_ft_iterate (CHISE_Feature_Table *table, CHISE_Char_ID cid, CHISE_Value *valdatum)); +typedef struct CHISE_Decoding_Table CHISE_Decoding_Table; + +CHISE_Decoding_Table* +chise_ds_open_decoding_table (CHISE_DS *ds, const char *ccs, + DBTYPE real_subtype, + u_int32_t accessmask, int modemask); + +int chise_dt_close (CHISE_Decoding_Table *table); + +CHISE_Char_ID 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_Char_ID chise_decode_char (CHISE_DS *ds, char *ccs, int code_point); int chise_get_feature (CHISE_DS *ds, CHISE_Char_ID cid, -- 1.7.10.4