diff --git a/client/src/core/abstract.cc b/client/src/core/abstract.cc index f2d3e55..333c931 100644 --- a/client/src/core/abstract.cc +++ b/client/src/core/abstract.cc @@ -49,6 +49,8 @@ #ifdef HAVE_ICONV this->converter.local = (iconv_t) (-1); this->converter.host = (iconv_t) (-1); +#else + this->converter = nullptr; #endif } @@ -63,6 +65,13 @@ if(this->converter.host != (iconv_t) (-1)) iconv_close(this->converter.host); +#else + + if(converter) { + lib3270_iconv_free(converter); + converter = nullptr; + } + #endif } @@ -102,8 +111,12 @@ #else - throw std::runtime_error("No ICONV Support"); + if(converter) + lib3270_iconv_free(converter); + + converter = lib3270_iconv_new(remote,local); + debug("lib3270_iconv_new(",remote,",",local,"=",(void *) converter); #endif @@ -147,21 +160,48 @@ /// @brief Converte string recebida do host para o charset atual. std::string Abstract::Session::convertFromHost(const std::string &str) const { -// debug(__FUNCTION__,"(",str.c_str(),")"); + #ifdef HAVE_ICONV + return convertCharset(const_cast(this)->converter.local,str.c_str(),str.size()); + #else + if(converter) { + + lib3270_auto_cleanup converted = lib3270_iconv_from_host(converter,str.c_str(),str.size()); + if(converted) { + return std::string(converted); + } + + } + return str; + #endif // HAVE_ICONV } // @brief Converte string do charset atual para o charset do host. std::string Abstract::Session::convertToHost(const char *text, int length) const { + #ifdef HAVE_ICONV + return convertCharset(const_cast(this)->converter.host,text,length); + #else - return std::string(text,length); + + if(converter) { + + lib3270_auto_cleanup converted = lib3270_iconv_to_host(converter,text,length); + if(converted) { + return std::string(converted); + } + + } + #endif // HAVE_ICONV + + return std::string(text,length); + } /// @brief Converte string do charset atual para o charset do host. diff --git a/client/src/include/ipc-client-internals.h b/client/src/include/ipc-client-internals.h index c89203e..ba011c4 100644 --- a/client/src/include/ipc-client-internals.h +++ b/client/src/include/ipc-client-internals.h @@ -61,13 +61,17 @@ #include #include +#ifndef HAVE_ICONV + #include +#endif // !HAVE_ICONV + #ifdef HAVE_LIBINTL - #include - #define _( x ) dgettext(PACKAGE_NAME, x) - #define N_( x ) x + #include + #define _( x ) dgettext(PACKAGE_NAME, x) + #define N_( x ) x #else - #define _( x ) x - #define N_( x ) x + #define _( x ) x + #define N_( x ) x #endif // HAVE_LIBINTL // @@ -145,10 +149,15 @@ } converter; - /// @brief Converte charset. static std::string convertCharset(iconv_t &converter, const char *str, int length); + +#else + + LIB3270_ICONV * converter; + #endif + /// @brief Converte charset. protected: diff --git a/client/src/session/local/init.cc b/client/src/session/local/init.cc index 4558cdf..7119f32 100644 --- a/client/src/session/local/init.cc +++ b/client/src/session/local/init.cc @@ -67,9 +67,7 @@ lib3270_set_user_data(this->hSession,(void *) this); -#ifdef HAVE_ICONV setCharSet(); -#endif // HAVE_ICONV lib3270_set_popup_handler(this->hSession, popupHandler); -- libgit2 0.21.2