From: tomo Date: Mon, 13 Oct 2003 06:40:47 +0000 (+0000) Subject: (chise_ds_foreach_char_feature_name): New function. X-Git-Tag: b1-r0_2_0-pre8~3 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=012038cbe70e2b6bc4f58c04c5d74d06424f45a5;p=chise%2Flibchise.git (chise_ds_foreach_char_feature_name): New function. (chise_feature_foreach_char_with_value): Renamed from `chise_char_feature_value_iterate'. --- diff --git a/chise.c b/chise.c index 0e5274d..111a52f 100644 --- a/chise.c +++ b/chise.c @@ -2,6 +2,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -152,6 +153,99 @@ chise_ds_get_ccs (CHISE_DS *ds, const unsigned char *ccs) return ct; } +int +chise_ds_foreach_char_feature_name (CHISE_DS *ds, + int (*func) (CHISE_DS *ds, + unsigned char *name)) +{ + unsigned char *dname + = alloca (strlen (ds->location) + sizeof ("/system-char-id") + 1); + DIR *dir; + struct dirent *de; + + strcpy (dname, ds->location); + strcat (dname, "/system-char-id"); + + if ( (dir = opendir (dname)) == NULL) + return -1; + + while ( (de = readdir (dir)) != NULL ) + { + if ( (strcmp (de->d_name, ".") != 0) && + (strcmp (de->d_name, "..") != 0) ) + { + int i, need_to_decode = 0; + unsigned char *cp; + unsigned char *name; + unsigned char *np; + + for (cp = de->d_name, i = 0; *cp != '\0'; i++) + { + if (*cp++ == '%') + need_to_decode = 1; + } + if (need_to_decode) + { + int index = -1; + int ch, c[2]; + int hex[2]; + + name = (unsigned char *) alloca (i); + cp = de->d_name; + np = name; + + while ( (ch = *cp++) != '\0') + { + if (ch == '%') + { + if (index >= 0) + { + *np++ = '%'; + if (index == 1) + *np++ = c[0]; + } + index = 0; + } + else if (index >= 0) + { + c[index] = ch; + + if ( ('0' <= ch) && (ch <= '9') ) + hex[index++] = ch - '0'; + else if ( ('A' <= ch) && (ch <= 'F') ) + hex[index++] = ch - 'A' + 10; + else if ( ('a' <= ch) && (ch <= 'f') ) + hex[index++] = ch - 'a' + 10; + else + { + *np++ = '%'; + if (index == 1) + *np++ = c[0]; + *np++ = ch; + index = -1; + continue; + } + if (index == 2) + { + *np++ = (hex[0] << 4) | hex[1]; + index = -1; + continue; + } + } + else + *np++ = ch; + } + *np = '\0'; + } + else + name = de->d_name; + + if (func (ds, name)) + return closedir (dir); + } + } + return closedir (dir); +} struct CHISE_Feature_Table { @@ -316,10 +410,10 @@ chise_char_gets_feature_value (CHISE_Char_ID cid, } int -chise_char_feature_value_iterate (CHISE_Feature feature, - int (*func) (CHISE_Char_ID cid, - CHISE_Feature feature, - CHISE_Value *valdatum)) +chise_feature_foreach_char_with_value (CHISE_Feature feature, + int (*func) (CHISE_Char_ID cid, + CHISE_Feature feature, + CHISE_Value *valdatum)) { DBT keydatum, valdatum; DBC *dbcp;