degesch: detect //TRANSLIT support, use cp1252

Now BSDs should have it enabled as well.
This commit is contained in:
Přemysl Eric Janouch 2016-03-26 14:07:09 +01:00
parent 9b12c830d1
commit 550a0419a6
3 changed files with 31 additions and 17 deletions

View File

@ -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 <iconv.h>
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})

View File

@ -8,4 +8,6 @@
#cmakedefine HAVE_EDITLINE
#cmakedefine HAVE_LUA
#cmakedefine01 ICONV_ACCEPTS_TRANSLIT
#endif // ! CONFIG_H

View File

@ -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);