From 550a0419a64f01e8b14f5ecaed6f1b8d190837f5 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 26 Mar 2016 14:07:09 +0100 Subject: degesch: detect //TRANSLIT support, use cp1252 Now BSDs should have it enabled as well. --- CMakeLists.txt | 10 +++++++++- config.h.in | 2 ++ degesch.c | 36 ++++++++++++++++++++---------------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aada20f..384098e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,10 +64,18 @@ endif ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD") foreach (extra iconv rt) find_library (extra_lib_${extra} ${extra}) if (extra_lib_${extra}) - list (APPEND project_libraries ${extra}) + list (APPEND project_libraries ${extra_lib_${extra}}) endif (extra_lib_${extra}) endforeach (extra) +include (CheckCSourceRuns) +set (CMAKE_REQUIRED_LIBRARIES ${project_libraries}) +get_property (CMAKE_REQUIRED_INCLUDES + DIRECTORY "${PROJECT_SOURCE_DIR}" PROPERTY INCLUDE_DIRECTORIES) +CHECK_C_SOURCE_RUNS ("#include + int main () { return iconv_open (\"UTF-8//TRANSLIT\", \"ISO-8859-1\") + == (iconv_t) -1; }" ICONV_ACCEPTS_TRANSLIT) + # Dependencies for degesch pkg_check_modules (libffi REQUIRED libffi) list (APPEND degesch_libraries ${libffi_LIBRARIES}) diff --git a/config.h.in b/config.h.in index 100ac26..e5a98d0 100644 --- a/config.h.in +++ b/config.h.in @@ -8,4 +8,6 @@ #cmakedefine HAVE_EDITLINE #cmakedefine HAVE_LUA +#cmakedefine01 ICONV_ACCEPTS_TRANSLIT + #endif // ! CONFIG_H 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); -- cgit v1.2.3-70-g09d2