summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-03-26 14:07:09 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-03-26 14:27:59 +0100
commit550a0419a64f01e8b14f5ecaed6f1b8d190837f5 (patch)
treec4d63ba229c8ac13316508c26141ecfc2bd150c0 /degesch.c
parent9b12c830d10a84460b79ac6b7a10e2bf190722ef (diff)
downloadxK-550a0419a64f01e8b14f5ecaed6f1b8d190837f5.tar.gz
xK-550a0419a64f01e8b14f5ecaed6f1b8d190837f5.tar.xz
xK-550a0419a64f01e8b14f5ecaed6f1b8d190837f5.zip
degesch: detect //TRANSLIT support, use cp1252
Now BSDs should have it enabled as well.
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/degesch.c b/degesch.c
index bee5ef8..7b83dd4 100644
--- a/degesch.c
+++ b/degesch.c
@@ -2021,6 +2021,20 @@ filter_color_cube_for_acceptable_nick_colors (size_t *len)
return table;
}
+static bool
+app_iconv_open (iconv_t *target, const char *to, const char *from)
+{
+ if (ICONV_ACCEPTS_TRANSLIT)
+ {
+ char *to_real = xstrdup_printf ("%s//TRANSLIT", to);
+ *target = iconv_open (to_real, from);
+ free (to_real);
+ }
+ else
+ *target = iconv_open (to, from);
+ return *target != (iconv_t) -1;
+}
+
static void
app_context_init (struct app_context *self)
{
@@ -2040,25 +2054,15 @@ app_context_init (struct app_context *self)
self->backlog_limit = 1000;
self->last_displayed_msg_time = time (NULL);
- char *encoding = nl_langinfo (CODESET);
- // FIXME: put a check for "//TRANSLIT" in CMakeLists.txt
-#ifdef __linux__
- encoding = xstrdup_printf ("%s//TRANSLIT", encoding);
-#else // ! __linux__
- encoding = xstrdup (encoding);
-#endif // ! __linux__
-
- if ((self->term_from_utf8 =
- iconv_open (encoding, "UTF-8")) == (iconv_t) -1
- || (self->latin1_to_utf8 =
- iconv_open ("UTF-8", "ISO-8859-1")) == (iconv_t) -1
- || (self->term_to_utf8 =
- iconv_open ("UTF-8", nl_langinfo (CODESET))) == (iconv_t) -1)
+ // Windows 1252 redefines several silly control characters as glyphs
+ char *native = nl_langinfo (CODESET);
+ if (!app_iconv_open (&self->term_from_utf8, native, "UTF-8")
+ || !app_iconv_open (&self->term_to_utf8, "UTF-8", native)
+ || (!app_iconv_open (&self->latin1_to_utf8, "UTF-8", "WINDOWS-1252")
+ && !app_iconv_open (&self->latin1_to_utf8, "UTF-8", "ISO-8859-1")))
exit_fatal ("creating the UTF-8 conversion object failed: %s",
strerror (errno));
- free (encoding);
-
self->input = input_new ();
self->input->user_data = self;
str_vector_init (&self->pending_input);