From: Pierre Habouzit Date: Thu, 29 Mar 2007 21:37:03 +0000 (+0200) Subject: Simplify charset.cpkg a bit X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=8f75834aeadb902879602a82a259f4d3bf9c569c;p=apps%2Fmadmutt.git Simplify charset.cpkg a bit Signed-off-by: Pierre Habouzit --- diff --git a/charset.cpkg b/charset.cpkg index 2c8f507..6934987 100644 --- a/charset.cpkg +++ b/charset.cpkg @@ -38,9 +38,36 @@ #endif @import "lib-lua/base.cpkg" +int Charset_is_utf8 = 0; +wchar_t CharsetReplacement = '?'; + static rx_t *charset_hooks = NULL; static rx_t *iconv_hooks = NULL; +static char *charset_init(void) +{ + const char *res = "iso-8859-1"; +#ifdef HAVE_LANGINFO_CODESET + char buff[STRING]; + char buff2[STRING]; + + m_strcpy(buff, sizeof(buff), nl_langinfo(CODESET)); + charset_canonicalize(buff2, sizeof(buff2), buff); + + /* finally, set $charset */ + if (!m_strisempty(buff2)) { + res = buff2; + } +#endif +#ifdef HAVE_BIND_TEXTDOMAIN_CODESET + bind_textdomain_codeset(PACKAGE, res); +#endif + + Charset_is_utf8 = charset_is_utf8(res); + CharsetReplacement = Charset_is_utf8 ? 0xfffd : '?'; + return m_strdup(res); +} + @package MCharset { /* ** .pp @@ -64,7 +91,7 @@ static rx_t *iconv_hooks = NULL; ** .pp ** Character set your terminal uses to display and enter textual data. */ - string_t charset = NULL; + string_t charset = charset_init(); /* ** .pp @@ -106,40 +133,10 @@ static rx_t *iconv_hooks = NULL; }; }; -int Charset_is_utf8 = 0; -wchar_t CharsetReplacement = '?'; - - /****************************************************************************/ /* charset functions */ /****************************************************************************/ -void charset_initialize(void) -{ -#ifdef HAVE_LANGINFO_CODESET - char buff[STRING]; - char buff2[STRING]; - - m_strcpy(buff, sizeof(buff), nl_langinfo(CODESET)); - charset_canonicalize(buff2, sizeof(buff2), buff); - - /* finally, set $charset */ - if (!m_strisempty(buff2)) { - m_strreplace(&MCharset.charset, buff2); - } else -#endif - { - m_strreplace(&MCharset.charset, "iso-8859-1"); - } - - Charset_is_utf8 = !m_strcmp(MCharset.charset, "utf-8"); - CharsetReplacement = Charset_is_utf8 ? 0xfffd : '?'; - -#ifdef HAVE_BIND_TEXTDOMAIN_CODESET - bind_textdomain_codeset(PACKAGE, MCharset.charset); -#endif -} - #include "charset.gperf" void charset_canonicalize(char *dest, ssize_t dlen, const char *name) { diff --git a/charset.h b/charset.h index 67eb482..5b1aa65 100644 --- a/charset.h +++ b/charset.h @@ -42,11 +42,9 @@ extern int Charset_is_utf8; extern wchar_t CharsetReplacement; -void charset_initialize(void); void charset_canonicalize(char *, ssize_t, const char *); -int charset_is_utf8(const char *s); -int charset_is_us_ascii(const char *s); - +int charset_is_utf8(const char *); +int charset_is_us_ascii(const char *); const char *charset_getfirst(const char *); diff --git a/init.c b/init.c index 3d17e76..2999e7e 100644 --- a/init.c +++ b/init.c @@ -2253,8 +2253,6 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) if ((p = getenv ("EMAIL")) != NULL) From = rfc822_parse_adrlist (NULL, p); - charset_initialize(); - /* Set standard defaults */ hash_map (ConfigOptions, mutt_set_default, 0); hash_map (ConfigOptions, mutt_restore_default, 0);