From f15620c372b8813a87d07eee169cf2096c99c173 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Thu, 14 Jul 2005 08:45:46 +0000 Subject: IConv and DB4 --- src/lngconfig.c | 137 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 112 insertions(+), 25 deletions(-) (limited to 'src/lngconfig.c') diff --git a/src/lngconfig.c b/src/lngconfig.c index eded9da..6e42181 100644 --- a/src/lngconfig.c +++ b/src/lngconfig.c @@ -144,29 +144,75 @@ rcc_charset_id rccConfigGetAutoCharsetByName(rcc_language_config config, const c int rccConfigInit(rcc_language_config config, rcc_context ctx) { unsigned int i; rcc_charset_id *charsets; + rcc_charset_id *dcharsets; + rcc_iconv *iconv_to; if ((!ctx)||(!config)) return -1; charsets = (rcc_charset_id*)malloc((ctx->max_classes)*sizeof(rcc_charset_id)); - if (!charsets) return -1; + dcharsets = (rcc_charset_id*)malloc((ctx->max_classes)*sizeof(rcc_charset_id)); + iconv_to = (rcc_iconv*)malloc((ctx->max_classes)*sizeof(rcc_iconv)); + if ((!charsets)||(!dcharsets)||(!iconv_to)) { + if (dcharsets) free(dcharsets); + if (charsets) free(charsets); + if (iconv_to) free(iconv_to); + return -1; + } - for (i=0;imax_classes;i++) - charsets[i] = 0; + for (i=0;imax_classes;i++) { + dcharsets[i] = 0; + charsets[i] = 0; + iconv_to[i] = NULL; + } + + config->fsiconv = NULL; config->ctx = ctx; config->language = NULL; config->charset = charsets; config->engine = -1; - config->default_charset = 0; + config->default_charset = dcharsets; config->configured = 0; + config->iconv_to = iconv_to; + config->configure = 1; + return 0; } -int rccConfigFree(rcc_language_config config) { - if (config->charset) { - free(config->charset); - config->charset = NULL; +void rccConfigFreeIConv(rcc_language_config config) { + unsigned int i; + + if ((!config)||(!config->charset)) return; + + if (config->fsiconv) { + rccIConvClose(config->fsiconv); + config->fsiconv = NULL; + } + + for (i=0;ictx->n_classes;i++) { + if (config->iconv_to[i]) { + rccIConvClose(config->iconv_to[i]); + config->iconv_to[i] = NULL; + } + } +} + +void rccConfigClear(rcc_language_config config) { + if ((config)&&(config->charset)) { + rccConfigFreeIConv(config); + if (config->iconv_to) { + free(config->iconv_to); + config->iconv_to = NULL; + } + if (config->charset) { + free(config->charset); + config->charset = NULL; + } + if (config->default_charset) { + free(config->default_charset); + config->default_charset = NULL; + } } } @@ -310,18 +356,18 @@ rcc_charset_id rccConfigGetCurrentCharset(rcc_language_config config, rcc_class_ } } else defvalue = config->ctx->locale_variable; - if (config->default_charset) return config->default_charset; + if (config->default_charset[class_id]) return config->default_charset[class_id]; charset_id = rccConfigGetLocaleCharset(config, defvalue); if ((charset_id != 0)&&(charset_id != (rcc_charset_id)-1)) { - config->default_charset = charset_id; + config->default_charset[class_id] = charset_id; return charset_id; } if (cl->defvalue) { charset_id = rccConfigGetCharsetByName(config, defvalue); if ((charset_id != 0)&&(charset_id != (rcc_charset_id)-1)) { - config->default_charset = charset_id; + config->default_charset[class_id] = charset_id; return charset_id; } } @@ -334,16 +380,22 @@ rcc_charset_id rccConfigGetCurrentCharset(rcc_language_config config, rcc_class_ if (!strcasecmp(lang, defcharset[i].lang)) { charset_id = rccConfigGetCharsetByName(config, defcharset[i].charset); if ((charset_id != 0)&&(charset_id != (rcc_charset_id)-1)) { - config->default_charset = charset_id; + config->default_charset[class_id] = charset_id; return charset_id; } else break; } } } + charset_id = rccConfigGetLocaleUnicodeCharset(config, defvalue); + if ((charset_id != 0)&&(charset_id != (rcc_charset_id)-1)) { + config->default_charset[class_id] = charset_id; + return charset_id; + } + charsets=language->charsets; if ((charsets[0])&&(charsets[1])) { - config->default_charset=(rcc_charset_id)1; + config->default_charset[class_id]=(rcc_charset_id)1; return (rcc_charset_id)1; } return (rcc_charset_id)-1; @@ -373,6 +425,7 @@ int rccConfigSetEngine(rcc_language_config config, rcc_engine_id engine_id) { if (config->engine != engine_id) { if (config->ctx->current_config == config) config->ctx->configure = 1; + config->configure = 1; config->engine = engine_id; } return 0; @@ -404,6 +457,7 @@ int rccConfigSetCharset(rcc_language_config config, rcc_class_id class_id, rcc_c if (config->charset[class_id] != charset_id) { if (config->ctx->current_config == config) config->ctx->configure = 1; + config->configure = 1; config->charset[class_id] = charset_id; } @@ -420,28 +474,61 @@ int rccConfigSetCharsetByName(rcc_language_config config, rcc_class_id class_id, } rcc_charset_id rccConfigGetLocaleCharset(rcc_language_config config, const char *locale_variable) { - int err; + const char *lv; rcc_charset *charsets; rcc_language_id language_id; char stmp[RCC_MAX_CHARSET_CHARS+1]; if ((!config)||(!config->language)) return (rcc_charset_id)-1; - language_id = rccGetCurrentLanguage(config->ctx); - if (language_id) err = rccLocaleGetLanguage(stmp, locale_variable?locale_variable:config->ctx->locale_variable, RCC_MAX_CHARSET_CHARS); + lv = locale_variable?locale_variable:config->ctx->locale_variable; - if ((language_id == 0)||((!err)&&(!strcmp(rccGetCurrentLanguageName(config->ctx), stmp)))) - err = rccLocaleGetCharset(stmp, locale_variable?locale_variable:config->ctx->locale_variable, RCC_MAX_CHARSET_CHARS); - else - err = 1; + language_id = rccGetLanguageByName(config->ctx, config->language->sn); + if (language_id != (rcc_language_id)-1) { + if (!rccLocaleGetLanguage(stmp, lv, RCC_MAX_CHARSET_CHARS)) { + if (!strcmp(config->language->sn, stmp)) { + if (!rccLocaleGetCharset(stmp, lv, RCC_MAX_CHARSET_CHARS)) + return rccConfigGetCharsetByName(config, stmp); + } + } + } + + return (rcc_charset_id)-1; +} + +rcc_charset_id rccConfigGetLocaleUnicodeCharset(rcc_language_config config, const char *locale_variable) { + char stmp[RCC_MAX_CHARSET_CHARS+1]; + + if ((!config)||(!config->language)) return (rcc_charset_id)-1; + + if (!rccLocaleGetCharset(stmp, locale_variable?locale_variable:config->ctx->locale_variable, RCC_MAX_CHARSET_CHARS)) { + if (rccIsUTF8(stmp)) return rccConfigGetCharsetByName(config, stmp); + } - if (err) { - charsets=config->language->charsets; - if ((charsets[0])&&(charsets[1])) return (rcc_charset_id)1; - return (rcc_charset_id)-1; + return (rcc_charset_id)-1; +} + +int rccConfigConfigure(rcc_language_config config) { + rcc_context ctx; + const char *charset; + unsigned int i; + + if (!config) return -1; + if (!config->configure) return 0; + + ctx = config->ctx; + if (!ctx) return -1; + + rccConfigFreeIConv(config); + for (i=0;in_classes;i++) { + charset = rccConfigGetCurrentCharsetName(config, (rcc_class_id)i); + if ((!charset)||(rccIsUTF8(charset))) continue; + config->iconv_to[i] = rccIConvOpen(charset, "UTF-8"); } + + config->configure = 0; - return rccConfigGetCharsetByName(config, stmp); + return 0; } /* -- cgit v1.2.3