Browse Source

degesch: detect //TRANSLIT support, use cp1252

Now BSDs should have it enabled as well.
Přemysl Janouch 2 years ago
parent
commit
550a0419a6
3 changed files with 31 additions and 17 deletions
  1. 9
    1
      CMakeLists.txt
  2. 2
    0
      config.h.in
  3. 20
    16
      degesch.c

+ 9
- 1
CMakeLists.txt View File

@@ -64,10 +64,18 @@ endif ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
64 64
 foreach (extra iconv rt)
65 65
 	find_library (extra_lib_${extra} ${extra})
66 66
 	if (extra_lib_${extra})
67
-		list (APPEND project_libraries ${extra})
67
+		list (APPEND project_libraries ${extra_lib_${extra}})
68 68
 	endif (extra_lib_${extra})
69 69
 endforeach (extra)
70 70
 
71
+include (CheckCSourceRuns)
72
+set (CMAKE_REQUIRED_LIBRARIES ${project_libraries})
73
+get_property (CMAKE_REQUIRED_INCLUDES
74
+	DIRECTORY "${PROJECT_SOURCE_DIR}" PROPERTY INCLUDE_DIRECTORIES)
75
+CHECK_C_SOURCE_RUNS ("#include <iconv.h>
76
+	int main () { return iconv_open (\"UTF-8//TRANSLIT\", \"ISO-8859-1\")
77
+		== (iconv_t) -1; }" ICONV_ACCEPTS_TRANSLIT)
78
+
71 79
 # Dependencies for degesch
72 80
 pkg_check_modules (libffi REQUIRED libffi)
73 81
 list (APPEND degesch_libraries ${libffi_LIBRARIES})

+ 2
- 0
config.h.in View File

@@ -8,4 +8,6 @@
8 8
 #cmakedefine HAVE_EDITLINE
9 9
 #cmakedefine HAVE_LUA
10 10
 
11
+#cmakedefine01 ICONV_ACCEPTS_TRANSLIT
12
+
11 13
 #endif  // ! CONFIG_H

+ 20
- 16
degesch.c View File

@@ -2021,6 +2021,20 @@ filter_color_cube_for_acceptable_nick_colors (size_t *len)
2021 2021
 	return table;
2022 2022
 }
2023 2023
 
2024
+static bool
2025
+app_iconv_open (iconv_t *target, const char *to, const char *from)
2026
+{
2027
+	if (ICONV_ACCEPTS_TRANSLIT)
2028
+	{
2029
+		char *to_real = xstrdup_printf ("%s//TRANSLIT", to);
2030
+		*target = iconv_open (to_real, from);
2031
+		free (to_real);
2032
+	}
2033
+	else
2034
+		*target = iconv_open (to, from);
2035
+	return *target != (iconv_t) -1;
2036
+}
2037
+
2024 2038
 static void
2025 2039
 app_context_init (struct app_context *self)
2026 2040
 {
@@ -2040,25 +2054,15 @@ app_context_init (struct app_context *self)
2040 2054
 	self->backlog_limit = 1000;
2041 2055
 	self->last_displayed_msg_time = time (NULL);
2042 2056
 
2043
-	char *encoding = nl_langinfo (CODESET);
2044
-	// FIXME: put a check for "//TRANSLIT" in CMakeLists.txt
2045
-#ifdef __linux__
2046
-	encoding = xstrdup_printf ("%s//TRANSLIT", encoding);
2047
-#else // ! __linux__
2048
-	encoding = xstrdup (encoding);
2049
-#endif // ! __linux__
2050
-
2051
-	if ((self->term_from_utf8 =
2052
-		iconv_open (encoding, "UTF-8")) == (iconv_t) -1
2053
-	 || (self->latin1_to_utf8 =
2054
-		iconv_open ("UTF-8", "ISO-8859-1")) == (iconv_t) -1
2055
-	 || (self->term_to_utf8 =
2056
-		iconv_open ("UTF-8", nl_langinfo (CODESET))) == (iconv_t) -1)
2057
+	// Windows 1252 redefines several silly control characters as glyphs
2058
+	char *native = nl_langinfo (CODESET);
2059
+	if (!app_iconv_open (&self->term_from_utf8, native, "UTF-8")
2060
+	 || !app_iconv_open (&self->term_to_utf8, "UTF-8", native)
2061
+	 || (!app_iconv_open (&self->latin1_to_utf8, "UTF-8", "WINDOWS-1252")
2062
+	  && !app_iconv_open (&self->latin1_to_utf8, "UTF-8", "ISO-8859-1")))
2057 2063
 		exit_fatal ("creating the UTF-8 conversion object failed: %s",
2058 2064
 			strerror (errno));
2059 2065
 
2060
-	free (encoding);
2061
-
2062 2066
 	self->input = input_new ();
2063 2067
 	self->input->user_data = self;
2064 2068
 	str_vector_init (&self->pending_input);

Loading…
Cancel
Save