#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)))
struct CHISE_Decoding_Table
{
CHISE_DS *ds;
- DB *db;
+ CHISE_Attribute_Table *db;
};
CHISE_Decoding_Table*
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
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
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*
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
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);
}
}
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;
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;
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;
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;
}