2004-04-01 15:11:16 -08:00
|
|
|
/*
|
2007-01-13 11:14:29 -08:00
|
|
|
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
|
2015-01-15 22:25:38 -08:00
|
|
|
* Copyright (C) 2004-2015 Kim Woelders
|
2004-04-01 15:11:16 -08:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies of the Software, its documentation and marketing & publicity
|
|
|
|
* materials, and acknowledgment shall be given in the documentation, materials
|
|
|
|
* and software packages that this Software was used.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2015-01-15 22:25:38 -08:00
|
|
|
#include "config.h"
|
2006-04-19 12:13:46 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
2004-05-22 08:18:04 -07:00
|
|
|
#if HAVE_LANGINFO_CODESET
|
|
|
|
#include <langinfo.h>
|
|
|
|
#endif
|
2015-01-15 22:25:38 -08:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
|
|
|
#include "E.h"
|
|
|
|
#include "emodule.h"
|
|
|
|
#include "lang.h"
|
2004-05-22 08:18:04 -07:00
|
|
|
|
2006-04-19 12:13:46 -07:00
|
|
|
#ifndef ENABLE_NLS
|
|
|
|
#define bindtextdomain(pkg,locale)
|
|
|
|
#define textdomain(pkg)
|
|
|
|
#define bind_textdomain_codeset(pkg,enc)
|
|
|
|
#endif
|
|
|
|
|
2004-05-23 09:11:36 -07:00
|
|
|
#if HAVE_ICONV
|
2004-04-01 15:11:16 -08:00
|
|
|
|
|
|
|
#include <iconv.h>
|
2006-11-24 15:26:43 -08:00
|
|
|
#define BAD_CD ((iconv_t)-1)
|
|
|
|
|
2008-12-04 14:17:02 -08:00
|
|
|
#ifndef ICONV_CONST /* Not sure this is necessary */
|
|
|
|
#define ICONV_CONST
|
|
|
|
#endif
|
|
|
|
|
2006-11-24 15:26:43 -08:00
|
|
|
static iconv_t iconv_cd_int2utf8 = BAD_CD;
|
|
|
|
static iconv_t iconv_cd_utf82int = BAD_CD;
|
|
|
|
static iconv_t iconv_cd_int2loc = BAD_CD;
|
|
|
|
static iconv_t iconv_cd_loc2int = BAD_CD;
|
2004-04-01 15:11:16 -08:00
|
|
|
|
2004-05-23 09:11:36 -07:00
|
|
|
static char *
|
|
|
|
Eiconv(iconv_t icd, const char *txt, size_t len)
|
2004-04-01 15:11:16 -08:00
|
|
|
{
|
|
|
|
char buf[4096];
|
2008-12-04 14:17:02 -08:00
|
|
|
ICONV_CONST char *pi;
|
|
|
|
char *po;
|
2011-01-29 16:07:50 -08:00
|
|
|
size_t ni, no;
|
2004-04-01 15:11:16 -08:00
|
|
|
|
2008-12-04 14:17:02 -08:00
|
|
|
pi = (ICONV_CONST char *)txt;
|
2004-04-01 15:11:16 -08:00
|
|
|
po = buf;
|
|
|
|
ni = (len > 0) ? len : strlen(txt);
|
2008-06-26 14:57:22 -07:00
|
|
|
if (icd == BAD_CD)
|
|
|
|
return Estrndup(txt, ni);
|
2004-04-01 15:11:16 -08:00
|
|
|
no = sizeof(buf);
|
2011-01-29 16:07:50 -08:00
|
|
|
iconv(icd, &pi, &ni, &po, &no);
|
2004-04-01 15:11:16 -08:00
|
|
|
|
|
|
|
po = Estrndup(buf, sizeof(buf) - no);
|
|
|
|
|
|
|
|
return po;
|
|
|
|
}
|
|
|
|
|
2008-06-26 14:57:22 -07:00
|
|
|
static iconv_t
|
|
|
|
EiconvOpen(const char *to, const char *from)
|
|
|
|
{
|
|
|
|
iconv_t icd;
|
|
|
|
|
|
|
|
icd = iconv_open(to, from);
|
|
|
|
if (icd == BAD_CD)
|
|
|
|
Eprintf("*** WARNING - Missing conversion %s->%s\n", from, to);
|
|
|
|
|
|
|
|
return icd;
|
|
|
|
}
|
|
|
|
|
2004-04-01 15:11:16 -08:00
|
|
|
#endif
|
|
|
|
|
2008-05-10 16:22:31 -07:00
|
|
|
#if 0 /* Unused */
|
2004-05-23 09:11:36 -07:00
|
|
|
/* Convert locale to internal format (alloc always) */
|
|
|
|
char *
|
|
|
|
EstrLoc2Int(const char *str, int len)
|
|
|
|
{
|
|
|
|
if (str == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
#if HAVE_ICONV
|
2006-11-24 15:26:43 -08:00
|
|
|
if (iconv_cd_loc2int != BAD_CD)
|
2004-05-23 09:11:36 -07:00
|
|
|
return Eiconv(iconv_cd_loc2int, str, len);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
len = strlen(str);
|
|
|
|
return Estrndup(str, len);
|
|
|
|
}
|
2008-05-10 16:22:31 -07:00
|
|
|
#endif
|
2004-05-23 09:11:36 -07:00
|
|
|
|
|
|
|
/* Convert UTF-8 to internal format (alloc always) */
|
|
|
|
char *
|
|
|
|
EstrUtf82Int(const char *str, int len)
|
|
|
|
{
|
2010-08-13 10:04:13 -07:00
|
|
|
if (!str)
|
2004-05-23 09:11:36 -07:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
#if HAVE_ICONV
|
2006-11-24 15:26:43 -08:00
|
|
|
if (iconv_cd_utf82int != BAD_CD)
|
2004-05-23 09:11:36 -07:00
|
|
|
return Eiconv(iconv_cd_utf82int, str, len);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
len = strlen(str);
|
|
|
|
return Estrndup(str, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert internal to required (alloc only if necessary) */
|
|
|
|
const char *
|
|
|
|
EstrInt2Enc(const char *str, int want_utf8)
|
|
|
|
{
|
|
|
|
#if HAVE_ICONV
|
2005-07-17 05:55:13 -07:00
|
|
|
if (Mode.locale.utf8_int == want_utf8)
|
2005-03-23 11:40:56 -08:00
|
|
|
return str;
|
2004-05-23 09:11:36 -07:00
|
|
|
|
2010-08-13 10:04:13 -07:00
|
|
|
if (!str)
|
2004-05-24 10:39:51 -07:00
|
|
|
return NULL;
|
|
|
|
|
2004-05-23 09:11:36 -07:00
|
|
|
if (want_utf8)
|
|
|
|
return Eiconv(iconv_cd_int2utf8, str, strlen(str));
|
|
|
|
|
|
|
|
return Eiconv(iconv_cd_int2loc, str, strlen(str));
|
|
|
|
#else
|
2006-04-21 16:47:30 -07:00
|
|
|
want_utf8 = 0;
|
2005-03-23 11:40:56 -08:00
|
|
|
return str;
|
2004-05-23 09:11:36 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free string returned by EstrInt2Enc() */
|
|
|
|
void
|
|
|
|
EstrInt2EncFree(const char *str, int want_utf8)
|
|
|
|
{
|
|
|
|
#if HAVE_ICONV
|
2005-07-17 05:55:13 -07:00
|
|
|
if (Mode.locale.utf8_int == want_utf8)
|
2004-05-23 09:11:36 -07:00
|
|
|
return;
|
|
|
|
|
2008-02-23 04:09:38 -08:00
|
|
|
Efree((char *)str);
|
2006-04-21 16:47:30 -07:00
|
|
|
#else
|
|
|
|
str = NULL;
|
|
|
|
want_utf8 = 0;
|
2004-05-23 09:11:36 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-11-11 16:39:19 -08:00
|
|
|
/*
|
|
|
|
* Stuff to do mb/utf8 <-> wc conversions.
|
|
|
|
*/
|
|
|
|
#if HAVE_ICONV
|
2006-11-24 15:26:43 -08:00
|
|
|
static iconv_t iconv_cd_str2wcs = BAD_CD;
|
|
|
|
static iconv_t iconv_cd_wcs2str = BAD_CD;
|
2006-11-11 16:39:19 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
EwcOpen(int utf8)
|
|
|
|
{
|
|
|
|
#if HAVE_ICONV
|
|
|
|
const char *enc;
|
|
|
|
|
|
|
|
if (utf8)
|
|
|
|
enc = "UTF-8";
|
|
|
|
else
|
|
|
|
enc = nl_langinfo(CODESET);
|
|
|
|
|
2006-11-30 14:03:20 -08:00
|
|
|
#if SIZEOF_WCHAR_T == 4
|
2008-06-26 14:57:22 -07:00
|
|
|
iconv_cd_str2wcs = EiconvOpen("UCS-4", enc);
|
|
|
|
iconv_cd_wcs2str = EiconvOpen(enc, "UCS-4");
|
2006-11-30 14:03:20 -08:00
|
|
|
#else
|
2008-06-26 14:57:22 -07:00
|
|
|
iconv_cd_str2wcs = EiconvOpen("WCHAR_T", enc);
|
|
|
|
iconv_cd_wcs2str = EiconvOpen(enc, "WCHAR_T");
|
2006-11-30 14:03:20 -08:00
|
|
|
#endif
|
2006-11-11 16:39:19 -08:00
|
|
|
|
2006-11-24 15:26:43 -08:00
|
|
|
if (iconv_cd_str2wcs != BAD_CD && iconv_cd_wcs2str != BAD_CD)
|
2006-11-11 16:39:19 -08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
EwcClose();
|
|
|
|
return -1;
|
|
|
|
#else
|
|
|
|
/* NB! This case will not work properly if needed MB encoding is utf8
|
|
|
|
* but locale isn't */
|
|
|
|
utf8 = 0;
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EwcClose(void)
|
|
|
|
{
|
|
|
|
#if HAVE_ICONV
|
2006-11-24 15:26:43 -08:00
|
|
|
if (iconv_cd_str2wcs != BAD_CD)
|
2006-11-11 16:39:19 -08:00
|
|
|
iconv_close(iconv_cd_str2wcs);
|
2006-11-24 15:26:43 -08:00
|
|
|
iconv_cd_str2wcs = BAD_CD;
|
|
|
|
if (iconv_cd_wcs2str != BAD_CD)
|
2006-11-11 16:39:19 -08:00
|
|
|
iconv_close(iconv_cd_wcs2str);
|
2006-11-24 15:26:43 -08:00
|
|
|
iconv_cd_wcs2str = BAD_CD;
|
2006-11-11 16:39:19 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
EwcStrToWcs(const char *str, int len, wchar_t * wcs, int wcl)
|
|
|
|
{
|
|
|
|
#if HAVE_ICONV
|
2008-12-04 14:17:02 -08:00
|
|
|
ICONV_CONST char *pi;
|
|
|
|
char *po;
|
2006-11-11 16:39:19 -08:00
|
|
|
size_t ni, no, rc;
|
2006-11-19 14:55:32 -08:00
|
|
|
char buf[4096];
|
2006-11-11 16:39:19 -08:00
|
|
|
|
2008-12-04 14:17:02 -08:00
|
|
|
pi = (ICONV_CONST char *)str;
|
2006-11-24 15:26:43 -08:00
|
|
|
ni = len;
|
|
|
|
|
2006-11-11 16:39:19 -08:00
|
|
|
if (!wcs)
|
|
|
|
{
|
|
|
|
no = 4096;
|
|
|
|
po = buf;
|
2006-11-24 15:26:43 -08:00
|
|
|
rc = iconv(iconv_cd_str2wcs, &pi, &ni, &po, &no);
|
2006-11-11 16:39:19 -08:00
|
|
|
if (rc == (size_t) (-1) || no == 0)
|
|
|
|
return -1;
|
|
|
|
wcl = (4096 - no) / sizeof(wchar_t);
|
|
|
|
return wcl;
|
|
|
|
}
|
|
|
|
|
2006-11-19 04:34:18 -08:00
|
|
|
po = (char *)wcs;
|
2006-11-11 16:39:19 -08:00
|
|
|
no = wcl * sizeof(wchar_t);
|
2006-11-19 04:34:18 -08:00
|
|
|
rc = iconv(iconv_cd_str2wcs, &pi, &ni, &po, &no);
|
2006-11-11 16:39:19 -08:00
|
|
|
if (rc == (size_t) (-1))
|
|
|
|
return 0;
|
|
|
|
return wcl - no / sizeof(wchar_t);
|
|
|
|
#else
|
|
|
|
if (!wcs)
|
|
|
|
return mbstowcs(NULL, str, 0);
|
|
|
|
|
|
|
|
mbstowcs(wcs, str, wcl);
|
|
|
|
wcs[wcl] = (wchar_t) '\0';
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
return wcl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
EwcWcsToStr(const wchar_t * wcs, int wcl, char *str, int len)
|
|
|
|
{
|
|
|
|
#if HAVE_ICONV
|
2008-12-04 14:17:02 -08:00
|
|
|
ICONV_CONST char *pi;
|
2006-11-11 16:39:19 -08:00
|
|
|
size_t ni, no, rc;
|
|
|
|
|
2008-12-04 14:17:02 -08:00
|
|
|
pi = (ICONV_CONST char *)wcs;
|
2006-11-11 16:39:19 -08:00
|
|
|
ni = wcl * sizeof(wchar_t);
|
|
|
|
no = len;
|
2006-11-19 04:34:18 -08:00
|
|
|
rc = iconv(iconv_cd_wcs2str, &pi, &ni, &str, &no);
|
2006-11-11 16:39:19 -08:00
|
|
|
if (rc == (size_t) (-1))
|
|
|
|
return 0;
|
|
|
|
return len - no;
|
|
|
|
#else
|
|
|
|
int i, j, n;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < wcl; i++)
|
|
|
|
{
|
|
|
|
if (j + (int)MB_CUR_MAX > len)
|
|
|
|
break;
|
|
|
|
n = wctomb(str + j, wcs[i]);
|
|
|
|
if (n > 0)
|
|
|
|
j += n;
|
|
|
|
}
|
|
|
|
str[j] = '\0';
|
|
|
|
return j;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup
|
|
|
|
*/
|
|
|
|
|
2008-03-23 04:54:24 -07:00
|
|
|
static struct {
|
2006-04-21 16:47:30 -07:00
|
|
|
char *internal;
|
|
|
|
char *exported;
|
|
|
|
} Conf_locale =
|
|
|
|
{
|
|
|
|
NULL, NULL};
|
|
|
|
|
2008-03-23 04:54:24 -07:00
|
|
|
static struct {
|
2006-04-21 16:47:30 -07:00
|
|
|
char init;
|
|
|
|
char *env_language;
|
|
|
|
char *env_lc_all;
|
|
|
|
char *env_lc_messages;
|
|
|
|
char *env_lang;
|
|
|
|
} locale_data;
|
|
|
|
|
|
|
|
static void
|
|
|
|
LangEnvironmentSetup(const char *locale)
|
|
|
|
{
|
|
|
|
/* Precedence: LANGUAGE, LC_ALL, LC_MESSAGES, LANG */
|
|
|
|
if (locale)
|
|
|
|
{
|
|
|
|
/* Set requested */
|
|
|
|
Esetenv("LANGUAGE", locale);
|
|
|
|
Esetenv("LC_ALL", locale);
|
|
|
|
Esetenv("LANG", locale);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Restore saved */
|
|
|
|
Esetenv("LANGUAGE", locale_data.env_language);
|
|
|
|
Esetenv("LC_ALL", locale_data.env_lc_all);
|
|
|
|
Esetenv("LC_MESSAGES", locale_data.env_lc_messages);
|
|
|
|
Esetenv("LANG", locale_data.env_lang);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LangEnvironmentSave(void)
|
|
|
|
{
|
|
|
|
if (locale_data.init)
|
|
|
|
return;
|
|
|
|
locale_data.init = 1;
|
|
|
|
|
|
|
|
locale_data.env_language = Estrdup(getenv("LANGUAGE"));
|
|
|
|
locale_data.env_lc_all = Estrdup(getenv("LC_ALL"));
|
|
|
|
locale_data.env_lc_messages = Estrdup(getenv("LC_MESSAGES"));
|
|
|
|
locale_data.env_lang = Estrdup(getenv("LANG"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LangExport(void)
|
|
|
|
{
|
|
|
|
if (Conf_locale.exported)
|
|
|
|
LangEnvironmentSetup(Conf_locale.exported);
|
|
|
|
else if (Conf_locale.internal)
|
|
|
|
LangEnvironmentSetup(NULL);
|
|
|
|
}
|
|
|
|
|
2004-04-01 15:11:16 -08:00
|
|
|
void
|
|
|
|
LangInit(void)
|
|
|
|
{
|
2004-05-23 09:11:36 -07:00
|
|
|
const char *enc_loc, *enc_int;
|
2004-04-01 15:11:16 -08:00
|
|
|
|
2006-04-21 16:47:30 -07:00
|
|
|
if (!locale_data.init)
|
|
|
|
LangEnvironmentSave();
|
|
|
|
|
|
|
|
LangEnvironmentSetup(Conf_locale.internal);
|
|
|
|
|
|
|
|
setlocale(LC_ALL, ""); /* Set up things according to env vars */
|
2004-05-22 08:18:04 -07:00
|
|
|
|
2004-04-01 15:11:16 -08:00
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
|
|
|
|
|
|
|
if (!XSupportsLocale())
|
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
XSetLocaleModifiers("");
|
|
|
|
|
|
|
|
/* I dont want any internationalisation of my numeric input & output */
|
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
|
2004-05-22 08:18:04 -07:00
|
|
|
/* Get the environment character encoding */
|
|
|
|
#if HAVE_LANGINFO_CODESET
|
2004-05-23 09:11:36 -07:00
|
|
|
enc_loc = nl_langinfo(CODESET);
|
2004-05-22 08:18:04 -07:00
|
|
|
#else
|
2004-05-23 09:11:36 -07:00
|
|
|
enc_loc = "ISO-8859-1";
|
2004-04-01 15:11:16 -08:00
|
|
|
#endif
|
2004-05-22 08:18:04 -07:00
|
|
|
|
|
|
|
/* Debug - possibility to set desired internal representation */
|
|
|
|
enc_int = getenv("E_CHARSET");
|
|
|
|
if (enc_int)
|
|
|
|
bind_textdomain_codeset(PACKAGE, enc_int);
|
|
|
|
else
|
2004-05-23 09:11:36 -07:00
|
|
|
enc_int = enc_loc;
|
|
|
|
|
2005-07-17 05:55:13 -07:00
|
|
|
Mode.locale.lang = setlocale(LC_MESSAGES, NULL);
|
2006-11-19 13:55:52 -08:00
|
|
|
if (EDebug(EDBUG_TYPE_VERBOSE))
|
2005-02-22 13:04:24 -08:00
|
|
|
{
|
|
|
|
Eprintf("Locale: %s\n", setlocale(LC_ALL, NULL));
|
2009-03-06 13:40:09 -08:00
|
|
|
Eprintf("Character encoding: locale=%s internal=%s MB_CUR_MAX=%zu\n",
|
|
|
|
enc_loc, enc_int, MB_CUR_MAX);
|
2005-02-22 13:04:24 -08:00
|
|
|
}
|
2004-05-22 08:18:04 -07:00
|
|
|
|
2008-08-14 11:44:23 -07:00
|
|
|
if (!Estrcasecmp(enc_loc, "utf8") || !Estrcasecmp(enc_loc, "utf-8"))
|
2005-07-17 05:55:13 -07:00
|
|
|
Mode.locale.utf8_loc = 1;
|
2008-08-14 11:44:23 -07:00
|
|
|
if (!Estrcasecmp(enc_int, "utf8") || !Estrcasecmp(enc_int, "utf-8"))
|
2005-07-17 05:55:13 -07:00
|
|
|
Mode.locale.utf8_int = 1;
|
2004-05-23 09:11:36 -07:00
|
|
|
|
|
|
|
#if HAVE_ICONV
|
2008-06-26 14:59:23 -07:00
|
|
|
if (Mode.locale.utf8_int && Mode.locale.utf8_loc)
|
|
|
|
return;
|
2005-07-17 05:55:13 -07:00
|
|
|
if (Mode.locale.utf8_int)
|
2004-05-23 09:11:36 -07:00
|
|
|
{
|
2008-06-26 14:57:22 -07:00
|
|
|
iconv_cd_loc2int = EiconvOpen("UTF-8", enc_loc);
|
|
|
|
iconv_cd_int2loc = EiconvOpen(enc_loc, "UTF-8");
|
2004-05-23 09:11:36 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-26 14:57:22 -07:00
|
|
|
iconv_cd_utf82int = EiconvOpen(enc_loc, "UTF-8");
|
|
|
|
iconv_cd_int2utf8 = EiconvOpen("UTF-8", enc_loc);
|
2004-05-23 09:11:36 -07:00
|
|
|
}
|
|
|
|
#endif
|
2004-04-01 15:11:16 -08:00
|
|
|
}
|
|
|
|
|
2006-04-21 16:47:30 -07:00
|
|
|
void
|
|
|
|
LangExit(void)
|
|
|
|
{
|
|
|
|
#if HAVE_ICONV
|
2006-11-24 15:26:43 -08:00
|
|
|
if (iconv_cd_int2utf8 != BAD_CD)
|
2006-04-21 16:47:30 -07:00
|
|
|
iconv_close(iconv_cd_int2utf8);
|
2006-11-24 15:26:43 -08:00
|
|
|
if (iconv_cd_utf82int != BAD_CD)
|
2006-04-21 16:47:30 -07:00
|
|
|
iconv_close(iconv_cd_utf82int);
|
2006-11-24 15:26:43 -08:00
|
|
|
if (iconv_cd_int2loc != BAD_CD)
|
2006-04-21 16:47:30 -07:00
|
|
|
iconv_close(iconv_cd_int2loc);
|
2006-11-24 15:26:43 -08:00
|
|
|
if (iconv_cd_loc2int != BAD_CD)
|
2006-04-21 16:47:30 -07:00
|
|
|
iconv_close(iconv_cd_loc2int);
|
2006-11-24 15:26:43 -08:00
|
|
|
iconv_cd_int2utf8 = iconv_cd_utf82int = BAD_CD;
|
|
|
|
iconv_cd_int2loc = iconv_cd_loc2int = BAD_CD;
|
2006-04-21 16:47:30 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
LangEnvironmentSetup(NULL);
|
|
|
|
}
|
2004-04-01 15:11:16 -08:00
|
|
|
|
|
|
|
static void
|
2006-04-21 16:47:30 -07:00
|
|
|
LangCfgChange(void *item __UNUSED__, const char *locale)
|
2004-04-01 15:11:16 -08:00
|
|
|
{
|
2006-04-21 16:47:30 -07:00
|
|
|
if (*locale == '\0')
|
|
|
|
locale = NULL;
|
|
|
|
LangExit();
|
|
|
|
_EFDUP(Conf_locale.internal, locale);
|
|
|
|
LangInit();
|
2004-04-01 15:11:16 -08:00
|
|
|
}
|
|
|
|
|
2006-04-21 16:47:30 -07:00
|
|
|
static const CfgItem LocaleCfgItems[] = {
|
|
|
|
CFG_FUNC_STR(Conf_locale, internal, LangCfgChange),
|
|
|
|
CFG_ITEM_STR(Conf_locale, exported),
|
|
|
|
};
|
|
|
|
#define N_CFG_ITEMS (sizeof(LocaleCfgItems)/sizeof(CfgItem))
|
|
|
|
|
2007-01-16 17:10:44 -08:00
|
|
|
extern const EModule ModLocale;
|
2010-08-08 12:03:34 -07:00
|
|
|
|
2006-04-21 16:47:30 -07:00
|
|
|
const EModule ModLocale = {
|
|
|
|
"locale", NULL,
|
|
|
|
NULL,
|
|
|
|
{0, NULL},
|
|
|
|
{N_CFG_ITEMS, LocaleCfgItems}
|
|
|
|
};
|