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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
36 # include <CoreFoundation/CFBundle.h>
37 # include <CoreFoundation/CFLocale.h>
38 # include <CoreFoundation/CFString.h>
42 #define WIN32_NO_STATUS
45 #include "winuser.h" /* for RT_STRINGW */
47 #include "wine/unicode.h"
51 #include "kernel_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(nls);
56 #define LOCALE_LOCALEINFOFLAGSMASK (LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP|\
57 LOCALE_RETURN_NUMBER|LOCALE_RETURN_GENITIVE_NAMES)
59 /* current code pages */
60 static const union cptable *ansi_cptable;
61 static const union cptable *oem_cptable;
62 static const union cptable *mac_cptable;
63 static const union cptable *unix_cptable; /* NULL if UTF8 */
65 static const WCHAR szLocaleKeyName[] = {
66 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
67 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
68 'C','o','n','t','r','o','l','\\','N','l','s','\\','L','o','c','a','l','e',0
71 static const WCHAR szLangGroupsKeyName[] = {
72 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
73 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
74 'C','o','n','t','r','o','l','\\','N','l','s','\\',
75 'L','a','n','g','u','a','g','e',' ','G','r','o','u','p','s',0
78 /* Charset to codepage map, sorted by name. */
79 static const struct charset_entry
81 const char *charset_name;
120 { "ISO88591", 28591 },
121 { "ISO885910", 28600 },
122 { "ISO885913", 28603 },
123 { "ISO885914", 28604 },
124 { "ISO885915", 28605 },
125 { "ISO885916", 28606 },
126 { "ISO88592", 28592 },
127 { "ISO88593", 28593 },
128 { "ISO88594", 28594 },
129 { "ISO88595", 28595 },
130 { "ISO88596", 28596 },
131 { "ISO88597", 28597 },
132 { "ISO88598", 28598 },
133 { "ISO88599", 28599 },
142 WCHAR win_name[128]; /* Windows name ("en-US") */
143 WCHAR lang[128]; /* language ("en") (note: buffer contains the other strings too) */
144 WCHAR *country; /* country ("US") */
145 WCHAR *charset; /* charset ("UTF-8") for Unix format only */
146 WCHAR *script; /* script ("Latn") for Windows format only */
147 WCHAR *modifier; /* modifier or sort order */
148 LCID lcid; /* corresponding LCID */
149 int matches; /* number of elements matching LCID (0..4) */
150 UINT codepage; /* codepage corresponding to charset */
153 /* locale ids corresponding to the various Unix locale parameters */
154 static LCID lcid_LC_COLLATE;
155 static LCID lcid_LC_CTYPE;
156 static LCID lcid_LC_MESSAGES;
157 static LCID lcid_LC_MONETARY;
158 static LCID lcid_LC_NUMERIC;
159 static LCID lcid_LC_TIME;
160 static LCID lcid_LC_PAPER;
161 static LCID lcid_LC_MEASUREMENT;
162 static LCID lcid_LC_TELEPHONE;
164 /* Copy Ascii string to Unicode without using codepages */
165 static inline void strcpynAtoW( WCHAR *dst, const char *src, size_t n )
167 while (n > 1 && *src)
169 *dst++ = (unsigned char)*src++;
176 /***********************************************************************
179 * Retrieve the ANSI codepage for a given locale.
181 static inline UINT get_lcid_codepage( LCID lcid )
184 if (!GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE|LOCALE_RETURN_NUMBER, (WCHAR *)&ret,
185 sizeof(ret)/sizeof(WCHAR) )) ret = 0;
190 /***********************************************************************
193 * Find the table for a given codepage, handling CP_ACP etc. pseudo-codepages
195 static const union cptable *get_codepage_table( unsigned int codepage )
197 const union cptable *ret = NULL;
199 assert( ansi_cptable ); /* init must have been done already */
213 if (NtCurrentTeb()->CurrentLocale == GetUserDefaultLCID()) return ansi_cptable;
214 codepage = get_lcid_codepage( NtCurrentTeb()->CurrentLocale );
217 if (codepage == ansi_cptable->info.codepage) return ansi_cptable;
218 if (codepage == oem_cptable->info.codepage) return oem_cptable;
219 if (codepage == mac_cptable->info.codepage) return mac_cptable;
220 ret = wine_cp_get_table( codepage );
227 /***********************************************************************
228 * charset_cmp (internal)
230 static int charset_cmp( const void *name, const void *entry )
232 const struct charset_entry *charset = entry;
233 return strcasecmp( name, charset->charset_name );
236 /***********************************************************************
239 static UINT find_charset( const WCHAR *name )
241 const struct charset_entry *entry;
242 char charset_name[16];
245 /* remove punctuation characters from charset name */
246 for (i = j = 0; name[i] && j < sizeof(charset_name)-1; i++)
247 if (isalnum((unsigned char)name[i])) charset_name[j++] = name[i];
250 entry = bsearch( charset_name, charset_names,
251 sizeof(charset_names)/sizeof(charset_names[0]),
252 sizeof(charset_names[0]), charset_cmp );
253 if (entry) return entry->codepage;
258 /***********************************************************************
259 * find_locale_id_callback
261 static BOOL CALLBACK find_locale_id_callback( HMODULE hModule, LPCWSTR type,
262 LPCWSTR name, WORD LangID, LPARAM lParam )
264 struct locale_name *data = (struct locale_name *)lParam;
267 LCID lcid = MAKELCID( LangID, SORT_DEFAULT ); /* FIXME: handle sort order */
269 if (PRIMARYLANGID(LangID) == LANG_NEUTRAL) return TRUE; /* continue search */
271 /* first check exact name */
272 if (data->win_name[0] &&
273 GetLocaleInfoW( lcid, LOCALE_SNAME | LOCALE_NOUSEROVERRIDE,
274 buffer, sizeof(buffer)/sizeof(WCHAR) ))
276 if (!strcmpW( data->win_name, buffer ))
278 matches = 4; /* everything matches */
283 if (!GetLocaleInfoW( lcid, LOCALE_SISO639LANGNAME | LOCALE_NOUSEROVERRIDE,
284 buffer, sizeof(buffer)/sizeof(WCHAR) ))
286 if (strcmpW( buffer, data->lang )) return TRUE;
287 matches++; /* language name matched */
291 if (GetLocaleInfoW( lcid, LOCALE_SISO3166CTRYNAME|LOCALE_NOUSEROVERRIDE,
292 buffer, sizeof(buffer)/sizeof(WCHAR) ))
294 if (strcmpW( buffer, data->country )) goto done;
295 matches++; /* country name matched */
298 else /* match default language */
300 if (SUBLANGID(LangID) == SUBLANG_DEFAULT) matches++;
306 if (GetLocaleInfoW( lcid, LOCALE_IDEFAULTUNIXCODEPAGE | LOCALE_RETURN_NUMBER,
307 (LPWSTR)&unix_cp, sizeof(unix_cp)/sizeof(WCHAR) ))
309 if (unix_cp == data->codepage) matches++;
313 /* FIXME: check sort order */
316 if (matches > data->matches)
319 data->matches = matches;
321 return (data->matches < 4); /* no need to continue for perfect match */
325 /***********************************************************************
328 * Parse a locale name into a struct locale_name, handling both Windows and Unix formats.
329 * Unix format is: lang[_country][.charset][@modifier]
330 * Windows format is: lang[-script][-country][_modifier]
332 static void parse_locale_name( const WCHAR *str, struct locale_name *name )
334 static const WCHAR sepW[] = {'-','_','.','@',0};
335 static const WCHAR winsepW[] = {'-','_',0};
336 static const WCHAR posixW[] = {'P','O','S','I','X',0};
337 static const WCHAR cW[] = {'C',0};
338 static const WCHAR latinW[] = {'l','a','t','i','n',0};
339 static const WCHAR latnW[] = {'-','L','a','t','n',0};
342 TRACE("%s\n", debugstr_w(str));
344 name->country = name->charset = name->script = name->modifier = NULL;
345 name->lcid = MAKELCID( MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), SORT_DEFAULT );
348 name->win_name[0] = 0;
349 lstrcpynW( name->lang, str, sizeof(name->lang)/sizeof(WCHAR) );
351 if (!(p = strpbrkW( name->lang, sepW )))
353 if (!strcmpW( name->lang, posixW ) || !strcmpW( name->lang, cW ))
355 name->matches = 4; /* perfect match for default English lcid */
358 strcpyW( name->win_name, name->lang );
360 else if (*p == '-') /* Windows format */
362 strcpyW( name->win_name, name->lang );
365 if (!(p = strpbrkW( p, winsepW ))) goto done;
369 name->script = name->country;
371 if (!(p = strpbrkW( p, winsepW ))) goto done;
376 else /* Unix format */
382 p = strpbrkW( p, sepW + 2 );
388 p = strchrW( p, '@' );
397 name->codepage = find_charset( name->charset );
399 /* rebuild a Windows name if possible */
401 if (name->charset) goto done; /* can't specify charset in Windows format */
402 if (name->modifier && strcmpW( name->modifier, latinW ))
403 goto done; /* only Latn script supported for now */
404 strcpyW( name->win_name, name->lang );
405 if (name->modifier) strcatW( name->win_name, latnW );
408 p = name->win_name + strlenW(name->win_name);
410 strcpyW( p, name->country );
414 EnumResourceLanguagesW( kernel32_handle, (LPCWSTR)RT_STRING, (LPCWSTR)LOCALE_ILANGUAGE,
415 find_locale_id_callback, (LPARAM)name );
419 /***********************************************************************
420 * convert_default_lcid
422 * Get the default LCID to use for a given lctype in GetLocaleInfo.
424 static LCID convert_default_lcid( LCID lcid, LCTYPE lctype )
426 if (lcid == LOCALE_SYSTEM_DEFAULT ||
427 lcid == LOCALE_USER_DEFAULT ||
428 lcid == LOCALE_NEUTRAL)
432 switch(lctype & 0xffff)
434 case LOCALE_SSORTNAME:
435 default_id = lcid_LC_COLLATE;
438 case LOCALE_FONTSIGNATURE:
439 case LOCALE_IDEFAULTANSICODEPAGE:
440 case LOCALE_IDEFAULTCODEPAGE:
441 case LOCALE_IDEFAULTEBCDICCODEPAGE:
442 case LOCALE_IDEFAULTMACCODEPAGE:
443 case LOCALE_IDEFAULTUNIXCODEPAGE:
444 default_id = lcid_LC_CTYPE;
447 case LOCALE_ICURRDIGITS:
448 case LOCALE_ICURRENCY:
449 case LOCALE_IINTLCURRDIGITS:
450 case LOCALE_INEGCURR:
451 case LOCALE_INEGSEPBYSPACE:
452 case LOCALE_INEGSIGNPOSN:
453 case LOCALE_INEGSYMPRECEDES:
454 case LOCALE_IPOSSEPBYSPACE:
455 case LOCALE_IPOSSIGNPOSN:
456 case LOCALE_IPOSSYMPRECEDES:
457 case LOCALE_SCURRENCY:
458 case LOCALE_SINTLSYMBOL:
459 case LOCALE_SMONDECIMALSEP:
460 case LOCALE_SMONGROUPING:
461 case LOCALE_SMONTHOUSANDSEP:
462 case LOCALE_SNATIVECURRNAME:
463 default_id = lcid_LC_MONETARY;
467 case LOCALE_IDIGITSUBSTITUTION:
469 case LOCALE_INEGNUMBER:
470 case LOCALE_SDECIMAL:
471 case LOCALE_SGROUPING:
473 case LOCALE_SNATIVEDIGITS:
474 case LOCALE_SNEGATIVESIGN:
475 case LOCALE_SNEGINFINITY:
476 case LOCALE_SPOSINFINITY:
477 case LOCALE_SPOSITIVESIGN:
478 case LOCALE_STHOUSAND:
479 default_id = lcid_LC_NUMERIC;
482 case LOCALE_ICALENDARTYPE:
483 case LOCALE_ICENTURY:
485 case LOCALE_IDAYLZERO:
486 case LOCALE_IFIRSTDAYOFWEEK:
487 case LOCALE_IFIRSTWEEKOFYEAR:
489 case LOCALE_IMONLZERO:
490 case LOCALE_IOPTIONALCALENDAR:
492 case LOCALE_ITIMEMARKPOSN:
496 case LOCALE_SABBREVDAYNAME1:
497 case LOCALE_SABBREVDAYNAME2:
498 case LOCALE_SABBREVDAYNAME3:
499 case LOCALE_SABBREVDAYNAME4:
500 case LOCALE_SABBREVDAYNAME5:
501 case LOCALE_SABBREVDAYNAME6:
502 case LOCALE_SABBREVDAYNAME7:
503 case LOCALE_SABBREVMONTHNAME1:
504 case LOCALE_SABBREVMONTHNAME2:
505 case LOCALE_SABBREVMONTHNAME3:
506 case LOCALE_SABBREVMONTHNAME4:
507 case LOCALE_SABBREVMONTHNAME5:
508 case LOCALE_SABBREVMONTHNAME6:
509 case LOCALE_SABBREVMONTHNAME7:
510 case LOCALE_SABBREVMONTHNAME8:
511 case LOCALE_SABBREVMONTHNAME9:
512 case LOCALE_SABBREVMONTHNAME10:
513 case LOCALE_SABBREVMONTHNAME11:
514 case LOCALE_SABBREVMONTHNAME12:
515 case LOCALE_SABBREVMONTHNAME13:
517 case LOCALE_SDAYNAME1:
518 case LOCALE_SDAYNAME2:
519 case LOCALE_SDAYNAME3:
520 case LOCALE_SDAYNAME4:
521 case LOCALE_SDAYNAME5:
522 case LOCALE_SDAYNAME6:
523 case LOCALE_SDAYNAME7:
524 case LOCALE_SDURATION:
525 case LOCALE_SLONGDATE:
526 case LOCALE_SMONTHNAME1:
527 case LOCALE_SMONTHNAME2:
528 case LOCALE_SMONTHNAME3:
529 case LOCALE_SMONTHNAME4:
530 case LOCALE_SMONTHNAME5:
531 case LOCALE_SMONTHNAME6:
532 case LOCALE_SMONTHNAME7:
533 case LOCALE_SMONTHNAME8:
534 case LOCALE_SMONTHNAME9:
535 case LOCALE_SMONTHNAME10:
536 case LOCALE_SMONTHNAME11:
537 case LOCALE_SMONTHNAME12:
538 case LOCALE_SMONTHNAME13:
539 case LOCALE_SSHORTDATE:
540 case LOCALE_SSHORTESTDAYNAME1:
541 case LOCALE_SSHORTESTDAYNAME2:
542 case LOCALE_SSHORTESTDAYNAME3:
543 case LOCALE_SSHORTESTDAYNAME4:
544 case LOCALE_SSHORTESTDAYNAME5:
545 case LOCALE_SSHORTESTDAYNAME6:
546 case LOCALE_SSHORTESTDAYNAME7:
548 case LOCALE_STIMEFORMAT:
549 case LOCALE_SYEARMONTH:
550 default_id = lcid_LC_TIME;
553 case LOCALE_IPAPERSIZE:
554 default_id = lcid_LC_PAPER;
557 case LOCALE_IMEASURE:
558 default_id = lcid_LC_MEASUREMENT;
561 case LOCALE_ICOUNTRY:
562 default_id = lcid_LC_TELEPHONE;
565 if (default_id) lcid = default_id;
567 return ConvertDefaultLocale( lcid );
570 /***********************************************************************
571 * is_genitive_name_supported
573 * Determine could LCTYPE basically support genitive name form or not.
575 static BOOL is_genitive_name_supported( LCTYPE lctype )
577 switch(lctype & 0xffff)
579 case LOCALE_SMONTHNAME1:
580 case LOCALE_SMONTHNAME2:
581 case LOCALE_SMONTHNAME3:
582 case LOCALE_SMONTHNAME4:
583 case LOCALE_SMONTHNAME5:
584 case LOCALE_SMONTHNAME6:
585 case LOCALE_SMONTHNAME7:
586 case LOCALE_SMONTHNAME8:
587 case LOCALE_SMONTHNAME9:
588 case LOCALE_SMONTHNAME10:
589 case LOCALE_SMONTHNAME11:
590 case LOCALE_SMONTHNAME12:
591 case LOCALE_SMONTHNAME13:
598 /***********************************************************************
599 * create_registry_key
601 * Create the Control Panel\\International registry key.
603 static inline HANDLE create_registry_key(void)
605 static const WCHAR cplW[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l',0};
606 static const WCHAR intlW[] = {'I','n','t','e','r','n','a','t','i','o','n','a','l',0};
607 OBJECT_ATTRIBUTES attr;
608 UNICODE_STRING nameW;
609 HANDLE cpl_key, hkey = 0;
611 if (RtlOpenCurrentUser( KEY_ALL_ACCESS, &hkey ) != STATUS_SUCCESS) return 0;
613 attr.Length = sizeof(attr);
614 attr.RootDirectory = hkey;
615 attr.ObjectName = &nameW;
617 attr.SecurityDescriptor = NULL;
618 attr.SecurityQualityOfService = NULL;
619 RtlInitUnicodeString( &nameW, cplW );
621 if (!NtCreateKey( &cpl_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ))
623 NtClose( attr.RootDirectory );
624 attr.RootDirectory = cpl_key;
625 RtlInitUnicodeString( &nameW, intlW );
626 if (NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) hkey = 0;
628 NtClose( attr.RootDirectory );
633 /* update the registry settings for a given locale parameter */
634 /* return TRUE if an update was needed */
635 static BOOL locale_update_registry( HKEY hkey, const WCHAR *name, LCID lcid,
636 const LCTYPE *values, UINT nb_values )
638 static const WCHAR formatW[] = { '%','0','8','x',0 };
640 UNICODE_STRING nameW;
643 RtlInitUnicodeString( &nameW, name );
644 count = sizeof(bufferW);
645 if (!NtQueryValueKey(hkey, &nameW, KeyValuePartialInformation, bufferW, count, &count))
647 const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)bufferW;
648 LPCWSTR text = (LPCWSTR)info->Data;
650 if (strtoulW( text, NULL, 16 ) == lcid) return FALSE; /* already set correctly */
651 TRACE( "updating registry, locale %s changed %s -> %08x\n",
652 debugstr_w(name), debugstr_w(text), lcid );
654 else TRACE( "updating registry, locale %s changed none -> %08x\n", debugstr_w(name), lcid );
655 sprintfW( bufferW, formatW, lcid );
656 NtSetValueKey( hkey, &nameW, 0, REG_SZ, bufferW, (strlenW(bufferW) + 1) * sizeof(WCHAR) );
658 for (i = 0; i < nb_values; i++)
660 GetLocaleInfoW( lcid, values[i] | LOCALE_NOUSEROVERRIDE, bufferW,
661 sizeof(bufferW)/sizeof(WCHAR) );
662 SetLocaleInfoW( lcid, values[i], bufferW );
668 /***********************************************************************
669 * LOCALE_InitRegistry
671 * Update registry contents on startup if the user locale has changed.
672 * This simulates the action of the Windows control panel.
674 void LOCALE_InitRegistry(void)
676 static const WCHAR acpW[] = {'A','C','P',0};
677 static const WCHAR oemcpW[] = {'O','E','M','C','P',0};
678 static const WCHAR maccpW[] = {'M','A','C','C','P',0};
679 static const WCHAR localeW[] = {'L','o','c','a','l','e',0};
680 static const WCHAR lc_ctypeW[] = { 'L','C','_','C','T','Y','P','E',0 };
681 static const WCHAR lc_monetaryW[] = { 'L','C','_','M','O','N','E','T','A','R','Y',0 };
682 static const WCHAR lc_numericW[] = { 'L','C','_','N','U','M','E','R','I','C',0 };
683 static const WCHAR lc_timeW[] = { 'L','C','_','T','I','M','E',0 };
684 static const WCHAR lc_measurementW[] = { 'L','C','_','M','E','A','S','U','R','E','M','E','N','T',0 };
685 static const WCHAR lc_telephoneW[] = { 'L','C','_','T','E','L','E','P','H','O','N','E',0 };
686 static const WCHAR lc_paperW[] = { 'L','C','_','P','A','P','E','R',0};
691 } update_cp_values[] = {
692 { acpW, LOCALE_IDEFAULTANSICODEPAGE },
693 { oemcpW, LOCALE_IDEFAULTCODEPAGE },
694 { maccpW, LOCALE_IDEFAULTMACCODEPAGE }
696 static const LCTYPE lc_messages_values[] = {
697 LOCALE_SABBREVLANGNAME,
700 static const LCTYPE lc_monetary_values[] = {
706 LOCALE_SMONDECIMALSEP,
708 LOCALE_SMONTHOUSANDSEP };
709 static const LCTYPE lc_numeric_values[] = {
713 LOCALE_IDIGITSUBSTITUTION,
714 LOCALE_SNATIVEDIGITS,
716 LOCALE_SNEGATIVESIGN,
717 LOCALE_SPOSITIVESIGN,
719 static const LCTYPE lc_time_values[] = {
728 LOCALE_ITIMEMARKPOSN,
729 LOCALE_ICALENDARTYPE,
730 LOCALE_IFIRSTDAYOFWEEK,
731 LOCALE_IFIRSTWEEKOFYEAR,
735 static const LCTYPE lc_measurement_values[] = { LOCALE_IMEASURE };
736 static const LCTYPE lc_telephone_values[] = { LOCALE_ICOUNTRY };
737 static const LCTYPE lc_paper_values[] = { LOCALE_IPAPERSIZE };
739 UNICODE_STRING nameW;
743 LCID lcid = GetUserDefaultLCID();
745 if (!(hkey = create_registry_key()))
746 return; /* don't do anything if we can't create the registry key */
748 locale_update_registry( hkey, localeW, lcid_LC_MESSAGES, lc_messages_values,
749 sizeof(lc_messages_values)/sizeof(lc_messages_values[0]) );
750 locale_update_registry( hkey, lc_monetaryW, lcid_LC_MONETARY, lc_monetary_values,
751 sizeof(lc_monetary_values)/sizeof(lc_monetary_values[0]) );
752 locale_update_registry( hkey, lc_numericW, lcid_LC_NUMERIC, lc_numeric_values,
753 sizeof(lc_numeric_values)/sizeof(lc_numeric_values[0]) );
754 locale_update_registry( hkey, lc_timeW, lcid_LC_TIME, lc_time_values,
755 sizeof(lc_time_values)/sizeof(lc_time_values[0]) );
756 locale_update_registry( hkey, lc_measurementW, lcid_LC_MEASUREMENT, lc_measurement_values,
757 sizeof(lc_measurement_values)/sizeof(lc_measurement_values[0]) );
758 locale_update_registry( hkey, lc_telephoneW, lcid_LC_TELEPHONE, lc_telephone_values,
759 sizeof(lc_telephone_values)/sizeof(lc_telephone_values[0]) );
760 locale_update_registry( hkey, lc_paperW, lcid_LC_PAPER, lc_paper_values,
761 sizeof(lc_paper_values)/sizeof(lc_paper_values[0]) );
763 if (locale_update_registry( hkey, lc_ctypeW, lcid_LC_CTYPE, NULL, 0 ))
765 static const WCHAR codepageW[] =
766 {'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
767 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
768 'C','o','n','t','r','o','l','\\','N','l','s','\\','C','o','d','e','p','a','g','e',0};
770 OBJECT_ATTRIBUTES attr;
774 RtlInitUnicodeString( &nameW, codepageW );
775 InitializeObjectAttributes( &attr, &nameW, 0, 0, NULL );
776 while (codepageW[len])
778 nameW.Length = len * sizeof(WCHAR);
779 if (NtCreateKey( &nls_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) break;
782 while (codepageW[len] && codepageW[len] != '\\') len++;
784 nameW.Length = len * sizeof(WCHAR);
785 if (!NtCreateKey( &nls_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ))
787 for (i = 0; i < sizeof(update_cp_values)/sizeof(update_cp_values[0]); i++)
789 count = GetLocaleInfoW( lcid, update_cp_values[i].value | LOCALE_NOUSEROVERRIDE,
790 bufferW, sizeof(bufferW)/sizeof(WCHAR) );
791 RtlInitUnicodeString( &nameW, update_cp_values[i].name );
792 NtSetValueKey( nls_key, &nameW, 0, REG_SZ, bufferW, count * sizeof(WCHAR) );
802 /***********************************************************************
805 static UINT setup_unix_locales(void)
807 struct locale_name locale_name;
808 WCHAR buffer[128], ctype_buff[128];
812 if ((locale = setlocale( LC_CTYPE, NULL )))
814 strcpynAtoW( ctype_buff, locale, sizeof(ctype_buff)/sizeof(WCHAR) );
815 parse_locale_name( ctype_buff, &locale_name );
816 lcid_LC_CTYPE = locale_name.lcid;
817 unix_cp = locale_name.codepage;
819 if (!lcid_LC_CTYPE) /* this one needs a default value */
820 lcid_LC_CTYPE = MAKELCID( MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT), SORT_DEFAULT );
822 TRACE( "got lcid %04x (%d matches) for LC_CTYPE=%s\n",
823 locale_name.lcid, locale_name.matches, debugstr_a(locale) );
825 #define GET_UNIX_LOCALE(cat) do \
826 if ((locale = setlocale( cat, NULL ))) \
828 strcpynAtoW( buffer, locale, sizeof(buffer)/sizeof(WCHAR) ); \
829 if (!strcmpW( buffer, ctype_buff )) lcid_##cat = lcid_LC_CTYPE; \
831 parse_locale_name( buffer, &locale_name ); \
832 lcid_##cat = locale_name.lcid; \
833 TRACE( "got lcid %04x (%d matches) for " #cat "=%s\n", \
834 locale_name.lcid, locale_name.matches, debugstr_a(locale) ); \
838 GET_UNIX_LOCALE( LC_COLLATE );
839 GET_UNIX_LOCALE( LC_MESSAGES );
840 GET_UNIX_LOCALE( LC_MONETARY );
841 GET_UNIX_LOCALE( LC_NUMERIC );
842 GET_UNIX_LOCALE( LC_TIME );
844 GET_UNIX_LOCALE( LC_PAPER );
846 #ifdef LC_MEASUREMENT
847 GET_UNIX_LOCALE( LC_MEASUREMENT );
850 GET_UNIX_LOCALE( LC_TELEPHONE );
853 #undef GET_UNIX_LOCALE
859 /***********************************************************************
860 * GetUserDefaultLangID (KERNEL32.@)
862 * Get the default language Id for the current user.
868 * The current LANGID of the default language for the current user.
870 LANGID WINAPI GetUserDefaultLangID(void)
872 return LANGIDFROMLCID(GetUserDefaultLCID());
876 /***********************************************************************
877 * GetSystemDefaultLangID (KERNEL32.@)
879 * Get the default language Id for the system.
885 * The current LANGID of the default language for the system.
887 LANGID WINAPI GetSystemDefaultLangID(void)
889 return LANGIDFROMLCID(GetSystemDefaultLCID());
893 /***********************************************************************
894 * GetUserDefaultLCID (KERNEL32.@)
896 * Get the default locale Id for the current user.
902 * The current LCID of the default locale for the current user.
904 LCID WINAPI GetUserDefaultLCID(void)
907 NtQueryDefaultLocale( TRUE, &lcid );
912 /***********************************************************************
913 * GetSystemDefaultLCID (KERNEL32.@)
915 * Get the default locale Id for the system.
921 * The current LCID of the default locale for the system.
923 LCID WINAPI GetSystemDefaultLCID(void)
926 NtQueryDefaultLocale( FALSE, &lcid );
931 /***********************************************************************
932 * GetUserDefaultUILanguage (KERNEL32.@)
934 * Get the default user interface language Id for the current user.
940 * The current LANGID of the default UI language for the current user.
942 LANGID WINAPI GetUserDefaultUILanguage(void)
945 NtQueryDefaultUILanguage( &lang );
950 /***********************************************************************
951 * GetSystemDefaultUILanguage (KERNEL32.@)
953 * Get the default user interface language Id for the system.
959 * The current LANGID of the default UI language for the system. This is
960 * typically the same language used during the installation process.
962 LANGID WINAPI GetSystemDefaultUILanguage(void)
965 NtQueryInstallUILanguage( &lang );
970 /***********************************************************************
971 * LocaleNameToLCID (KERNEL32.@)
973 LCID WINAPI LocaleNameToLCID( LPCWSTR name, DWORD flags )
975 struct locale_name locale_name;
977 if (flags) FIXME( "unsupported flags %x\n", flags );
979 parse_locale_name( name, &locale_name );
981 TRACE( "found lcid %x for %s, matches %d\n",
982 locale_name.lcid, debugstr_w(name), locale_name.matches );
984 if (!locale_name.matches)
985 WARN( "locale %s not recognized, defaulting to English\n", debugstr_w(name) );
986 else if (locale_name.matches == 1)
987 WARN( "locale %s not recognized, defaulting to %s\n",
988 debugstr_w(name), debugstr_w(locale_name.lang) );
990 return locale_name.lcid;
994 /***********************************************************************
995 * LCIDToLocaleName (KERNEL32.@)
997 INT WINAPI LCIDToLocaleName( LCID lcid, LPWSTR name, INT count, DWORD flags )
999 if (flags) FIXME( "unsupported flags %x\n", flags );
1001 return GetLocaleInfoW( lcid, LOCALE_SNAME | LOCALE_NOUSEROVERRIDE, name, count );
1005 /******************************************************************************
1006 * get_locale_value_name
1008 * Gets the registry value name for a given lctype.
1010 static const WCHAR *get_locale_value_name( DWORD lctype )
1012 static const WCHAR iCalendarTypeW[] = {'i','C','a','l','e','n','d','a','r','T','y','p','e',0};
1013 static const WCHAR iCountryW[] = {'i','C','o','u','n','t','r','y',0};
1014 static const WCHAR iCurrDigitsW[] = {'i','C','u','r','r','D','i','g','i','t','s',0};
1015 static const WCHAR iCurrencyW[] = {'i','C','u','r','r','e','n','c','y',0};
1016 static const WCHAR iDateW[] = {'i','D','a','t','e',0};
1017 static const WCHAR iDigitsW[] = {'i','D','i','g','i','t','s',0};
1018 static const WCHAR iFirstDayOfWeekW[] = {'i','F','i','r','s','t','D','a','y','O','f','W','e','e','k',0};
1019 static const WCHAR iFirstWeekOfYearW[] = {'i','F','i','r','s','t','W','e','e','k','O','f','Y','e','a','r',0};
1020 static const WCHAR iLDateW[] = {'i','L','D','a','t','e',0};
1021 static const WCHAR iLZeroW[] = {'i','L','Z','e','r','o',0};
1022 static const WCHAR iMeasureW[] = {'i','M','e','a','s','u','r','e',0};
1023 static const WCHAR iNegCurrW[] = {'i','N','e','g','C','u','r','r',0};
1024 static const WCHAR iNegNumberW[] = {'i','N','e','g','N','u','m','b','e','r',0};
1025 static const WCHAR iPaperSizeW[] = {'i','P','a','p','e','r','S','i','z','e',0};
1026 static const WCHAR iTLZeroW[] = {'i','T','L','Z','e','r','o',0};
1027 static const WCHAR iTimePrefixW[] = {'i','T','i','m','e','P','r','e','f','i','x',0};
1028 static const WCHAR iTimeW[] = {'i','T','i','m','e',0};
1029 static const WCHAR s1159W[] = {'s','1','1','5','9',0};
1030 static const WCHAR s2359W[] = {'s','2','3','5','9',0};
1031 static const WCHAR sCountryW[] = {'s','C','o','u','n','t','r','y',0};
1032 static const WCHAR sCurrencyW[] = {'s','C','u','r','r','e','n','c','y',0};
1033 static const WCHAR sDateW[] = {'s','D','a','t','e',0};
1034 static const WCHAR sDecimalW[] = {'s','D','e','c','i','m','a','l',0};
1035 static const WCHAR sGroupingW[] = {'s','G','r','o','u','p','i','n','g',0};
1036 static const WCHAR sLanguageW[] = {'s','L','a','n','g','u','a','g','e',0};
1037 static const WCHAR sListW[] = {'s','L','i','s','t',0};
1038 static const WCHAR sLongDateW[] = {'s','L','o','n','g','D','a','t','e',0};
1039 static const WCHAR sMonDecimalSepW[] = {'s','M','o','n','D','e','c','i','m','a','l','S','e','p',0};
1040 static const WCHAR sMonGroupingW[] = {'s','M','o','n','G','r','o','u','p','i','n','g',0};
1041 static const WCHAR sMonThousandSepW[] = {'s','M','o','n','T','h','o','u','s','a','n','d','S','e','p',0};
1042 static const WCHAR sNativeDigitsW[] = {'s','N','a','t','i','v','e','D','i','g','i','t','s',0};
1043 static const WCHAR sNegativeSignW[] = {'s','N','e','g','a','t','i','v','e','S','i','g','n',0};
1044 static const WCHAR sPositiveSignW[] = {'s','P','o','s','i','t','i','v','e','S','i','g','n',0};
1045 static const WCHAR sShortDateW[] = {'s','S','h','o','r','t','D','a','t','e',0};
1046 static const WCHAR sThousandW[] = {'s','T','h','o','u','s','a','n','d',0};
1047 static const WCHAR sTimeFormatW[] = {'s','T','i','m','e','F','o','r','m','a','t',0};
1048 static const WCHAR sTimeW[] = {'s','T','i','m','e',0};
1049 static const WCHAR sYearMonthW[] = {'s','Y','e','a','r','M','o','n','t','h',0};
1050 static const WCHAR NumShapeW[] = {'N','u','m','s','h','a','p','e',0};
1054 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
1055 * the values are stored in the registry, confirmed under Windows.
1057 case LOCALE_ICALENDARTYPE: return iCalendarTypeW;
1058 case LOCALE_ICURRDIGITS: return iCurrDigitsW;
1059 case LOCALE_ICURRENCY: return iCurrencyW;
1060 case LOCALE_IDIGITS: return iDigitsW;
1061 case LOCALE_IFIRSTDAYOFWEEK: return iFirstDayOfWeekW;
1062 case LOCALE_IFIRSTWEEKOFYEAR: return iFirstWeekOfYearW;
1063 case LOCALE_ILZERO: return iLZeroW;
1064 case LOCALE_IMEASURE: return iMeasureW;
1065 case LOCALE_INEGCURR: return iNegCurrW;
1066 case LOCALE_INEGNUMBER: return iNegNumberW;
1067 case LOCALE_IPAPERSIZE: return iPaperSizeW;
1068 case LOCALE_ITIME: return iTimeW;
1069 case LOCALE_S1159: return s1159W;
1070 case LOCALE_S2359: return s2359W;
1071 case LOCALE_SCURRENCY: return sCurrencyW;
1072 case LOCALE_SDATE: return sDateW;
1073 case LOCALE_SDECIMAL: return sDecimalW;
1074 case LOCALE_SGROUPING: return sGroupingW;
1075 case LOCALE_SLIST: return sListW;
1076 case LOCALE_SLONGDATE: return sLongDateW;
1077 case LOCALE_SMONDECIMALSEP: return sMonDecimalSepW;
1078 case LOCALE_SMONGROUPING: return sMonGroupingW;
1079 case LOCALE_SMONTHOUSANDSEP: return sMonThousandSepW;
1080 case LOCALE_SNEGATIVESIGN: return sNegativeSignW;
1081 case LOCALE_SPOSITIVESIGN: return sPositiveSignW;
1082 case LOCALE_SSHORTDATE: return sShortDateW;
1083 case LOCALE_STHOUSAND: return sThousandW;
1084 case LOCALE_STIME: return sTimeW;
1085 case LOCALE_STIMEFORMAT: return sTimeFormatW;
1086 case LOCALE_SYEARMONTH: return sYearMonthW;
1088 /* The following are not listed under MSDN as supported,
1089 * but seem to be used and also stored in the registry.
1091 case LOCALE_ICOUNTRY: return iCountryW;
1092 case LOCALE_IDATE: return iDateW;
1093 case LOCALE_ILDATE: return iLDateW;
1094 case LOCALE_ITLZERO: return iTLZeroW;
1095 case LOCALE_SCOUNTRY: return sCountryW;
1096 case LOCALE_SABBREVLANGNAME: return sLanguageW;
1098 /* The following are used in XP and later */
1099 case LOCALE_IDIGITSUBSTITUTION: return NumShapeW;
1100 case LOCALE_SNATIVEDIGITS: return sNativeDigitsW;
1101 case LOCALE_ITIMEMARKPOSN: return iTimePrefixW;
1107 /******************************************************************************
1108 * get_registry_locale_info
1110 * Retrieve user-modified locale info from the registry.
1111 * Return length, 0 on error, -1 if not found.
1113 static INT get_registry_locale_info( LPCWSTR value, LPWSTR buffer, INT len )
1119 UNICODE_STRING nameW;
1120 KEY_VALUE_PARTIAL_INFORMATION *info;
1121 static const int info_size = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
1123 if (!(hkey = create_registry_key())) return -1;
1125 RtlInitUnicodeString( &nameW, value );
1126 size = info_size + len * sizeof(WCHAR);
1128 if (!(info = HeapAlloc( GetProcessHeap(), 0, size )))
1131 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1135 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, info, size, &size );
1139 ret = (size - info_size) / sizeof(WCHAR);
1140 /* append terminating null if needed */
1141 if (!ret || ((WCHAR *)info->Data)[ret-1])
1143 if (ret < len || !buffer) ret++;
1146 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1152 memcpy( buffer, info->Data, (ret-1) * sizeof(WCHAR) );
1156 else if (status == STATUS_BUFFER_OVERFLOW && !buffer)
1158 ret = (size - info_size) / sizeof(WCHAR) + 1;
1160 else if (status == STATUS_OBJECT_NAME_NOT_FOUND)
1166 SetLastError( RtlNtStatusToDosError(status) );
1170 HeapFree( GetProcessHeap(), 0, info );
1175 /******************************************************************************
1176 * GetLocaleInfoA (KERNEL32.@)
1178 * Get information about an aspect of a locale.
1181 * lcid [I] LCID of the locale
1182 * lctype [I] LCTYPE_ flags from "winnls.h"
1183 * buffer [O] Destination for the information
1184 * len [I] Length of buffer in characters
1187 * Success: The size of the data requested. If buffer is non-NULL, it is filled
1188 * with the information.
1189 * Failure: 0. Use GetLastError() to determine the cause.
1192 * - LOCALE_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
1193 * - The string returned is NUL terminated, except for LOCALE_FONTSIGNATURE,
1194 * which is a bit string.
1196 INT WINAPI GetLocaleInfoA( LCID lcid, LCTYPE lctype, LPSTR buffer, INT len )
1201 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid, lctype, buffer, len );
1203 if (len < 0 || (len && !buffer))
1205 SetLastError( ERROR_INVALID_PARAMETER );
1208 if (lctype & LOCALE_RETURN_GENITIVE_NAMES )
1210 SetLastError( ERROR_INVALID_FLAGS );
1214 if (!len) buffer = NULL;
1216 if (!(lenW = GetLocaleInfoW( lcid, lctype, NULL, 0 ))) return 0;
1218 if (!(bufferW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
1220 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1223 if ((ret = GetLocaleInfoW( lcid, lctype, bufferW, lenW )))
1225 if ((lctype & LOCALE_RETURN_NUMBER) ||
1226 ((lctype & ~LOCALE_LOCALEINFOFLAGSMASK) == LOCALE_FONTSIGNATURE))
1228 /* it's not an ASCII string, just bytes */
1229 ret *= sizeof(WCHAR);
1232 if (ret <= len) memcpy( buffer, bufferW, ret );
1235 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1242 UINT codepage = CP_ACP;
1243 if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
1244 ret = WideCharToMultiByte( codepage, 0, bufferW, ret, buffer, len, NULL, NULL );
1247 HeapFree( GetProcessHeap(), 0, bufferW );
1252 /******************************************************************************
1253 * GetLocaleInfoW (KERNEL32.@)
1255 * See GetLocaleInfoA.
1257 INT WINAPI GetLocaleInfoW( LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len )
1267 if (len < 0 || (len && !buffer))
1269 SetLastError( ERROR_INVALID_PARAMETER );
1272 if (lctype & LOCALE_RETURN_GENITIVE_NAMES &&
1273 !is_genitive_name_supported( lctype ))
1275 SetLastError( ERROR_INVALID_FLAGS );
1279 if (!len) buffer = NULL;
1281 lcid = convert_default_lcid( lcid, lctype );
1283 lcflags = lctype & LOCALE_LOCALEINFOFLAGSMASK;
1286 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d)\n", lcid, lctype, buffer, len );
1288 /* first check for overrides in the registry */
1290 if (!(lcflags & LOCALE_NOUSEROVERRIDE) &&
1291 lcid == convert_default_lcid( LOCALE_USER_DEFAULT, lctype ))
1293 const WCHAR *value = get_locale_value_name(lctype);
1297 if (lcflags & LOCALE_RETURN_NUMBER)
1300 ret = get_registry_locale_info( value, tmp, sizeof(tmp)/sizeof(WCHAR) );
1304 UINT number = strtolW( tmp, &end, 10 );
1305 if (*end) /* invalid number */
1307 SetLastError( ERROR_INVALID_FLAGS );
1310 ret = sizeof(UINT)/sizeof(WCHAR);
1311 if (!buffer) return ret;
1314 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1317 memcpy( buffer, &number, sizeof(number) );
1320 else ret = get_registry_locale_info( value, buffer, len );
1322 if (ret != -1) return ret;
1326 /* now load it from kernel resources */
1328 lang_id = LANGIDFROMLCID( lcid );
1330 /* replace SUBLANG_NEUTRAL by SUBLANG_DEFAULT */
1331 if (SUBLANGID(lang_id) == SUBLANG_NEUTRAL)
1332 lang_id = MAKELANGID(PRIMARYLANGID(lang_id), SUBLANG_DEFAULT);
1334 if (!(hrsrc = FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING,
1335 ULongToPtr((lctype >> 4) + 1), lang_id )))
1337 SetLastError( ERROR_INVALID_FLAGS ); /* no such lctype */
1340 if (!(hmem = LoadResource( kernel32_handle, hrsrc )))
1343 p = LockResource( hmem );
1344 for (i = 0; i < (lctype & 0x0f); i++) p += *p + 1;
1346 if (lcflags & LOCALE_RETURN_NUMBER) ret = sizeof(UINT)/sizeof(WCHAR);
1347 else if (is_genitive_name_supported( lctype ) && *p)
1349 /* genitive form's stored after a null separator from a nominative */
1350 for (i = 1; i <= *p; i++) if (!p[i]) break;
1352 if (i <= *p && (lcflags & LOCALE_RETURN_GENITIVE_NAMES))
1360 ret = (lctype == LOCALE_FONTSIGNATURE) ? *p : *p + 1;
1362 if (!buffer) return ret;
1366 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1370 if (lcflags & LOCALE_RETURN_NUMBER)
1373 WCHAR *end, *tmp = HeapAlloc( GetProcessHeap(), 0, (*p + 1) * sizeof(WCHAR) );
1375 memcpy( tmp, p + 1, *p * sizeof(WCHAR) );
1377 number = strtolW( tmp, &end, 10 );
1379 memcpy( buffer, &number, sizeof(number) );
1380 else /* invalid number */
1382 SetLastError( ERROR_INVALID_FLAGS );
1385 HeapFree( GetProcessHeap(), 0, tmp );
1387 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning number %d\n",
1388 lcid, lctype, buffer, len, number );
1392 memcpy( buffer, p + 1, ret * sizeof(WCHAR) );
1393 if (lctype != LOCALE_FONTSIGNATURE) buffer[ret-1] = 0;
1395 TRACE( "(lcid=0x%x,lctype=0x%x,%p,%d) returning %d %s\n",
1396 lcid, lctype, buffer, len, ret, debugstr_w(buffer) );
1402 /******************************************************************************
1403 * SetLocaleInfoA [KERNEL32.@]
1405 * Set information about an aspect of a locale.
1408 * lcid [I] LCID of the locale
1409 * lctype [I] LCTYPE_ flags from "winnls.h"
1410 * data [I] Information to set
1413 * Success: TRUE. The information given will be returned by GetLocaleInfoA()
1414 * whenever it is called without LOCALE_NOUSEROVERRIDE.
1415 * Failure: FALSE. Use GetLastError() to determine the cause.
1418 * - Values are only be set for the current user locale; the system locale
1419 * settings cannot be changed.
1420 * - Any settings changed by this call are lost when the locale is changed by
1421 * the control panel (in Wine, this happens every time you change LANG).
1422 * - The native implementation of this function does not check that lcid matches
1423 * the current user locale, and simply sets the new values. Wine warns you in
1424 * this case, but behaves the same.
1426 BOOL WINAPI SetLocaleInfoA(LCID lcid, LCTYPE lctype, LPCSTR data)
1428 UINT codepage = CP_ACP;
1433 if (!(lctype & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( lcid );
1437 SetLastError( ERROR_INVALID_PARAMETER );
1440 len = MultiByteToWideChar( codepage, 0, data, -1, NULL, 0 );
1441 if (!(strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
1443 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1446 MultiByteToWideChar( codepage, 0, data, -1, strW, len );
1447 ret = SetLocaleInfoW( lcid, lctype, strW );
1448 HeapFree( GetProcessHeap(), 0, strW );
1453 /******************************************************************************
1454 * SetLocaleInfoW (KERNEL32.@)
1456 * See SetLocaleInfoA.
1458 BOOL WINAPI SetLocaleInfoW( LCID lcid, LCTYPE lctype, LPCWSTR data )
1461 static const WCHAR intlW[] = {'i','n','t','l',0 };
1462 UNICODE_STRING valueW;
1467 value = get_locale_value_name( lctype );
1469 if (!data || !value)
1471 SetLastError( ERROR_INVALID_PARAMETER );
1475 if (lctype == LOCALE_IDATE || lctype == LOCALE_ILDATE)
1477 SetLastError( ERROR_INVALID_FLAGS );
1481 TRACE("setting %x (%s) to %s\n", lctype, debugstr_w(value), debugstr_w(data) );
1483 /* FIXME: should check that data to set is sane */
1485 /* FIXME: profile functions should map to registry */
1486 WriteProfileStringW( intlW, value, data );
1488 if (!(hkey = create_registry_key())) return FALSE;
1489 RtlInitUnicodeString( &valueW, value );
1490 status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, data, (strlenW(data)+1)*sizeof(WCHAR) );
1492 if (lctype == LOCALE_SSHORTDATE || lctype == LOCALE_SLONGDATE)
1494 /* Set I-value from S value */
1495 WCHAR *lpD, *lpM, *lpY;
1498 lpD = strrchrW(data, 'd');
1499 lpM = strrchrW(data, 'M');
1500 lpY = strrchrW(data, 'y');
1504 szBuff[0] = '1'; /* D-M-Y */
1509 szBuff[0] = '2'; /* Y-M-D */
1511 szBuff[0] = '0'; /* M-D-Y */
1516 if (lctype == LOCALE_SSHORTDATE)
1517 lctype = LOCALE_IDATE;
1519 lctype = LOCALE_ILDATE;
1521 value = get_locale_value_name( lctype );
1523 WriteProfileStringW( intlW, value, szBuff );
1525 RtlInitUnicodeString( &valueW, value );
1526 status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, szBuff, sizeof(szBuff) );
1531 if (status) SetLastError( RtlNtStatusToDosError(status) );
1536 /******************************************************************************
1537 * GetACP (KERNEL32.@)
1539 * Get the current Ansi code page Id for the system.
1545 * The current Ansi code page identifier for the system.
1547 UINT WINAPI GetACP(void)
1549 assert( ansi_cptable );
1550 return ansi_cptable->info.codepage;
1554 /******************************************************************************
1555 * SetCPGlobal (KERNEL32.@)
1557 * Set the current Ansi code page Id for the system.
1560 * acp [I] code page ID to be the new ACP.
1565 UINT WINAPI SetCPGlobal( UINT acp )
1567 UINT ret = GetACP();
1568 const union cptable *new_cptable = wine_cp_get_table( acp );
1570 if (new_cptable) ansi_cptable = new_cptable;
1575 /***********************************************************************
1576 * GetOEMCP (KERNEL32.@)
1578 * Get the current OEM code page Id for the system.
1584 * The current OEM code page identifier for the system.
1586 UINT WINAPI GetOEMCP(void)
1588 assert( oem_cptable );
1589 return oem_cptable->info.codepage;
1593 /***********************************************************************
1594 * IsValidCodePage (KERNEL32.@)
1596 * Determine if a given code page identifier is valid.
1599 * codepage [I] Code page Id to verify.
1602 * TRUE, If codepage is valid and available on the system,
1605 BOOL WINAPI IsValidCodePage( UINT codepage )
1612 return wine_cp_get_table( codepage ) != NULL;
1617 /***********************************************************************
1618 * IsDBCSLeadByteEx (KERNEL32.@)
1620 * Determine if a character is a lead byte in a given code page.
1623 * codepage [I] Code page for the test.
1624 * testchar [I] Character to test
1627 * TRUE, if testchar is a lead byte in codepage,
1630 BOOL WINAPI IsDBCSLeadByteEx( UINT codepage, BYTE testchar )
1632 const union cptable *table = get_codepage_table( codepage );
1633 return table && wine_is_dbcs_leadbyte( table, testchar );
1637 /***********************************************************************
1638 * IsDBCSLeadByte (KERNEL32.@)
1639 * IsDBCSLeadByte (KERNEL.207)
1641 * Determine if a character is a lead byte.
1644 * testchar [I] Character to test
1647 * TRUE, if testchar is a lead byte in the ANSI code page,
1650 BOOL WINAPI IsDBCSLeadByte( BYTE testchar )
1652 if (!ansi_cptable) return FALSE;
1653 return wine_is_dbcs_leadbyte( ansi_cptable, testchar );
1657 /***********************************************************************
1658 * GetCPInfo (KERNEL32.@)
1660 * Get information about a code page.
1663 * codepage [I] Code page number
1664 * cpinfo [O] Destination for code page information
1667 * Success: TRUE. cpinfo is updated with the information about codepage.
1668 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1670 BOOL WINAPI GetCPInfo( UINT codepage, LPCPINFO cpinfo )
1672 const union cptable *table;
1676 SetLastError( ERROR_INVALID_PARAMETER );
1680 if (!(table = get_codepage_table( codepage )))
1686 cpinfo->DefaultChar[0] = 0x3f;
1687 cpinfo->DefaultChar[1] = 0;
1688 cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = 0;
1689 cpinfo->MaxCharSize = (codepage == CP_UTF7) ? 5 : 4;
1693 SetLastError( ERROR_INVALID_PARAMETER );
1696 if (table->info.def_char & 0xff00)
1698 cpinfo->DefaultChar[0] = (table->info.def_char & 0xff00) >> 8;
1699 cpinfo->DefaultChar[1] = table->info.def_char & 0x00ff;
1703 cpinfo->DefaultChar[0] = table->info.def_char & 0xff;
1704 cpinfo->DefaultChar[1] = 0;
1706 if ((cpinfo->MaxCharSize = table->info.char_size) == 2)
1707 memcpy( cpinfo->LeadByte, table->dbcs.lead_bytes, sizeof(cpinfo->LeadByte) );
1709 cpinfo->LeadByte[0] = cpinfo->LeadByte[1] = 0;
1714 /***********************************************************************
1715 * GetCPInfoExA (KERNEL32.@)
1717 * Get extended information about a code page.
1720 * codepage [I] Code page number
1721 * dwFlags [I] Reserved, must to 0.
1722 * cpinfo [O] Destination for code page information
1725 * Success: TRUE. cpinfo is updated with the information about codepage.
1726 * Failure: FALSE, if codepage is invalid or cpinfo is NULL.
1728 BOOL WINAPI GetCPInfoExA( UINT codepage, DWORD dwFlags, LPCPINFOEXA cpinfo )
1732 if (!GetCPInfoExW( codepage, dwFlags, &cpinfoW ))
1735 /* the layout is the same except for CodePageName */
1736 memcpy(cpinfo, &cpinfoW, sizeof(CPINFOEXA));
1737 WideCharToMultiByte(CP_ACP, 0, cpinfoW.CodePageName, -1, cpinfo->CodePageName, sizeof(cpinfo->CodePageName), NULL, NULL);
1741 /***********************************************************************
1742 * GetCPInfoExW (KERNEL32.@)
1744 * Unicode version of GetCPInfoExA.
1746 BOOL WINAPI GetCPInfoExW( UINT codepage, DWORD dwFlags, LPCPINFOEXW cpinfo )
1748 if (!GetCPInfo( codepage, (LPCPINFO)cpinfo ))
1755 static const WCHAR utf7[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','7',')',0};
1757 cpinfo->CodePage = CP_UTF7;
1758 cpinfo->UnicodeDefaultChar = 0x3f;
1759 strcpyW(cpinfo->CodePageName, utf7);
1765 static const WCHAR utf8[] = {'U','n','i','c','o','d','e',' ','(','U','T','F','-','8',')',0};
1767 cpinfo->CodePage = CP_UTF8;
1768 cpinfo->UnicodeDefaultChar = 0x3f;
1769 strcpyW(cpinfo->CodePageName, utf8);
1775 const union cptable *table = get_codepage_table( codepage );
1777 cpinfo->CodePage = table->info.codepage;
1778 cpinfo->UnicodeDefaultChar = table->info.def_unicode_char;
1779 MultiByteToWideChar( CP_ACP, 0, table->info.name, -1, cpinfo->CodePageName,
1780 sizeof(cpinfo->CodePageName)/sizeof(WCHAR));
1787 /***********************************************************************
1788 * EnumSystemCodePagesA (KERNEL32.@)
1790 * Call a user defined function for every code page installed on the system.
1793 * lpfnCodePageEnum [I] User CODEPAGE_ENUMPROC to call with each found code page
1794 * flags [I] Reserved, set to 0.
1797 * TRUE, If all code pages have been enumerated, or
1798 * FALSE if lpfnCodePageEnum returned FALSE to stop the enumeration.
1800 BOOL WINAPI EnumSystemCodePagesA( CODEPAGE_ENUMPROCA lpfnCodePageEnum, DWORD flags )
1802 const union cptable *table;
1808 if (!(table = wine_cp_enum_table( index++ ))) break;
1809 sprintf( buffer, "%d", table->info.codepage );
1810 if (!lpfnCodePageEnum( buffer )) break;
1816 /***********************************************************************
1817 * EnumSystemCodePagesW (KERNEL32.@)
1819 * See EnumSystemCodePagesA.
1821 BOOL WINAPI EnumSystemCodePagesW( CODEPAGE_ENUMPROCW lpfnCodePageEnum, DWORD flags )
1823 const union cptable *table;
1824 WCHAR buffer[10], *p;
1825 int page, index = 0;
1829 if (!(table = wine_cp_enum_table( index++ ))) break;
1830 p = buffer + sizeof(buffer)/sizeof(WCHAR);
1832 page = table->info.codepage;
1835 *--p = '0' + (page % 10);
1838 if (!lpfnCodePageEnum( p )) break;
1844 /***********************************************************************
1845 * MultiByteToWideChar (KERNEL32.@)
1847 * Convert a multibyte character string into a Unicode string.
1850 * page [I] Codepage character set to convert from
1851 * flags [I] Character mapping flags
1852 * src [I] Source string buffer
1853 * srclen [I] Length of src (in bytes), or -1 if src is NUL terminated
1854 * dst [O] Destination buffer
1855 * dstlen [I] Length of dst (in WCHARs), or 0 to compute the required length
1858 * Success: If dstlen > 0, the number of characters written to dst.
1859 * If dstlen == 0, the number of characters needed to perform the
1860 * conversion. In both cases the count includes the terminating NUL.
1861 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1862 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1863 * and dstlen != 0; ERROR_INVALID_PARAMETER, if an invalid parameter
1864 * is passed, and ERROR_NO_UNICODE_TRANSLATION if no translation is
1867 INT WINAPI MultiByteToWideChar( UINT page, DWORD flags, LPCSTR src, INT srclen,
1868 LPWSTR dst, INT dstlen )
1870 const union cptable *table;
1873 if (!src || (!dst && dstlen))
1875 SetLastError( ERROR_INVALID_PARAMETER );
1879 if (srclen < 0) srclen = strlen(src) + 1;
1886 SetLastError( ERROR_INVALID_PARAMETER );
1889 ret = wine_cpsymbol_mbstowcs( src, srclen, dst, dstlen );
1892 FIXME("UTF-7 not supported\n");
1893 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
1898 ret = wine_cp_mbstowcs( unix_cptable, flags, src, srclen, dst, dstlen );
1902 flags |= MB_COMPOSITE; /* work around broken Mac OS X filesystem that enforces decomposed Unicode */
1906 ret = wine_utf8_mbstowcs( flags, src, srclen, dst, dstlen );
1909 if (!(table = get_codepage_table( page )))
1911 SetLastError( ERROR_INVALID_PARAMETER );
1914 ret = wine_cp_mbstowcs( table, flags, src, srclen, dst, dstlen );
1922 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER ); break;
1923 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION ); break;
1927 TRACE("cp %d %s -> %s, ret = %d\n",
1928 page, debugstr_an(src, srclen), debugstr_wn(dst, ret), ret);
1933 /***********************************************************************
1934 * WideCharToMultiByte (KERNEL32.@)
1936 * Convert a Unicode character string into a multibyte string.
1939 * page [I] Code page character set to convert to
1940 * flags [I] Mapping Flags (MB_ constants from "winnls.h").
1941 * src [I] Source string buffer
1942 * srclen [I] Length of src (in WCHARs), or -1 if src is NUL terminated
1943 * dst [O] Destination buffer
1944 * dstlen [I] Length of dst (in bytes), or 0 to compute the required length
1945 * defchar [I] Default character to use for conversion if no exact
1946 * conversion can be made
1947 * used [O] Set if default character was used in the conversion
1950 * Success: If dstlen > 0, the number of characters written to dst.
1951 * If dstlen == 0, number of characters needed to perform the
1952 * conversion. In both cases the count includes the terminating NUL.
1953 * Failure: 0. Use GetLastError() to determine the cause. Possible errors are
1954 * ERROR_INSUFFICIENT_BUFFER, if not enough space is available in dst
1955 * and dstlen != 0, and ERROR_INVALID_PARAMETER, if an invalid
1956 * parameter was given.
1958 INT WINAPI WideCharToMultiByte( UINT page, DWORD flags, LPCWSTR src, INT srclen,
1959 LPSTR dst, INT dstlen, LPCSTR defchar, BOOL *used )
1961 const union cptable *table;
1964 if (!src || (!dst && dstlen))
1966 SetLastError( ERROR_INVALID_PARAMETER );
1970 if (srclen < 0) srclen = strlenW(src) + 1;
1975 if( flags || defchar || used)
1977 SetLastError( ERROR_INVALID_PARAMETER );
1980 ret = wine_cpsymbol_wcstombs( src, srclen, dst, dstlen );
1983 FIXME("UTF-7 not supported\n");
1984 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
1989 ret = wine_cp_wcstombs( unix_cptable, flags, src, srclen, dst, dstlen,
1990 defchar, used ? &used_tmp : NULL );
1995 if (used) *used = FALSE; /* all chars are valid for UTF-8 */
1996 ret = wine_utf8_wcstombs( flags, src, srclen, dst, dstlen );
1999 if (!(table = get_codepage_table( page )))
2001 SetLastError( ERROR_INVALID_PARAMETER );
2004 ret = wine_cp_wcstombs( table, flags, src, srclen, dst, dstlen,
2005 defchar, used ? &used_tmp : NULL );
2006 if (used) *used = used_tmp;
2014 case -1: SetLastError( ERROR_INSUFFICIENT_BUFFER ); break;
2015 case -2: SetLastError( ERROR_NO_UNICODE_TRANSLATION ); break;
2019 TRACE("cp %d %s -> %s, ret = %d\n",
2020 page, debugstr_wn(src, srclen), debugstr_an(dst, ret), ret);
2025 /***********************************************************************
2026 * GetThreadLocale (KERNEL32.@)
2028 * Get the current threads locale.
2034 * The LCID currently associated with the calling thread.
2036 LCID WINAPI GetThreadLocale(void)
2038 LCID ret = NtCurrentTeb()->CurrentLocale;
2039 if (!ret) NtCurrentTeb()->CurrentLocale = ret = GetUserDefaultLCID();
2043 /**********************************************************************
2044 * SetThreadLocale (KERNEL32.@)
2046 * Set the current threads locale.
2049 * lcid [I] LCID of the locale to set
2052 * Success: TRUE. The threads locale is set to lcid.
2053 * Failure: FALSE. Use GetLastError() to determine the cause.
2055 BOOL WINAPI SetThreadLocale( LCID lcid )
2057 TRACE("(0x%04X)\n", lcid);
2059 lcid = ConvertDefaultLocale(lcid);
2061 if (lcid != GetThreadLocale())
2063 if (!IsValidLocale(lcid, LCID_SUPPORTED))
2065 SetLastError(ERROR_INVALID_PARAMETER);
2069 NtCurrentTeb()->CurrentLocale = lcid;
2074 /**********************************************************************
2075 * SetThreadUILanguage (KERNEL32.@)
2077 * Set the current threads UI language.
2080 * langid [I] LANGID of the language to set, or 0 to use
2081 * the available language which is best supported
2082 * for console applications
2085 * Success: The return value is the same as the input value.
2086 * Failure: The return value differs from the input value.
2087 * Use GetLastError() to determine the cause.
2089 LANGID WINAPI SetThreadUILanguage( LANGID langid )
2091 TRACE("(0x%04x) stub - returning success\n", langid);
2095 /******************************************************************************
2096 * ConvertDefaultLocale (KERNEL32.@)
2098 * Convert a default locale identifier into a real identifier.
2101 * lcid [I] LCID identifier of the locale to convert
2104 * lcid unchanged, if not a default locale or its sublanguage is
2105 * not SUBLANG_NEUTRAL.
2106 * GetSystemDefaultLCID(), if lcid == LOCALE_SYSTEM_DEFAULT.
2107 * GetUserDefaultLCID(), if lcid == LOCALE_USER_DEFAULT or LOCALE_NEUTRAL.
2108 * Otherwise, lcid with sublanguage changed to SUBLANG_DEFAULT.
2110 LCID WINAPI ConvertDefaultLocale( LCID lcid )
2116 case LOCALE_SYSTEM_DEFAULT:
2117 lcid = GetSystemDefaultLCID();
2119 case LOCALE_USER_DEFAULT:
2120 case LOCALE_NEUTRAL:
2121 lcid = GetUserDefaultLCID();
2124 /* Replace SUBLANG_NEUTRAL with SUBLANG_DEFAULT */
2125 langid = LANGIDFROMLCID(lcid);
2126 if (SUBLANGID(langid) == SUBLANG_NEUTRAL)
2128 langid = MAKELANGID(PRIMARYLANGID(langid), SUBLANG_DEFAULT);
2129 lcid = MAKELCID(langid, SORTIDFROMLCID(lcid));
2136 /******************************************************************************
2137 * IsValidLocale (KERNEL32.@)
2139 * Determine if a locale is valid.
2142 * lcid [I] LCID of the locale to check
2143 * flags [I] LCID_SUPPORTED = Valid, LCID_INSTALLED = Valid and installed on the system
2146 * TRUE, if lcid is valid,
2150 * Wine does not currently make the distinction between supported and installed. All
2151 * languages supported are installed by default.
2153 BOOL WINAPI IsValidLocale( LCID lcid, DWORD flags )
2155 /* check if language is registered in the kernel32 resources */
2156 return FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING,
2157 (LPCWSTR)LOCALE_ILANGUAGE, LANGIDFROMLCID(lcid)) != 0;
2161 static BOOL CALLBACK enum_lang_proc_a( HMODULE hModule, LPCSTR type,
2162 LPCSTR name, WORD LangID, LONG_PTR lParam )
2164 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
2167 sprintf(buf, "%08x", (UINT)LangID);
2168 return lpfnLocaleEnum( buf );
2171 static BOOL CALLBACK enum_lang_proc_w( HMODULE hModule, LPCWSTR type,
2172 LPCWSTR name, WORD LangID, LONG_PTR lParam )
2174 static const WCHAR formatW[] = {'%','0','8','x',0};
2175 LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
2177 sprintfW( buf, formatW, (UINT)LangID );
2178 return lpfnLocaleEnum( buf );
2181 /******************************************************************************
2182 * EnumSystemLocalesA (KERNEL32.@)
2184 * Call a users function for each locale available on the system.
2187 * lpfnLocaleEnum [I] Callback function to call for each locale
2188 * dwFlags [I] LOCALE_SUPPORTED=All supported, LOCALE_INSTALLED=Installed only
2192 * Failure: FALSE. Use GetLastError() to determine the cause.
2194 BOOL WINAPI EnumSystemLocalesA( LOCALE_ENUMPROCA lpfnLocaleEnum, DWORD dwFlags )
2196 TRACE("(%p,%08x)\n", lpfnLocaleEnum, dwFlags);
2197 EnumResourceLanguagesA( kernel32_handle, (LPSTR)RT_STRING,
2198 (LPCSTR)LOCALE_ILANGUAGE, enum_lang_proc_a,
2199 (LONG_PTR)lpfnLocaleEnum);
2204 /******************************************************************************
2205 * EnumSystemLocalesW (KERNEL32.@)
2207 * See EnumSystemLocalesA.
2209 BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum, DWORD dwFlags )
2211 TRACE("(%p,%08x)\n", lpfnLocaleEnum, dwFlags);
2212 EnumResourceLanguagesW( kernel32_handle, (LPWSTR)RT_STRING,
2213 (LPCWSTR)LOCALE_ILANGUAGE, enum_lang_proc_w,
2214 (LONG_PTR)lpfnLocaleEnum);
2219 struct enum_locale_ex_data
2221 LOCALE_ENUMPROCEX proc;
2226 static BOOL CALLBACK enum_locale_ex_proc( HMODULE module, LPCWSTR type,
2227 LPCWSTR name, WORD lang, LONG_PTR lparam )
2229 struct enum_locale_ex_data *data = (struct enum_locale_ex_data *)lparam;
2234 GetLocaleInfoW( MAKELCID( lang, SORT_DEFAULT ), LOCALE_SNAME | LOCALE_NOUSEROVERRIDE,
2235 buffer, sizeof(buffer) / sizeof(WCHAR) );
2236 if (!GetLocaleInfoW( MAKELCID( lang, SORT_DEFAULT ),
2237 LOCALE_INEUTRAL | LOCALE_NOUSEROVERRIDE | LOCALE_RETURN_NUMBER,
2238 (LPWSTR)&neutral, sizeof(neutral) / sizeof(WCHAR) ))
2240 flags = LOCALE_WINDOWS;
2241 flags |= neutral ? LOCALE_NEUTRALDATA : LOCALE_SPECIFICDATA;
2242 if (data->flags && ~(data->flags & flags)) return TRUE;
2243 return data->proc( buffer, flags, data->lparam );
2246 /******************************************************************************
2247 * EnumSystemLocalesEx (KERNEL32.@)
2249 BOOL WINAPI EnumSystemLocalesEx( LOCALE_ENUMPROCEX proc, DWORD flags, LPARAM lparam, LPVOID reserved )
2251 struct enum_locale_ex_data data;
2255 SetLastError( ERROR_INVALID_PARAMETER );
2260 data.lparam = lparam;
2261 EnumResourceLanguagesW( kernel32_handle, (LPCWSTR)RT_STRING,
2262 (LPCWSTR)MAKEINTRESOURCE((LOCALE_SNAME >> 4) + 1),
2263 enum_locale_ex_proc, (LONG_PTR)&data );
2268 /***********************************************************************
2269 * VerLanguageNameA (KERNEL32.@)
2271 * Get the name of a language.
2274 * wLang [I] LANGID of the language
2275 * szLang [O] Destination for the language name
2278 * Success: The size of the language name. If szLang is non-NULL, it is filled
2280 * Failure: 0. Use GetLastError() to determine the cause.
2283 DWORD WINAPI VerLanguageNameA( DWORD wLang, LPSTR szLang, DWORD nSize )
2285 return GetLocaleInfoA( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
2289 /***********************************************************************
2290 * VerLanguageNameW (KERNEL32.@)
2292 * See VerLanguageNameA.
2294 DWORD WINAPI VerLanguageNameW( DWORD wLang, LPWSTR szLang, DWORD nSize )
2296 return GetLocaleInfoW( MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize );
2300 /******************************************************************************
2301 * GetStringTypeW (KERNEL32.@)
2303 * See GetStringTypeA.
2305 BOOL WINAPI GetStringTypeW( DWORD type, LPCWSTR src, INT count, LPWORD chartype )
2307 static const unsigned char type2_map[16] =
2309 C2_NOTAPPLICABLE, /* unassigned */
2310 C2_LEFTTORIGHT, /* L */
2311 C2_RIGHTTOLEFT, /* R */
2312 C2_EUROPENUMBER, /* EN */
2313 C2_EUROPESEPARATOR, /* ES */
2314 C2_EUROPETERMINATOR, /* ET */
2315 C2_ARABICNUMBER, /* AN */
2316 C2_COMMONSEPARATOR, /* CS */
2317 C2_BLOCKSEPARATOR, /* B */
2318 C2_SEGMENTSEPARATOR, /* S */
2319 C2_WHITESPACE, /* WS */
2320 C2_OTHERNEUTRAL, /* ON */
2321 C2_RIGHTTOLEFT, /* AL */
2322 C2_NOTAPPLICABLE, /* NSM */
2323 C2_NOTAPPLICABLE, /* BN */
2324 C2_OTHERNEUTRAL /* LRE, LRO, RLE, RLO, PDF */
2327 if (count == -1) count = strlenW(src) + 1;
2331 while (count--) *chartype++ = get_char_typeW( *src++ ) & 0xfff;
2334 while (count--) *chartype++ = type2_map[get_char_typeW( *src++ ) >> 12];
2338 WARN("CT_CTYPE3: semi-stub.\n");
2342 WORD type1, type3 = 0; /* C3_NOTAPPLICABLE */
2344 type1 = get_char_typeW( *src++ ) & 0xfff;
2345 /* try to construct type3 from type1 */
2346 if(type1 & C1_SPACE) type3 |= C3_SYMBOL;
2347 if(type1 & C1_ALPHA) type3 |= C3_ALPHA;
2348 if ((c>=0x30A0)&&(c<=0x30FF)) type3 |= C3_KATAKANA;
2349 if ((c>=0x3040)&&(c<=0x309F)) type3 |= C3_HIRAGANA;
2350 if ((c>=0x4E00)&&(c<=0x9FAF)) type3 |= C3_IDEOGRAPH;
2351 if ((c>=0x0600)&&(c<=0x06FF)) type3 |= C3_KASHIDA;
2352 if ((c>=0x3000)&&(c<=0x303F)) type3 |= C3_SYMBOL;
2354 if ((c>=0xFF00)&&(c<=0xFF60)) type3 |= C3_FULLWIDTH;
2355 if ((c>=0xFF00)&&(c<=0xFF20)) type3 |= C3_SYMBOL;
2356 if ((c>=0xFF3B)&&(c<=0xFF40)) type3 |= C3_SYMBOL;
2357 if ((c>=0xFF5B)&&(c<=0xFF60)) type3 |= C3_SYMBOL;
2358 if ((c>=0xFF21)&&(c<=0xFF3A)) type3 |= C3_ALPHA;
2359 if ((c>=0xFF41)&&(c<=0xFF5A)) type3 |= C3_ALPHA;
2360 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_FULLWIDTH;
2361 if ((c>=0xFFE0)&&(c<=0xFFE6)) type3 |= C3_SYMBOL;
2363 if ((c>=0xFF61)&&(c<=0xFFDC)) type3 |= C3_HALFWIDTH;
2364 if ((c>=0xFF61)&&(c<=0xFF64)) type3 |= C3_SYMBOL;
2365 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_KATAKANA;
2366 if ((c>=0xFF65)&&(c<=0xFF9F)) type3 |= C3_ALPHA;
2367 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_HALFWIDTH;
2368 if ((c>=0xFFE8)&&(c<=0xFFEE)) type3 |= C3_SYMBOL;
2369 *chartype++ = type3;
2374 SetLastError( ERROR_INVALID_PARAMETER );
2381 /******************************************************************************
2382 * GetStringTypeExW (KERNEL32.@)
2384 * See GetStringTypeExA.
2386 BOOL WINAPI GetStringTypeExW( LCID locale, DWORD type, LPCWSTR src, INT count, LPWORD chartype )
2388 /* locale is ignored for Unicode */
2389 return GetStringTypeW( type, src, count, chartype );
2393 /******************************************************************************
2394 * GetStringTypeA (KERNEL32.@)
2396 * Get characteristics of the characters making up a string.
2399 * locale [I] Locale Id for the string
2400 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
2401 * src [I] String to analyse
2402 * count [I] Length of src in chars, or -1 if src is NUL terminated
2403 * chartype [O] Destination for the calculated characteristics
2406 * Success: TRUE. chartype is filled with the requested characteristics of each char
2408 * Failure: FALSE. Use GetLastError() to determine the cause.
2410 BOOL WINAPI GetStringTypeA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
2417 if(count == -1) count = strlen(src) + 1;
2419 if (!(cp = get_lcid_codepage( locale )))
2421 FIXME("For locale %04x using current ANSI code page\n", locale);
2425 countW = MultiByteToWideChar(cp, 0, src, count, NULL, 0);
2426 if((srcW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
2428 MultiByteToWideChar(cp, 0, src, count, srcW, countW);
2430 * NOTE: the target buffer has 1 word for each CHARACTER in the source
2431 * string, with multibyte characters there maybe be more bytes in count
2432 * than character space in the buffer!
2434 ret = GetStringTypeW(type, srcW, countW, chartype);
2435 HeapFree(GetProcessHeap(), 0, srcW);
2440 /******************************************************************************
2441 * GetStringTypeExA (KERNEL32.@)
2443 * Get characteristics of the characters making up a string.
2446 * locale [I] Locale Id for the string
2447 * type [I] CT_CTYPE1 = classification, CT_CTYPE2 = directionality, CT_CTYPE3 = typographic info
2448 * src [I] String to analyse
2449 * count [I] Length of src in chars, or -1 if src is NUL terminated
2450 * chartype [O] Destination for the calculated characteristics
2453 * Success: TRUE. chartype is filled with the requested characteristics of each char
2455 * Failure: FALSE. Use GetLastError() to determine the cause.
2457 BOOL WINAPI GetStringTypeExA( LCID locale, DWORD type, LPCSTR src, INT count, LPWORD chartype )
2459 return GetStringTypeA(locale, type, src, count, chartype);
2463 /*************************************************************************
2464 * LCMapStringW (KERNEL32.@)
2468 INT WINAPI LCMapStringW(LCID lcid, DWORD flags, LPCWSTR src, INT srclen,
2469 LPWSTR dst, INT dstlen)
2473 if (!src || !srclen || dstlen < 0)
2475 SetLastError(ERROR_INVALID_PARAMETER);
2479 /* mutually exclusive flags */
2480 if ((flags & (LCMAP_LOWERCASE | LCMAP_UPPERCASE)) == (LCMAP_LOWERCASE | LCMAP_UPPERCASE) ||
2481 (flags & (LCMAP_HIRAGANA | LCMAP_KATAKANA)) == (LCMAP_HIRAGANA | LCMAP_KATAKANA) ||
2482 (flags & (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH)) == (LCMAP_HALFWIDTH | LCMAP_FULLWIDTH) ||
2483 (flags & (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE)) == (LCMAP_TRADITIONAL_CHINESE | LCMAP_SIMPLIFIED_CHINESE))
2485 SetLastError(ERROR_INVALID_FLAGS);
2489 if (!dstlen) dst = NULL;
2491 lcid = ConvertDefaultLocale(lcid);
2493 if (flags & LCMAP_SORTKEY)
2498 SetLastError(ERROR_INVALID_FLAGS);
2502 if (srclen < 0) srclen = strlenW(src);
2504 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
2505 lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
2507 ret = wine_get_sortkey(flags, src, srclen, (char *)dst, dstlen);
2509 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2515 /* SORT_STRINGSORT must be used exclusively with LCMAP_SORTKEY */
2516 if (flags & SORT_STRINGSORT)
2518 SetLastError(ERROR_INVALID_FLAGS);
2522 if (srclen < 0) srclen = strlenW(src) + 1;
2524 TRACE("(0x%04x,0x%08x,%s,%d,%p,%d)\n",
2525 lcid, flags, debugstr_wn(src, srclen), srclen, dst, dstlen);
2527 if (!dst) /* return required string length */
2531 for (len = 0; srclen; src++, srclen--)
2534 /* tests show that win2k just ignores NORM_IGNORENONSPACE,
2535 * and skips white space and punctuation characters for
2536 * NORM_IGNORESYMBOLS.
2538 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
2545 if (flags & LCMAP_UPPERCASE)
2547 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
2550 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
2552 *dst_ptr++ = toupperW(wch);
2556 else if (flags & LCMAP_LOWERCASE)
2558 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
2561 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
2563 *dst_ptr++ = tolowerW(wch);
2571 SetLastError(ERROR_INVALID_FLAGS);
2574 for (dst_ptr = dst; srclen && dstlen; src++, srclen--)
2577 if ((flags & NORM_IGNORESYMBOLS) && (get_char_typeW(wch) & (C1_PUNCT | C1_SPACE)))
2586 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2590 return dst_ptr - dst;
2593 /*************************************************************************
2594 * LCMapStringA (KERNEL32.@)
2596 * Map characters in a locale sensitive string.
2599 * lcid [I] LCID for the conversion.
2600 * flags [I] Flags controlling the mapping (LCMAP_ constants from "winnls.h").
2601 * src [I] String to map
2602 * srclen [I] Length of src in chars, or -1 if src is NUL terminated
2603 * dst [O] Destination for mapped string
2604 * dstlen [I] Length of dst in characters
2607 * Success: The length of the mapped string in dst, including the NUL terminator.
2608 * Failure: 0. Use GetLastError() to determine the cause.
2610 INT WINAPI LCMapStringA(LCID lcid, DWORD flags, LPCSTR src, INT srclen,
2611 LPSTR dst, INT dstlen)
2613 WCHAR *bufW = NtCurrentTeb()->StaticUnicodeBuffer;
2615 INT ret = 0, srclenW, dstlenW;
2616 UINT locale_cp = CP_ACP;
2618 if (!src || !srclen || dstlen < 0)
2620 SetLastError(ERROR_INVALID_PARAMETER);
2624 if (!(flags & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
2626 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, bufW, 260);
2631 srclenW = MultiByteToWideChar(locale_cp, 0, src, srclen, NULL, 0);
2632 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
2635 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2638 MultiByteToWideChar(locale_cp, 0, src, srclen, srcW, srclenW);
2641 if (flags & LCMAP_SORTKEY)
2645 SetLastError(ERROR_INVALID_FLAGS);
2646 goto map_string_exit;
2648 ret = wine_get_sortkey(flags, srcW, srclenW, dst, dstlen);
2650 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2653 goto map_string_exit;
2656 if (flags & SORT_STRINGSORT)
2658 SetLastError(ERROR_INVALID_FLAGS);
2659 goto map_string_exit;
2662 dstlenW = LCMapStringW(lcid, flags, srcW, srclenW, NULL, 0);
2664 goto map_string_exit;
2666 dstW = HeapAlloc(GetProcessHeap(), 0, dstlenW * sizeof(WCHAR));
2669 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2670 goto map_string_exit;
2673 LCMapStringW(lcid, flags, srcW, srclenW, dstW, dstlenW);
2674 ret = WideCharToMultiByte(locale_cp, 0, dstW, dstlenW, dst, dstlen, NULL, NULL);
2675 HeapFree(GetProcessHeap(), 0, dstW);
2678 if (srcW != bufW) HeapFree(GetProcessHeap(), 0, srcW);
2682 /*************************************************************************
2683 * FoldStringA (KERNEL32.@)
2685 * Map characters in a string.
2688 * dwFlags [I] Flags controlling chars to map (MAP_ constants from "winnls.h")
2689 * src [I] String to map
2690 * srclen [I] Length of src, or -1 if src is NUL terminated
2691 * dst [O] Destination for mapped string
2692 * dstlen [I] Length of dst, or 0 to find the required length for the mapped string
2695 * Success: The length of the string written to dst, including the terminating NUL. If
2696 * dstlen is 0, the value returned is the same, but nothing is written to dst,
2697 * and dst may be NULL.
2698 * Failure: 0. Use GetLastError() to determine the cause.
2700 INT WINAPI FoldStringA(DWORD dwFlags, LPCSTR src, INT srclen,
2701 LPSTR dst, INT dstlen)
2703 INT ret = 0, srclenW = 0;
2704 WCHAR *srcW = NULL, *dstW = NULL;
2706 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
2708 SetLastError(ERROR_INVALID_PARAMETER);
2712 srclenW = MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
2713 src, srclen, NULL, 0);
2714 srcW = HeapAlloc(GetProcessHeap(), 0, srclenW * sizeof(WCHAR));
2718 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2719 goto FoldStringA_exit;
2722 MultiByteToWideChar(CP_ACP, dwFlags & MAP_COMPOSITE ? MB_COMPOSITE : 0,
2723 src, srclen, srcW, srclenW);
2725 dwFlags = (dwFlags & ~MAP_PRECOMPOSED) | MAP_FOLDCZONE;
2727 ret = FoldStringW(dwFlags, srcW, srclenW, NULL, 0);
2730 dstW = HeapAlloc(GetProcessHeap(), 0, ret * sizeof(WCHAR));
2734 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2735 goto FoldStringA_exit;
2738 ret = FoldStringW(dwFlags, srcW, srclenW, dstW, ret);
2739 if (!WideCharToMultiByte(CP_ACP, 0, dstW, ret, dst, dstlen, NULL, NULL))
2742 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2746 HeapFree(GetProcessHeap(), 0, dstW);
2749 HeapFree(GetProcessHeap(), 0, srcW);
2753 /*************************************************************************
2754 * FoldStringW (KERNEL32.@)
2758 INT WINAPI FoldStringW(DWORD dwFlags, LPCWSTR src, INT srclen,
2759 LPWSTR dst, INT dstlen)
2763 switch (dwFlags & (MAP_COMPOSITE|MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES))
2768 /* Fall through for dwFlags == 0 */
2769 case MAP_PRECOMPOSED|MAP_COMPOSITE:
2770 case MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES:
2771 case MAP_COMPOSITE|MAP_EXPAND_LIGATURES:
2772 SetLastError(ERROR_INVALID_FLAGS);
2776 if (!src || !srclen || dstlen < 0 || (dstlen && !dst) || src == dst)
2778 SetLastError(ERROR_INVALID_PARAMETER);
2782 ret = wine_fold_string(dwFlags, src, srclen, dst, dstlen);
2784 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2788 /******************************************************************************
2789 * CompareStringW (KERNEL32.@)
2791 * See CompareStringA.
2793 INT WINAPI CompareStringW(LCID lcid, DWORD style,
2794 LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
2800 SetLastError(ERROR_INVALID_PARAMETER);
2804 if( style & ~(NORM_IGNORECASE|NORM_IGNORENONSPACE|NORM_IGNORESYMBOLS|
2805 SORT_STRINGSORT|NORM_IGNOREKANATYPE|NORM_IGNOREWIDTH|LOCALE_USE_CP_ACP|0x10000000) )
2807 SetLastError(ERROR_INVALID_FLAGS);
2811 /* this style is related to diacritics in Arabic, Japanese, and Hebrew */
2812 if (style & 0x10000000)
2813 WARN("Ignoring unknown style 0x10000000\n");
2815 if (len1 < 0) len1 = strlenW(str1);
2816 if (len2 < 0) len2 = strlenW(str2);
2818 ret = wine_compare_string(style, str1, len1, str2, len2);
2820 if (ret) /* need to translate result */
2821 return (ret < 0) ? CSTR_LESS_THAN : CSTR_GREATER_THAN;
2825 /******************************************************************************
2826 * CompareStringA (KERNEL32.@)
2828 * Compare two locale sensitive strings.
2831 * lcid [I] LCID for the comparison
2832 * style [I] Flags for the comparison (NORM_ constants from "winnls.h").
2833 * str1 [I] First string to compare
2834 * len1 [I] Length of str1, or -1 if str1 is NUL terminated
2835 * str2 [I] Second string to compare
2836 * len2 [I] Length of str2, or -1 if str2 is NUL terminated
2839 * Success: CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN depending on whether
2840 * str1 is less than, equal to or greater than str2 respectively.
2841 * Failure: FALSE. Use GetLastError() to determine the cause.
2843 INT WINAPI CompareStringA(LCID lcid, DWORD style,
2844 LPCSTR str1, INT len1, LPCSTR str2, INT len2)
2846 WCHAR *buf1W = NtCurrentTeb()->StaticUnicodeBuffer;
2847 WCHAR *buf2W = buf1W + 130;
2848 LPWSTR str1W, str2W;
2849 INT len1W, len2W, ret;
2850 UINT locale_cp = CP_ACP;
2854 SetLastError(ERROR_INVALID_PARAMETER);
2857 if (len1 < 0) len1 = strlen(str1);
2858 if (len2 < 0) len2 = strlen(str2);
2860 if (!(style & LOCALE_USE_CP_ACP)) locale_cp = get_lcid_codepage( lcid );
2862 len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
2867 len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, NULL, 0);
2868 str1W = HeapAlloc(GetProcessHeap(), 0, len1W * sizeof(WCHAR));
2871 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2874 MultiByteToWideChar(locale_cp, 0, str1, len1, str1W, len1W);
2876 len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
2881 len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, NULL, 0);
2882 str2W = HeapAlloc(GetProcessHeap(), 0, len2W * sizeof(WCHAR));
2885 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
2886 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2889 MultiByteToWideChar(locale_cp, 0, str2, len2, str2W, len2W);
2892 ret = CompareStringW(lcid, style, str1W, len1W, str2W, len2W);
2894 if (str1W != buf1W) HeapFree(GetProcessHeap(), 0, str1W);
2895 if (str2W != buf2W) HeapFree(GetProcessHeap(), 0, str2W);
2899 /*************************************************************************
2900 * lstrcmp (KERNEL32.@)
2901 * lstrcmpA (KERNEL32.@)
2903 * Compare two strings using the current thread locale.
2906 * str1 [I] First string to compare
2907 * str2 [I] Second string to compare
2910 * Success: A number less than, equal to or greater than 0 depending on whether
2911 * str1 is less than, equal to or greater than str2 respectively.
2912 * Failure: FALSE. Use GetLastError() to determine the cause.
2914 int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
2918 if ((str1 == NULL) && (str2 == NULL)) return 0;
2919 if (str1 == NULL) return -1;
2920 if (str2 == NULL) return 1;
2922 ret = CompareStringA(GetThreadLocale(), LOCALE_USE_CP_ACP, str1, -1, str2, -1);
2928 /*************************************************************************
2929 * lstrcmpi (KERNEL32.@)
2930 * lstrcmpiA (KERNEL32.@)
2932 * Compare two strings using the current thread locale, ignoring case.
2935 * str1 [I] First string to compare
2936 * str2 [I] Second string to compare
2939 * Success: A number less than, equal to or greater than 0 depending on whether
2940 * str2 is less than, equal to or greater than str1 respectively.
2941 * Failure: FALSE. Use GetLastError() to determine the cause.
2943 int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
2947 if ((str1 == NULL) && (str2 == NULL)) return 0;
2948 if (str1 == NULL) return -1;
2949 if (str2 == NULL) return 1;
2951 ret = CompareStringA(GetThreadLocale(), NORM_IGNORECASE|LOCALE_USE_CP_ACP, str1, -1, str2, -1);
2957 /*************************************************************************
2958 * lstrcmpW (KERNEL32.@)
2962 int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
2966 if ((str1 == NULL) && (str2 == NULL)) return 0;
2967 if (str1 == NULL) return -1;
2968 if (str2 == NULL) return 1;
2970 ret = CompareStringW(GetThreadLocale(), 0, str1, -1, str2, -1);
2976 /*************************************************************************
2977 * lstrcmpiW (KERNEL32.@)
2981 int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
2985 if ((str1 == NULL) && (str2 == NULL)) return 0;
2986 if (str1 == NULL) return -1;
2987 if (str2 == NULL) return 1;
2989 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, -1, str2, -1);
2995 /******************************************************************************
2998 void LOCALE_Init(void)
3000 extern void CDECL __wine_init_codepages( const union cptable *ansi_cp, const union cptable *oem_cp,
3001 const union cptable *unix_cp );
3003 UINT ansi_cp = 1252, oem_cp = 437, mac_cp = 10000, unix_cp;
3006 /* MacOS doesn't set the locale environment variables so we have to do it ourselves */
3007 char user_locale[50];
3009 CFLocaleRef user_locale_ref = CFLocaleCopyCurrent();
3010 CFStringRef user_locale_lang_ref = CFLocaleGetValue( user_locale_ref, kCFLocaleLanguageCode );
3011 CFStringRef user_locale_country_ref = CFLocaleGetValue( user_locale_ref, kCFLocaleCountryCode );
3012 CFStringRef user_locale_string_ref;
3014 if (user_locale_country_ref)
3016 user_locale_string_ref = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@_%@.UTF-8"),
3017 user_locale_lang_ref, user_locale_country_ref);
3021 user_locale_string_ref = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@.UTF-8"),
3022 user_locale_lang_ref);
3025 CFStringGetCString( user_locale_string_ref, user_locale, sizeof(user_locale), kCFStringEncodingUTF8 );
3027 unix_cp = CP_UTF8; /* default to utf-8 even if we don't get a valid locale */
3028 setenv( "LANG", user_locale, 0 );
3029 TRACE( "setting locale to '%s'\n", user_locale );
3030 #endif /* __APPLE__ */
3032 setlocale( LC_ALL, "" );
3034 unix_cp = setup_unix_locales();
3035 if (!lcid_LC_MESSAGES) lcid_LC_MESSAGES = lcid_LC_CTYPE;
3038 /* Override lcid_LC_MESSAGES with user's preferred language if LC_MESSAGES is set to default */
3039 if (!getenv("LC_ALL") && !getenv("LC_MESSAGES"))
3041 /* Retrieve the preferred language as chosen in System Preferences. */
3042 /* If language is a less specific variant of locale (e.g. 'en' vs. 'en_US'),
3044 CFArrayRef all_locales = CFLocaleCopyAvailableLocaleIdentifiers();
3045 CFArrayRef preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL );
3046 CFStringRef user_language_string_ref;
3047 if (preferred_locales && CFArrayGetCount( preferred_locales ) &&
3048 (user_language_string_ref = CFArrayGetValueAtIndex( preferred_locales, 0 )) &&
3049 !CFEqual(user_language_string_ref, user_locale_lang_ref))
3051 struct locale_name locale_name;
3053 CFStringGetCString( user_language_string_ref, user_locale, sizeof(user_locale), kCFStringEncodingUTF8 );
3054 strcpynAtoW( buffer, user_locale, sizeof(buffer)/sizeof(WCHAR) );
3055 parse_locale_name( buffer, &locale_name );
3056 lcid_LC_MESSAGES = locale_name.lcid;
3057 TRACE( "setting lcid_LC_MESSAGES to '%s'\n", user_locale );
3059 CFRelease( all_locales );
3060 if (preferred_locales)
3061 CFRelease( preferred_locales );
3064 CFRelease( user_locale_ref );
3065 CFRelease( user_locale_string_ref );
3068 NtSetDefaultUILanguage( LANGIDFROMLCID(lcid_LC_MESSAGES) );
3069 NtSetDefaultLocale( TRUE, lcid_LC_MESSAGES );
3070 NtSetDefaultLocale( FALSE, lcid_LC_CTYPE );
3072 ansi_cp = get_lcid_codepage( LOCALE_USER_DEFAULT );
3073 GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTMACCODEPAGE | LOCALE_RETURN_NUMBER,
3074 (LPWSTR)&mac_cp, sizeof(mac_cp)/sizeof(WCHAR) );
3075 GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
3076 (LPWSTR)&oem_cp, sizeof(oem_cp)/sizeof(WCHAR) );
3078 GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTUNIXCODEPAGE | LOCALE_RETURN_NUMBER,
3079 (LPWSTR)&unix_cp, sizeof(unix_cp)/sizeof(WCHAR) );
3081 if (!(ansi_cptable = wine_cp_get_table( ansi_cp )))
3082 ansi_cptable = wine_cp_get_table( 1252 );
3083 if (!(oem_cptable = wine_cp_get_table( oem_cp )))
3084 oem_cptable = wine_cp_get_table( 437 );
3085 if (!(mac_cptable = wine_cp_get_table( mac_cp )))
3086 mac_cptable = wine_cp_get_table( 10000 );
3087 if (unix_cp != CP_UTF8)
3089 if (!(unix_cptable = wine_cp_get_table( unix_cp )))
3090 unix_cptable = wine_cp_get_table( 28591 );
3093 __wine_init_codepages( ansi_cptable, oem_cptable, unix_cptable );
3095 TRACE( "ansi=%03d oem=%03d mac=%03d unix=%03d\n",
3096 ansi_cptable->info.codepage, oem_cptable->info.codepage,
3097 mac_cptable->info.codepage, unix_cp );
3099 setlocale(LC_NUMERIC, "C"); /* FIXME: oleaut32 depends on this */
3102 static HANDLE NLS_RegOpenKey(HANDLE hRootKey, LPCWSTR szKeyName)
3104 UNICODE_STRING keyName;
3105 OBJECT_ATTRIBUTES attr;
3108 RtlInitUnicodeString( &keyName, szKeyName );
3109 InitializeObjectAttributes(&attr, &keyName, 0, hRootKey, NULL);
3111 if (NtOpenKey( &hkey, KEY_READ, &attr ) != STATUS_SUCCESS)
3117 static BOOL NLS_RegEnumSubKey(HANDLE hKey, UINT ulIndex, LPWSTR szKeyName,
3121 KEY_BASIC_INFORMATION *info = (KEY_BASIC_INFORMATION *)buffer;
3124 if (NtEnumerateKey( hKey, ulIndex, KeyBasicInformation, buffer,
3125 sizeof(buffer), &dwLen) != STATUS_SUCCESS ||
3126 info->NameLength > keyNameSize)
3131 TRACE("info->Name %s info->NameLength %d\n", debugstr_w(info->Name), info->NameLength);
3133 memcpy( szKeyName, info->Name, info->NameLength);
3134 szKeyName[info->NameLength / sizeof(WCHAR)] = '\0';
3136 TRACE("returning %s\n", debugstr_w(szKeyName));
3140 static BOOL NLS_RegEnumValue(HANDLE hKey, UINT ulIndex,
3141 LPWSTR szValueName, ULONG valueNameSize,
3142 LPWSTR szValueData, ULONG valueDataSize)
3145 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
3148 if (NtEnumerateValueKey( hKey, ulIndex, KeyValueFullInformation,
3149 buffer, sizeof(buffer), &dwLen ) != STATUS_SUCCESS ||
3150 info->NameLength > valueNameSize ||
3151 info->DataLength > valueDataSize)
3156 TRACE("info->Name %s info->DataLength %d\n", debugstr_w(info->Name), info->DataLength);
3158 memcpy( szValueName, info->Name, info->NameLength);
3159 szValueName[info->NameLength / sizeof(WCHAR)] = '\0';
3160 memcpy( szValueData, buffer + info->DataOffset, info->DataLength );
3161 szValueData[info->DataLength / sizeof(WCHAR)] = '\0';
3163 TRACE("returning %s %s\n", debugstr_w(szValueName), debugstr_w(szValueData));
3167 static BOOL NLS_RegGetDword(HANDLE hKey, LPCWSTR szValueName, DWORD *lpVal)
3170 const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
3171 DWORD dwSize = sizeof(buffer);
3172 UNICODE_STRING valueName;
3174 RtlInitUnicodeString( &valueName, szValueName );
3176 TRACE("%p, %s\n", hKey, debugstr_w(szValueName));
3177 if (NtQueryValueKey( hKey, &valueName, KeyValuePartialInformation,
3178 buffer, dwSize, &dwSize ) == STATUS_SUCCESS &&
3179 info->DataLength == sizeof(DWORD))
3181 memcpy(lpVal, info->Data, sizeof(DWORD));
3188 static BOOL NLS_GetLanguageGroupName(LGRPID lgrpid, LPWSTR szName, ULONG nameSize)
3191 LPCWSTR szResourceName = MAKEINTRESOURCEW(((lgrpid + 0x2000) >> 4) + 1);
3195 /* FIXME: Is it correct to use the system default langid? */
3196 langId = GetSystemDefaultLangID();
3198 if (SUBLANGID(langId) == SUBLANG_NEUTRAL)
3199 langId = MAKELANGID( PRIMARYLANGID(langId), SUBLANG_DEFAULT );
3201 hResource = FindResourceExW( kernel32_handle, (LPWSTR)RT_STRING, szResourceName, langId );
3205 HGLOBAL hResDir = LoadResource( kernel32_handle, hResource );
3209 ULONG iResourceIndex = lgrpid & 0xf;
3210 LPCWSTR lpResEntry = LockResource( hResDir );
3213 for (i = 0; i < iResourceIndex; i++)
3214 lpResEntry += *lpResEntry + 1;
3216 if (*lpResEntry < nameSize)
3218 memcpy( szName, lpResEntry + 1, *lpResEntry * sizeof(WCHAR) );
3219 szName[*lpResEntry] = '\0';
3224 FreeResource( hResource );
3229 /* Registry keys for NLS related information */
3231 static const WCHAR szCountryListName[] = {
3232 'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
3233 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
3234 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3235 'T','e','l','e','p','h','o','n','y','\\',
3236 'C','o','u','n','t','r','y',' ','L','i','s','t','\0'
3240 /* Callback function ptrs for EnumSystemLanguageGroupsA/W */
3243 LANGUAGEGROUP_ENUMPROCA procA;
3244 LANGUAGEGROUP_ENUMPROCW procW;
3247 } ENUMLANGUAGEGROUP_CALLBACKS;
3249 /* Internal implementation of EnumSystemLanguageGroupsA/W */
3250 static BOOL NLS_EnumSystemLanguageGroups(ENUMLANGUAGEGROUP_CALLBACKS *lpProcs)
3252 WCHAR szNumber[10], szValue[4];
3254 BOOL bContinue = TRUE;
3259 SetLastError(ERROR_INVALID_PARAMETER);
3263 switch (lpProcs->dwFlags)
3266 /* Default to LGRPID_INSTALLED */
3267 lpProcs->dwFlags = LGRPID_INSTALLED;
3268 /* Fall through... */
3269 case LGRPID_INSTALLED:
3270 case LGRPID_SUPPORTED:
3273 SetLastError(ERROR_INVALID_FLAGS);
3277 hKey = NLS_RegOpenKey( 0, szLangGroupsKeyName );
3280 FIXME("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
3284 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
3285 szValue, sizeof(szValue) ))
3287 BOOL bInstalled = szValue[0] == '1' ? TRUE : FALSE;
3288 LGRPID lgrpid = strtoulW( szNumber, NULL, 16 );
3290 TRACE("grpid %s (%sinstalled)\n", debugstr_w(szNumber),
3291 bInstalled ? "" : "not ");
3293 if (lpProcs->dwFlags == LGRPID_SUPPORTED || bInstalled)
3295 WCHAR szGrpName[48];
3297 if (!NLS_GetLanguageGroupName( lgrpid, szGrpName, sizeof(szGrpName) / sizeof(WCHAR) ))
3298 szGrpName[0] = '\0';
3301 bContinue = lpProcs->procW( lgrpid, szNumber, szGrpName, lpProcs->dwFlags,
3305 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
3306 char szGrpNameA[48];
3308 /* FIXME: MSDN doesn't say which code page the W->A translation uses,
3309 * or whether the language names are ever localised. Assume CP_ACP.
3312 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
3313 WideCharToMultiByte(CP_ACP, 0, szGrpName, -1, szGrpNameA, sizeof(szGrpNameA), 0, 0);
3315 bContinue = lpProcs->procA( lgrpid, szNumberA, szGrpNameA, lpProcs->dwFlags,
3335 /******************************************************************************
3336 * EnumSystemLanguageGroupsA (KERNEL32.@)
3338 * Call a users function for each language group available on the system.
3341 * pLangGrpEnumProc [I] Callback function to call for each language group
3342 * dwFlags [I] LGRPID_SUPPORTED=All Supported, LGRPID_INSTALLED=Installed only
3343 * lParam [I] User parameter to pass to pLangGrpEnumProc
3347 * Failure: FALSE. Use GetLastError() to determine the cause.
3349 BOOL WINAPI EnumSystemLanguageGroupsA(LANGUAGEGROUP_ENUMPROCA pLangGrpEnumProc,
3350 DWORD dwFlags, LONG_PTR lParam)
3352 ENUMLANGUAGEGROUP_CALLBACKS procs;
3354 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
3356 procs.procA = pLangGrpEnumProc;
3358 procs.dwFlags = dwFlags;
3359 procs.lParam = lParam;
3361 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
3364 /******************************************************************************
3365 * EnumSystemLanguageGroupsW (KERNEL32.@)
3367 * See EnumSystemLanguageGroupsA.
3369 BOOL WINAPI EnumSystemLanguageGroupsW(LANGUAGEGROUP_ENUMPROCW pLangGrpEnumProc,
3370 DWORD dwFlags, LONG_PTR lParam)
3372 ENUMLANGUAGEGROUP_CALLBACKS procs;
3374 TRACE("(%p,0x%08X,0x%08lX)\n", pLangGrpEnumProc, dwFlags, lParam);
3377 procs.procW = pLangGrpEnumProc;
3378 procs.dwFlags = dwFlags;
3379 procs.lParam = lParam;
3381 return NLS_EnumSystemLanguageGroups( pLangGrpEnumProc ? &procs : NULL);
3384 /******************************************************************************
3385 * IsValidLanguageGroup (KERNEL32.@)
3387 * Determine if a language group is supported and/or installed.
3390 * lgrpid [I] Language Group Id (LGRPID_ values from "winnls.h")
3391 * dwFlags [I] LGRPID_SUPPORTED=Supported, LGRPID_INSTALLED=Installed
3394 * TRUE, if lgrpid is supported and/or installed, according to dwFlags.
3397 BOOL WINAPI IsValidLanguageGroup(LGRPID lgrpid, DWORD dwFlags)
3399 static const WCHAR szFormat[] = { '%','x','\0' };
3400 WCHAR szValueName[16], szValue[2];
3401 BOOL bSupported = FALSE, bInstalled = FALSE;
3407 case LGRPID_INSTALLED:
3408 case LGRPID_SUPPORTED:
3410 hKey = NLS_RegOpenKey( 0, szLangGroupsKeyName );
3412 sprintfW( szValueName, szFormat, lgrpid );
3414 if (NLS_RegGetDword( hKey, szValueName, (LPDWORD)szValue ))
3418 if (szValue[0] == '1')
3428 if ((dwFlags == LGRPID_SUPPORTED && bSupported) ||
3429 (dwFlags == LGRPID_INSTALLED && bInstalled))
3435 /* Callback function ptrs for EnumLanguageGrouplocalesA/W */
3438 LANGGROUPLOCALE_ENUMPROCA procA;
3439 LANGGROUPLOCALE_ENUMPROCW procW;
3443 } ENUMLANGUAGEGROUPLOCALE_CALLBACKS;
3445 /* Internal implementation of EnumLanguageGrouplocalesA/W */
3446 static BOOL NLS_EnumLanguageGroupLocales(ENUMLANGUAGEGROUPLOCALE_CALLBACKS *lpProcs)
3448 static const WCHAR szAlternateSortsKeyName[] = {
3449 'A','l','t','e','r','n','a','t','e',' ','S','o','r','t','s','\0'
3451 WCHAR szNumber[10], szValue[4];
3453 BOOL bContinue = TRUE, bAlternate = FALSE;
3455 ULONG ulIndex = 1; /* Ignore default entry of 1st key */
3457 if (!lpProcs || !lpProcs->lgrpid || lpProcs->lgrpid > LGRPID_ARMENIAN)
3459 SetLastError(ERROR_INVALID_PARAMETER);
3463 if (lpProcs->dwFlags)
3465 SetLastError(ERROR_INVALID_FLAGS);
3469 hKey = NLS_RegOpenKey( 0, szLocaleKeyName );
3472 WARN("NLS registry key not found. Please apply the default registry file 'wine.inf'\n");
3476 if (NLS_RegEnumValue( hKey, ulIndex, szNumber, sizeof(szNumber),
3477 szValue, sizeof(szValue) ))
3479 lgrpid = strtoulW( szValue, NULL, 16 );
3481 TRACE("lcid %s, grpid %d (%smatched)\n", debugstr_w(szNumber),
3482 lgrpid, lgrpid == lpProcs->lgrpid ? "" : "not ");
3484 if (lgrpid == lpProcs->lgrpid)
3488 lcid = strtoulW( szNumber, NULL, 16 );
3490 /* FIXME: native returns extra text for a few (17/150) locales, e.g:
3491 * '00000437 ;Georgian'
3492 * At present we only pass the LCID string.
3496 bContinue = lpProcs->procW( lgrpid, lcid, szNumber, lpProcs->lParam );
3499 char szNumberA[sizeof(szNumber)/sizeof(WCHAR)];
3501 WideCharToMultiByte(CP_ACP, 0, szNumber, -1, szNumberA, sizeof(szNumberA), 0, 0);
3503 bContinue = lpProcs->procA( lgrpid, lcid, szNumberA, lpProcs->lParam );
3511 /* Finished enumerating this key */
3514 /* Enumerate alternate sorts also */
3515 hKey = NLS_RegOpenKey( hKey, szAlternateSortsKeyName );
3520 bContinue = FALSE; /* Finished both keys */
3533 /******************************************************************************
3534 * EnumLanguageGroupLocalesA (KERNEL32.@)
3536 * Call a users function for every locale in a language group available on the system.
3539 * pLangGrpLcEnumProc [I] Callback function to call for each locale
3540 * lgrpid [I] Language group (LGRPID_ values from "winnls.h")
3541 * dwFlags [I] Reserved, set to 0
3542 * lParam [I] User parameter to pass to pLangGrpLcEnumProc
3546 * Failure: FALSE. Use GetLastError() to determine the cause.
3548 BOOL WINAPI EnumLanguageGroupLocalesA(LANGGROUPLOCALE_ENUMPROCA pLangGrpLcEnumProc,
3549 LGRPID lgrpid, DWORD dwFlags, LONG_PTR lParam)
3551 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks;
3553 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
3555 callbacks.procA = pLangGrpLcEnumProc;
3556 callbacks.procW = NULL;
3557 callbacks.dwFlags = dwFlags;
3558 callbacks.lgrpid = lgrpid;
3559 callbacks.lParam = lParam;
3561 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
3564 /******************************************************************************
3565 * EnumLanguageGroupLocalesW (KERNEL32.@)
3567 * See EnumLanguageGroupLocalesA.
3569 BOOL WINAPI EnumLanguageGroupLocalesW(LANGGROUPLOCALE_ENUMPROCW pLangGrpLcEnumProc,
3570 LGRPID lgrpid, DWORD dwFlags, LONG_PTR lParam)
3572 ENUMLANGUAGEGROUPLOCALE_CALLBACKS callbacks;
3574 TRACE("(%p,0x%08X,0x%08X,0x%08lX)\n", pLangGrpLcEnumProc, lgrpid, dwFlags, lParam);
3576 callbacks.procA = NULL;
3577 callbacks.procW = pLangGrpLcEnumProc;
3578 callbacks.dwFlags = dwFlags;
3579 callbacks.lgrpid = lgrpid;
3580 callbacks.lParam = lParam;
3582 return NLS_EnumLanguageGroupLocales( pLangGrpLcEnumProc ? &callbacks : NULL );
3585 /******************************************************************************
3586 * EnumSystemGeoID (KERNEL32.@)
3588 * Call a users function for every location available on the system.
3591 * geoclass [I] Type of information desired (SYSGEOTYPE enum from "winnls.h")
3592 * reserved [I] Reserved, set to 0
3593 * pGeoEnumProc [I] Callback function to call for each location
3597 * Failure: FALSE. Use GetLastError() to determine the cause.
3599 BOOL WINAPI EnumSystemGeoID(GEOCLASS geoclass, GEOID reserved, GEO_ENUMPROC pGeoEnumProc)
3601 static const WCHAR szCountryCodeValueName[] = {
3602 'C','o','u','n','t','r','y','C','o','d','e','\0'
3608 TRACE("(0x%08X,0x%08X,%p)\n", geoclass, reserved, pGeoEnumProc);
3610 if (geoclass != GEOCLASS_NATION || reserved || !pGeoEnumProc)
3612 SetLastError(ERROR_INVALID_PARAMETER);
3616 hKey = NLS_RegOpenKey( 0, szCountryListName );
3618 while (NLS_RegEnumSubKey( hKey, ulIndex, szNumber, sizeof(szNumber) ))
3620 BOOL bContinue = TRUE;
3622 HANDLE hSubKey = NLS_RegOpenKey( hKey, szNumber );
3626 if (NLS_RegGetDword( hSubKey, szCountryCodeValueName, &dwGeoId ))
3628 TRACE("Got geoid %d\n", dwGeoId);
3630 if (!pGeoEnumProc( dwGeoId ))
3649 /******************************************************************************
3650 * InvalidateNLSCache (KERNEL32.@)
3652 * Invalidate the cache of NLS values.
3661 BOOL WINAPI InvalidateNLSCache(void)
3667 /******************************************************************************
3668 * GetUserGeoID (KERNEL32.@)
3670 GEOID WINAPI GetUserGeoID( GEOCLASS GeoClass )
3672 GEOID ret = GEOID_NOT_AVAILABLE;
3673 static const WCHAR geoW[] = {'G','e','o',0};
3674 static const WCHAR nationW[] = {'N','a','t','i','o','n',0};
3675 WCHAR bufferW[40], *end;
3677 HANDLE hkey, hSubkey = 0;
3678 UNICODE_STRING keyW;
3679 const KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)bufferW;
3680 RtlInitUnicodeString( &keyW, nationW );
3681 count = sizeof(bufferW);
3683 if(!(hkey = create_registry_key())) return ret;
3686 case GEOCLASS_NATION:
3687 if ((hSubkey = NLS_RegOpenKey(hkey, geoW)))
3689 if((NtQueryValueKey(hSubkey, &keyW, KeyValuePartialInformation,
3690 bufferW, count, &count) == STATUS_SUCCESS ) && info->DataLength)
3691 ret = strtolW((LPCWSTR)info->Data, &end, 10);
3694 case GEOCLASS_REGION:
3695 FIXME("GEOCLASS_REGION not handled yet\n");
3700 if (hSubkey) NtClose(hSubkey);
3704 /******************************************************************************
3705 * SetUserGeoID (KERNEL32.@)
3707 BOOL WINAPI SetUserGeoID( GEOID GeoID )
3709 static const WCHAR geoW[] = {'G','e','o',0};
3710 static const WCHAR nationW[] = {'N','a','t','i','o','n',0};
3711 static const WCHAR formatW[] = {'%','i',0};
3712 UNICODE_STRING nameW,keyW;
3714 OBJECT_ATTRIBUTES attr;
3717 if(!(hkey = create_registry_key())) return FALSE;
3719 attr.Length = sizeof(attr);
3720 attr.RootDirectory = hkey;
3721 attr.ObjectName = &nameW;
3722 attr.Attributes = 0;
3723 attr.SecurityDescriptor = NULL;
3724 attr.SecurityQualityOfService = NULL;
3725 RtlInitUnicodeString( &nameW, geoW );
3726 RtlInitUnicodeString( &keyW, nationW );
3728 if (NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) != STATUS_SUCCESS)
3731 NtClose(attr.RootDirectory);
3735 sprintfW(bufferW, formatW, GeoID);
3736 NtSetValueKey(hkey, &keyW, 0, REG_SZ, bufferW, (strlenW(bufferW) + 1) * sizeof(WCHAR));
3737 NtClose(attr.RootDirectory);
3746 UILANGUAGE_ENUMPROCA procA;
3747 UILANGUAGE_ENUMPROCW procW;
3751 } ENUM_UILANG_CALLBACK;
3753 static BOOL CALLBACK enum_uilang_proc_a( HMODULE hModule, LPCSTR type,
3754 LPCSTR name, WORD LangID, LONG_PTR lParam )
3756 ENUM_UILANG_CALLBACK *enum_uilang = (ENUM_UILANG_CALLBACK *)lParam;
3759 sprintf(buf, "%08x", (UINT)LangID);
3760 return enum_uilang->u.procA( buf, enum_uilang->param );
3763 static BOOL CALLBACK enum_uilang_proc_w( HMODULE hModule, LPCWSTR type,
3764 LPCWSTR name, WORD LangID, LONG_PTR lParam )
3766 static const WCHAR formatW[] = {'%','0','8','x',0};
3767 ENUM_UILANG_CALLBACK *enum_uilang = (ENUM_UILANG_CALLBACK *)lParam;
3770 sprintfW( buf, formatW, (UINT)LangID );
3771 return enum_uilang->u.procW( buf, enum_uilang->param );
3774 /******************************************************************************
3775 * EnumUILanguagesA (KERNEL32.@)
3777 BOOL WINAPI EnumUILanguagesA(UILANGUAGE_ENUMPROCA pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam)
3779 ENUM_UILANG_CALLBACK enum_uilang;
3781 TRACE("%p, %x, %lx\n", pUILangEnumProc, dwFlags, lParam);
3783 if(!pUILangEnumProc) {
3784 SetLastError(ERROR_INVALID_PARAMETER);
3788 SetLastError(ERROR_INVALID_FLAGS);
3792 enum_uilang.u.procA = pUILangEnumProc;
3793 enum_uilang.flags = dwFlags;
3794 enum_uilang.param = lParam;
3796 EnumResourceLanguagesA( kernel32_handle, (LPCSTR)RT_STRING,
3797 (LPCSTR)LOCALE_ILANGUAGE, enum_uilang_proc_a,
3798 (LONG_PTR)&enum_uilang);
3802 /******************************************************************************
3803 * EnumUILanguagesW (KERNEL32.@)
3805 BOOL WINAPI EnumUILanguagesW(UILANGUAGE_ENUMPROCW pUILangEnumProc, DWORD dwFlags, LONG_PTR lParam)
3807 ENUM_UILANG_CALLBACK enum_uilang;
3809 TRACE("%p, %x, %lx\n", pUILangEnumProc, dwFlags, lParam);
3812 if(!pUILangEnumProc) {
3813 SetLastError(ERROR_INVALID_PARAMETER);
3817 SetLastError(ERROR_INVALID_FLAGS);
3821 enum_uilang.u.procW = pUILangEnumProc;
3822 enum_uilang.flags = dwFlags;
3823 enum_uilang.param = lParam;
3825 EnumResourceLanguagesW( kernel32_handle, (LPCWSTR)RT_STRING,
3826 (LPCWSTR)LOCALE_ILANGUAGE, enum_uilang_proc_w,
3827 (LONG_PTR)&enum_uilang);
3831 INT WINAPI GetGeoInfoW(GEOID GeoId, GEOTYPE GeoType, LPWSTR lpGeoData,
3832 int cchData, LANGID language)
3834 FIXME("%d %d %p %d %d\n", GeoId, GeoType, lpGeoData, cchData, language);
3838 INT WINAPI GetGeoInfoA(GEOID GeoId, GEOTYPE GeoType, LPSTR lpGeoData,
3839 int cchData, LANGID language)
3841 FIXME("%d %d %p %d %d\n", GeoId, GeoType, lpGeoData, cchData, language);
3845 INT WINAPI GetUserDefaultLocaleName(LPWSTR localename, int buffersize)
3849 TRACE("%p, %d\n", localename, buffersize);
3851 userlcid = GetUserDefaultLCID();
3852 return LCIDToLocaleName(userlcid, localename, buffersize, 0);
3855 /******************************************************************************
3856 * NormalizeString (KERNEL32.@)
3858 INT WINAPI NormalizeString(NORM_FORM NormForm, LPCWSTR lpSrcString, INT cwSrcLength,
3859 LPWSTR lpDstString, INT cwDstLength)
3861 FIXME("%x %p %d %p %d\n", NormForm, lpSrcString, cwSrcLength, lpDstString, cwDstLength);
3862 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3866 /******************************************************************************
3867 * IsNormalizedString (KERNEL32.@)
3869 BOOL WINAPI IsNormalizedString(NORM_FORM NormForm, LPCWSTR lpString, INT cwLength)
3871 FIXME("%x %p %d\n", NormForm, lpString, cwLength);
3872 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3876 /******************************************************************************
3877 * IdnToAscii (KERNEL32.@)
3879 INT WINAPI IdnToAscii(DWORD dwFlags, LPCWSTR lpUnicodeCharStr, INT cchUnicodeChar,
3880 LPWSTR lpASCIICharStr, INT cchASCIIChar)
3882 FIXME("%x %p %d %p %d\n", dwFlags, lpUnicodeCharStr, cchUnicodeChar,
3883 lpASCIICharStr, cchASCIIChar);
3884 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3888 /******************************************************************************
3889 * IdnToNameprepUnicode (KERNEL32.@)
3891 INT WINAPI IdnToNameprepUnicode(DWORD dwFlags, LPCWSTR lpUnicodeCharStr, INT cchUnicodeChar,
3892 LPWSTR lpNameprepCharStr, INT cchNameprepChar)
3894 FIXME("%x %p %d %p %d\n", dwFlags, lpUnicodeCharStr, cchUnicodeChar,
3895 lpNameprepCharStr, cchNameprepChar);
3896 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3900 /******************************************************************************
3901 * IdnToUnicode (KERNEL32.@)
3903 INT WINAPI IdnToUnicode(DWORD dwFlags, LPCWSTR lpASCIICharStr, INT cchASCIIChar,
3904 LPWSTR lpUnicodeCharStr, INT cchUnicodeChar)
3906 FIXME("%x %p %d %p %d\n", dwFlags, lpASCIICharStr, cchASCIIChar,
3907 lpUnicodeCharStr, cchUnicodeChar);
3908 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);