OpenToonz - An open-source full-featured 2D animation creation software
C
Remove ICONV dep (#3304)
rim26a2b2fc1139
diff --git a/toonz/sources/CMakeLists.txt b/toonz/sources/CMakeLists.txtindex 30cb181cd..05c3cc2eb 100644--- a/toonz/sources/CMakeLists.txt+++ b/toonz/sources/CMakeLists.txt@@ -459,6 +459,8 @@ elseif(BUILD_ENV_UNIXLIKE)find_package(LZO REQUIRED)message("LZO:" ${LZO_INCLUDE_DIR})+ find_library(PTHREAD_LIBRARY pthread)+if(NOT BUILD_TARGET_WIN)pkg_check_modules(USB_LIB REQUIRED libusb-1.0)pkg_check_modules(FREETYPE REQUIRED freetype2)diff --git a/toonz/sources/stdfx/CMakeLists.txt b/toonz/sources/stdfx/CMakeLists.txtindex e172e89a4..5c38beac9 100644--- a/toonz/sources/stdfx/CMakeLists.txt+++ b/toonz/sources/stdfx/CMakeLists.txt@@ -303,15 +303,4 @@ include_directories(_find_toonz_library(TNZLIBS "tnzcore;tnzbase;toonzlib")-if(BUILD_ENV_APPLE)- # macports を使っていると symbol が非互換の /opt/lib が引っ掛かってしまう- find_library(ICONV_LIB iconv HINTS /usr/lib)- if(ICONV_LIB-NOTFOUND)- message("************* NO ICONV ****************")- else()- message("************* ICONV:" ${ICONV_LIB})- endif()- target_link_libraries(tnzstdfx Qt5::Core Qt5::Gui Qt5::OpenGL ${GL_LIB} ${GLEW_LIB} ${TNZLIBS} ${ICONV_LIB})-else()- target_link_libraries(tnzstdfx Qt5::Core Qt5::Gui Qt5::OpenGL ${GL_LIB} ${GLEW_LIB} ${TNZLIBS})-endif()+target_link_libraries(tnzstdfx Qt5::Core Qt5::Gui Qt5::OpenGL ${GL_LIB} ${GLEW_LIB} ${TNZLIBS} ${PTHREAD_LIBRARY})diff --git a/toonz/sources/stdfx/igs_resource_msg_from_err_unix.cpp b/toonz/sources/stdfx/igs_resource_msg_from_err_unix.cppindex 0bd3f4e5b..da51594e7 100644--- a/toonz/sources/stdfx/igs_resource_msg_from_err_unix.cpp+++ b/toonz/sources/stdfx/igs_resource_msg_from_err_unix.cpp@@ -3,102 +3,12 @@#include <vector>#include <stdexcept> // std::domain_error(-)#include <locale>-#include <iconv.h>#include "igs_resource_msg_from_err.h"-/*------ localeを日本に設定し日本語を扱うことを指示(必須)-使う文字コードは"locale -a"で調べる */-void igs::resource::locale_to_jp(void) { setlocale(LC_CTYPE, "ja_JP.utf8"); }-#if 0 //-------/*- リサーチ中- 日本語環境を環境変数から取ってくる場合のルーチン- deamonの場合これでいいのか???- さらに調査が必要- 2013-02-18- */-#include <X11/Xlib.h>-#include <X11/Xlocale.h>-void igs::resource::locale_to_jp(void) {- /*- Software Design 1993年3月号- "SPECIAL ISSUE どうする?UNIXの日本語環境"- 稚内北星短期大学 丸山 不二夫- Page14 リスト4 より- X11R5での日本語処理 - ロケールの設定- 標準的な処理手順- 全てのX(lib)プログラムの先頭で行う- */-- /* 次の場合、環境変数 LANG から、地域名を得ます- 引数locale が "" の場合、- ロケールの各部分の設定には環境変数が参照される。- その詳細は実装依存である。- Linux Programmer’s Manual July 4, 1999より- */- if ( ::setlocale( LC_ALL ,"" ) == NULL ) {- throw std::domain_error( "Can not set locale." );- }-- /* Xlibが、現在の地域をサポートしているかチェックします */- if ( !::XSupportsLocale() ) {- std::string msg("X is not support locale ");- msg += setlocale( LC_ALL ,NULL );- msg += ".\n";- throw std::domain_error( msg.c_str() );- }-- /* 次の場合、環境変数 XMODIFIERS から修飾子が得られます- この修飾子は。入力メソッド (IM) の指定に使われます */- if ( ::XSetLocaleModifiers("") == NULL ) {- throw std::domain_error( "Can not set locale modifiers." );- }-}-/*-#g++ -L/usr/X11R6/lib/ -lXmu -lXext -lX11 -lgthread -lglib -lm tes82.cxx-g++ tes82.cxx -L/usr/X11R6/lib/ -lX11-*/-#endif //-------/*------ マルチバイト文字列 --> ワイド文字文字列 ------*/-void igs::resource::mbs_to_wcs(const std::string &mbs, std::wstring &wcs) {- size_t length = 0;- {- const char *src_ptr = mbs.c_str();- mbstate_t ss;- ::memset(&ss, 0, sizeof(ss));- length = ::mbsrtowcs(NULL, &src_ptr, 0, &ss);- if (length == (size_t)(-1)) { /* 不正なマルチバイト列に遭遇した */- throw std::domain_error(- "mbstowcs(-) got bad multi byte character,when size");- }- if (length <= 0) {- return;- } /* 文字がないなら何もしない */- ++length;- }- // std::vector<wchar_t> dst(length);- wcs.resize(length);- {- const char *src_ptr = mbs.c_str();- mbstate_t ss;- ::memset(&ss, 0, sizeof(ss));- // length = ::mbsrtowcs(&dst.at(0) ,&src_ptr ,length ,&ss);- length =- ::mbsrtowcs(const_cast<wchar_t *>(wcs.c_str()), &src_ptr, length, &ss);- if (length == (size_t)(-1)) { /* 不正なマルチバイト列に遭遇した */- throw std::domain_error(- "mbstowcs(-) got bad multi byte character,when conv");- }- if (length <= 0) {- throw std::domain_error("mbstowcs(-) got zero or under equal -2 ");- }- }- // wcs = std::wstring(dst.begin() ,dst.end()-1);/* 終端以外を */- wcs.erase(wcs.end() - 1); /* 終端文字を消す */-}+#if defined UNICODE/*------ ワイド文字文字列 --> マルチバイト文字列 ------*/-void igs::resource::wcs_to_mbs(const std::wstring &wcs, std::string &mbs) {+static void wcs_to_mbs(const std::wstring &wcs, std::string &mbs) {size_t length = 0;{const wchar_t *src_ptr = wcs.c_str();@@ -126,75 +36,20 @@ void igs::resource::wcs_to_mbs(const std::wstring &wcs, std::string &mbs) {// mbs = std::string(dst.begin() ,dst.end()-1);/* 終端以外を */mbs.erase(mbs.end() - 1); /* 終端文字を消す */}-/*------ UNICODE宣言ならマルチバイト文字列をワイド文字文字列に変換 ------*/-const std::basic_string<TCHAR> igs::resource::ts_from_mbs(- const std::string &mbs) {-#if defined UNICODE- std::wstring wcs;- igs::resource::mbs_to_wcs(mbs, wcs);- return wcs;-#else- /* MBCSの場合のsize()は文字数ではなくchar(byte)数,2bytes文字は2 */- return mbs;#endif-}/*------ UNICODE宣言ならワイド文字文字列をマルチバイト文字列に変換 ------*/-const std::string igs::resource::mbs_from_ts(+const static std::string mbs_from_ts(const std::basic_string<TCHAR> &ts) {#if defined UNICODEstd::string mbs;- igs::resource::wcs_to_mbs(ts, mbs);+ wcs_to_mbs(ts, mbs);return mbs;#else/* MBCSの場合のsize()は文字数ではなくchar(byte)数,2bytes文字は2 */return ts;#endif}-/*------ cp932を含む文字列をutf-8に変換(マルチバイト文字列) ------*/-namespace {-const std::string iconv_to_from_(const std::string &text, const char *tocode,- const char *fromcode) {- iconv_t icd = ::iconv_open(tocode, fromcode); // "iconv --list"- if (reinterpret_cast<iconv_t>(-1) == icd) {- throw std::domain_error(- igs_resource_msg_from_err(TEXT("iconv_open(-)"), errno));- }-- std::vector<char> dst(text.size() * 4);- char *inbuf = const_cast<char *>(text.c_str());- char *outbuf = &dst.at(0);- size_t inbytesleft = text.size();- size_t outbytesleft = dst.size();- size_t ret = ::iconv(icd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);- *outbuf = '\0';- /*- retに処理した数が入るはずだが、rhel5ではゼロが帰るので、- 処理数を別途計算する- */- ret = dst.size() - outbytesleft;- if (ret <= 0) {- // if (static_cast<size_t>(-1) == ret) {- ::iconv_close(icd);-- throw std::domain_error(igs_resource_msg_from_err(TEXT("iconv(-)"), errno));- }-- if (-1 == ::iconv_close(icd)) {- throw std::domain_error(- igs_resource_msg_from_err(TEXT("iconv_close(-)"), errno));- }-- std::string mbs(std::string(dst.begin(), dst.begin() + ret));- return mbs;-}-}-const std::string igs::resource::utf8_from_cp932_mb(const std::string &text) {- return iconv_to_from_(text, "UTF-8", "CP932"); // "iconv --list"-}-const std::string igs::resource::cp932_from_utf8_mb(const std::string &text) {- return iconv_to_from_(text, "CP932", "UTF-8"); // "iconv --list"-}/*------ エラーメッセージ表示の元関数、直接呼び出すことはしない ------*/#include <cerrno> // errno#include <cstring> // strerror_r()@@ -254,7 +109,7 @@ const std::string igs::resource::msg_from_err_(errmsg += ' ';errmsg += '\"';if (0 < tit.size()) {- errmsg += igs::resource::mbs_from_ts(tit);+ errmsg += mbs_from_ts(tit);}if (0 != erno) {errmsg += ':';@@ -265,7 +120,7 @@ HP-UX(v11.23)では、strerror_r()をサポートしない。注意::strerror()はThread SafeではなくMulti Threadでは正常動作しない*/errmsg += ::strerror(erno);-#elif ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE)+#elif defined(FREEBSD) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE)/*http://japanese-linux-man-pages.coding-school.com/man/X_strerror_r-3より、POSIX.1.2002で規定されたXSI準拠のバージョンのstrerror_r()@@ -275,7 +130,7 @@ http://japanese-linux-man-pages.coding-school.com/man/X_strerror_r-3if (0 == ret) {errmsg += buff;} else if (-1 == ret) {- swtich(errno) {+ switch(errno) {case EINVAL:errmsg +="strerror_r() gets Error : The value of errnum is not a "@@ -290,7 +145,7 @@ http://japanese-linux-man-pages.coding-school.com/man/X_strerror_r-3/* エラーコードを説明する文字列のために、充分な領域が確保できな かった */break;- deatult:+ default:errmsg += "strerror_r() gets Error and Returns bad errno";break;}diff --git a/toonz/sources/stdfx/igs_resource_msg_from_err_unix.h b/toonz/sources/stdfx/igs_resource_msg_from_err_unix.hindex 0e28305bb..9f727b6d2 100644--- a/toonz/sources/stdfx/igs_resource_msg_from_err_unix.h+++ b/toonz/sources/stdfx/igs_resource_msg_from_err_unix.h@@ -13,32 +13,6 @@#define IGS_RESOURCE_LOG_EXPORT#endif-/*------ 文字コード変換 --------------------------------------------*/-namespace igs {-namespace resource {-/*--- localeを日本に設定し日本語を扱うことを指示 ---*/-IGS_RESOURCE_LOG_EXPORT void locale_to_jp(void);-/*--- マルチバイト文字列 --> ワイド文字文字列 ---*/-IGS_RESOURCE_LOG_EXPORT void mbs_to_wcs(const std::string &mbs,- std::wstring &wcs);-/*--- ワイド文字文字列 --> マルチバイト文字列 ---*/-IGS_RESOURCE_LOG_EXPORT void wcs_to_mbs(const std::wstring &wcs,- std::string &mbs);-/*- 2012-08-22 呼び側の名前も変更- from_mbcs(-) --> ts_from_mbs(-)- mbcs_from(-) --> mbs_from_ts(-)-*/-/*--- UNICODE宣言ならマルチバイト文字列をワイド文字文字列に変換 ---*/-const std::basic_string<TCHAR> ts_from_mbs(const std::string &mbs);-/*--- UNICODE宣言ならワイド文字文字列をマルチバイト文字列に変換 ---*/-const std::string mbs_from_ts(const std::basic_string<TCHAR> &ts);-/*--- cp932を含む文字列をutf-8に変換(mbcsのみ) ---*/-const std::string utf8_from_cp932_mb(const std::string &text);-/*--- utf-8を含む文字列をcp932に変換(mbcsのみ) ---*/-const std::string cp932_from_utf8_mb(const std::string &text);-}-}/*------ エラーメッセージ表示 --------------------------------------*/namespace igs {diff --git a/toonz/sources/stdfx/igs_resource_msg_from_err_win.cpp b/toonz/sources/stdfx/igs_resource_msg_from_err_win.cppindex 2869abb11..f8dcebcd3 100644--- a/toonz/sources/stdfx/igs_resource_msg_from_err_win.cpp+++ b/toonz/sources/stdfx/igs_resource_msg_from_err_win.cpp@@ -2,58 +2,10 @@#include <locale>#include <stdexcept>-/*------ localeを日本に設定し日本語を扱うことを指示-(しないと日本語文字部分のみ処理しない)-ただし数値カテゴリはC localeのままに-(しないと3桁ごとにカンマが付く(1000-->1,000)) */-void igs::resource::locale_to_jp(void) {- std::locale::global(- std::locale(std::locale(), "japanese", std::locale::ctype));-}-/*------ マルチバイト文字列 --> ワイド文字文字列 ------*/-void igs::resource::mbs_to_wcs(const std::string &mbs, std::wstring &wcs,- const UINT code_page) {- /* 第4引数で -1 指定により終端文字を含む大きさを返す */- /* int MultiByteToWideChar(- UINT CodePage- ,DWORD dwFlags- ,LPCSTR lpMultiByteStr- ,int cbMultiByte- ,LPWSTR lpWideCharStr- ,int cchWideChar- );- */- int length = ::MultiByteToWideChar(code_page, 0, mbs.c_str(), -1, 0, 0);- if (length <= 1) {- return;- } /* 終端以外の文字がないなら何もしない */- /*** std::vector<wchar_t> buf(length);- length = ::MultiByteToWideChar(- code_page ,0 ,mbs.c_str() ,-1- ,&buf.at(0) ,static_cast<int>(buf.size())- );***/- wcs.resize(length);- length = ::MultiByteToWideChar(code_page, 0, mbs.c_str(), -1,- const_cast<LPWSTR>(wcs.data()),- static_cast<int>(wcs.size()));- if (0 == length) {- switch (::GetLastError()) {- case ERROR_INSUFFICIENT_BUFFER:- throw std::domain_error("MultiByteToWideChar():insufficient buffer");- case ERROR_INVALID_FLAGS:- throw std::domain_error("MultiByteToWideChar():invalid flags");- case ERROR_INVALID_PARAMETER:- throw std::domain_error("MultiByteToWideChar():invalid parameter");- case ERROR_NO_UNICODE_TRANSLATION:- throw std::domain_error("MultiByteToWideChar():no unicode translation");- }- }- // wcs = std::wstring(buf.begin() ,buf.end()-1); /* 終端以外を */- wcs.erase(wcs.end() - 1); /* 終端文字を消す。end()は終端より先位置 */-}+#if defined UNICODE/*------ ワイド文字文字列 --> マルチバイト文字列 ------*/-void igs::resource::wcs_to_mbs(const std::wstring &wcs, std::string &mbs,+static void wcs_to_mbs(const std::wstring &wcs, std::string &mbs,const UINT code_page) {/* 第4引数で -1 指定により終端文字を含む大きさを返す */int length = ::WideCharToMultiByte(code_page, 0, wcs.c_str(), -1, 0, 0, 0, 0);@@ -83,48 +35,19 @@ void igs::resource::wcs_to_mbs(const std::wstring &wcs, std::string &mbs,// mbs = std::string(buf.begin() ,buf.end()-1); /* 終端以外を */mbs.erase(mbs.end() - 1); /* 終端文字を消す。end()は終端より先位置 */}-/*------ UNICODE宣言ならマルチバイト文字列をワイド文字文字列に変換 ------*/-const std::basic_string<TCHAR> igs::resource::ts_from_mbs(- const std::string &mbs, const UINT code_page) {-#if defined UNICODE- std::wstring wcs;- igs::resource::mbs_to_wcs(mbs, wcs, code_page);- return wcs;-#else- code_page;- /* MBCSの場合のsize()は文字数ではなくchar(byte)数,2bytes文字は2 */- return mbs;#endif-}/*------ UNICODE宣言ならワイド文字文字列をマルチバイト文字列に変換 ------*/-const std::string igs::resource::mbs_from_ts(const std::basic_string<TCHAR> &ts,- const UINT code_page) {+static const std::string mbs_from_ts(const std::basic_string<TCHAR> &ts) {#if defined UNICODEstd::string mbs;- igs::resource::wcs_to_mbs(ts, mbs, code_page);+ wcs_to_mbs(ts, mbs, CP_THREAD_ACP);return mbs;#else- code_page;/* MBCSの場合のsize()は文字数ではなくchar(byte)数,2bytes文字は2 */return ts;#endif}-/*------ cp932を含む文字列をutf-8に変換(マルチバイト文字列) ------*/-const std::string igs::resource::utf8_from_cp932_mb(const std::string &text) {- std::wstring wcs;- igs::resource::mbs_to_wcs(text, wcs);- std::string mbs;- igs::resource::wcs_to_mbs(wcs, mbs, CP_UTF8);- return mbs;-}-/*------ utf-8を含む文字列をcp932に変換(マルチバイト文字列) ------*/-const std::string igs::resource::cp932_from_utf8_mb(const std::string &text) {- std::wstring wcs;- igs::resource::mbs_to_wcs(text, wcs, CP_UTF8);- std::string mbs;- igs::resource::wcs_to_mbs(wcs, mbs, 932);- return mbs;-}+/*------ エラーメッセージ表示の元関数、直接呼び出すことはしない ------*/#include <sstream>const std::string igs::resource::msg_from_err_(@@ -220,5 +143,5 @@ LPCTSTR const wchar_t * const char *errmsg += TEXT('\"');/* MBCSで返す */- return igs::resource::mbs_from_ts(errmsg);+ return mbs_from_ts(errmsg);}diff --git a/toonz/sources/stdfx/igs_resource_msg_from_err_win.h b/toonz/sources/stdfx/igs_resource_msg_from_err_win.hindex 6f20f2781..ca85fb25e 100644--- a/toonz/sources/stdfx/igs_resource_msg_from_err_win.h+++ b/toonz/sources/stdfx/igs_resource_msg_from_err_win.h@@ -13,37 +13,6 @@#define IGS_RESOURCE_LOG_EXPORT#endif-/*------ 文字コード変換 --------------------------------------------*/-namespace igs {-namespace resource {-/*--- localeを日本に設定し日本語を扱うことを指示 ---*/-IGS_RESOURCE_LOG_EXPORT void locale_to_jp(void);-/*--- マルチバイト文字列 --> ワイド文字文字列 ---*/-IGS_RESOURCE_LOG_EXPORT void mbs_to_wcs(const std::string &mbs,- std::wstring &wcs,- const UINT code_page = CP_THREAD_ACP);-/*--- ワイド文字文字列 --> マルチバイト文字列 ---*/-IGS_RESOURCE_LOG_EXPORT void wcs_to_mbs(const std::wstring &wcs,- std::string &mbs,- const UINT code_page = CP_THREAD_ACP);-/*- 2012-08-22 呼び側の名前も変更- from_mbcs(-) --> ts_from_mbs(-)- mbcs_from(-) --> mbs_from_ts(-)-*/-/*--- UNICODE宣言ならマルチバイト文字列をワイド文字文字列に変換 ---*/-const std::basic_string<TCHAR> ts_from_mbs(- const std::string &mbs, const UINT code_page = CP_THREAD_ACP);-/*--- UNICODE宣言ならワイド文字文字列をマルチバイト文字列に変換 ---*/-const std::string mbs_from_ts(const std::basic_string<TCHAR> &ts,- const UINT code_page = CP_THREAD_ACP);-/*--- cp932を含む文字列をutf-8に変換(mbcsのみ) ---*/-const std::string utf8_from_cp932_mb(const std::string &text);-/*--- utf-8を含む文字列をcp932に変換(mbcsのみ) ---*/-const std::string cp932_from_utf8_mb(const std::string &text);-}-}-/*------ エラーメッセージ表示 --------------------------------------*/namespace igs {namespace resource {