From 3eb88ab4dec430a961c8d16dcc8ef7d32c8c41a4 Mon Sep 17 00:00:00 2001 From: tomo Date: Sun, 10 Aug 2003 19:58:15 +0000 Subject: [PATCH] (chise_format_char_id): New function. (chise_ft_get_value): Use `chise_format_char_id'. --- chise.c | 243 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 132 insertions(+), 111 deletions(-) diff --git a/chise.c b/chise.c index 63c104b..fdb73b1 100644 --- a/chise.c +++ b/chise.c @@ -93,6 +93,133 @@ chise_char_id_parse_c_string (unsigned char *str, int len) } int +chise_format_char_id (CHISE_Char_ID cid, unsigned char *dest, int len) +{ + int i = 0; + + dest[i++] = '?'; + if (cid == '\t') + { + dest[i++] = '\\'; + dest[i++] = 't'; + dest[i] = '\0'; + return i; + } + else if (cid == '\n') + { + dest[i++] = '\\'; + dest[i++] = 'n'; + dest[i] = '\0'; + return i; + } + else if (cid == '\r') + { + dest[i++] = '\\'; + dest[i++] = 'r'; + dest[i] = '\0'; + return i; + } + else if (cid == 0x1C) + { + dest[i++] = '\\'; + dest[i++] = '^'; + dest[i++] = '\\'; + dest[i++] = '\\'; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x1F) + { + dest[i++] = '\\'; + dest[i++] = '^'; + dest[i++] = '@' + cid; + dest[i] = '\0'; + return i; + } + else if ( (cid == ' ') || (cid == '"') || + (cid == '#') || (cid == '\'') || + (cid == '(') || (cid == ')') || + (cid == ',') || (cid == '.') || + (cid == ';') || (cid == '?') || + (cid == '[') || (cid == '\\') || + (cid == ']') || (cid == '`') ) + { + dest[i++] = '\\'; + dest[i++] = cid; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x7E) + { + dest[i++] = cid; + dest[i] = '\0'; + return i; + } + else if (cid == 0x7F) + { + dest[i++] = '\\'; + dest[i++] = '^'; + dest[i++] = '?'; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x9F) + { + dest[i++] = '\\'; + dest[i++] = '^'; + dest[i++] = ((cid + '@') >> 6) | 0xC0; + dest[i++] = ((cid + '@') & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x7FF) + { + dest[i++] = (cid >> 6) | 0xC0; + dest[i++] = (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else if (cid <= 0xFFFF) + { + dest[i++] = (cid >> 12) | 0xE0; + dest[i++]= ((cid >> 6) & 0x3F) | 0x80; + dest[i++]= (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x1FFFFF) + { + dest[i++]= (cid >> 18) | 0xF0; + dest[i++]= ((cid >> 12) & 0x3F) | 0x80; + dest[i++]= ((cid >> 6) & 0x3F) | 0x80; + dest[i++]= (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else if (cid <= 0x3FFFFFF) + { + dest[i++]= (cid >> 24) | 0xF8; + dest[i++]= ((cid >> 18) & 0x3F) | 0x80; + dest[i++]= ((cid >> 12) & 0x3F) | 0x80; + dest[i++]= ((cid >> 6) & 0x3F) | 0x80; + dest[i++]= (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } + else + { + dest[i++]= (cid >> 30) | 0xFC; + dest[i++]= ((cid >> 24) & 0x3F) | 0x80; + dest[i++]= ((cid >> 18) & 0x3F) | 0x80; + dest[i++]= ((cid >> 12) & 0x3F) | 0x80; + dest[i++]= ((cid >> 6) & 0x3F) | 0x80; + dest[i++]= (cid & 0x3F) | 0x80; + dest[i] = '\0'; + return i; + } +} + +int chise_open_data_source (CHISE_DS *ds, CHISE_DS_Type type, char *location) { ds->type = type; @@ -171,120 +298,14 @@ chise_close_feature_table (CHISE_Feature_Table *db) return -1; } -int chise_ft_get_value (CHISE_Feature_Table *db, - CHISE_Char_ID cid, CHISE_Value *valdatum) +int +chise_ft_get_value (CHISE_Feature_Table *db, + CHISE_Char_ID cid, CHISE_Value *valdatum) { unsigned char key_buf[8]; - key_buf[0] = '?'; - if (cid == '\t') - { - key_buf[1] = '\\'; - key_buf[2] = 't'; - key_buf[3] = '\0'; - } - else if (cid == '\n') - { - key_buf[1] = '\\'; - key_buf[2] = 'n'; - key_buf[3] = '\0'; - } - else if (cid == '\r') - { - key_buf[1] = '\\'; - key_buf[2] = 'r'; - key_buf[3] = '\0'; - } - else if (cid == 0x1C) - { - key_buf[1] = '\\'; - key_buf[2] = '^'; - key_buf[3] = '\\'; - key_buf[4] = '\\'; - key_buf[5] = '\0'; - } - else if (cid <= 0x1F) - { - key_buf[1] = '\\'; - key_buf[2] = '^'; - key_buf[3] = '@' + cid; - key_buf[4] = '\0'; - } - else if ( (cid == ' ') || (cid == '"') || - (cid == '#') || (cid == '\'') || - (cid == '(') || (cid == ')') || - (cid == ',') || (cid == '.') || - (cid == ';') || (cid == '?') || - (cid == '[') || (cid == '\\') || - (cid == ']') || (cid == '`') ) - { - key_buf[1] = '\\'; - key_buf[2] = cid; - key_buf[3] = '\0'; - } - else if (cid <= 0x7E) - { - key_buf[1] = cid; - key_buf[2] = '\0'; - } - else if (cid == 0x7F) - { - key_buf[1] = '\\'; - key_buf[2] = '^'; - key_buf[3] = '?'; - key_buf[4] = '\0'; - } - else if (cid <= 0x9F) - { - key_buf[1] = '\\'; - key_buf[2] = '^'; - key_buf[3] = ((cid + '@') >> 6) | 0xC0; - key_buf[4] = ((cid + '@') & 0x3F) | 0x80; - key_buf[5] = '\0'; - - } - else if (cid <= 0x7FF) - { - key_buf[1] = (cid >> 6) | 0xC0; - key_buf[2] = (cid & 0x3F) | 0x80; - key_buf[3] = '\0'; - } - else if (cid <= 0xFFFF) - { - key_buf[1] = (cid >> 12) | 0xE0; - key_buf[2]= ((cid >> 6) & 0x3F) | 0x80; - key_buf[3]= (cid & 0x3F) | 0x80; - key_buf[4] = '\0'; - } - else if (cid <= 0x1FFFFF) - { - key_buf[1]= (cid >> 18) | 0xF0; - key_buf[2]= ((cid >> 12) & 0x3F) | 0x80; - key_buf[3]= ((cid >> 6) & 0x3F) | 0x80; - key_buf[4]= (cid & 0x3F) | 0x80; - key_buf[5] = '\0'; - } - else if (cid <= 0x3FFFFFF) - { - key_buf[1]= (cid >> 24) | 0xF8; - key_buf[2]= ((cid >> 18) & 0x3F) | 0x80; - key_buf[3]= ((cid >> 12) & 0x3F) | 0x80; - key_buf[4]= ((cid >> 6) & 0x3F) | 0x80; - key_buf[5]= (cid & 0x3F) | 0x80; - key_buf[6] = '\0'; - } - else - { - key_buf[1]= (cid >> 30) | 0xFC; - key_buf[2]= ((cid >> 24) & 0x3F) | 0x80; - key_buf[3]= ((cid >> 18) & 0x3F) | 0x80; - key_buf[4]= ((cid >> 12) & 0x3F) | 0x80; - key_buf[5]= ((cid >> 6) & 0x3F) | 0x80; - key_buf[6]= (cid & 0x3F) | 0x80; - key_buf[7] = '\0'; - } - return - chise_get_attribute_table (db, key_buf, valdatum); + chise_format_char_id (cid, key_buf, 8); + return chise_get_attribute_table (db, key_buf, valdatum); } void -- 1.7.10.4