fix HP( and other unix) bustage dealing with locale setting

bug #35480 r=tao@netscape.com
This commit is contained in:
jgaunt%netscape.com 2000-08-24 00:50:13 +00:00
Родитель cdd2414ff6
Коммит a60ab99074
1 изменённых файлов: 38 добавлений и 45 удалений

Просмотреть файл

@ -102,11 +102,11 @@ const char* LocaleList[LocaleListLength] =
#if defined(XP_UNIX) || defined(XP_BEOS) #if defined(XP_UNIX) || defined(XP_BEOS)
static int posix_locale_category[LocaleListLength] = static int posix_locale_category[LocaleListLength] =
{ {
LC_TIME,
LC_COLLATE, LC_COLLATE,
LC_CTYPE, LC_CTYPE,
LC_MONETARY, LC_MONETARY,
LC_NUMERIC, LC_NUMERIC,
LC_TIME,
#ifdef HAVE_I18N_LC_MESSAGES #ifdef HAVE_I18N_LC_MESSAGES
LC_MESSAGES LC_MESSAGES
#else #else
@ -231,55 +231,48 @@ nsLocaleService::nsLocaleService(void)
#endif #endif
#if defined(XP_UNIX) || defined(XP_BEOS) #if defined(XP_UNIX) || defined(XP_BEOS)
nsIPosixLocale* posixConverter; nsIPosixLocale* posixConverter;
nsString xpLocale; nsAutoString xpLocale;
nsresult result = nsComponentManager::CreateInstance(kPosixLocaleFactoryCID, nsresult result = nsComponentManager::CreateInstance(kPosixLocaleFactoryCID,
NULL,kIPosixLocaleIID,(void**)&posixConverter); NULL,kIPosixLocaleIID,(void**)&posixConverter);
if (NS_SUCCEEDED(result) && posixConverter!=nsnull) { if (NS_SUCCEEDED(result) && posixConverter!=nsnull) {
char* lc_all = setlocale(LC_ALL,""); nsAutoString category;
char* lang = getenv("LANG"); nsLocale* resultLocale;
if (lc_all!=nsnull) {
result = posixConverter->GetXPLocale(lc_all,&xpLocale);
if (NS_FAILED(result)) { posixConverter->Release(); return; }
PRUnichar* loc = xpLocale.ToNewUnicode();
result = NewLocale(loc, &mSystemLocale);
nsCRT::free(loc);
if (NS_FAILED(result)) { posixConverter->Release(); return; }
mApplicationLocale=mSystemLocale;
mApplicationLocale->AddRef();
posixConverter->Release();
} else {
if (lang==nsnull) {
xpLocale.AssignWithConversion("en-US");
PRUnichar* loc = xpLocale.ToNewUnicode();
result = NewLocale(loc, &mSystemLocale);
nsCRT::free(loc);
if (NS_FAILED(result)) { posixConverter->Release(); return; }
mApplicationLocale = mSystemLocale;
mApplicationLocale->AddRef();
posixConverter->Release();
} else {
int i; int i;
nsString category;
nsLocale* resultLocale = new nsLocale(); resultLocale = new nsLocale();
if (resultLocale==NULL) { posixConverter->Release(); return; } if ( resultLocale == NULL ) {
for(i=0;i<LocaleListLength;i++) { posixConverter->Release();
char* lc_temp = setlocale(posix_locale_category[i],""); return;
}
for( i = 0; i < LocaleListLength; i++ ) {
char* lc_temp = nsCRT::strdup(setlocale(posix_locale_category[i],""));
category.AssignWithConversion(LocaleList[i]); category.AssignWithConversion(LocaleList[i]);
if (lc_temp==nsnull) xpLocale.AssignWithConversion("en-US"); if (lc_temp != nsnull)
else xpLocale.AssignWithConversion(lc_temp); result = posixConverter->GetXPLocale(lc_temp,&xpLocale);
PRUnichar* loc = xpLocale.ToNewUnicode(); else {
PRUnichar* cat = category.ToNewUnicode(); char* lang = getenv("LANG");
resultLocale->AddCategory(cat, loc); if ( lang == nsnull ) {
nsCRT::free(cat); nsCAutoString langcstr = "en-US";
nsCRT::free(loc); lang = nsCRT::strdup( langcstr.GetBuffer() );
result = posixConverter->GetXPLocale(lang,&xpLocale);
nsCRT::free(lang);
}
else
result = posixConverter->GetXPLocale(lang,&xpLocale);
}
if (NS_FAILED(result)) {
posixConverter->Release();
nsCRT::free(lc_temp);
return;
}
resultLocale->AddCategory(category.GetUnicode(),xpLocale.GetUnicode());
nsCRT::free(lc_temp);
} }
(void)resultLocale->QueryInterface(kILocaleIID,(void**)&mSystemLocale); (void)resultLocale->QueryInterface(kILocaleIID,(void**)&mSystemLocale);
(void)resultLocale->QueryInterface(kILocaleIID,(void**)&mApplicationLocale); (void)resultLocale->QueryInterface(kILocaleIID,(void**)&mApplicationLocale);
posixConverter->Release(); posixConverter->Release();
} } // if ( NS_SUCCEEDED )...
}
}
#endif // XP_UNIX || XP_BEOS #endif // XP_UNIX || XP_BEOS
#if defined(XP_OS2) #if defined(XP_OS2)
nsIOS2Locale* os2Converter; nsIOS2Locale* os2Converter;