From bcf70f374070953f19cc6edd8fea2f6227f79606 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 7 May 2017 17:59:53 +0200 Subject: [PATCH] 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 --- awesomeConfig.cmake | 37 ------------------------------ draw.c | 55 --------------------------------------------- draw.h | 23 ------------------- objects/tag.c | 7 +++--- 4 files changed, 3 insertions(+), 119 deletions(-) diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index 8648cb20..6371551b 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -160,43 +160,6 @@ endforeach() # Do it again, but this time with the CFLAGS/LDFLAGS 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) find_library(${variable} ${library}) if(NOT ${variable}) diff --git a/draw.c b/draw.c index 1d720783..72d3541c 100644 --- a/draw.c +++ b/draw.c @@ -24,7 +24,6 @@ #include "globalconf.h" #include -#include #include #include #include @@ -33,60 +32,6 @@ #include #include -/** 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 inline void diff --git a/draw.h b/draw.h index 0a414752..d2a0f7e0 100644 --- a/draw.h +++ b/draw.h @@ -47,29 +47,6 @@ struct area_t #define AREA_EQUAL(a, b) ((a).x == (b).x && (a).y == (b).y && \ (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 cairo_surface_array_destroy_surface(cairo_surface_t **s) { diff --git a/objects/tag.c b/objects/tag.c index f8bf7874..8013ad1a 100644 --- a/objects/tag.c +++ b/objects/tag.c @@ -366,7 +366,7 @@ is_client_tagged(client_t *c, tag_t *t) return false; } -/** Get the index of the tag with focused client or first selected +/** Get the index of the tag with focused client or first selected * \return Its index */ int @@ -475,10 +475,9 @@ LUA_OBJECT_EXPORT_PROPERTY(tag, tag_t, activated, lua_pushboolean) static int luaA_tag_set_name(lua_State *L, tag_t *tag) { - size_t len; - const char *buf = luaL_checklstring(L, -1, &len); + const char *buf = luaL_checkstring(L, -1); 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); ewmh_update_net_desktop_names(); return 0;