#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
** .pp
** Character set your terminal uses to display and enter textual data.
*/
- string_t charset = NULL;
+ string_t charset = charset_init();
/*
** .pp
};
};
-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)
{
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 *);