From: <man...@us...> - 2014-03-06 12:00:43
|
Revision: 3828 http://sourceforge.net/p/modplug/code/3828 Author: manxorist Date: 2014-03-06 12:00:31 +0000 (Thu, 06 Mar 2014) Log Message: ----------- [Ref] Ban locale-dependent strings in libopenmpt and make mpt::CharsetLocale, mpt::ToLocale and mpt::PathString unavailable in non-test libopenmpt builds by making them conditional on MPT_WITH_CHARSET_LOCALE an MPT_WITH_PATHSTRING . Modified Paths: -------------- trunk/OpenMPT/common/BuildSettings.h trunk/OpenMPT/common/Logging.cpp trunk/OpenMPT/common/mptFstream.h trunk/OpenMPT/common/mptPathString.cpp trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/soundlib/Sndfile.cpp Modified: trunk/OpenMPT/common/BuildSettings.h =================================================================== --- trunk/OpenMPT/common/BuildSettings.h 2014-03-05 15:36:12 UTC (rev 3827) +++ trunk/OpenMPT/common/BuildSettings.h 2014-03-06 12:00:31 UTC (rev 3828) @@ -261,8 +261,20 @@ #define MPT_CHARSET_INTERNAL #endif +#if defined(MODPLUG_TRACKER) && !defined(MPT_WITH_PATHSTRING) +#define MPT_WITH_PATHSTRING // Tracker requires PathString +#endif +#if !defined(MODPLUG_NO_FILESAVE) && !defined(MPT_WITH_PATHSTRING) +#define MPT_WITH_PATHSTRING // file saving requires PathString +#endif +#if defined(MPT_WITH_PATHSTRING) && !defined(MPT_WITH_CHARSET_LOCALE) +#define MPT_WITH_CHARSET_LOCALE // PathString requires locale charset +#endif + + + #if MPT_COMPILER_MSVC #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #endif @@ -319,3 +331,4 @@ #define _SCL_SECURE_NO_WARNINGS #endif #endif + Modified: trunk/OpenMPT/common/Logging.cpp =================================================================== --- trunk/OpenMPT/common/Logging.cpp 2014-03-05 15:36:12 UTC (rev 3827) +++ trunk/OpenMPT/common/Logging.cpp 2014-03-06 12:00:31 UTC (rev 3828) @@ -137,7 +137,11 @@ std::clog << "openmpt: " << context.file << "(" << context.line << ")" << ": " +#if defined(MPT_WITH_CHARSET_LOCALE) << mpt::ToLocale(message) +#else + << mpt::To(mpt::CharsetUTF8, message) +#endif << " [" << context.function << "]" << std::endl; #endif // MODPLUG_TRACKER @@ -153,7 +157,11 @@ vsnprintf(message, LOGBUF_SIZE, format, va); message[LOGBUF_SIZE - 1] = '\0'; va_end(va); +#if defined(MPT_WITH_CHARSET_LOCALE) DoLog(context, mpt::ToWide(mpt::CharsetLocale, message)); +#else + DoLog(context, mpt::ToWide(mpt::CharsetUTF8, message)); +#endif } @@ -169,7 +177,11 @@ void Logger::operator () (const std::string &text) //------------------------------------------------ { +#if defined(MPT_WITH_CHARSET_LOCALE) DoLog(context, mpt::ToWide(mpt::CharsetLocale, text)); +#else + DoLog(context, mpt::ToWide(mpt::CharsetUTF8, text)); +#endif } void Logger::operator () (const std::wstring &text) Modified: trunk/OpenMPT/common/mptFstream.h =================================================================== --- trunk/OpenMPT/common/mptFstream.h 2014-03-05 15:36:12 UTC (rev 3827) +++ trunk/OpenMPT/common/mptFstream.h 2014-03-06 12:00:31 UTC (rev 3828) @@ -14,6 +14,8 @@ #include "../common/mptString.h" #include "../common/mptPathString.h" +#if defined(MPT_WITH_PATHSTRING) + namespace mpt { @@ -192,3 +194,6 @@ #undef MPT_FSTREAM_OPEN } // namespace mpt + +#endif // MPT_WITH_PATHSTRING + Modified: trunk/OpenMPT/common/mptPathString.cpp =================================================================== --- trunk/OpenMPT/common/mptPathString.cpp 2014-03-05 15:36:12 UTC (rev 3827) +++ trunk/OpenMPT/common/mptPathString.cpp 2014-03-06 12:00:31 UTC (rev 3828) @@ -11,6 +11,8 @@ #include "mptPathString.h" +#if defined(MPT_WITH_PATHSTRING) + #if defined(MODPLUG_TRACKER) namespace mpt @@ -185,7 +187,11 @@ //----------------------------------------------------------------- { #if defined(WIN32) - return _wfopen(filename.AsNative().c_str(), mode ? mpt::ToWide(mpt::CharsetLocale, mode).c_str() : nullptr); + #if defined(MPT_WITH_CHARSET_LOCALE) + return _wfopen(filename.AsNative().c_str(), mode ? mpt::ToWide(mpt::CharsetLocale, mode).c_str() : nullptr); + #else + return _wfopen(filename.AsNative().c_str(), mode ? mpt::ToWide(mpt::CharsetUTF8, mode).c_str() : nullptr); + #endif #else // !WIN32 return fopen(filename.AsNative().c_str(), mode); #endif // WIN32 @@ -197,7 +203,11 @@ #if defined(WIN32) return _wfopen(filename.AsNative().c_str(), mode); #else // !WIN32 - return fopen(filename.AsNative().c_str(), mode ? mpt::ToLocale(mode).c_str() : nullptr); + #if defined(MPT_WITH_CHARSET_LOCALE) + return fopen(filename.AsNative().c_str(), mode ? mpt::ToLocale(mode).c_str() : nullptr); + #else + return fopen(filename.AsNative().c_str(), mode ? mpt::To(mpt::CharsetUTF8, mode).c_str() : nullptr); + #endif #endif // WIN32 } @@ -296,3 +306,6 @@ #endif #endif // MODPLUG_TRACKER + +#endif // MPT_WITH_PATHSTRING + Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2014-03-05 15:36:12 UTC (rev 3827) +++ trunk/OpenMPT/common/mptPathString.h 2014-03-06 12:00:31 UTC (rev 3828) @@ -13,6 +13,8 @@ #include <cstdio> #include <stdio.h> +#if defined(MPT_WITH_PATHSTRING) + //#define MPT_DEPRECATED_PATH #define MPT_DEPRECATED_PATH MPT_DEPRECATED @@ -134,10 +136,14 @@ #if defined(WIN32) // conversions +#if defined(MPT_WITH_CHARSET_LOCALE) MPT_DEPRECATED_PATH std::string ToLocale() const { return mpt::ToLocale(path); } +#endif std::string ToUTF8() const { return mpt::To(mpt::CharsetUTF8, path); } std::wstring ToWide() const { return path; } +#if defined(MPT_WITH_CHARSET_LOCALE) MPT_DEPRECATED_PATH static PathString FromLocale(const std::string &path) { return PathString(mpt::ToWide(mpt::CharsetLocale, path)); } +#endif static PathString FromUTF8(const std::string &path) { return PathString(mpt::ToWide(mpt::CharsetUTF8, path)); } static PathString FromWide(const std::wstring &path) { return PathString(path); } RawPathString AsNative() const { return path; } @@ -157,6 +163,7 @@ #else // !WIN32 // conversions +#if defined(MPT_WITH_CHARSET_LOCALE) std::string ToLocale() const { return path; } std::string ToUTF8() const { return mpt::To(mpt::CharsetUTF8, mpt::CharsetLocale, path); } std::wstring ToWide() const { return mpt::ToWide(mpt::CharsetLocale, path); } @@ -165,12 +172,22 @@ static PathString FromWide(const std::wstring &path) { return PathString(mpt::To(mpt::CharsetLocale, path)); } RawPathString AsNative() const { return path; } static PathString FromNative(const RawPathString &path) { return PathString(path); } +#else + std::string ToUTF8() const { return path; } + std::wstring ToWide() const { return mpt::ToWide(mpt::CharsetUTF8, path); } + static PathString FromUTF8(const std::string &path) { return path; } + static PathString FromWide(const std::wstring &path) { return PathString(mpt::To(mpt::CharsetUTF8, path)); } + RawPathString AsNative() const { return path; } + static PathString FromNative(const RawPathString &path) { return PathString(path); } +#endif #endif // WIN32 }; +#if defined(MPT_WITH_CHARSET_LOCALE) MPT_DEPRECATED_PATH static inline std::string ToString(const mpt::PathString & x) { return mpt::ToLocale(x.ToWide()); } +#endif static inline std::wstring ToWString(const mpt::PathString & x) { return x.ToWide(); } } // namespace mpt @@ -220,3 +237,6 @@ #endif #endif // MODPLUG_TRACKER + +#endif // MPT_WITH_PATHSTRING + Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2014-03-05 15:36:12 UTC (rev 3827) +++ trunk/OpenMPT/common/mptString.cpp 2014-03-06 12:00:31 UTC (rev 3828) @@ -348,6 +348,8 @@ return res; } +#if defined(MPT_WITH_CHARSET_LOCALE) + static std::wstring LocaleDecode(const std::string &str, const std::locale & locale, wchar_t replacement = L'\uFFFD') //------------------------------------------------------------------------------------------------------------------- { @@ -498,6 +500,8 @@ return String::ToAscii(str, replacement); // fallback } +#endif + #endif // MPT_CHARSET_CODECVTUTF8 || MPT_CHARSET_INTERNAL #if defined(MPT_CHARSET_CODECVTUTF8) @@ -687,7 +691,9 @@ { switch(charset) { +#if defined(MPT_WITH_CHARSET_LOCALE) case CharsetLocale: return CP_ACP; break; +#endif case CharsetUTF8: return CP_UTF8; break; case CharsetASCII: return 20127; break; case CharsetISO8859_1: return 28591; break; @@ -708,7 +714,9 @@ { switch(charset) { +#if defined(MPT_WITH_CHARSET_LOCALE) case CharsetLocale: return ""; break; // "char" breaks with glibc when no locale is set +#endif case CharsetUTF8: return "UTF-8"; break; case CharsetASCII: return "ASCII"; break; case CharsetISO8859_1: return "ISO-8859-1"; break; @@ -725,7 +733,9 @@ { switch(charset) { +#if defined(MPT_WITH_CHARSET_LOCALE) case CharsetLocale: return "//TRANSLIT"; break; // "char" breaks with glibc when no locale is set +#endif case CharsetUTF8: return "UTF-8//TRANSLIT"; break; case CharsetASCII: return "ASCII//TRANSLIT"; break; case CharsetISO8859_1: return "ISO-8859-1//TRANSLIT"; break; @@ -787,12 +797,14 @@ std::copy(out.begin(), out.end(), std::back_inserter(result)); return result; } +#if defined(MPT_WITH_CHARSET_LOCALE) #if defined(MPT_LOCALE_ASSUME_CHARSET) if(charset == CharsetLocale) { charset = MPT_LOCALE_ASSUME_CHARSET; } #endif +#endif #if defined(MPT_CHARSET_WIN32) const UINT codepage = CharsetToCodepage(charset); int required_size = WideCharToMultiByte(codepage, 0, src.c_str(), -1, nullptr, 0, nullptr, nullptr); @@ -844,7 +856,9 @@ std::string out; switch(charset) { +#if defined(MPT_WITH_CHARSET_LOCALE) case CharsetLocale: out = String::ToLocale(src); break; +#endif case CharsetUTF8: out = String::ToUTF8(src); break; case CharsetASCII: out = String::ToAscii(src); break; case CharsetISO8859_1: out = String::ToISO_8859_1(src); break; @@ -875,12 +889,14 @@ if(charset == CharsetCP437AMS2) out = String::From8bit(in, CharsetTableCP437AMS2); return out; } +#if defined(MPT_WITH_CHARSET_LOCALE) #if defined(MPT_LOCALE_ASSUME_CHARSET) if(charset == CharsetLocale) { charset = MPT_LOCALE_ASSUME_CHARSET; } #endif +#endif #if defined(MPT_CHARSET_WIN32) const UINT codepage = CharsetToCodepage(charset); int required_size = MultiByteToWideChar(codepage, 0, reinterpret_cast<const char*>(src.c_str()), -1, nullptr, 0); @@ -938,7 +954,9 @@ std::wstring out; switch(charset) { +#if defined(MPT_WITH_CHARSET_LOCALE) case CharsetLocale: out = String::FromLocale(in); break; +#endif case CharsetUTF8: out = String::FromUTF8(in); break; case CharsetASCII: out = String::FromAscii(in); break; case CharsetISO8859_1: out = String::FromISO_8859_1(in); break; @@ -1018,6 +1036,7 @@ return String::DecodeImpl(from, str); } +#if defined(MPT_WITH_CHARSET_LOCALE) std::string ToLocale(const std::wstring &str) { return String::EncodeImpl<std::string>(CharsetLocale, str); @@ -1026,6 +1045,7 @@ { return String::ConvertImpl<std::string>(CharsetLocale, from, str); } +#endif std::string To(Charset to, const std::wstring &str) { @@ -1115,10 +1135,17 @@ return o.str(); } +#if defined(MPT_WITH_CHARSET_LOCALE) std::string ToString(const std::wstring & x) { return mpt::ToLocale(x); } std::string ToString(const wchar_t * const & x) { return mpt::ToLocale(x); }; std::string ToString(const char & x) { return std::string(1, x); } std::string ToString(const wchar_t & x) { return mpt::ToLocale(std::wstring(1, x)); } +#else +std::string ToString(const std::wstring & x) { return mpt::To(mpt::CharsetUTF8, x); } +std::string ToString(const wchar_t * const & x) { return mpt::To(mpt::CharsetUTF8, x); }; +std::string ToString(const char & x) { return std::string(1, x); } +std::string ToString(const wchar_t & x) { return mpt::To(mpt::CharsetUTF8, std::wstring(1, x)); } +#endif std::string ToString(const bool & x) { return ToStringHelper(x); } std::string ToString(const signed char & x) { return ToStringHelper(x); } std::string ToString(const unsigned char & x) { return ToStringHelper(x); } @@ -1134,10 +1161,17 @@ std::string ToString(const double & x) { return ToStringHelper(x); } std::string ToString(const long double & x) { return ToStringHelper(x); } +#if defined(MPT_WITH_CHARSET_LOCALE) std::wstring ToWString(const std::string & x) { return mpt::ToWide(mpt::CharsetLocale, x); } std::wstring ToWString(const char * const & x) { return mpt::ToWide(mpt::CharsetLocale, x); } std::wstring ToWString(const char & x) { return mpt::ToWide(mpt::CharsetLocale, std::string(1, x)); } std::wstring ToWString(const wchar_t & x) { return std::wstring(1, x); } +#else +std::wstring ToWString(const std::string & x) { return mpt::ToWide(mpt::CharsetUTF8, x); } +std::wstring ToWString(const char * const & x) { return mpt::ToWide(mpt::CharsetUTF8, x); } +std::wstring ToWString(const char & x) { return mpt::ToWide(mpt::CharsetUTF8, std::string(1, x)); } +std::wstring ToWString(const wchar_t & x) { return std::wstring(1, x); } +#endif std::wstring ToWString(const bool & x) { return ToWStringHelper(x); } std::wstring ToWString(const signed char & x) { return ToWStringHelper(x); } std::wstring ToWString(const unsigned char & x) { return ToWStringHelper(x); } Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2014-03-05 15:36:12 UTC (rev 3827) +++ trunk/OpenMPT/common/mptString.h 2014-03-06 12:00:31 UTC (rev 3828) @@ -160,7 +160,9 @@ enum Charset { +#if defined(MPT_WITH_CHARSET_LOCALE) CharsetLocale, // CP_ACP on windows, current C locale otherwise +#endif CharsetUTF8, @@ -184,6 +186,7 @@ static inline std::wstring ToWide(const std::wstring &str) { return str; } std::wstring ToWide(Charset from, const std::string &str); +#if defined(MPT_WITH_CHARSET_LOCALE) // Convert to locale-encoded string. // On Windows, CP_ACP is used, // otherwise, the global "C" locale is used. @@ -194,6 +197,7 @@ // destination charset will be replaced by some replacement character or string. std::string ToLocale(const std::wstring &str); std::string ToLocale(Charset from, const std::string &str); +#endif // Convert to a string encoded in the 'to'-specified character set. // If str does not contain any invalid characters, Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2014-03-05 15:36:12 UTC (rev 3827) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2014-03-06 12:00:31 UTC (rev 3828) @@ -2370,10 +2370,14 @@ // Convert ANSI plugin path names to UTF-8 (irrelevant in probably 99% of all cases anyway, I think I've never seen a VST plugin with a non-ASCII file name) for(PLUGINDEX i = 0; i < MAX_MIXPLUGINS; i++) { +#if defined(MPT_WITH_CHARSET_LOCALE) const std::string name = mpt::To(mpt::CharsetUTF8, mpt::CharsetLocale, m_MixPlugins[i].Info.szLibraryName); +#else + const std::string name = mpt::To(mpt::CharsetUTF8, mpt::CharsetWindows1252, m_MixPlugins[i].Info.szLibraryName); +#endif mpt::String::Copy(m_MixPlugins[i].Info.szLibraryName, name); } } Patterns.ForEachModCommand(UpgradePatternData(*this)); -} \ No newline at end of file +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |