From fd5a3e142c0350f524f7e132c970af29c1ad71a6 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sat, 17 Jan 2009 14:10:44 +0100 Subject: [PATCH] do not exclude iconv support if unicode is enabled --- configure.in | 14 +++++++++----- src/charset.cpp | 19 ++++++++++++++++--- src/charset.h | 6 +++--- src/helpers.cpp | 3 ++- src/ncmpcpp.cpp | 10 +++++----- src/song.cpp | 4 ++-- 6 files changed, 37 insertions(+), 19 deletions(-) diff --git a/configure.in b/configure.in index 4ffc3663..b7db2005 100644 --- a/configure.in +++ b/configure.in @@ -13,6 +13,15 @@ AC_ARG_ENABLE(unicode, AS_HELP_STRING([--enable-unicode], [Enable utf8 support]) AC_ARG_WITH(taglib, AS_HELP_STRING([--with-taglib], [Enable tag editor]), [taglib=$withval], [taglib=no]) AC_ARG_WITH(curl, AS_HELP_STRING([--with-curl], [Enable fetching lyrics from the Internet]), [curl=$withval], [curl=no]) +dnl ====================== +dnl = checking for iconv = +dnl ====================== +AC_CHECK_FILE([/usr/share/i18n/SUPPORTED], AC_DEFINE([SUPPORTED_LOCALES], ["/usr/share/i18n/SUPPORTED"], [ ]), + AC_CHECK_FILE([/etc/locale.gen], AC_DEFINE([SUPPORTED_LOCALES], ["/etc/locale.gen"], [ ]), + AC_MSG_NOTICE(cannot find list of supported locales, iconv support will be disabled)) +) +AC_CHECK_HEADERS([iconv.h], , AC_MSG_NOTICE(cannot find iconv.h header, iconv support will be disabled)) + dnl ======================== dnl = checking for ncurses = dnl ======================== @@ -23,11 +32,6 @@ if test "$unicode" = "yes" ; then else ncurses_config_bin=ncurses5-config ncurses_lib=ncurses - AC_CHECK_FILE([/usr/share/i18n/SUPPORTED], AC_DEFINE([SUPPORTED_LOCALES], ["/usr/share/i18n/SUPPORTED"], [ ]), - AC_CHECK_FILE([/etc/locale.gen], AC_DEFINE([SUPPORTED_LOCALES], ["/etc/locale.gen"], [ ]), - AC_MSG_ERROR([cannot find list of supported locales])) - ) - AC_CHECK_HEADERS([iconv.h], ,) fi AC_PATH_PROG(NCURSES_CONFIG, $ncurses_config_bin) if test "$NCURSES_CONFIG" != "" ; then diff --git a/src/charset.cpp b/src/charset.cpp index 98dc29ae..aed3e806 100644 --- a/src/charset.cpp +++ b/src/charset.cpp @@ -20,12 +20,13 @@ #include "charset.h" -#if !defined(_UTF8) && defined(HAVE_ICONV_H) +#if defined(SUPPORTED_LOCALES) && defined(HAVE_ICONV_H) #include #include #include #include +#include #include #include "locale.h" @@ -95,7 +96,10 @@ void init_current_locale() return; std::ifstream f(SUPPORTED_LOCALES); if (!f.is_open()) + { + std::cerr << "ncmpcpp: cannot open file "SUPPORTED_LOCALES"!\n"; return; + } envlocale += " "; std::string line; while (!f.eof()) @@ -105,10 +109,19 @@ void init_current_locale() { try { - locale_charset = strdup((line.substr(line.find(" ")+1) + "//TRANSLIT").c_str()); + std::string charset = line.substr(line.find(" ")+1); + if (charset == "UTF-8" + || charset == "utf-8" + || charset == "utf8") + { + f.close(); + return; + } + locale_charset = strdup((charset + "//TRANSLIT").c_str()); } catch (std::out_of_range) { + f.close(); return; } break; @@ -165,5 +178,5 @@ void str_pool_locale_to_utf(char *&s) charset_convert(locale_charset, "utf8", s); } -#endif +#endif // SUPPORTED_LOCALES && HAVE_ICONV_H diff --git a/src/charset.h b/src/charset.h index f885c38f..8d093d70 100644 --- a/src/charset.h +++ b/src/charset.h @@ -25,9 +25,9 @@ #include #endif -#include +#if defined(SUPPORTED_LOCALES) && defined(HAVE_ICONV_H) -#if !defined(_UTF8) && defined(HAVE_ICONV_H) +#include void init_current_locale(); @@ -53,7 +53,7 @@ void str_pool_locale_to_utf(char *&); #define str_pool_utf_to_locale(x); #define str_pool_locale_to_utf(x); -#endif // !_UTF8 && HAVE_ICONV_H +#endif // SUPPORTED_LOCALES && HAVE_ICONV_H #endif diff --git a/src/helpers.cpp b/src/helpers.cpp index 5216e83b..fa731fa5 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -533,7 +533,8 @@ void DisplaySongInColumns(const Song &s, void *s_template, Menu *menu) void DisplaySong(const Song &s, void *data, Menu *menu) { - const_cast(&s)->Localize(); + if (!s.Localized()) + const_cast(&s)->Localize(); const string &song_template = data ? *static_cast(data) : ""; basic_buffer buf; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 4ee34924..159596ae 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -193,6 +193,11 @@ int main(int argc, char *argv[]) if (!ConnectToMPD()) return -1; + // redirect std::cerr output to ~/.ncmpcpp/error.log file + std::ofstream errorlog((config_dir + "error.log").c_str(), std::ios::app); + std::streambuf *cerr_buffer = std::cerr.rdbuf(); + std::cerr.rdbuf(errorlog.rdbuf()); + InitScreen(Config.colors_enabled); init_current_locale(); @@ -359,11 +364,6 @@ int main(int argc, char *argv[]) signal(SIGPIPE, SIG_IGN); - // redirect std::cerr output to ~/.ncmpcpp/error.log file - std::ofstream errorlog((config_dir + "error.log").c_str(), std::ios::app); - std::streambuf * cerr_buffer = std::cerr.rdbuf(); - std::cerr.rdbuf(errorlog.rdbuf()); - # ifdef HAVE_CURL_CURL_H pthread_attr_t attr_detached; pthread_attr_init(&attr_detached); diff --git a/src/song.cpp b/src/song.cpp index 4e96da4d..a8e2f481 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -77,7 +77,7 @@ string Song::GetLength() const void Song::Localize() { -# if !defined(_UTF8) && defined(HAVE_ICONV_H) +# if defined(SUPPORTED_LOCALES) && defined(HAVE_ICONV_H) if (isLocalised) return; str_pool_utf_to_locale(itsSong->file); @@ -94,7 +94,7 @@ void Song::Localize() str_pool_utf_to_locale(itsSong->disc); str_pool_utf_to_locale(itsSong->comment); isLocalised = 1; -# endif // !_UTF8 && HAVE_ICONV_H +# endif // SUPPORTED_LOCALES && HAVE_ICONV_H } /*void Song::Delocalize()