From 3317f535d107643e88209ae6925ebfd8da09893f Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 13 Oct 2010 15:10:27 +0100 Subject: AIX tweaks --- shell/source/backends/localebe/localebackend.cxx | 142 +++++++++++------------ 1 file changed, 69 insertions(+), 73 deletions(-) (limited to 'shell/source/backends') diff --git a/shell/source/backends/localebe/localebackend.cxx b/shell/source/backends/localebe/localebackend.cxx index f2c929ff1273..808aab8d1440 100644 --- a/shell/source/backends/localebe/localebackend.cxx +++ b/shell/source/backends/localebe/localebackend.cxx @@ -35,54 +35,37 @@ #include -#if defined(LINUX) || defined(SOLARIS) || defined(NETBSD) || defined(FREEBSD) || defined(OS2) +#ifdef WNT -#include -#include -#include +#ifdef WINVER +#undef WINVER +#endif +#define WINVER 0x0501 -/* - * Note: setlocale is not at all thread safe, so is this code. It could - * especially interfere with the stuff VCL is doing, so make sure this - * is called from the main thread only. - */ +#if defined _MSC_VER +#pragma warning(push, 1) +#endif +#include +#if defined _MSC_VER +#pragma warning(pop) +#endif -static rtl::OUString ImplGetLocale(int category) +rtl::OUString ImplGetLocale(LCID lcid) { - const char *locale = setlocale(category, ""); - - // Return "en-US" for C locales - if( (locale == NULL) || ( locale[0] == 'C' && locale[1] == '\0' ) ) - return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "en-US" ) ); - - - const char *cp; - const char *uscore = NULL; + TCHAR buffer[8]; + LPTSTR cp = buffer; - // locale string have the format lang[_ctry][.encoding][@modifier] - // we are only interested in the first two items, so we handle - // '.' and '@' as string end. - for (cp = locale; *cp; cp++) + cp += GetLocaleInfo( lcid, LOCALE_SISO639LANGNAME , buffer, 4 ); + if( cp > buffer ) { - if (*cp == '_') - uscore = cp; - if (*cp == '.' || *cp == '@') - break; - } + if( 0 < GetLocaleInfo( lcid, LOCALE_SISO3166CTRYNAME, cp, buffer + 8 - cp) ) + // #i50822# minus character must be written before cp + *(cp - 1) = '-'; - rtl::OUStringBuffer aLocaleBuffer; - if( uscore != NULL ) - { - aLocaleBuffer.appendAscii(locale, uscore++ - locale); - aLocaleBuffer.appendAscii("-"); - aLocaleBuffer.appendAscii(uscore, cp - uscore); - } - else - { - aLocaleBuffer.appendAscii(locale, cp - locale); + return rtl::OUString::createFromAscii(buffer); } - return aLocaleBuffer.makeStringAndClear(); + return rtl::OUString(); } #elif defined(MACOSX) @@ -184,44 +167,57 @@ namespace /* private */ } // namespace /* private */ -#endif +#else -// ------------------------------------------------------------------------------- +#include +#include +#include -#ifdef WNT +/* + * Note: setlocale is not at all thread safe, so is this code. It could + * especially interfere with the stuff VCL is doing, so make sure this + * is called from the main thread only. + */ -#ifdef WINVER -#undef WINVER -#endif -#define WINVER 0x0501 +static rtl::OUString ImplGetLocale(int category) +{ + const char *locale = setlocale(category, ""); -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include -#if defined _MSC_VER -#pragma warning(pop) -#endif + // Return "en-US" for C locales + if( (locale == NULL) || ( locale[0] == 'C' && locale[1] == '\0' ) ) + return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "en-US" ) ); -rtl::OUString ImplGetLocale(LCID lcid) -{ - TCHAR buffer[8]; - LPTSTR cp = buffer; - cp += GetLocaleInfo( lcid, LOCALE_SISO639LANGNAME , buffer, 4 ); - if( cp > buffer ) + const char *cp; + const char *uscore = NULL; + + // locale string have the format lang[_ctry][.encoding][@modifier] + // we are only interested in the first two items, so we handle + // '.' and '@' as string end. + for (cp = locale; *cp; cp++) { - if( 0 < GetLocaleInfo( lcid, LOCALE_SISO3166CTRYNAME, cp, buffer + 8 - cp) ) - // #i50822# minus character must be written before cp - *(cp - 1) = '-'; + if (*cp == '_') + uscore = cp; + if (*cp == '.' || *cp == '@') + break; + } - return rtl::OUString::createFromAscii(buffer); + rtl::OUStringBuffer aLocaleBuffer; + if( uscore != NULL ) + { + aLocaleBuffer.appendAscii(locale, uscore++ - locale); + aLocaleBuffer.appendAscii("-"); + aLocaleBuffer.appendAscii(uscore, cp - uscore); + } + else + { + aLocaleBuffer.appendAscii(locale, cp - locale); } - return rtl::OUString(); + return aLocaleBuffer.makeStringAndClear(); } -#endif // WNT +#endif // ------------------------------------------------------------------------------- @@ -246,12 +242,12 @@ LocaleBackend* LocaleBackend::createInstance() rtl::OUString LocaleBackend::getLocale(void) { -#if defined(LINUX) || defined(SOLARIS) || defined(NETBSD) || defined(FREEBSD) || defined(OS2) - return ImplGetLocale(LC_CTYPE); +#if defined WNT + return ImplGetLocale( GetUserDefaultLCID() ); #elif defined (MACOSX) return ImplGetLocale("AppleLocale"); -#elif defined WNT - return ImplGetLocale( GetUserDefaultLCID() ); +#else + return ImplGetLocale(LC_CTYPE); #endif } @@ -259,12 +255,12 @@ rtl::OUString LocaleBackend::getLocale(void) rtl::OUString LocaleBackend::getUILocale(void) { -#if defined(LINUX) || defined(SOLARIS) || defined(NETBSD) || defined(FREEBSD) || defined(OS2) - return ImplGetLocale(LC_MESSAGES); +#if defined WNT + return ImplGetLocale( MAKELCID(GetUserDefaultUILanguage(), SORT_DEFAULT) ); #elif defined(MACOSX) return ImplGetLocale("AppleLanguages"); -#elif defined WNT - return ImplGetLocale( MAKELCID(GetUserDefaultUILanguage(), SORT_DEFAULT) ); +#else + return ImplGetLocale(LC_MESSAGES); #endif } -- cgit