4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
7 * Copyright 2002 Alexandre Julliard for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/port.h"
35 #define WIN32_NO_STATUS
38 #include "winuser.h" /* for RT_STRINGW */
40 #include "wine/unicode.h"
44 #include "kernel_private.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(nls);
49 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|LOCALE_RETURN_NUMBER)
51 /* current code pages */
52 static const union cptable *ansi_cptable;
53 static const union cptable *oem_cptable;
54 static const union cptable *mac_cptable;
55 static const union cptable *unix_cptable; /* NULL if UTF8 */
57 static HANDLE NLS_RegOpenKey(HANDLE hRootKey, LPCWSTR szKeyName);
58 static HANDLE NLS_RegOpenSubKey(HANDLE hRootKey, LPCWSTR szKeyName);
60 static const WCHAR szNlsKeyName[] = {
61 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
62 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
63 'C','o','n','t','r','o','l','\\','N','l','s','\0'
66 /* Charset to codepage map, sorted by name. */
67 static const struct charset_entry
69 const char *charset_name;
108 { "ISO88591", 28591 },
109 { "ISO885910", 28600 },
110 { "ISO885913", 28603 },
111 { "ISO885914", 28604 },
112 { "ISO885915", 28605 },
113 { "ISO885916", 28606 },
114 { "ISO88592", 28592 },
115 { "ISO88593", 28593 },
116 { "ISO88594", 28594 },
117 { "ISO88595", 28595 },
118 { "ISO88596", 28596 },
119 { "ISO88597", 28597 },
120 { "ISO88598", 28598 },
121 { "ISO88599", 28599 },
127 #define NLS_MAX_LANGUAGES 20
131 LANGID found_lang_id[NLS_MAX_LANGUAGES];
136 /* copy Unicode string to Ascii without using codepages */
137 static inline void strcpyWtoA( char *dst, const WCHAR *src )
139 while ((*dst++ = *src++));
142 /* Copy Ascii string to Unicode without using codepages */
143 static inline void strcpynAtoW( WCHAR *dst, const char *src, size_t n )
145 while (n > 1 && *src)
147 *dst++ = (unsigned char)*src++;
153 /* return a printable string for a language id */
154 static const char *debugstr_lang( LANGID lang )
156 WCHAR langW[4], countryW[4];
158 LCID lcid = MAKELCID( lang, SORT_DEFAULT );
160 GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME|LOCALE_NOUSEROVERRIDE, langW, sizeof(langW)/sizeof(WCHAR));
161 GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME|LOCALE_NOUSEROVERRIDE, countryW, sizeof(countryW)/sizeof(WCHAR));
162 strcpyWtoA( buffer, langW );
163 strcat( buffer, "_" );
164 strcpyWtoA( buffer + strlen(buffer), countryW );
165 return wine_dbg_sprintf( "%s", buffer );
168 /***********************************************************************
171 * Retrieve the ANSI codepage for a given locale.
173 inline static UINT get_lcid_codepage( LCID lcid )
176 if (!GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE|LOCALE_RETURN_NUMBER, (WCHAR *)&ret,
177 sizeof(ret)/sizeof(WCHAR) )) ret = 0;
182 /***********************************************************************
185 * Find the table for a given codepage, handling CP_ACP etc. pseudo-codepages
187 static const union cptable *get_codepage_table( unsigned int codepage )
189 const union cptable *ret = NULL;
191 assert( ansi_cptable ); /* init must have been done already */
205 if (!(codepage = kernel_get_thread_data()->code_page)) return ansi_cptable;
208 if (codepage == ansi_cptable->info.codepage) return ansi_cptable;
209 if (codepage == oem_cptable->info.codepage) return oem_cptable;
210 if (codepage == mac_cptable->info.codepage) return mac_cptable;
211 ret = wine_cp_get_table( codepage );
217 /***********************************************************************
218 * create_registry_key
220 * Create the Control Panel\\International registry key.
222 inline static HANDLE create_registry_key(void)
224 static const WCHAR intlW[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
225 'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
226 OBJECT_ATTRIBUTES attr;
227 UNICODE_STRING nameW;
230 if (RtlOpenCurrentUser( KEY_ALL_ACCESS, &hkey ) != STATUS_SUCCESS) return 0;
232 attr.Length = sizeof(attr);
233 attr.RootDirectory = hkey;
234 attr.ObjectName = &nameW;
236 attr.SecurityDescriptor = NULL;
237 attr.SecurityQualityOfService = NULL;
238 RtlInitUnicodeString( &nameW, intlW );
240 if (NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) != STATUS_SUCCESS) hkey = 0;
241 NtClose( attr.RootDirectory );
246 /***********************************************************************
247 * LOCALE_InitRegistry
249 * Update registry contents on startup if the user locale has changed.
250 * This simulates the action of the Windows control panel.
252 void LOCALE_InitRegistry(void)
254 static const WCHAR CodepageW[] = {'C','o','d','e','p','a','g','e',0};
255 static const WCHAR acpW[] = {'A','C','P',0};
256 static const WCHAR oemcpW[] = {'O','E','M','C','P',0};
257 static const WCHAR maccpW[] = {'M','A','C','C','P',0};
262 } update_cp_values[] = {
263 { acpW, LOCALE_IDEFAULTANSICODEPAGE },
264 { oemcpW, LOCALE_IDEFAULTCODEPAGE },
265 { maccpW, LOCALE_IDEFAULTMACCODEPAGE }
267 static const USHORT updateValues[] = {
269 LOCALE_SCOUNTRY, LOCALE_ICOUNTRY,
270 LOCALE_S1159, LOCALE_S2359,
271 LOCALE_STIME, LOCALE_ITIME,
276 LOCALE_SCURRENCY, LOCALE_ICURRENCY,
283 LOCALE_IDIGITSUBSTITUTION,
284 LOCALE_SNATIVEDIGITS,
285 LOCALE_ITIMEMARKPOSN,
286 LOCALE_ICALENDARTYPE,
290 static const WCHAR LocaleW[] = {'L','o','c','a','l','e',0};
291 UNICODE_STRING nameW;
296 LCID lcid = GetUserDefaultLCID();
298 if (!(hkey = create_registry_key()))
299 return; /* don't do anything if we can't create the registry key */
301 RtlInitUnicodeString( &nameW, LocaleW );
302 count = sizeof(bufferW);
303 if (!NtQueryValueKey(hkey, &nameW, KeyValuePartialInformation, (LPBYTE)bufferW, count, &count))
305 const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)bufferW;
306 LPCWSTR szValueText = (LPCWSTR)info->Data;
308 if (strtoulW( szValueText, NULL, 16 ) == lcid) /* already set correctly */
313 TRACE( "updating registry, locale changed %s -> %08lx\n", debugstr_w(szValueText), lcid );
315 else TRACE( "updating registry, locale changed none -> %08lx\n", lcid );
317 sprintf( buffer, "%08lx", lcid );
318 /* Note: '9' constant below is strlen(buffer) + 1 */
319 RtlMultiByteToUnicodeN( bufferW, sizeof(bufferW), NULL, buffer, 9 );
320 NtSetValueKey( hkey, &nameW, 0, REG_SZ, bufferW, 9 * sizeof(WCHAR) );
323 for (i = 0; i < sizeof(updateValues)/sizeof(updateValues[0]); i++)
325 GetLocaleInfoW( lcid, updateValues[i] | LOCALE_NOUSEROVERRIDE, bufferW,
326 sizeof(bufferW)/sizeof(WCHAR) );
327 SetLocaleInfoW( lcid, updateValues[i], bufferW );
330 hkey = NLS_RegOpenSubKey( NLS_RegOpenKey( 0, szNlsKeyName ), CodepageW );
332 for (i = 0; i < sizeof(update_cp_values)/sizeof(update_cp_values[0]); i++)
334 count = GetLocaleInfoW( lcid, update_cp_values[i].value | LOCALE_NOUSEROVERRIDE,
335 bufferW, sizeof(bufferW)/sizeof(WCHAR) );
336 RtlInitUnicodeString( &nameW, update_cp_values[i].name );
337 NtSetValueKey( hkey, &nameW, 0, REG_SZ, bufferW, count * sizeof(WCHAR) );
344 /***********************************************************************
345 * find_language_id_proc
347 static BOOL CALLBACK find_language_id_proc( HMODULE hModule, LPCWSTR type,
348 LPCWSTR name, WORD LangID, LPARAM lParam )
350 LANG_FIND_DATA *l_data = (LANG_FIND_DATA *)lParam;
351 LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
352 WCHAR buf_language[128];
353 WCHAR buf_country[128];
354 WCHAR buf_en_language[128];
356 if(PRIMARYLANGID(LangID) == LANG_NEUTRAL)
357 return TRUE; /* continue search */
362 GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME|LOCALE_NOUSEROVERRIDE,
363 buf_language, sizeof(buf_language)/sizeof(WCHAR));
364 GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME|LOCALE_NOUSEROVERRIDE,
365 buf_country, sizeof(buf_country)/sizeof(WCHAR));
367 if(l_data->lang[0] && !strcmpiW(l_data->lang, buf_language))
369 if(l_data->country[0])
371 if(!strcmpiW(l_data->country, buf_country))
373 l_data->found_lang_id[0] = LangID;
375 TRACE("Found id %04X for lang %s country %s\n",
376 LangID, debugstr_w(l_data->lang), debugstr_w(l_data->country));
377 return FALSE; /* stop enumeration */
380 else goto found; /* l_data->country not specified */
383 /* Just in case, check LOCALE_SENGLANGUAGE too,
384 * in hope that possible alias name might have that value.
386 buf_en_language[0] = 0;
387 GetLocaleInfoW(lcid, LOCALE_SENGLANGUAGE|LOCALE_NOUSEROVERRIDE,
388 buf_en_language, sizeof(buf_en_language)/sizeof(WCHAR));
390 if(l_data->lang[0] && !strcmpiW(l_data->lang, buf_en_language)) goto found;
391 return TRUE; /* not found, continue search */
394 l_data->found_lang_id[l_data->n_found] = LangID;
396 TRACE("Found id %04X for lang %s\n", LangID, debugstr_w(l_data->lang));
397 return (l_data->n_found < NLS_MAX_LANGUAGES); /* continue search, unless we have enough */
401 /***********************************************************************
405 * Lang: a string whose two first chars are the iso name of a language.
406 * Country: a string whose two first chars are the iso name of country
407 * Charset: a string defining the chosen charset encoding
408 * Dialect: a string defining a variation of the locale
410 * all those values are from the standardized format of locale
411 * name in unix which is: Lang[_Country][.Charset][@Dialect]
414 * the numeric code of the language used by Windows
416 * FIXME: Charset and Dialect are not handled
418 static LANGID get_language_id(LPCSTR Lang, LPCSTR Country, LPCSTR Charset, LPCSTR Dialect)
420 LANG_FIND_DATA l_data;
424 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
429 strcpynAtoW(l_data.lang, Lang, sizeof(l_data.lang)/sizeof(WCHAR));
431 if (Country) strcpynAtoW(l_data.country, Country, sizeof(l_data.country)/sizeof(WCHAR));
432 else l_data.country[0] = 0;
434 EnumResourceLanguagesW(kernel32_handle, (LPCWSTR)RT_STRING, (LPCWSTR)LOCALE_ILANGUAGE,
435 find_language_id_proc, (LPARAM)&l_data);
437 if (l_data.n_found == 1) goto END;
441 if(l_data.country[0])
443 /* retry without country name */
444 l_data.country[0] = 0;
445 EnumResourceLanguagesW(kernel32_handle, (LPCWSTR)RT_STRING, (LPCWSTR)LOCALE_ILANGUAGE,
446 find_language_id_proc, (LONG)&l_data);
449 MESSAGE("Warning: Language '%s_%s' was not recognized, defaulting to English.\n",
451 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
453 else MESSAGE("Warning: Language '%s_%s' was not recognized, defaulting to '%s'.\n",
454 Lang, Country, debugstr_lang(l_data.found_lang_id[0]) );
458 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English.\n", Lang);
459 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
466 if (Country && Country[0])
467 MESSAGE("For language '%s_%s' several language ids were found:\n", Lang, Country);
469 MESSAGE("For language '%s' several language ids were found:\n", Lang);
471 /* print a list of languages with their description */
472 for (i = 0; i < l_data.n_found; i++)
476 GetLocaleInfoW( MAKELCID( l_data.found_lang_id[i], SORT_DEFAULT ),
477 LOCALE_SLANGUAGE|LOCALE_NOUSEROVERRIDE, buffW, sizeof(buffW)/sizeof(WCHAR));
478 strcpyWtoA( buffA, buffW );
479 MESSAGE( " %s (%04X) - %s\n", debugstr_lang(l_data.found_lang_id[i]),
480 l_data.found_lang_id[i], buffA );
482 MESSAGE("Defaulting to '%s'. You should specify the exact language you want\n"
483 "by defining your LANG environment variable like this: LANG=%s\n",
484 debugstr_lang(l_data.found_lang_id[0]), debugstr_lang(l_data.found_lang_id[0]) );
487 TRACE("Returning %04X (%s)\n", l_data.found_lang_id[0], debugstr_lang(l_data.found_lang_id[0]));
488 return l_data.found_lang_id[0];
492 /***********************************************************************
493 * charset_cmp (internal)
495 static int charset_cmp( const void *name, const void *entry )
497 const struct charset_entry *charset = (const struct charset_entry *)entry;
498 return strcasecmp( (const char *)name, charset->charset_name );
501 /***********************************************************************
504 static LCID get_env_lcid( UINT *unix_cp, const char *env_str )
506 char *buf, *lang,*country,*charset,*dialect,*next;
509 if (((lang = getenv( "LC_ALL" )) && *lang) ||
510 (env_str && (lang = getenv( env_str )) && *lang) ||
511 ((lang = getenv( "LANG" )) && *lang))
513 if (!strcmp(lang,"POSIX") || !strcmp(lang,"C")) goto done;
515 buf = RtlAllocateHeap( GetProcessHeap(), 0, strlen(lang) + 1 );
520 next=strchr(lang,':'); if (next) *next++='\0';
521 dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
522 charset=strchr(lang,'.'); if (charset) *charset++='\0';
523 country=strchr(lang,'_'); if (country) *country++='\0';
525 ret = get_language_id(lang, country, charset, dialect);
526 if (ret && charset && unix_cp)
528 const struct charset_entry *entry;
529 char charset_name[16];
532 /* remove punctuation characters from charset name */
533 for (i = j = 0; charset[i] && j < sizeof(charset_name)-1; i++)
534 if (isalnum(charset[i])) charset_name[j++] = charset[i];
537 entry = bsearch( charset_name, charset_names,
538 sizeof(charset_names)/sizeof(charset_names[0]),
539 sizeof(charset_names[0]), charset_cmp );
542 *unix_cp = entry->codepage;
543 TRACE("charset %s was mapped to cp %u\n", charset, *unix_cp);
546 FIXME("charset %s was not recognized\n", charset);
550 } while (lang && !ret);
552 if (!ret) MESSAGE("Warning: language '%s' not recognized, defaulting to English\n", buf);
553 RtlFreeHeap( GetProcessHeap(), 0, buf );
557 if (!ret) ret = MAKELCID( MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), SORT_DEFAULT) ;
562 /***********************************************************************
563 * GetUserDefaultLangID (KERNEL32.@)
565 * Get the default language Id for the current user.
571 * The current LANGID of the default language for the current user.
573 LANGID WINAPI GetUserDefaultLangID(void)
575 return LANGIDFROMLCID(GetUserDefaultLCID());
579 /***********************************************************************
580 * GetSystemDefaultLangID (KERNEL32.@)
582 * Get the default language Id for the system.
588 * The current LANGID of the default language for the system.
590 LANGID WINAPI GetSystemDefaultLangID(void)
592 return LANGIDFROMLCID(GetSystemDefaultLCID());
596 /***********************************************************************
597 * GetUserDefaultLCID (KERNEL32.@)
599 * Get the default locale Id for the current user.
605 * The current LCID of the default locale for the current user.
607 LCID WINAPI GetUserDefaultLCID(void)
610 NtQueryDefaultLocale( TRUE, &lcid );
615 /***********************************************************************
616 * GetSystemDefaultLCID (KERNEL32.@)
618 * Get the default locale Id for the system.
624 * The current LCID of the default locale for the system.
626 LCID WINAPI GetSystemDefaultLCID(void)
629 NtQueryDefaultLocale( FALSE, &lcid );
634 /***********************************************************************
635 * GetUserDefaultUILanguage (KERNEL32.@)
637 * Get the default user interface language Id for the current user.
643 * The current LANGID of the default UI language for the current user.
645 LANGID WINAPI GetUserDefaultUILanguage(void)
648 NtQueryDefaultUILanguage( &lang );
653 /***********************************************************************
654 * GetSystemDefaultUILanguage (KERNEL32.@)
656 * Get the default user interface language Id for the system.
662 * The current LANGID of the default UI language for the system. This is
663 * typically the same language used during the installation process.
665 LANGID WINAPI GetSystemDefaultUILanguage(void)
668 NtQueryInstallUILanguage( &lang );
673 /******************************************************************************
674 * get_locale_value_name
676 * Gets the registry value name for a given lctype.
678 static const WCHAR *get_locale_value_name( DWORD lctype )
680 static const WCHAR iCalendarTypeW[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
681 static const WCHAR iCountryW[] = {'i','C','o','u','n','t','r','y',0};
682 static const WCHAR iCurrDigitsW[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
683 static const WCHAR iCurrencyW[] = {'i','C','u','r','r','e','n','c','y',0};
684 static const WCHAR iDateW[] = {'i','D','a','t','e',0};
685 static const WCHAR iDigitsW[] = {'i','D','i','g','i','t','s',0};
686 static const WCHAR iFirstDayOfWeekW[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
687 static const WCHAR iFirstWeekOfYearW[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
688 static const WCHAR iLDateW[] = {'i','L','D','a','t','e',0};
689 static const WCHAR iLZeroW[] = {'i','L','Z','e','r','o',0};
690 static const WCHAR iMeasureW[] = {'i','M','e','a','s','u','r','e',0};
691 static const WCHAR iNegCurrW[] = {'i','N','e','g','C','u','r','r',0};
692 static const WCHAR iNegNumberW[] = {'i','N','e','g','N','u','m','b','e','r',0};
693 static const WCHAR iPaperSizeW[] = {'i','P','a','p','e','r','S','i','z','e',0};
694 static const WCHAR iTLZeroW[] = {'i','T','L','Z','e','r','o',0};
695 static const WCHAR iTimePrefixW[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
696 static const WCHAR iTimeW[] = {'i','T','i','m','e',0};
697 static const WCHAR s1159W[] = {'s','1','1','5','9',0};
698 static const WCHAR s2359W[] = {'s','2','3','5','9',0};
699 static const WCHAR sCountryW[] = {'s','C','o','u','n','t','r','y',0};
700 static const WCHAR sCurrencyW[] = {'s','C','u','r','r','e','n','c','y',0};
701 static const WCHAR sDateW[] = {'s','D','a','t','e',0};
702 static const WCHAR sDecimalW[] = {'s','D','e','c','i','m','a','l',0};
703 static const WCHAR sGroupingW[] = {'s','G','r','o','u','p','i','n','g',0};
704 static const WCHAR sLanguageW[] = {'s','L','a','n','g','u','a','g','e',0};
705 static const WCHAR sListW[] = {'s','L','i','s','t',0};
706 static const WCHAR sLongDateW[] = {'s','L','o','n','g','D','a','t','e',0};
707 static const WCHAR sMonDecimalSepW[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
708 static const WCHAR sMonGroupingW[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
709 static const WCHAR sMonThousandSepW[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
710 static const WCHAR sNativeDigitsW[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
711 static const WCHAR sNegativeSignW[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
712 static const WCHAR sPositiveSignW[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
713 static const WCHAR sShortDateW[] = {'s','S','h','o','r','t','D','a','t','e',0};
714 static const WCHAR sThousandW[] = {'s','T','h','o','u','s','a','n','d',0};
715 static const WCHAR sTimeFormatW[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
716 static const WCHAR sTimeW[] = {'s','T','i','m','e',0};
717 static const WCHAR sYearMonthW[] = {'s','Y','e','a','r','M','o','n','t','h',0};
718 static const WCHAR NumShapeW[] = {'N','u','m','s','h','a','p','e',0};
722 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
723 * the values are stored in the registry, confirmed under Windows.
725 case LOCALE_ICALENDARTYPE: return iCalendarTypeW;
726 case LOCALE_ICURRDIGITS: return iCurrDigitsW;
727 case LOCALE_ICURRENCY: return iCurrencyW;
728 case LOCALE_IDIGITS: return iDigitsW;
729 case LOCALE_IFIRSTDAYOFWEEK: return iFirstDayOfWeekW;
730 case LOCALE_IFIRSTWEEKOFYEAR: return iFirstWeekOfYearW;
731 case LOCALE_ILZERO: return iLZeroW;
732 case LOCALE_IMEASURE: return iMeasureW;
733 case LOCALE_INEGCURR: return iNegCurrW;
734 case LOCALE_INEGNUMBER: return iNegNumberW;
735 case LOCALE_IPAPERSIZE: return iPaperSizeW;
736 case LOCALE_ITIME: return iTimeW;
737 case LOCALE_S1159: return s1159W;
738 case LOCALE_S2359: return s2359W;
739 case LOCALE_SCURRENCY: return sCurrencyW;
740 case LOCALE_SDATE: return sDateW;
741 case LOCALE_SDECIMAL: return sDecimalW;
742 case LOCALE_SGROUPING: return sGroupingW;
743 case LOCALE_SLIST: return sListW;
744 case LOCALE_SLONGDATE: return sLongDateW;
745 case LOCALE_SMONDECIMALSEP: return sMonDecimalSepW;
746 case LOCALE_SMONGROUPING: return sMonGroupingW;
747 case LOCALE_SMONTHOUSANDSEP: return sMonThousandSepW;
748 case LOCALE_SNEGATIVESIGN: return sNegativeSignW;
749 case LOCALE_SPOSITIVESIGN: return sPositiveSignW;
750 case LOCALE_SSHORTDATE: return sShortDateW;
751 case LOCALE_STHOUSAND: return sThousandW;
752 case LOCALE_STIME: return sTimeW;
753 case LOCALE_STIMEFORMAT: return sTimeFormatW;
754 case LOCALE_SYEARMONTH: return sYearMonthW;
756 /* The following are not listed under MSDN as supported,
757 * but seem to be used and also stored in the registry.
759 case LOCALE_ICOUNTRY: return iCountryW;
760 case LOCALE_IDATE: return iDateW;
761 case LOCALE_ILDATE: return iLDateW;
762 case LOCALE_ITLZERO: return iTLZeroW;
763 case LOCALE_SCOUNTRY: return sCountryW;
764 case LOCALE_SLANGUAGE: return sLanguageW;
766 /* The following are used in XP and later */
767 case LOCALE_IDIGITSUBSTITUTION: return NumShapeW;
768 case LOCALE_SNATIVEDIGITS: return sNativeDigitsW;
769 case LOCALE_ITIMEMARKPOSN: return iTimePrefixW;
775 /******************************************************************************
776 * get_registry_locale_info
778 * Retrieve user-modified locale info from the registry.
779 * Return length, 0 on error, -1 if not found.
781 static INT get_registry_locale_info( LPCWSTR value, LPWSTR buffer, INT len )
787 UNICODE_STRING nameW;
788 KEY_VALUE_PARTIAL_INFORMATION *info;
789 static const int info_size = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
791 if (!(hkey = create_registry_key())) return -1;
793 RtlInitUnicodeString( &nameW, value );
794 size = info_size + len * sizeof(WCHAR);
796 if (!(info = HeapAlloc( GetProcessHeap(), 0, size )))
799 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
803 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, info, size, &size );
804 if (status == STATUS_BUFFER_OVERFLOW && !buffer) status = 0;
808 ret = (size - info_size) / sizeof(WCHAR);
809 /* append terminating null if needed */
810 if (!ret || ((WCHAR *)info->Data)[ret-1])
812 if (ret < len || !buffer) ret++;
815 SetLastError( ERROR_INSUFFICIENT_BUFFER );
821 memcpy( buffer, info->Data, (ret-1) * sizeof(WCHAR) );
827 if (status == STATUS_OBJECT_NAME_NOT_FOUND) ret = -1;
830 SetLastError( RtlNtStatusToDosError(status) );
835 HeapFree( GetProcessHeap(), 0, info );
840 /******************************************************************************
841 * GetLocaleInfoA (KERNEL32.@)
843 * Get information about an aspect of a locale.
846 * lcid [I] LCID of the locale
847 * lctype [I] LCTYPE_ flags from "winnls.h"
848 * buffer [O] Destination for the information
849 * len [I] Length of buffer in characters
852 * Success: The size of the data requested. If buffer is non-NULL, it is filled
853 * with the information.
854 * Failure: 0. Use GetLastError() to determine the cause.
857 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
858 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
859 * which is a bit string.
861 INT WINAPI GetLocaleInfoA( LCID lcid, LCTYPE lctype, LPSTR buffer, INT len )
866 TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d)\n", lcid, lctype, buffer, len );
868 if (len < 0 || (len && !buffer))
870 SetLastError( ERROR_INVALID_PARAMETER );
873 if (!len) buffer = NULL;
875 if (!(lenW = GetLocaleInfoW( lcid, lctype, NULL, 0 ))) return 0;
877 if (!(bufferW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
879 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
882 if ((ret = GetLocaleInfoW( lcid, lctype, bufferW, lenW )))
884 if ((lctype & LOCALE_RETURN_NUMBER) ||
885 ((lctype & ~LOCALE_LOCALEINFOFLAGSMASK) == LOCALE_FONTSIGNATURE))
887 /* it's not an ASCII string, just bytes */
888 ret *= sizeof(WCHAR);
891 if (ret <= len) memcpy( buffer, bufferW, ret );
894 SetLastError( ERROR_INSUFFICIENT_BUFFER );
901 UINT codepage = CP_ACP;
902 if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
903 ret = WideCharToMultiByte( codepage, 0, bufferW, ret, buffer, len, NULL, NULL );
906 HeapFree( GetProcessHeap(), 0, bufferW );
911 /******************************************************************************
912 * GetLocaleInfoW (KERNEL32.@)
914 * See GetLocaleInfoA.
916 INT WINAPI GetLocaleInfoW( LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len )
926 if (len < 0 || (len && !buffer))
928 SetLastError( ERROR_INVALID_PARAMETER );
931 if (!len) buffer = NULL;
933 lcid = ConvertDefaultLocale(lcid);
935 lcflags = lctype & LOCALE_LOCALEINFOFLAGSMASK;
938 TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d)\n", lcid, lctype, buffer, len );
940 /* first check for overrides in the registry */
942 if (!(lcflags & LOCALE_NOUSEROVERRIDE) && lcid == GetUserDefaultLCID())
944 const WCHAR *value = get_locale_value_name(lctype);
948 if (lcflags & LOCALE_RETURN_NUMBER)
951 ret = get_registry_locale_info( value, tmp, sizeof(tmp)/sizeof(WCHAR) );
955 UINT number = strtolW( tmp, &end, 10 );
956 if (*end) /* invalid number */
958 SetLastError( ERROR_INVALID_FLAGS );
961 ret = sizeof(UINT)/sizeof(WCHAR);
962 if (!buffer) return ret;
965 SetLastError( ERROR_INSUFFICIENT_BUFFER );
968 memcpy( buffer, &number, sizeof(number) );
971 else ret = get_registry_locale_info( value, buffer, len );
973 if (ret != -1) return ret;
977 /* now load it from kernel resources */
979 lang_id = LANGIDFROMLCID( lcid );
981 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
982 if (SUBLANGID(lang_id) == SUBLANG_NEUTRAL)
983 lang_id = MAKELANGID(PRIMARYLANGID(lang_id), SUBLANG_DEFAULT);
985 if (!(hrsrc = FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING,
986 (LPCWSTR)((lctype >> 4) + 1), lang_id )))
988 SetLastError( ERROR_INVALID_FLAGS ); /* no such lctype */
991 if (!(hmem = LoadResource( kernel32_handle, hrsrc )))
994 p = LockResource( hmem );
995 for (i = 0; i < (lctype & 0x0f); i++) p += *p + 1;
997 if (lcflags & LOCALE_RETURN_NUMBER) ret = sizeof(UINT)/sizeof(WCHAR);
998 else ret = (lctype == LOCALE_FONTSIGNATURE) ? *p : *p + 1;
1000 if (!buffer) return ret;
1004 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1008 if (lcflags & LOCALE_RETURN_NUMBER)
1011 WCHAR *end, *tmp = HeapAlloc( GetProcessHeap(), 0, (*p + 1) * sizeof(WCHAR) );
1013 memcpy( tmp, p + 1, *p * sizeof(WCHAR) );
1015 number = strtolW( tmp, &end, 10 );
1017 memcpy( buffer, &number, sizeof(number) );
1018 else /* invalid number */
1020 SetLastError( ERROR_INVALID_FLAGS );
1023 HeapFree( GetProcessHeap(), 0, tmp );
1025 TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d) returning number %d\n",
1026 lcid, lctype, buffer, len, number );
1030 memcpy( buffer, p + 1, *p * sizeof(WCHAR) );
1031 if (lctype != LOCALE_FONTSIGNATURE) buffer[ret-1] = 0;
1033 TRACE( "(lcid=0x%lx,lctype=0x%lx,%p,%d) returning %d %s\n",
1034 lcid, lctype, buffer, len, ret, debugstr_w(buffer) );
1040 /******************************************************************************
1041 * SetLocaleInfoA [KERNEL32.@]
1043 * Set information about an aspect of a locale.
1046 * lcid [I] LCID of the locale
1047 * lctype [I] LCTYPE_ flags from "winnls.h"
1048 * data [I] Information to set
1051 * Success: TRUE. The information given will be returned by GetLocaleInfoA()
1052 * whenever it is called without LOCALE_NOUSEROVERRIDE.
1053 * Failure: FALSE. Use GetLastError() to determine the cause.
1056 * - Values are only be set for the current user locale; the system locale
1057 * settings cannot be changed.
1058 * - Any settings changed by this call are lost when the locale is changed by
1059 * the control panel (in Wine, this happens every time you change LANG).
1060 * - The native implementation of this function does not check that lcid matches
1061 * the current user locale, and simply sets the new values. Wine warns you in
1062 * this case, but behaves the same.
1064 BOOL WINAPI SetLocaleInfoA(LCID lcid, LCTYPE lctype, LPCSTR data)
1066 UINT codepage = CP_ACP;
1071 lcid = ConvertDefaultLocale(lcid);
1073 if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
1077 SetLastError( ERROR_INVALID_PARAMETER );
1080 len = MultiByteToWideChar( codepage, 0, data, -1, NULL, 0 );
1081 if (!(strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
1083 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1086 MultiByteToWideChar( codepage, 0, data, -1, strW, len );
1087 ret = SetLocaleInfoW( lcid, lctype, strW );
1088 HeapFree( GetProcessHeap(), 0, strW );
1093 /******************************************************************************
1094 * SetLocaleInfoW (KERNEL32.@)
1096 * See SetLocaleInfoA.
1098 BOOL WINAPI SetLocaleInfoW( LCID lcid, LCTYPE lctype, LPCWSTR data )
1101 static const WCHAR intlW[] = {'i','n','t','l',0 };
1102 UNICODE_STRING valueW;
1106 lcid = ConvertDefaultLocale(lcid);
1109 value = get_locale_value_name( lctype );
1111 if (!data || !value)
1113 SetLastError( ERROR_INVALID_PARAMETER );
1117 if (lctype == LOCALE_IDATE || lctype == LOCALE_ILDATE)
1119 SetLastError( ERROR_INVALID_FLAGS );
1123 if (lcid != GetUserDefaultLCID())
1125 /* Windows does not check that the lcid matches the current lcid */
1126 WARN("locale 0x%08lx isn't the current locale (0x%08lx), setting anyway!\n",
1127 lcid, GetUserDefaultLCID());
1130 TRACE("setting %lx (%s) to %s\n", lctype, debugstr_w(value), debugstr_w(data) );
1132 /* FIXME: should check that data to set is sane */
1134 /* FIXME: profile functions should map to registry */
1135 WriteProfileStringW( intlW, value, data );
1137 if (!(hkey = create_registry_key())) return FALSE;
1138 RtlInitUnicodeString( &valueW, value );
1139 status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, data, (strlenW(data)+1)*sizeof(WCHAR) );
1141 if (lctype == LOCALE_SSHORTDATE || lctype == LOCALE_SLONGDATE)
1143 /* Set I-value from S value */
1144 WCHAR *lpD, *lpM, *lpY;
1147 lpD = strrchrW(data, 'd');
1148 lpM = strrchrW(data, 'M');
1149 lpY = strrchrW(data, 'y');
1153 szBuff[0] = '1'; /* D-M-Y */
1158 szBuff[0] = '2'; /* Y-M-D */
1160 szBuff[0] = '0'; /* M-D-Y */
1165 if (lctype == LOCALE_SSHORTDATE)
1166 lctype = LOCALE_IDATE;
1168 lctype = LOCALE_ILDATE;
1170 value = get_locale_value_name( lctype );
1172 WriteProfileStringW( intlW, value, szBuff );
1174 RtlInitUnicodeString( &valueW, value );
1175 status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, szBuff, sizeof(szBuff) );
1180 if (status) SetLastError( RtlNtStatusToDosError(status) );
1185 /******************************************************************************
1186 * GetACP (KERNEL32.@)
1188 * Get the current Ansi code page Id for the system.
1194 * The current Ansi code page identifier for the system.
1196 UINT WINAPI GetACP(void)
1198 assert( ansi_cptable );
1199 return ansi_cptable->info.codepage;
1203 /******************************************************************************
1204 * SetCPGlobal (KERNEL32.@)
1206 * Set the current Ansi code page Id for the system.
1209 * acp [I] code page ID to be the new ACP.
1214 UINT WINAPI SetCPGlobal( UINT acp )
1216 UINT ret = GetACP();
1217 const union cptable *new_cptable = wine_cp_get_table( acp );
1219 if (new_cptable) ansi_cptable = new_cptable;
1224 /***********************************************************************
1225 * GetOEMCP (KERNEL32.@)
1227 * Get the current OEM code page Id for the system.
1233 * The current OEM code page identifier for the system.
1235 UINT WINAPI GetOEMCP(void)
1237 assert( oem_cptable );
1238 return oem_cptable->info.codepage;
1242 /***********************************************************************
1243 * IsValidCodePage (KERNEL32.@)
1245 * Determine if a given code page identifier is valid.
1248 * codepage [I] Code page Id to verify.
1251 * TRUE, If codepage is valid and available on the system,
1254 BOOL WINAPI IsValidCodePage( UINT codepage )
1261 return wine_cp_get_table( codepage ) != NULL;
1266 /***********************************************************************
1267 * IsDBCSLeadByteEx (KERNEL32.@)
1269 * Determine if a character is a lead byte in a given code page.
1272 * codepage [I] Code page for the test.
1273 * testchar [I] Character to test
1276 * TRUE, if testchar is a lead byte in codepage,
1279 BOOL WINAPI IsDBCSLeadByteEx( UINT codepage, BYTE testchar )
1281 const union cptable *table = get_codepage_table( codepage );
1282 return table && is_dbcs_leadbyte( table, testchar );
1286 /***********************************************************************
1287 * IsDBCSLeadByte (KERNEL32.@)
1288 * IsDBCSLeadByte (KERNEL.207)
1290 * Determine if a character is a lead byte.
1293 * testchar [I] Character to test
1296 * TRUE, if testchar is a lead byte in the Ansii code page,
1299 BOOL WINAPI IsDBCSLeadByte( BYTE testchar )
1301 if (!ansi_cptable) return FALSE;
1302 return is_dbcs_leadbyte( ansi_cptable, testchar );
1306 /***********************************************************************
1307 * GetCPInfo (KERNEL32.@)
1309 * Get information about a code page.
1312 * codepage [I] Code page number
1313 * cpinfo [O] Destination for code page information
1316 * Success: TRUE. cpinfo is updated with the information about codepage.
1317 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1319 BOOL WINAPI GetCPInfo( UINT codepage, LPCPINFO cpinfo )
1321 const union cptable *table;
1325 SetLastError( ERROR_INVALID_PARAMETER );
1329 if (!(table = get_codepage_table( codepage )))
1335 cpinfo->DefaultChar[0] = 0x3f;
1336 cpinfo->DefaultChar[1] = 0;
1337 cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = 0;
1338 cpinfo->MaxCharSize = (codepage == CP_UTF7) ? 5 : 4;
1342 SetLastError( ERROR_INVALID_PARAMETER );
1345 if (table->info.def_char & 0xff00)
1347 cpinfo->DefaultChar[0] = table->info.def_char & 0xff00;
1348 cpinfo->DefaultChar[1] = table->info.def_char & 0x00ff;
1352 cpinfo->DefaultChar[0] = table->info.def_char & 0xff;
1353 cpinfo->DefaultChar[1] = 0;
1355 if ((cpinfo->MaxCharSize = table->info.char_size) == 2)
1356 memcpy( cpinfo->LeadByte, table->dbcs.lead_bytes, sizeof(cpinfo->LeadByte) );
1358 cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = 0;
1363 /***********************************************************************
1364 * GetCPInfoExA (KERNEL32.@)
1366 * Get extended information about a code page.
1369 * codepage [I] Code page number
1370 * dwFlags [I] Reserved, must to 0.
1371 * cpinfo [O] Destination for code page information
1374 * Success: TRUE. cpinfo is updated with the information about codepage.
1375 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1377 BOOL WINAPI GetCPInfoExA( UINT codepage, DWORD dwFlags, LPCPINFOEXA cpinfo )
1381 if (!GetCPInfoExW( codepage, dwFlags, &cpinfoW ))
1384 /* the layout is the same except for CodePageName */
1385 memcpy(cpinfo, &cpinfoW, sizeof(CPINFOEXA));
1386 WideCharToMultiByte(CP_ACP, 0, cpinfoW.CodePageName, -1, cpinfo->CodePageName, sizeof(cpinfo->CodePageName), NULL, NULL);
1390 /***********************************************************************
1391 * GetCPInfoExW (KERNEL32.@)
1393 * Unicode version of GetCPInfoExA.
1395 BOOL WINAPI GetCPInfoExW( UINT codepage, DWORD dwFlags, LPCPINFOEXW cpinfo )
1397 if (!GetCPInfo( codepage, (LPCPINFO)cpinfo ))
1404 static const WCHAR utf7[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','7',')',0};
1406 cpinfo->CodePage = CP_UTF7;
1407 cpinfo->UnicodeDefaultChar = 0x3f;
1408 strcpyW(cpinfo->CodePageName, utf7);
1414 static const WCHAR utf8[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','8',')',0};
1416 cpinfo->CodePage = CP_UTF8;
1417 cpinfo->UnicodeDefaultChar = 0x3f;
1418 strcpyW(cpinfo->CodePageName, utf8);
1424 const union cptable *table = get_codepage_table( codepage );
1426 cpinfo->CodePage = table->info.codepage;
1427 cpinfo->UnicodeDefaultChar = table->info.def_unicode_char;
1428 MultiByteToWideChar( CP_ACP, 0, table->info.name, -1, cpinfo->CodePageName,
1429 sizeof(cpinfo->CodePageName)/sizeof(WCHAR));
1436 /***********************************************************************
1437 * EnumSystemCodePagesA (KERNEL32.@)
1439 * Call a user defined function for every code page installed on the system.
1442 * lpfnCodePageEnum [I] User CODEPAGE_ENUMPROC to call with each found code page
1443 * flags [I] Reserved, set to 0.
1446 * TRUE, If all code pages have been enumerated, or
1447 * FALSE if lpfnCodePageEnum returned FALSE to stop the enumeration.
1449 BOOL WINAPI EnumSystemCodePagesA( CODEPAGE_ENUMPROCA lpfnCodePageEnum, DWORD flags )
1451 const union cptable *table;
1457 if (!(table = wine_cp_enum_table( index++ ))) break;
1458 sprintf( buffer, "%d", table->info.codepage );
1459 if (!lpfnCodePageEnum( buffer )) break;
1465 /***********************************************************************
1466 * EnumSystemCodePagesW (KERNEL32.@)
1468 * See EnumSystemCodePagesA.
1470 BOOL WINAPI EnumSystemCodePagesW( CODEPAGE_ENUMPROCW lpfnCodePageEnum, DWORD flags )
1472 const union cptable *table;
1473 WCHAR buffer[10], *p;
1474 int page, index = 0;
1478 if (!(table = wine_cp_enum_table( index++ ))) break;
1479 p = buffer + sizeof(buffer)/sizeof(WCHAR);
1481 page = table->info.codepage;
1484 *--p = '0' + (page % 10);
1487 if (!lpfnCodePageEnum( p )) break;
1493 /***********************************************************************
1494 * MultiByteToWideChar (KERNEL32.@)
1496 * Convert a multibyte character string into a Unicode string.
1499 * page [I] Codepage character set to convert from
1500 * flags [I] Character mapping flags
1501 * src [I] Source string buffer
1502 * srclen [I] Length of src, or -1 if src is NUL terminated
1503 * dst [O] Destination buffer
1504 * dstlen [I] Length of dst, or 0 to compute the required length
1507 * Success: If dstlen > 0, the number of characters written to dst.
1508 * If dstlen == 0, the number of characters needed to perform the
1509 * conversion. In both cases the count includes the terminating NUL.
1510 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1511 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1512 * and dstlen != 0; ERROR_INVALID_PARAMETER, if an invalid parameter
1513 * is passed, and ERROR_NO_UNICODE_TRANSLATION if no translation is
1516 INT WINAPI MultiByteToWideChar( UINT page, DWORD flags, LPCSTR src, INT srclen,
1517 LPWSTR dst, INT dstlen )
1519 const union cptable *table;
1522 if (!src || (!dst && dstlen))
1524 SetLastError( ERROR_INVALID_PARAMETER );
1528 if (srclen < 0) srclen = strlen(src) + 1;
1530 if (flags & MB_USEGLYPHCHARS) FIXME("MB_USEGLYPHCHARS not supported\n");
1537 SetLastError( ERROR_INVALID_PARAMETER );
1540 ret = wine_cpsymbol_mbstowcs( src, srclen, dst, dstlen );
1543 FIXME("UTF-7 not supported\n");
1544 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
1549 ret = wine_cp_mbstowcs( unix_cptable, flags, src, srclen, dst, dstlen );
1554 ret = wine_utf8_mbstowcs( flags, src, srclen, dst, dstlen );
1557 if (!(table = get_codepage_table( page )))
1559 SetLastError( ERROR_INVALID_PARAMETER );
1562 ret = wine_cp_mbstowcs( table, flags, src, srclen, dst, dstlen );
1570 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER ); break;
1571 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION ); break;
1579 /***********************************************************************
1580 * WideCharToMultiByte (KERNEL32.@)
1582 * Convert a Unicode character string into a multibyte string.
1585 * page [I] Code page character set to convert to
1586 * flags [I] Mapping Flags (MB_ constants from "winnls.h").
1587 * src [I] Source string buffer
1588 * srclen [I] Length of src, or -1 if src is NUL terminated
1589 * dst [O] Destination buffer
1590 * dstlen [I] Length of dst, or 0 to compute the required length
1591 * defchar [I] Default character to use for conversion if no exact
1592 * conversion can be made
1593 * used [O] Set if default character was used in the conversion
1596 * Success: If dstlen > 0, the number of characters written to dst.
1597 * If dstlen == 0, number of characters needed to perform the
1598 * conversion. In both cases the count includes the terminating NUL.
1599 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1600 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1601 * and dstlen != 0, and ERROR_INVALID_PARAMETER, if an invalid
1602 * parameter was given.
1604 INT WINAPI WideCharToMultiByte( UINT page, DWORD flags, LPCWSTR src, INT srclen,
1605 LPSTR dst, INT dstlen, LPCSTR defchar, BOOL *used )
1607 const union cptable *table;
1610 if (!src || (!dst && dstlen))
1612 SetLastError( ERROR_INVALID_PARAMETER );
1616 if (srclen < 0) srclen = strlenW(src) + 1;
1621 if( flags || defchar || used)
1623 SetLastError( ERROR_INVALID_PARAMETER );
1626 ret = wine_cpsymbol_wcstombs( src, srclen, dst, dstlen );
1629 FIXME("UTF-7 not supported\n");
1630 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
1635 ret = wine_cp_wcstombs( unix_cptable, flags, src, srclen, dst, dstlen,
1636 defchar, used ? &used_tmp : NULL );
1641 if (used) *used = FALSE; /* all chars are valid for UTF-8 */
1642 ret = wine_utf8_wcstombs( src, srclen, dst, dstlen );
1645 if (!(table = get_codepage_table( page )))
1647 SetLastError( ERROR_INVALID_PARAMETER );
1650 ret = wine_cp_wcstombs( table, flags, src, srclen, dst, dstlen,
1651 defchar, used ? &used_tmp : NULL );
1652 if (used) *used = used_tmp;
1660 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER ); break;
1661 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION ); break;
1665 TRACE("cp %d %s -> %s\n", page, debugstr_w(src), debugstr_a(dst));
1670 /***********************************************************************
1671 * GetThreadLocale (KERNEL32.@)
1673 * Get the current threads locale.
1679 * The LCID currently assocated with the calling thread.
1681 LCID WINAPI GetThreadLocale(void)
1683 LCID ret = NtCurrentTeb()->CurrentLocale;
1684 if (!ret) NtCurrentTeb()->CurrentLocale = ret = GetUserDefaultLCID();
1688 /**********************************************************************
1689 * SetThreadLocale (KERNEL32.@)
1691 * Set the current threads locale.
1694 * lcid [I] LCID of the locale to set
1697 * Success: TRUE. The threads locale is set to lcid.
1698 * Failure: FALSE. Use GetLastError() to determine the cause.
1700 BOOL WINAPI SetThreadLocale( LCID lcid )
1702 TRACE("(0x%04lX)\n", lcid);
1704 lcid = ConvertDefaultLocale(lcid);
1706 if (lcid != GetThreadLocale())
1708 if (!IsValidLocale(lcid, LCID_SUPPORTED))
1710 SetLastError(ERROR_INVALID_PARAMETER);
1714 NtCurrentTeb()->CurrentLocale = lcid;
1715 kernel_get_thread_data()->code_page = get_lcid_codepage( lcid );
1720 /******************************************************************************
1721 * ConvertDefaultLocale (KERNEL32.@)
1723 * Convert a default locale identifier into a real identifier.
1726 * lcid [I] LCID identifier of the locale to convert
1729 * lcid unchanged, if not a default locale or its sublanguage is
1730 * not SUBLANG_NEUTRAL.
1731 * GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
1732 * GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
1733 * Otherwise, lcid with sublanguage changed to SUBLANG_DEFAULT.
1735 LCID WINAPI ConvertDefaultLocale( LCID lcid )
1741 case LOCALE_SYSTEM_DEFAULT:
1742 lcid = GetSystemDefaultLCID();
1744 case LOCALE_USER_DEFAULT:
1745 case LOCALE_NEUTRAL:
1746 lcid = GetUserDefaultLCID();
1749 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
1750 langid = LANGIDFROMLCID(lcid);
1751 if (SUBLANGID(langid) == SUBLANG_NEUTRAL)
1753 langid = MAKELANGID(PRIMARYLANGID(langid), SUBLANG_DEFAULT);
1754 lcid = MAKELCID(langid, SORTIDFROMLCID(lcid));
1761 /******************************************************************************
1762 * IsValidLocale (KERNEL32.@)
1764 * Determine if a locale is valid.
1767 * lcid [I] LCID of the locale to check
1768 * flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
1771 * TRUE, if lcid is valid,
1775 * Wine does not currently make the distinction between supported and installed. All
1776 * languages supported are installed by default.
1778 BOOL WINAPI IsValidLocale( LCID lcid, DWORD flags )
1780 /* check if language is registered in the kernel32 resources */
1781 return FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING,
1782 (LPCWSTR)LOCALE_ILANGUAGE, LANGIDFROMLCID(lcid)) != 0;
1786 static BOOL CALLBACK enum_lang_proc_a( HMODULE hModule, LPCSTR type,
1787 LPCSTR name, WORD LangID, LONG_PTR lParam )
1789 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
1792 sprintf(buf, "%08x", (UINT)LangID);
1793 return lpfnLocaleEnum( buf );
1796 static BOOL CALLBACK enum_lang_proc_w( HMODULE hModule, LPCWSTR type,
1797 LPCWSTR name, WORD LangID, LONG_PTR lParam )
1799 static const WCHAR formatW[] = {'%','0','8','x',0};
1800 LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
1802 sprintfW( buf, formatW, (UINT)LangID );
1803 return lpfnLocaleEnum( buf );
1806 /******************************************************************************
1807 * EnumSystemLocalesA (KERNEL32.@)
1809 * Call a users function for each locale available on the system.
1812 * lpfnLocaleEnum [I] Callback function to call for each locale
1813 * dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
1817 * Failure: FALSE. Use GetLastError() to determine the cause.
1819 BOOL WINAPI EnumSystemLocalesA( LOCALE_ENUMPROCA lpfnLocaleEnum, DWORD dwFlags )
1821 TRACE("(%p,%08lx)\n", lpfnLocaleEnum, dwFlags);
1822 EnumResourceLanguagesA( kernel32_handle, (LPSTR)RT_STRING,
1823 (LPCSTR)LOCALE_ILANGUAGE, enum_lang_proc_a,
1824 (LONG_PTR)lpfnLocaleEnum);
1829 /******************************************************************************
1830 * EnumSystemLocalesW (KERNEL32.@)
1832 * See EnumSystemLocalesA.
1834 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum, DWORD dwFlags )
1836 TRACE("(%p,%08lx)\n", lpfnLocaleEnum, dwFlags);
1837 EnumResourceLanguagesW( kernel32_handle, (LPWSTR)RT_STRING,
1838 (LPCWSTR)LOCALE_ILANGUAGE, enum_lang_proc_w,
1839 (LONG_PTR)lpfnLocaleEnum);
1844 /***********************************************************************
1845 * VerLanguageNameA (KERNEL32.@)
1847 * Get the name of a language.
1850 * wLang [I] LANGID of the language
1851 * szLang [O] Destination for the language name
1854 * Success: The size of the language name. If szLang is non-NULL, it is filled
1856 * Failure: 0. Use GetLastError() to determine the cause.
1859 DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
1861 return GetLocaleInfoA( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
1865 /***********************************************************************
1866 * VerLanguageNameW (KERNEL32.@)
1868 * See VerLanguageNameA.
1870 DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
1872 return GetLocaleInfoW( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
1876 /******************************************************************************
1877 * GetStringTypeW (KERNEL32.@)
1879 * See GetStringTypeA.
1881 BOOL WINAPI GetStringTypeW( DWORD type, LPCWSTR src, INT count, LPWORD chartype )
1883 if (count == -1) count = strlenW(src) + 1;
1887 while (count--) *chartype++ = get_char_typeW( *src++ ) & 0xfff;
1890 while (count--) *chartype++ = get_char_typeW( *src++ ) >> 12;
1894 WARN("CT_CTYPE3: semi-stub.\n");
1898 WORD type1, type3 = 0; /* C3_NOTAPPLICABLE */
1900 type1 = get_char_typeW( *src++ ) & 0xfff;
1901 /* try to construct type3 from type1 */
1902 if(type1 & C1_SPACE) type3 |= C3_SYMBOL;
1903 if(type1 & C1_ALPHA) type3 |= C3_ALPHA;
1904 if ((c>=0x30A0)&&(c<=0x30FF)) type3 |= C3_KATAKANA;
1905 if ((c>=0x3040)&&(c<=0x309F)) type3 |= C3_HIRAGANA;
1906 if ((c>=0x4E00)&&(c<=0x9FAF)) type3 |= C3_IDEOGRAPH;
1907 if ((c>=0x0600)&&(c<=0x06FF)) type3 |= C3_KASHIDA;
1908 if ((c>=0x3000)&&(c<=0x303F)) type3 |= C3_SYMBOL;
1910 if ((c>=0xFF00)&&(c<=0xFF60)) type3 |= C3_FULLWIDTH;
1911 if ((c>=0xFF00)&&(c<=0xFF20)) type3 |= C3_SYMBOL;
1912 if ((c>=0xFF3B)&&(c<=0xFF40)) type3 |= C3_SYMBOL;
1913 if ((c>=0xFF5B)&&(c<=0xFF60)) type3 |= C3_SYMBOL;
1914 if ((c>=0xFF21)&&(c<=0xFF3A)) type3 |= C3_ALPHA;
1915 if ((c>=0xFF41)&&(c<=0xFF5A)) type3 |= C3_ALPHA;
1916 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_FULLWIDTH;
1917 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_SYMBOL;
1919 if ((c>=0xFF61)&&(c<=0xFFDC)) type3 |= C3_HALFWIDTH;
1920 if ((c>=0xFF61)&&(c<=0xFF64)) type3 |= C3_SYMBOL;
1921 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_KATAKANA;
1922 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_ALPHA;
1923 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_HALFWIDTH;
1924 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_SYMBOL;
1925 *chartype++ = type3;
1930 SetLastError( ERROR_INVALID_PARAMETER );
1937 /******************************************************************************
1938 * GetStringTypeExW (KERNEL32.@)
1940 * See GetStringTypeExA.
1942 BOOL WINAPI GetStringTypeExW( LCID locale, DWORD type, LPCWSTR src, INT count, LPWORD chartype )
1944 /* locale is ignored for Unicode */
1945 return GetStringTypeW( type, src, count, chartype );
1949 /******************************************************************************
1950 * GetStringTypeA (KERNEL32.@)
1952 * Get characteristics of the characters making up a string.
1955 * locale [I] Locale Id for the string
1956 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
1957 * src [I] String to analyse
1958 * count [I] Length of src in chars, or -1 if src is NUL terminated
1959 * chartype [O] Destination for the calculated characteristics
1962 * Success: TRUE. chartype is filled with the requested characteristics of each char
1964 * Failure: FALSE. Use GetLastError() to determine the cause.
1966 BOOL WINAPI GetStringTypeA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
1973 if(count == -1) count = strlen(src) + 1;
1975 if (!(cp = get_lcid_codepage( locale )))
1977 FIXME("For locale %04lx using current ANSI code page\n", locale);
1981 countW = MultiByteToWideChar(cp, 0, src, count, NULL, 0);
1982 if((srcW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
1984 MultiByteToWideChar(cp, 0, src, count, srcW, countW);
1986 * NOTE: the target buffer has 1 word for each CHARACTER in the source
1987 * string, with multibyte characters there maybe be more bytes in count
1988 * than character space in the buffer!
1990 ret = GetStringTypeW(type, srcW, countW, chartype);
1991 HeapFree(GetProcessHeap(), 0, srcW);
1996 /******************************************************************************
1997 * GetStringTypeExA (KERNEL32.@)
1999 * Get characteristics of the characters making up a string.
2002 * locale [I] Locale Id for the string
2003 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
2004 * src [I] String to analyse
2005 * count [I] Length of src in chars, or -1 if src is NUL terminated
2006 * chartype [O] Destination for the calculated characteristics
2009 * Success: TRUE. chartype is filled with the requested characteristics of each char
2011 * Failure: FALSE. Use GetLastError() to determine the cause.
2013 BOOL WINAPI GetStringTypeExA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
2015 return GetStringTypeA(locale, type, src, count, chartype);
2019 /*************************************************************************
2020 * LCMapStringW (KERNEL32.@)
2024 INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen,
2025 LPWSTR dst, INT dstlen)
2029 if (!src || !srclen || dstlen < 0)
2031 SetLastError(ERROR_INVALID_PARAMETER);
2035 /* mutually exclusive flags */
2036 if ((flags & (LCMAP_LOWERCASE | LCMAP_UPPERCASE)) == (LCMAP_LOWERCASE | LCMAP_UPPERCASE) ||
2037 (flags & (LCMAP_HIRAGANA | LCMAP_KATAKANA)) == (LCMAP_HIRAGANA | LCMAP_KATAKANA) ||
2038 (flags & (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH)) == (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH) ||
2039 (flags & (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE)) == (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE))
2041 SetLastError(ERROR_INVALID_FLAGS);
2045 if (!dstlen) dst = NULL;
2047 lcid = ConvertDefaultLocale(lcid);
2049 if (flags & LCMAP_SORTKEY)
2053 SetLastError(ERROR_INVALID_FLAGS);
2057 if (srclen < 0) srclen = strlenW(src);
2059 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
2060 lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
2062 return wine_get_sortkey(flags, src, srclen, (char *)dst, dstlen);
2065 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
2066 if (flags & SORT_STRINGSORT)
2068 SetLastError(ERROR_INVALID_FLAGS);
2072 if (srclen < 0) srclen = strlenW(src) + 1;
2074 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
2075 lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
2077 if (!dst) /* return required string length */
2081 for (len = 0; srclen; src++, srclen--)
2084 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
2085 * and skips white space and punctuation characters for
2086 * NORM_IGNORESYMBOLS.
2088 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
2095 if (flags & LCMAP_UPPERCASE)
2097 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
2100 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
2102 *dst_ptr++ = toupperW(wch);
2106 else if (flags & LCMAP_LOWERCASE)
2108 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
2111 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
2113 *dst_ptr++ = tolowerW(wch);
2121 SetLastError(ERROR_INVALID_FLAGS);
2124 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
2127 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
2136 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2140 return dst_ptr - dst;
2143 /*************************************************************************
2144 * LCMapStringA (KERNEL32.@)
2146 * Map characters in a locale sensitive string.
2149 * lcid [I] LCID for the conversion.
2150 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
2151 * src [I] String to map
2152 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
2153 * dst [O] Destination for mapped string
2154 * dstlen [I] Length of dst in characters
2157 * Success: The length of the mapped string in dst, including the NUL terminator.
2158 * Failure: 0. Use GetLastError() to determine the cause.
2160 INT WINAPI LCMapStringA(LCID lcid, DWORD flags, LPCSTR src, INT srclen,
2161 LPSTR dst, INT dstlen)
2163 WCHAR *bufW = NtCurrentTeb()->StaticUnicodeBuffer;
2165 INT ret = 0, srclenW, dstlenW;
2166 UINT locale_cp = CP_ACP;
2168 if (!src || !srclen || dstlen < 0)
2170 SetLastError(ERROR_INVALID_PARAMETER);
2174 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
2176 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, bufW, 260);
2181 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, NULL, 0);
2182 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
2185 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2188 MultiByteToWideChar(locale_cp, 0, src, srclen, srcW, srclenW);
2191 if (flags & LCMAP_SORTKEY)
2195 SetLastError(ERROR_INVALID_FLAGS);
2196 goto map_string_exit;
2198 ret = wine_get_sortkey(flags, srcW, srclenW, dst, dstlen);
2199 goto map_string_exit;
2202 if (flags & SORT_STRINGSORT)
2204 SetLastError(ERROR_INVALID_FLAGS);
2205 goto map_string_exit;
2208 dstlenW = LCMapStringW(lcid, flags, srcW, srclenW, NULL, 0);
2210 goto map_string_exit;
2212 dstW = HeapAlloc(GetProcessHeap(), 0, dstlenW * sizeof(WCHAR));
2215 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2216 goto map_string_exit;
2219 LCMapStringW(lcid, flags, srcW, srclenW, dstW, dstlenW);
2220 ret = WideCharToMultiByte(locale_cp, 0, dstW, dstlenW, dst, dstlen, NULL, NULL);
2221 HeapFree(GetProcessHeap(), 0, dstW);
2224 if (srcW != bufW) HeapFree(GetProcessHeap(), 0, srcW);
2228 /*************************************************************************
2229 * FoldStringA (KERNEL32.@)
2231 * Map characters in a string.
2234 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
2235 * src [I] String to map
2236 * srclen [I] Length of src, or -1 if src is NUL terminated
2237 * dst [O] Destination for mapped string
2238 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
2241 * Success: The length of the string written to dst, including the terminating NUL. If
2242 * dstlen is 0, the value returned is the same, but nothing is written to dst,
2243 * and dst may be NULL.
2244 * Failure: 0. Use GetLastError() to determine the cause.
2246 INT WINAPI FoldStringA(DWORD dwFlags, LPCSTR src, INT srclen,
2247 LPSTR dst, INT dstlen)
2249 INT ret = 0, srclenW = 0;
2250 WCHAR *srcW = NULL, *dstW = NULL;
2252 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
2254 SetLastError(ERROR_INVALID_PARAMETER);
2258 srclenW = MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
2259 src, srclen, NULL, 0);
2260 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
2264 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2265 goto FoldStringA_exit;
2268 MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
2269 src, srclen, srcW, srclenW);
2271 dwFlags = (dwFlags & ~MAP_PRECOMPOSED) | MAP_FOLDCZONE;
2273 ret = FoldStringW(dwFlags, srcW, srclenW, NULL, 0);
2276 dstW = HeapAlloc(GetProcessHeap(), 0, ret * sizeof(WCHAR));
2280 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2281 goto FoldStringA_exit;
2284 ret = FoldStringW(dwFlags, srcW, srclenW, dstW, ret);
2285 if (!WideCharToMultiByte(CP_ACP, 0, dstW, ret, dst, dstlen, NULL, NULL))
2288 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2292 HeapFree(GetProcessHeap(), 0, dstW);
2295 HeapFree(GetProcessHeap(), 0, srcW);
2299 /*************************************************************************
2300 * FoldStringW (KERNEL32.@)
2304 INT WINAPI FoldStringW(DWORD dwFlags, LPCWSTR src, INT srclen,
2305 LPWSTR dst, INT dstlen)
2309 switch (dwFlags & (MAP_COMPOSITE|MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES))
2314 /* Fall through for dwFlags == 0 */
2315 case MAP_PRECOMPOSED|MAP_COMPOSITE:
2316 case MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES:
2317 case MAP_COMPOSITE|MAP_EXPAND_LIGATURES:
2318 SetLastError(ERROR_INVALID_FLAGS);
2322 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
2324 SetLastError(ERROR_INVALID_PARAMETER);
2328 ret = wine_fold_string(dwFlags, src, srclen, dst, dstlen);
2330 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2334 /******************************************************************************
2335 * CompareStringW (KERNEL32.@)
2337 * See CompareStringA.
2339 INT WINAPI CompareStringW(LCID lcid, DWORD style,
2340 LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
2346 SetLastError(ERROR_INVALID_PARAMETER);
2350 if( style & ~(NORM_IGNORECASE|NORM_IGNORENONSPACE|NORM_IGNORESYMBOLS|
2351 SORT_STRINGSORT|NORM_IGNOREKANATYPE|NORM_IGNOREWIDTH|LOCALE_USE_CP_ACP|0x10000000) )
2353 SetLastError(ERROR_INVALID_FLAGS);
2357 if (style & 0x10000000)
2358 FIXME("Ignoring unknown style 0x10000000\n");
2360 if (len1 < 0) len1 = strlenW(str1);
2361 if (len2 < 0) len2 = strlenW(str2);
2363 ret = wine_compare_string(style, str1, len1, str2, len2);
2365 if (ret) /* need to translate result */
2366 return (ret < 0) ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
2370 /******************************************************************************
2371 * CompareStringA (KERNEL32.@)
2373 * Compare two locale sensitive strings.
2376 * lcid [I] LCID for the comparison
2377 * style [I] Flags for the comparison (NORM_ constants from "winnls.h").
2378 * str1 [I] First string to compare
2379 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
2380 * str2 [I] Second string to compare
2381 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
2384 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
2385 * str2 is less than, equal to or greater than str1 respectively.
2386 * Failure: FALSE. Use GetLastError() to determine the cause.
2388 INT WINAPI CompareStringA(LCID lcid, DWORD style,
2389 LPCSTR str1, INT len1, LPCSTR str2, INT len2)
2391 WCHAR *buf1W = NtCurrentTeb()->StaticUnicodeBuffer;
2392 WCHAR *buf2W = buf1W + 130;
2393 LPWSTR str1W, str2W;
2394 INT len1W, len2W, ret;
2395 UINT locale_cp = CP_ACP;
2399 SetLastError(ERROR_INVALID_PARAMETER);
2402 if (len1 < 0) len1 = strlen(str1);
2403 if (len2 < 0) len2 = strlen(str2);
2405 if (!(style & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
2407 len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
2412 len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, NULL, 0);
2413 str1W = HeapAlloc(GetProcessHeap(), 0, len1W * sizeof(WCHAR));
2416 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2419 MultiByteToWideChar(locale_cp, 0, str1, len1, str1W, len1W);
2421 len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
2426 len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, NULL, 0);
2427 str2W = HeapAlloc(GetProcessHeap(), 0, len2W * sizeof(WCHAR));
2430 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
2431 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2434 MultiByteToWideChar(locale_cp, 0, str2, len2, str2W, len2W);
2437 ret = CompareStringW(lcid, style, str1W, len1W, str2W, len2W);
2439 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
2440 if (str2W != buf2W) HeapFree(GetProcessHeap(), 0, str2W);
2444 /*************************************************************************
2445 * lstrcmp (KERNEL32.@)
2446 * lstrcmpA (KERNEL32.@)
2448 * Compare two strings using the current thread locale.
2451 * str1 [I] First string to compare
2452 * str2 [I] Second string to compare
2455 * Success: A number less than, equal to or greater than 0 depending on whether
2456 * str2 is less than, equal to or greater than str1 respectively.
2457 * Failure: FALSE. Use GetLastError() to determine the cause.
2459 int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
2463 if ((str1 == NULL) && (str2 == NULL)) return 0;
2464 if (str1 == NULL) return -1;
2465 if (str2 == NULL) return 1;
2467 ret = CompareStringA(GetThreadLocale(), LOCALE_USE_CP_ACP, str1, -1, str2, -1);
2473 /*************************************************************************
2474 * lstrcmpi (KERNEL32.@)
2475 * lstrcmpiA (KERNEL32.@)
2477 * Compare two strings using the current thread locale, ignoring case.
2480 * str1 [I] First string to compare
2481 * str2 [I] Second string to compare
2484 * Success: A number less than, equal to or greater than 0 depending on whether
2485 * str2 is less than, equal to or greater than str1 respectively.
2486 * Failure: FALSE. Use GetLastError() to determine the cause.
2488 int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
2492 if ((str1 == NULL) && (str2 == NULL)) return 0;
2493 if (str1 == NULL) return -1;
2494 if (str2 == NULL) return 1;
2496 ret = CompareStringA(GetThreadLocale(), NORM_IGNORECASE|LOCALE_USE_CP_ACP, str1, -1, str2, -1);
2502 /*************************************************************************
2503 * lstrcmpW (KERNEL32.@)
2507 int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
2511 if ((str1 == NULL) && (str2 == NULL)) return 0;
2512 if (str1 == NULL) return -1;
2513 if (str2 == NULL) return 1;
2515 ret = CompareStringW(GetThreadLocale(), 0, str1, -1, str2, -1);
2521 /*************************************************************************
2522 * lstrcmpiW (KERNEL32.@)
2526 int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
2530 if ((str1 == NULL) && (str2 == NULL)) return 0;
2531 if (str1 == NULL) return -1;
2532 if (str2 == NULL) return 1;
2534 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, -1, str2, -1);
2540 /******************************************************************************
2543 void LOCALE_Init(void)
2545 extern void __wine_init_codepages( const union cptable *ansi_cp, const union cptable *oem_cp,
2546 const union cptable *unix_cp );
2548 UINT ansi_cp = 1252, oem_cp = 437, mac_cp = 10000, unix_cp = ~0U;
2551 lcid = get_env_lcid( NULL, NULL );
2552 NtSetDefaultLocale( TRUE, lcid );
2554 lcid = get_env_lcid( NULL, "LC_MESSAGES" );
2555 NtSetDefaultUILanguage( LANGIDFROMLCID(lcid) );
2557 lcid = get_env_lcid( &unix_cp, "LC_CTYPE" );
2558 NtSetDefaultLocale( FALSE, lcid );
2560 ansi_cp = get_lcid_codepage(lcid);
2561 GetLocaleInfoW( lcid, LOCALE_IDEFAULTMACCODEPAGE | LOCALE_RETURN_NUMBER,
2562 (LPWSTR)&mac_cp, sizeof(mac_cp)/sizeof(WCHAR) );
2563 GetLocaleInfoW( lcid, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
2564 (LPWSTR)&oem_cp, sizeof(oem_cp)/sizeof(WCHAR) );
2566 GetLocaleInfoW( lcid, LOCALE_IDEFAULTUNIXCODEPAGE | LOCALE_RETURN_NUMBER,
2567 (LPWSTR)&unix_cp, sizeof(unix_cp)/sizeof(WCHAR) );
2569 if (!(ansi_cptable = wine_cp_get_table( ansi_cp )))
2570 ansi_cptable = wine_cp_get_table( 1252 );
2571 if (!(oem_cptable = wine_cp_get_table( oem_cp )))
2572 oem_cptable = wine_cp_get_table( 437 );
2573 if (!(mac_cptable = wine_cp_get_table( mac_cp )))
2574 mac_cptable = wine_cp_get_table( 10000 );
2575 if (unix_cp != CP_UTF8)
2577 if (!(unix_cptable = wine_cp_get_table( unix_cp )))
2578 unix_cptable = wine_cp_get_table( 28591 );
2581 __wine_init_codepages( ansi_cptable, oem_cptable, unix_cptable );
2583 TRACE( "ansi=%03d oem=%03d mac=%03d unix=%03d\n",
2584 ansi_cptable->info.codepage, oem_cptable->info.codepage,
2585 mac_cptable->info.codepage, unix_cp );
2588 static HANDLE NLS_RegOpenKey(HANDLE hRootKey, LPCWSTR szKeyName)
2590 UNICODE_STRING keyName;
2591 OBJECT_ATTRIBUTES attr;
2594 RtlInitUnicodeString( &keyName, szKeyName );
2595 InitializeObjectAttributes(&attr, &keyName, 0, hRootKey, NULL);
2597 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS)
2603 static HANDLE NLS_RegOpenSubKey(HANDLE hRootKey, LPCWSTR szKeyName)
2605 HANDLE hKey = NLS_RegOpenKey(hRootKey, szKeyName);
2608 NtClose( hRootKey );
2613 static BOOL NLS_RegEnumSubKey(HANDLE hKey, UINT ulIndex, LPWSTR szKeyName,
2617 KEY_BASIC_INFORMATION *info = (KEY_BASIC_INFORMATION *)buffer;
2620 if (NtEnumerateKey( hKey, ulIndex, KeyBasicInformation, buffer,
2621 sizeof(buffer), &dwLen) != STATUS_SUCCESS ||
2622 info->NameLength > keyNameSize)
2627 TRACE("info->Name %s info->NameLength %ld\n", debugstr_w(info->Name), info->NameLength);
2629 memcpy( szKeyName, info->Name, info->NameLength);
2630 szKeyName[info->NameLength / sizeof(WCHAR)] = '\0';
2632 TRACE("returning %s\n", debugstr_w(szKeyName));
2636 static BOOL NLS_RegEnumValue(HANDLE hKey, UINT ulIndex,
2637 LPWSTR szValueName, ULONG valueNameSize,
2638 LPWSTR szValueData, ULONG valueDataSize)
2641 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
2644 if (NtEnumerateValueKey( hKey, ulIndex, KeyValueFullInformation,
2645 buffer, sizeof(buffer), &dwLen ) != STATUS_SUCCESS ||
2646 info->NameLength > valueNameSize ||
2647 info->DataLength > valueDataSize)
2652 TRACE("info->Name %s info->DataLength %ld\n", debugstr_w(info->Name), info->DataLength);
2654 memcpy( szValueName, info->Name, info->NameLength);
2655 szValueName[info->NameLength / sizeof(WCHAR)] = '\0';
2656 memcpy( szValueData, buffer + info->DataOffset, info->DataLength );
2657 szValueData[info->DataLength / sizeof(WCHAR)] = '\0';
2659 TRACE("returning %s %s\n", debugstr_w(szValueName), debugstr_w(szValueData));
2663 static BOOL NLS_RegGetDword(HANDLE hKey, LPCWSTR szValueName, DWORD *lpVal)
2666 const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
2667 DWORD dwSize = sizeof(buffer);
2668 UNICODE_STRING valueName;
2670 RtlInitUnicodeString( &valueName, szValueName );
2672 TRACE("%p, %s\n", hKey, debugstr_w(szValueName));
2673 if (NtQueryValueKey( hKey, &valueName, KeyValuePartialInformation,
2674 buffer, dwSize, &dwSize ) == STATUS_SUCCESS &&
2675 info->DataLength == sizeof(DWORD))
2677 memcpy(lpVal, info->Data, sizeof(DWORD));
2684 static BOOL NLS_GetLanguageGroupName(LGRPID lgrpid, LPWSTR szName, ULONG nameSize)
2687 LPCWSTR szResourceName = MAKEINTRESOURCEW(((lgrpid + 0x2000) >> 4) + 1);
2691 /* FIXME: Is it correct to use the system default langid? */
2692 langId = GetSystemDefaultLangID();
2694 if (SUBLANGID(langId) == SUBLANG_NEUTRAL)
2695 langId = MAKELANGID( PRIMARYLANGID(langId), SUBLANG_DEFAULT );
2697 hResource = FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING, szResourceName, langId );
2701 HGLOBAL hResDir = LoadResource( kernel32_handle, hResource );
2705 ULONG iResourceIndex = lgrpid & 0xf;
2706 LPCWSTR lpResEntry = LockResource( hResDir );
2709 for (i = 0; i < iResourceIndex; i++)
2710 lpResEntry += *lpResEntry + 1;
2712 if (*lpResEntry < nameSize)
2714 memcpy( szName, lpResEntry + 1, *lpResEntry * sizeof(WCHAR) );
2715 szName[*lpResEntry] = '\0';
2720 FreeResource( hResource );
2725 /* Registry keys for NLS related information */
2726 static const WCHAR szLangGroupsKeyName[] = {
2727 'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s','\0'
2730 static const WCHAR szCountryListName[] = {
2731 'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
2732 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
2733 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2734 'T','e','l','e','p','h','o','n','y','\\',
2735 'C','o','u','n','t','r','y',' ','L','i','s','t','\0'
2739 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
2742 LANGUAGEGROUP_ENUMPROCA procA;
2743 LANGUAGEGROUP_ENUMPROCW procW;
2746 } ENUMLANGUAGEGROUP_CALLBACKS;
2748 /* Internal implementation of EnumSystemLanguageGroupsA/W */
2749 static BOOL NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS *lpProcs)
2751 WCHAR szNumber[10], szValue[4];
2753 BOOL bContinue = TRUE;
2758 SetLastError(ERROR_INVALID_PARAMETER);
2762 switch (lpProcs->dwFlags)
2765 /* Default to LGRPID_INSTALLED */
2766 lpProcs->dwFlags = LGRPID_INSTALLED;
2767 /* Fall through... */
2768 case LGRPID_INSTALLED:
2769 case LGRPID_SUPPORTED:
2772 SetLastError(ERROR_INVALID_FLAGS);
2776 hKey = NLS_RegOpenSubKey( NLS_RegOpenKey( 0, szNlsKeyName ), szLangGroupsKeyName );
2779 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2783 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
2784 szValue, sizeof(szValue) ))
2786 BOOL bInstalled = szValue[0] == '1' ? TRUE : FALSE;
2787 LGRPID lgrpid = strtoulW( szNumber, NULL, 16 );
2789 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber),
2790 bInstalled ? "" : "not ");
2792 if (lpProcs->dwFlags == LGRPID_SUPPORTED || bInstalled)
2794 WCHAR szGrpName[48];
2796 if (!NLS_GetLanguageGroupName( lgrpid, szGrpName, sizeof(szGrpName) / sizeof(WCHAR) ))
2797 szGrpName[0] = '\0';
2800 bContinue = lpProcs->procW( lgrpid, szNumber, szGrpName, lpProcs->dwFlags,
2804 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
2805 char szGrpNameA[48];
2807 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
2808 * or whether the language names are ever localised. Assume CP_ACP.
2811 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
2812 WideCharToMultiByte(CP_ACP, 0, szGrpName, -1, szGrpNameA, sizeof(szGrpNameA), 0, 0);
2814 bContinue = lpProcs->procA( lgrpid, szNumberA, szGrpNameA, lpProcs->dwFlags,
2834 /******************************************************************************
2835 * EnumSystemLanguageGroupsA (KERNEL32.@)
2837 * Call a users function for each language group available on the system.
2840 * pLangGrpEnumProc [I] Callback function to call for each language group
2841 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
2842 * lParam [I] User parameter to pass to pLangGrpEnumProc
2846 * Failure: FALSE. Use GetLastError() to determine the cause.
2848 BOOL WINAPI EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc,
2849 DWORD dwFlags, LONG_PTR lParam)
2851 ENUMLANGUAGEGROUP_CALLBACKS procs;
2853 TRACE("(%p,0x%08lX,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
2855 procs.procA = pLangGrpEnumProc;
2857 procs.dwFlags = dwFlags;
2858 procs.lParam = lParam;
2860 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
2863 /******************************************************************************
2864 * EnumSystemLanguageGroupsW (KERNEL32.@)
2866 * See EnumSystemLanguageGroupsA.
2868 BOOL WINAPI EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc,
2869 DWORD dwFlags, LONG_PTR lParam)
2871 ENUMLANGUAGEGROUP_CALLBACKS procs;
2873 TRACE("(%p,0x%08lX,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
2876 procs.procW = pLangGrpEnumProc;
2877 procs.dwFlags = dwFlags;
2878 procs.lParam = lParam;
2880 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
2883 /******************************************************************************
2884 * IsValidLanguageGroup (KERNEL32.@)
2886 * Determine if a language group is supported and/or installed.
2889 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
2890 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
2893 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
2896 BOOL WINAPI IsValidLanguageGroup(LGRPID lgrpid, DWORD dwFlags)
2898 static const WCHAR szFormat[] = { '%','x','\0' };
2899 WCHAR szValueName[16], szValue[2];
2900 BOOL bSupported = FALSE, bInstalled = FALSE;
2906 case LGRPID_INSTALLED:
2907 case LGRPID_SUPPORTED:
2909 hKey = NLS_RegOpenSubKey( NLS_RegOpenKey( 0, szNlsKeyName ), szLangGroupsKeyName );
2911 sprintfW( szValueName, szFormat, lgrpid );
2913 if (NLS_RegGetDword( hKey, szValueName, (LPDWORD)&szValue ))
2917 if (szValue[0] == '1')
2927 if ((dwFlags == LGRPID_SUPPORTED && bSupported) ||
2928 (dwFlags == LGRPID_INSTALLED && bInstalled))
2934 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
2937 LANGGROUPLOCALE_ENUMPROCA procA;
2938 LANGGROUPLOCALE_ENUMPROCW procW;
2942 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS;
2944 /* Internal implementation of EnumLanguageGrouplocalesA/W */
2945 static BOOL NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS *lpProcs)
2947 static const WCHAR szLocaleKeyName[] = {
2948 'L','o','c','a','l','e','\0'
2950 static const WCHAR szAlternateSortsKeyName[] = {
2951 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
2953 WCHAR szNumber[10], szValue[4];
2955 BOOL bContinue = TRUE, bAlternate = FALSE;
2957 ULONG ulIndex = 1; /* Ignore default entry of 1st key */
2959 if (!lpProcs || !lpProcs->lgrpid || lpProcs->lgrpid > LGRPID_ARMENIAN)
2961 SetLastError(ERROR_INVALID_PARAMETER);
2965 if (lpProcs->dwFlags)
2967 SetLastError(ERROR_INVALID_FLAGS);
2971 hKey = NLS_RegOpenSubKey( NLS_RegOpenKey( 0, szNlsKeyName ), szLocaleKeyName );
2974 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
2978 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
2979 szValue, sizeof(szValue) ))
2981 lgrpid = strtoulW( szValue, NULL, 16 );
2983 TRACE("lcid %s, grpid %ld (%smatched)\n", debugstr_w(szNumber),
2984 lgrpid, lgrpid == lpProcs->lgrpid ? "" : "not ");
2986 if (lgrpid == lpProcs->lgrpid)
2990 lcid = strtoulW( szNumber, NULL, 16 );
2992 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
2993 * '00000437 ;Georgian'
2994 * At present we only pass the LCID string.
2998 bContinue = lpProcs->procW( lgrpid, lcid, szNumber, lpProcs->lParam );
3001 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
3003 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
3005 bContinue = lpProcs->procA( lgrpid, lcid, szNumberA, lpProcs->lParam );
3013 /* Finished enumerating this key */
3016 /* Enumerate alternate sorts also */
3017 hKey = NLS_RegOpenKey( hKey, szAlternateSortsKeyName );
3022 bContinue = FALSE; /* Finished both keys */
3035 /******************************************************************************
3036 * EnumLanguageGroupLocalesA (KERNEL32.@)
3038 * Call a users function for every locale in a language group available on the system.
3041 * pLangGrpLcEnumProc [I] Callback function to call for each locale
3042 * lgrpid [I] Language group (LGRPID_ values from "winnls.h")
3043 * dwFlags [I] Reserved, set to 0
3044 * lParam [I] User parameter to pass to pLangGrpLcEnumProc
3048 * Failure: FALSE. Use GetLastError() to determine the cause.
3050 BOOL WINAPI EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc,
3051 LGRPID lgrpid, DWORD dwFlags, LONG_PTR lParam)
3053 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks;
3055 TRACE("(%p,0x%08lX,0x%08lX,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
3057 callbacks.procA = pLangGrpLcEnumProc;
3058 callbacks.procW = NULL;
3059 callbacks.dwFlags = dwFlags;
3060 callbacks.lgrpid = lgrpid;
3061 callbacks.lParam = lParam;
3063 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
3066 /******************************************************************************
3067 * EnumLanguageGroupLocalesW (KERNEL32.@)
3069 * See EnumLanguageGroupLocalesA.
3071 BOOL WINAPI EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc,
3072 LGRPID lgrpid, DWORD dwFlags, LONG_PTR lParam)
3074 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks;
3076 TRACE("(%p,0x%08lX,0x%08lX,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
3078 callbacks.procA = NULL;
3079 callbacks.procW = pLangGrpLcEnumProc;
3080 callbacks.dwFlags = dwFlags;
3081 callbacks.lgrpid = lgrpid;
3082 callbacks.lParam = lParam;
3084 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
3087 /******************************************************************************
3088 * EnumSystemGeoID (KERNEL32.@)
3090 * Call a users function for every location available on the system.
3093 * geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
3094 * reserved [I] Reserved, set to 0
3095 * pGeoEnumProc [I] Callback function to call for each location
3099 * Failure: FALSE. Use GetLastError() to determine the cause.
3101 BOOL WINAPI EnumSystemGeoID(GEOCLASS geoclass, GEOID reserved, GEO_ENUMPROC pGeoEnumProc)
3103 static const WCHAR szCountryCodeValueName[] = {
3104 'C','o','u','n','t','r','y','C','o','d','e','\0'
3110 TRACE("(0x%08lX,0x%08lX,%p)\n", geoclass, reserved, pGeoEnumProc);
3112 if (geoclass != GEOCLASS_NATION || reserved || !pGeoEnumProc)
3114 SetLastError(ERROR_INVALID_PARAMETER);
3118 hKey = NLS_RegOpenKey( 0, szCountryListName );
3120 while (NLS_RegEnumSubKey( hKey, ulIndex, szNumber, sizeof(szNumber) ))
3122 BOOL bContinue = TRUE;
3124 HANDLE hSubKey = NLS_RegOpenKey( hKey, szNumber );
3128 if (NLS_RegGetDword( hSubKey, szCountryCodeValueName, &dwGeoId ))
3130 TRACE("Got geoid %ld\n", dwGeoId);
3132 if (!pGeoEnumProc( dwGeoId ))
3151 /******************************************************************************
3152 * InvalidateNLSCache (KERNEL32.@)
3154 * Invalidate the cache of NLS values.
3163 BOOL WINAPI InvalidateNLSCache(void)
3169 /******************************************************************************
3170 * GetUserGeoID (KERNEL32.@)
3172 GEOID WINAPI GetUserGeoID( GEOCLASS GeoClass )
3174 FIXME("%ld\n",GeoClass);
3175 return GEOID_NOT_AVAILABLE;
3178 /******************************************************************************
3179 * SetUserGeoID (KERNEL32.@)
3181 BOOL WINAPI SetUserGeoID( GEOID GeoID )
3183 FIXME("%ld\n",GeoID);
3191 UILANGUAGE_ENUMPROCA procA;
3192 UILANGUAGE_ENUMPROCW procW;
3196 } ENUM_UILANG_CALLBACK;
3198 static BOOL CALLBACK enum_uilang_proc_a( HMODULE hModule, LPCSTR type,
3199 LPCSTR name, WORD LangID, LONG_PTR lParam )
3201 ENUM_UILANG_CALLBACK *enum_uilang = (ENUM_UILANG_CALLBACK *)lParam;
3204 sprintf(buf, "%08x", (UINT)LangID);
3205 return enum_uilang->u.procA( buf, enum_uilang->param );
3208 static BOOL CALLBACK enum_uilang_proc_w( HMODULE hModule, LPCWSTR type,
3209 LPCWSTR name, WORD LangID, LONG_PTR lParam )
3211 static const WCHAR formatW[] = {'%','0','8','x',0};
3212 ENUM_UILANG_CALLBACK *enum_uilang = (ENUM_UILANG_CALLBACK *)lParam;
3215 sprintfW( buf, formatW, (UINT)LangID );
3216 return enum_uilang->u.procW( buf, enum_uilang->param );
3219 /******************************************************************************
3220 * EnumUILanguagesA (KERNEL32.@)
3222 BOOL WINAPI EnumUILanguagesA(UILANGUAGE_ENUMPROCA pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam)
3224 ENUM_UILANG_CALLBACK enum_uilang;
3226 TRACE("%p, %lx, %lx\n", pUILangEnumProc, dwFlags, lParam);
3228 if(!pUILangEnumProc) {
3229 SetLastError(ERROR_INVALID_PARAMETER);
3233 SetLastError(ERROR_INVALID_FLAGS);
3237 enum_uilang.u.procA = pUILangEnumProc;
3238 enum_uilang.flags = dwFlags;
3239 enum_uilang.param = lParam;
3241 EnumResourceLanguagesA( kernel32_handle, (LPCSTR)RT_STRING,
3242 (LPCSTR)LOCALE_ILANGUAGE, enum_uilang_proc_a,
3243 (LONG_PTR)&enum_uilang);
3247 /******************************************************************************
3248 * EnumUILanguagesW (KERNEL32.@)
3250 BOOL WINAPI EnumUILanguagesW(UILANGUAGE_ENUMPROCW pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam)
3252 ENUM_UILANG_CALLBACK enum_uilang;
3254 TRACE("%p, %lx, %lx\n", pUILangEnumProc, dwFlags, lParam);
3257 if(!pUILangEnumProc) {
3258 SetLastError(ERROR_INVALID_PARAMETER);
3262 SetLastError(ERROR_INVALID_FLAGS);
3266 enum_uilang.u.procW = pUILangEnumProc;
3267 enum_uilang.flags = dwFlags;
3268 enum_uilang.param = lParam;
3270 EnumResourceLanguagesW( kernel32_handle, (LPCWSTR)RT_STRING,
3271 (LPCWSTR)LOCALE_ILANGUAGE, enum_uilang_proc_w,
3272 (LONG_PTR)&enum_uilang);
3276 INT WINAPI GetGeoInfoW(GEOID GeoId, GEOTYPE GeoType, LPWSTR lpGeoData,
3277 int cchData, LANGID language)
3279 FIXME("%ld %ld %p %d %d\n", GeoId, GeoType, lpGeoData, cchData, language);
3283 INT WINAPI GetGeoInfoA(GEOID GeoId, GEOTYPE GeoType, LPSTR lpGeoData,
3284 int cchData, LANGID language)
3286 FIXME("%ld %ld %p %d %d\n", GeoId, GeoType, lpGeoData, cchData, language);