Drop our use of iconv (#1772)

We were only using this for tag names. This means we are assuming that
everything is UTF8, but tag names are provided in the local locale and
need to be translated into UTF8? That makes no sense, so just drop this.

Fixes: https://github.com/awesomeWM/awesome/issues/1753
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2017-05-07 17:59:53 +02:00 committed by Daniel Hahler
parent eba61df4ef
commit bcf70f3740
4 changed files with 3 additions and 119 deletions

View File

@ -160,43 +160,6 @@ endforeach()
# Do it again, but this time with the CFLAGS/LDFLAGS # Do it again, but this time with the CFLAGS/LDFLAGS
pkg_check_modules(AWESOME_REQUIRED REQUIRED ${AWESOME_DEPENDENCIES}) pkg_check_modules(AWESOME_REQUIRED REQUIRED ${AWESOME_DEPENDENCIES})
# On Mac OS X and FreeBSD, the executable of Awesome has to be linked against libiconv
# explicitly. Unfortunately, libiconv doesn't have its pkg-config file,
# and CMake doesn't provide a module for looking up the library. Thus, we
# have to do everything for ourselves...
if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
if(NOT DEFINED AWESOME_ICONV_SEARCH_PATHS)
set(AWESOME_ICONV_SEARCH_PATHS /opt/local /opt /usr/local /usr)
endif()
if(NOT DEFINED AWESOME_ICONV_INCLUDE_DIR)
find_path(AWESOME_ICONV_INCLUDE_DIR
iconv.h
PATHS ${AWESOME_ICONV_SEARCH_PATHS}
PATH_SUFFIXES include
NO_CMAKE_SYSTEM_PATH)
endif()
if(NOT DEFINED AWESOME_ICONV_LIBRARY_PATH)
get_filename_component(AWESOME_ICONV_BASE_DIRECTORY ${AWESOME_ICONV_INCLUDE_DIR} DIRECTORY)
find_library(AWESOME_ICONV_LIBRARY_PATH
NAMES iconv
HINTS ${AWESOME_ICONV_BASE_DIRECTORY}
PATH_SUFFIXES lib)
endif()
if(NOT DEFINED AWESOME_ICONV_LIBRARY_PATH)
message(FATAL_ERROR "Looking for iconv library - not found.")
else()
message(STATUS "Looking for iconv library - found: ${AWESOME_ICONV_LIBRARY_PATH}")
endif()
set(AWESOME_REQUIRED_LDFLAGS
${AWESOME_REQUIRED_LDFLAGS} ${AWESOME_ICONV_LIBRARY_PATH})
set(AWESOME_REQUIRED_INCLUDE_DIRS
${AWESOME_REQUIRED_INCLUDE_DIRS} ${AWESOME_ICONV_INCLUDE_DIR})
endif(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
macro(a_find_library variable library) macro(a_find_library variable library)
find_library(${variable} ${library}) find_library(${variable} ${library})
if(NOT ${variable}) if(NOT ${variable})

55
draw.c
View File

@ -24,7 +24,6 @@
#include "globalconf.h" #include "globalconf.h"
#include <langinfo.h> #include <langinfo.h>
#include <iconv.h>
#include <errno.h> #include <errno.h>
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
@ -33,60 +32,6 @@
#include <cairo-xcb.h> #include <cairo-xcb.h>
#include <lauxlib.h> #include <lauxlib.h>
/** Convert text from any charset to UTF-8 using iconv.
* \param iso The ISO string to convert.
* \param len The string size.
* \param dest The destination pointer. Memory will be allocated, up to you to
* free, like any char *.
* \param dlen The destination length, can be NULL.
* \return True if conversion was done.
*/
bool
draw_iso2utf8(const char *iso, size_t len, char **dest, ssize_t *dlen)
{
static iconv_t iso2utf8 = (iconv_t) -1;
static int8_t dont_need_convert = -1;
if(dont_need_convert == -1)
dont_need_convert = A_STREQ(nl_langinfo(CODESET), "UTF-8");
if(!len || dont_need_convert)
return false;
if(iso2utf8 == (iconv_t) -1)
{
iso2utf8 = iconv_open("UTF-8", nl_langinfo(CODESET));
if(iso2utf8 == (iconv_t) -1)
{
if(errno == EINVAL)
warn("unable to convert text from %s to UTF-8, not available",
nl_langinfo(CODESET));
else
warn("unable to convert text: %s", strerror(errno));
return false;
}
}
size_t orig_utf8len, utf8len;
char *utf8;
orig_utf8len = utf8len = 2 * len + 1;
utf8 = *dest = p_new(char, utf8len);
if(iconv(iso2utf8, (char **) &iso, &len, &utf8, &utf8len) == (size_t) -1)
{
warn("text conversion failed: %s", strerror(errno));
p_delete(dest);
return false;
}
if(dlen)
*dlen = orig_utf8len - utf8len;
return true;
}
static cairo_user_data_key_t data_key; static cairo_user_data_key_t data_key;
static inline void static inline void

23
draw.h
View File

@ -47,29 +47,6 @@ struct area_t
#define AREA_EQUAL(a, b) ((a).x == (b).x && (a).y == (b).y && \ #define AREA_EQUAL(a, b) ((a).x == (b).x && (a).y == (b).y && \
(a).width == (b).width && (a).height == (b).height) (a).width == (b).width && (a).height == (b).height)
bool draw_iso2utf8(const char *, size_t, char **, ssize_t *);
/** Convert a string to UTF-8.
* \param str The string to convert.
* \param len The string length.
* \param dest The destination string that will be allocated.
* \param dlen The destination string length allocated, can be NULL.
* \return True if the conversion happened, false otherwise. In both case, dest
* and dlen will have value and dest have to be free().
*/
static inline bool
a_iso2utf8(const char *str, ssize_t len, char **dest, ssize_t *dlen)
{
if(draw_iso2utf8(str, len, dest, dlen))
return true;
*dest = a_strdup(str);
if(dlen)
*dlen = len;
return false;
}
static inline void static inline void
cairo_surface_array_destroy_surface(cairo_surface_t **s) cairo_surface_array_destroy_surface(cairo_surface_t **s)
{ {

View File

@ -475,10 +475,9 @@ LUA_OBJECT_EXPORT_PROPERTY(tag, tag_t, activated, lua_pushboolean)
static int static int
luaA_tag_set_name(lua_State *L, tag_t *tag) luaA_tag_set_name(lua_State *L, tag_t *tag)
{ {
size_t len; const char *buf = luaL_checkstring(L, -1);
const char *buf = luaL_checklstring(L, -1, &len);
p_delete(&tag->name); p_delete(&tag->name);
a_iso2utf8(buf, len, &tag->name, NULL); tag->name = a_strdup(buf);
luaA_object_emit_signal(L, -3, "property::name", 0); luaA_object_emit_signal(L, -3, "property::name", 0);
ewmh_update_net_desktop_names(); ewmh_update_net_desktop_names();
return 0; return 0;