From: tomo Date: Mon, 6 Oct 2003 11:35:51 +0000 (+0000) Subject: (chise_feature_setup_db): Changed to public function. X-Git-Tag: b1-r0_2_0-pre7~2 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22e9a710f082ed87500bdd1ef3bb836dc5259e67;p=chise%2Flibchise.git (chise_feature_setup_db): Changed to public function. (chise_ccs_setup_db): New function. (chise_ccs_decode): Use `chise_ccs_setup_db'. (chise_ccs_set_decoded_char): Likewise. --- diff --git a/chise.c b/chise.c index da12d1b..be55f01 100644 --- a/chise.c +++ b/chise.c @@ -210,11 +210,14 @@ chise_ft_close (CHISE_Feature_Table *table) return status; } -static int +int chise_feature_setup_db (CHISE_Feature feature, int writable) { u_int32_t access; + if (feature == NULL) + return -1; + if (writable) { if ((feature->access & DB_CREATE) == 0) @@ -403,6 +406,45 @@ chise_ccst_close (CHISE_CCS_Table *table) } int +chise_ccs_setup_db (CHISE_CCS ccs, int writable) +{ + u_int32_t access; + + if (ccs == NULL) + return -1; + + if (writable) + { + if ((ccs->access & DB_CREATE) == 0) + { + if (ccs->db != NULL) + { + CHISE_Attribute_Table_close (ccs->db); + ccs->db = NULL; + } + ccs->access = 0; + } + access = DB_CREATE; + } + else + access = DB_RDONLY; + + if (ccs->db == NULL) + { + CHISE_DS *ds = ccs->ds; + + ccs->db + = CHISE_Attribute_Table_open (ds->location, + ccs->name, "system-char-id", + ds->subtype, access, ds->modemask); + if (ccs->db == NULL) + return -1; + ccs->access = access; + } + return 0; +} + +int chise_ccs_sync (CHISE_CCS ccs) { int status; @@ -426,18 +468,8 @@ chise_ccs_decode (CHISE_CCS ccs, int code_point) if (ccs == NULL) return -1; - if (ccs->db == NULL) - { - CHISE_DS *ds = ccs->ds; - - ccs->db = CHISE_Attribute_Table_open (ds->location, - ccs->name, "system-char-id", - ds->subtype, - DB_RDONLY, ds->modemask); - if (ccs->db == NULL) - return -1; - ccs->access = DB_RDONLY; - } + if (chise_ccs_setup_db (ccs, 0)) + return -1; sprintf(key_buf, "%d", code_point); status = chise_attribute_table_get (ccs->db, key_buf, &valdatum); @@ -461,27 +493,8 @@ chise_ccs_set_decoded_char (CHISE_CCS ccs, if (ccs == NULL) return -1; - if ((ccs->access & DB_CREATE) == 0) - { - if (ccs->db != NULL) - { - CHISE_Attribute_Table_close (ccs->db); - ccs->db = NULL; - } - ccs->access = 0; - } - if (ccs->db == NULL) - { - CHISE_DS *ds = ccs->ds; - - ccs->db - = CHISE_Attribute_Table_open (ds->location, - ccs->name, "system-char-id", - ds->subtype, DB_CREATE, ds->modemask); - if (ccs->db == NULL) - return -1; - ccs->access = DB_CREATE; - } + if (chise_ccs_setup_db (ccs, 1)) + return -1; sprintf(key_buf, "%d", code_point); chise_format_char_id (cid, val_buf, 8);