+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_H
+ 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
+ bind_textdomain_codeset(PACKAGE, res);
+ return m_strdup(res);
+}
+
+static void charset_onchange(const char *cset)
+{
+ Charset_is_utf8 = charset_is_utf8(cset);
+ CharsetReplacement = Charset_is_utf8 ? 0xfffd : '?';
+}
+
+@package mod_cset {