source: trunk/src/kernel32/ole2nls.cpp@ 6607

Last change on this file since 6607 was 6607, checked in by phaller, 24 years ago

.

File size: 133.1 KB
Line 
1/*
2 * National Language Support library
3 *
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 * Copyright 2000 Julio César Gázquez
7 */
8
9#ifdef __WIN32OS2__
10#include <odin.h>
11#include <odinwrap.h>
12
13#include <string.h>
14#include <stdio.h>
15#include <heapstring.h>
16#include <ctype.h>
17#include <wcstr.h>
18#endif
19
20#include <string.h>
21#include <stdio.h>
22#include <ctype.h>
23#include <stdlib.h>
24#include <locale.h>
25
26#include "windef.h"
27#include "winbase.h"
28#include "wingdi.h"
29#include "winuser.h"
30#include "wine/unicode.h"
31#include "heap.h"
32#include "options.h"
33#include "winver.h"
34#include "winnls.h"
35#include "winreg.h"
36#include "winerror.h"
37#include "debugtools.h"
38
39#ifdef __WIN32OS2__
40#include <wctype.h>
41#include <unicode.h>
42
43#define DBG_LOCALLOG DBG_kernel32
44#include "dbglocal.h"
45
46ODINDEBUGCHANNEL(KERNEL32-OLE2NLS)
47#endif
48
49DEFAULT_DEBUG_CHANNEL(string);
50
51/* Locale name to id map. used by EnumSystemLocales, GetLocaleInfoA
52 * MUST contain all #defines from winnls.h
53 * last entry has NULL name, 0 id.
54 */
55#define LOCALE_ENTRY(x) {#x,LOCALE_##x}
56static const struct tagLOCALE_NAME2ID {
57 const char *name;
58 LCTYPE id;
59} locale_name2id[]= {
60 LOCALE_ENTRY(ILANGUAGE),
61 LOCALE_ENTRY(SLANGUAGE),
62 LOCALE_ENTRY(SENGLANGUAGE),
63 LOCALE_ENTRY(SABBREVLANGNAME),
64 LOCALE_ENTRY(SNATIVELANGNAME),
65 LOCALE_ENTRY(ICOUNTRY),
66 LOCALE_ENTRY(SCOUNTRY),
67 LOCALE_ENTRY(SENGCOUNTRY),
68 LOCALE_ENTRY(SABBREVCTRYNAME),
69 LOCALE_ENTRY(SNATIVECTRYNAME),
70 LOCALE_ENTRY(IDEFAULTLANGUAGE),
71 LOCALE_ENTRY(IDEFAULTCOUNTRY),
72 LOCALE_ENTRY(IDEFAULTCODEPAGE),
73 LOCALE_ENTRY(IDEFAULTANSICODEPAGE),
74 LOCALE_ENTRY(IDEFAULTMACCODEPAGE),
75 LOCALE_ENTRY(SLIST),
76 LOCALE_ENTRY(IMEASURE),
77 LOCALE_ENTRY(SDECIMAL),
78 LOCALE_ENTRY(STHOUSAND),
79 LOCALE_ENTRY(SGROUPING),
80 LOCALE_ENTRY(IDIGITS),
81 LOCALE_ENTRY(ILZERO),
82 LOCALE_ENTRY(INEGNUMBER),
83 LOCALE_ENTRY(SNATIVEDIGITS),
84 LOCALE_ENTRY(SCURRENCY),
85 LOCALE_ENTRY(SINTLSYMBOL),
86 LOCALE_ENTRY(SMONDECIMALSEP),
87 LOCALE_ENTRY(SMONTHOUSANDSEP),
88 LOCALE_ENTRY(SMONGROUPING),
89 LOCALE_ENTRY(ICURRDIGITS),
90 LOCALE_ENTRY(IINTLCURRDIGITS),
91 LOCALE_ENTRY(ICURRENCY),
92 LOCALE_ENTRY(INEGCURR),
93 LOCALE_ENTRY(SDATE),
94 LOCALE_ENTRY(STIME),
95 LOCALE_ENTRY(SSHORTDATE),
96 LOCALE_ENTRY(SLONGDATE),
97 LOCALE_ENTRY(STIMEFORMAT),
98 LOCALE_ENTRY(IDATE),
99 LOCALE_ENTRY(ILDATE),
100 LOCALE_ENTRY(ITIME),
101 LOCALE_ENTRY(ITIMEMARKPOSN),
102 LOCALE_ENTRY(ICENTURY),
103 LOCALE_ENTRY(ITLZERO),
104 LOCALE_ENTRY(IDAYLZERO),
105 LOCALE_ENTRY(IMONLZERO),
106 LOCALE_ENTRY(S1159),
107 LOCALE_ENTRY(S2359),
108 LOCALE_ENTRY(ICALENDARTYPE),
109 LOCALE_ENTRY(IOPTIONALCALENDAR),
110 LOCALE_ENTRY(IFIRSTDAYOFWEEK),
111 LOCALE_ENTRY(IFIRSTWEEKOFYEAR),
112 LOCALE_ENTRY(SDAYNAME1),
113 LOCALE_ENTRY(SDAYNAME2),
114 LOCALE_ENTRY(SDAYNAME3),
115 LOCALE_ENTRY(SDAYNAME4),
116 LOCALE_ENTRY(SDAYNAME5),
117 LOCALE_ENTRY(SDAYNAME6),
118 LOCALE_ENTRY(SDAYNAME7),
119 LOCALE_ENTRY(SABBREVDAYNAME1),
120 LOCALE_ENTRY(SABBREVDAYNAME2),
121 LOCALE_ENTRY(SABBREVDAYNAME3),
122 LOCALE_ENTRY(SABBREVDAYNAME4),
123 LOCALE_ENTRY(SABBREVDAYNAME5),
124 LOCALE_ENTRY(SABBREVDAYNAME6),
125 LOCALE_ENTRY(SABBREVDAYNAME7),
126 LOCALE_ENTRY(SMONTHNAME1),
127 LOCALE_ENTRY(SMONTHNAME2),
128 LOCALE_ENTRY(SMONTHNAME3),
129 LOCALE_ENTRY(SMONTHNAME4),
130 LOCALE_ENTRY(SMONTHNAME5),
131 LOCALE_ENTRY(SMONTHNAME6),
132 LOCALE_ENTRY(SMONTHNAME7),
133 LOCALE_ENTRY(SMONTHNAME8),
134 LOCALE_ENTRY(SMONTHNAME9),
135 LOCALE_ENTRY(SMONTHNAME10),
136 LOCALE_ENTRY(SMONTHNAME11),
137 LOCALE_ENTRY(SMONTHNAME12),
138 LOCALE_ENTRY(SMONTHNAME13),
139 LOCALE_ENTRY(SABBREVMONTHNAME1),
140 LOCALE_ENTRY(SABBREVMONTHNAME2),
141 LOCALE_ENTRY(SABBREVMONTHNAME3),
142 LOCALE_ENTRY(SABBREVMONTHNAME4),
143 LOCALE_ENTRY(SABBREVMONTHNAME5),
144 LOCALE_ENTRY(SABBREVMONTHNAME6),
145 LOCALE_ENTRY(SABBREVMONTHNAME7),
146 LOCALE_ENTRY(SABBREVMONTHNAME8),
147 LOCALE_ENTRY(SABBREVMONTHNAME9),
148 LOCALE_ENTRY(SABBREVMONTHNAME10),
149 LOCALE_ENTRY(SABBREVMONTHNAME11),
150 LOCALE_ENTRY(SABBREVMONTHNAME12),
151 LOCALE_ENTRY(SABBREVMONTHNAME13),
152 LOCALE_ENTRY(SPOSITIVESIGN),
153 LOCALE_ENTRY(SNEGATIVESIGN),
154 LOCALE_ENTRY(IPOSSIGNPOSN),
155 LOCALE_ENTRY(INEGSIGNPOSN),
156 LOCALE_ENTRY(IPOSSYMPRECEDES),
157 LOCALE_ENTRY(IPOSSEPBYSPACE),
158 LOCALE_ENTRY(INEGSYMPRECEDES),
159 LOCALE_ENTRY(INEGSEPBYSPACE),
160 LOCALE_ENTRY(FONTSIGNATURE),
161 LOCALE_ENTRY(SISO639LANGNAME),
162 LOCALE_ENTRY(SISO3166CTRYNAME),
163 {NULL,0}
164};
165
166static char *GetLocaleSubkeyName( DWORD lctype );
167
168#ifndef __WIN32OS2__
169/***********************************************************************
170 * GetUserDefaultLCID (KERNEL32.@)
171 * GetUserDefaultLCID (OLE2NLS.1)
172 */
173LCID WINAPI GetUserDefaultLCID(void)
174{
175 return MAKELCID( GetUserDefaultLangID() , SORT_DEFAULT );
176}
177
178/***********************************************************************
179 * GetSystemDefaultLCID (KERNEL32.@)
180 * GetSystemDefaultLCID (OLE2NLS.2)
181 */
182LCID WINAPI GetSystemDefaultLCID(void)
183{
184 return GetUserDefaultLCID();
185}
186#endif //__WIN32OS2__
187
188#define NLS_MAX_LANGUAGES 20
189typedef struct {
190 char lang[128];
191 char country[128];
192 LANGID found_lang_id[NLS_MAX_LANGUAGES];
193 char found_language[NLS_MAX_LANGUAGES][3];
194 char found_country[NLS_MAX_LANGUAGES][3];
195 int n_found;
196} LANG_FIND_DATA;
197
198static BOOL CALLBACK NLS_FindLanguageID_ProcA(HMODULE hModule, LPCSTR type,
199 LPCSTR name, WORD LangID, LONG lParam)
200{
201 LANG_FIND_DATA *l_data = (LANG_FIND_DATA *)lParam;
202 LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
203 char buf_language[128];
204 char buf_country[128];
205 char buf_en_language[128];
206
207 TRACE("%04X\n", (UINT)LangID);
208 if(PRIMARYLANGID(LangID) == LANG_NEUTRAL)
209 return TRUE; /* continue search */
210
211 buf_language[0] = 0;
212 buf_country[0] = 0;
213
214 GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME|LOCALE_NOUSEROVERRIDE,
215 buf_language, sizeof(buf_language));
216 TRACE("LOCALE_SISO639LANGNAME: %s\n", buf_language);
217
218 GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME|LOCALE_NOUSEROVERRIDE,
219 buf_country, sizeof(buf_country));
220 TRACE("LOCALE_SISO3166CTRYNAME: %s\n", buf_country);
221
222 if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_language))
223 {
224 if(l_data->country && strlen(l_data->country) > 0)
225 {
226 if(!strcasecmp(l_data->country, buf_country))
227 {
228 l_data->found_lang_id[0] = LangID;
229 l_data->n_found = 1;
230 TRACE("Found lang_id %04X for %s_%s\n", LangID, l_data->lang, l_data->country);
231 return FALSE; /* stop enumeration */
232 }
233 }
234 else /* l_data->country not specified */
235 {
236 if(l_data->n_found < NLS_MAX_LANGUAGES)
237 {
238 l_data->found_lang_id[l_data->n_found] = LangID;
239 strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
240 strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
241 l_data->n_found++;
242 TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
243 return TRUE; /* continue search */
244 }
245 }
246 }
247
248 /* Just in case, check LOCALE_SENGLANGUAGE too,
249 * in hope that possible alias name might have that value.
250 */
251 buf_en_language[0] = 0;
252 GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE|LOCALE_NOUSEROVERRIDE,
253 buf_en_language, sizeof(buf_en_language));
254 TRACE("LOCALE_SENGLANGUAGE: %s\n", buf_en_language);
255
256 if(l_data->lang && strlen(l_data->lang) > 0 && !strcasecmp(l_data->lang, buf_en_language))
257 {
258 l_data->found_lang_id[l_data->n_found] = LangID;
259 strncpy(l_data->found_country[l_data->n_found], buf_country, 3);
260 strncpy(l_data->found_language[l_data->n_found], buf_language, 3);
261 l_data->n_found++;
262 TRACE("Found lang_id %04X for %s\n", LangID, l_data->lang);
263 }
264
265 return TRUE; /* continue search */
266}
267
268/***********************************************************************
269 * NLS_GetLanguageID
270 *
271 * INPUT:
272 * Lang: a string whose two first chars are the iso name of a language.
273 * Country: a string whose two first chars are the iso name of country
274 * Charset: a string defining the chossen charset encoding
275 * Dialect: a string defining a variation of the locale
276 *
277 * all those values are from the standardized format of locale
278 * name in unix which is: Lang[_Country][.Charset][@Dialect]
279 *
280 * RETURNS:
281 * the numeric code of the language used by Windows
282 *
283 * FIXME: Charset and Dialect are not handled
284 */
285static LANGID NLS_GetLanguageID(LPCSTR Lang, LPCSTR Country, LPCSTR Charset, LPCSTR Dialect)
286{
287 LANG_FIND_DATA l_data;
288 char lang_string[256];
289
290 if(!Lang)
291 {
292 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
293 goto END;
294 }
295
296 memset(&l_data, 0, sizeof(LANG_FIND_DATA));
297 strncpy(l_data.lang, Lang, sizeof(l_data.lang));
298
299 if(Country && strlen(Country) > 0)
300 strncpy(l_data.country, Country, sizeof(l_data.country));
301
302 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
303 (LPCSTR)LOCALE_ILANGUAGE, NLS_FindLanguageID_ProcA, (LONG)&l_data);
304
305 strcpy(lang_string, l_data.lang);
306 if(l_data.country && strlen(l_data.country) > 0)
307 {
308 strcat(lang_string, "_");
309 strcat(lang_string, l_data.country);
310 }
311
312 if(!l_data.n_found)
313 {
314 if(l_data.country && strlen(l_data.country) > 0)
315 {
316 MESSAGE("Warning: Language '%s' was not found, retrying without country name...\n", lang_string);
317 l_data.country[0] = 0;
318 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
319 (LPCSTR)LOCALE_ILANGUAGE, NLS_FindLanguageID_ProcA, (LONG)&l_data);
320 }
321 }
322
323 /* Re-evaluate lang_string */
324 strcpy(lang_string, l_data.lang);
325 if(l_data.country && strlen(l_data.country) > 0)
326 {
327 strcat(lang_string, "_");
328 strcat(lang_string, l_data.country);
329 }
330
331 if(!l_data.n_found)
332 {
333 MESSAGE("Warning: Language '%s' was not recognized, defaulting to English\n", lang_string);
334 l_data.found_lang_id[0] = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
335 }
336 else
337 {
338 if(l_data.n_found == 1)
339 TRACE("For language '%s' lang_id %04X was found\n", lang_string, l_data.found_lang_id[0]);
340 else /* l_data->n_found > 1 */
341 {
342 int i;
343 MESSAGE("For language '%s' several language ids were found:\n", lang_string);
344 for(i = 0; i < l_data.n_found; i++)
345 MESSAGE("%s_%s - %04X; ", l_data.found_language[i], l_data.found_country[i], l_data.found_lang_id[i]);
346
347 MESSAGE("\nInstead of using first in the list, suggest to define\n"
348 "your LANG environment variable like this: LANG=%s_%s\n",
349 l_data.found_language[0], l_data.found_country[0]);
350 }
351 }
352END:
353 TRACE("Returning %04X\n", l_data.found_lang_id[0]);
354 return l_data.found_lang_id[0];
355}
356#ifndef __WIN32OS2__
357/***********************************************************************
358 * GetUserDefaultLangID (KERNEL32.@)
359 * GetUserDefaultLangID (OLE2NLS.3)
360 */
361LANGID WINAPI GetUserDefaultLangID(void)
362{
363 /* caching result, if defined from environment, which should (?) not change during a WINE session */
364 static LANGID userLCID = 0;
365
366 if (userLCID == 0)
367 {
368 char buf[256];
369 char *lang,*country,*charset,*dialect,*next;
370
371 if (GetEnvironmentVariableA( "LANGUAGE", buf, sizeof(buf) )) goto ok;
372 if (GetEnvironmentVariableA( "LANG", buf, sizeof(buf) )) goto ok;
373 if (GetEnvironmentVariableA( "LC_ALL", buf, sizeof(buf) )) goto ok;
374 if (GetEnvironmentVariableA( "LC_MESSAGES", buf, sizeof(buf) )) goto ok;
375 if (GetEnvironmentVariableA( "LC_CTYPE", buf, sizeof(buf) )) goto ok;
376
377 return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
378
379 ok:
380 if (!strcmp(buf,"POSIX") || !strcmp(buf,"C"))
381 return userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
382
383 lang=buf;
384
385 do {
386 next=strchr(lang,':'); if (next) *next++='\0';
387 dialect=strchr(lang,'@'); if (dialect) *dialect++='\0';
388 charset=strchr(lang,'.'); if (charset) *charset++='\0';
389 country=strchr(lang,'_'); if (country) *country++='\0';
390
391 userLCID = NLS_GetLanguageID(lang, country, charset, dialect);
392
393 lang=next;
394 } while (lang && !userLCID);
395
396 if (!userLCID)
397 {
398 MESSAGE( "Warning: language '%s' not recognized, defaulting to English\n",
399 buf );
400 userLCID = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
401 }
402 }
403 return userLCID;
404}
405
406/***********************************************************************
407 * GetSystemDefaultLangID (KERNEL32.@)
408 * GetSystemDefaultLangID (OLE2NLS.4)
409 */
410LANGID WINAPI GetSystemDefaultLangID(void)
411{
412 return GetUserDefaultLangID();
413}
414#endif //__WIN32OS2__
415/******************************************************************************
416 * ConvertDefaultLocale (KERNEL32.@)
417 */
418LCID WINAPI ConvertDefaultLocale (LCID lcid)
419{ switch (lcid)
420 { case LOCALE_SYSTEM_DEFAULT:
421 return GetSystemDefaultLCID();
422 case LOCALE_USER_DEFAULT:
423 return GetUserDefaultLCID();
424 case LOCALE_NEUTRAL:
425 return MAKELCID (LANG_NEUTRAL, SUBLANG_NEUTRAL);
426 }
427 return MAKELANGID( PRIMARYLANGID(lcid), SUBLANG_NEUTRAL);
428}
429
430/* Enhanced version of LoadStringW.
431 * It takes LanguageId to find and load language dependant resources.
432 * Resource is copied as is: "binary" strings are not truncated.
433 * Return: length of resource + 1 to distinguish absent resources
434 * from the resources with zero length.
435 */
436static INT NLS_LoadStringExW(HMODULE hModule, LANGID lang_id, UINT res_id, LPWSTR buffer, INT buflen)
437{
438 HRSRC hrsrc;
439 HGLOBAL hmem;
440 WCHAR *p;
441 int string_num;
442 int i;
443
444 hrsrc = FindResourceExW(hModule, RT_STRINGW, (LPCWSTR)((res_id >> 4) + 1), lang_id);
445
446 if(!hrsrc) return 0;
447 hmem = LoadResource(hModule, hrsrc);
448 if(!hmem) return 0;
449
450#ifdef __WIN32OS2__
451 p = (WCHAR*)LockResource(hmem);
452#else
453 p = LockResource(hmem);
454#endif
455 string_num = res_id & 0x000f;
456 for(i = 0; i < string_num; i++)
457 p += *p + 1;
458
459 TRACE("strlen = %d\n", (int)*p );
460
461 if (buffer == NULL) return *p;
462 i = min(buflen - 1, *p);
463 if (i > 0) {
464 memcpy(buffer, p + 1, i * sizeof (WCHAR));
465 buffer[i] = (WCHAR) 0;
466 } else {
467 if (buflen > 1)
468 buffer[0] = (WCHAR) 0;
469 }
470
471 FreeResource(hmem);
472 TRACE("%s loaded!\n", debugstr_w(buffer));
473 return (i + 1);
474}
475#ifndef __WIN32OS2__
476/******************************************************************************
477 * GetLocaleInfoA (KERNEL32.@)
478 *
479 * NOTES
480 * LANG_NEUTRAL is equal to LOCALE_SYSTEM_DEFAULT
481 *
482 * MS online documentation states that the string returned is NULL terminated
483 * except for LOCALE_FONTSIGNATURE which "will return a non-NULL
484 * terminated string".
485 */
486INT WINAPI GetLocaleInfoA(LCID lcid,LCTYPE LCType,LPSTR buf,INT len)
487{
488 LPCSTR retString = NULL;
489 int found = 0, i;
490 char *pacKey;
491 char acBuffer[128];
492 DWORD dwBufferSize=128;
493 BOOL NoUserOverride;
494
495 TRACE("(lcid=0x%lx,lctype=0x%lx,%p,%x)\n",lcid,LCType,buf,len);
496
497 if (len && (! buf) ) {
498 SetLastError(ERROR_INSUFFICIENT_BUFFER);
499 return 0;
500 }
501
502 if (lcid == LOCALE_NEUTRAL || lcid == LANG_SYSTEM_DEFAULT)
503 {
504 lcid = GetSystemDefaultLCID();
505 }
506 else if (lcid == LANG_USER_DEFAULT) /*0x800*/
507 {
508 lcid = GetUserDefaultLCID();
509 }
510
511 /* LOCALE_NOUSEROVERRIDE means: do not get user redefined settings
512 from the registry. Instead, use system default values. */
513 NoUserOverride = (LCType & LOCALE_NOUSEROVERRIDE) != 0;
514
515 LCType &= ~(LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP);
516
517 /* First, check if it's in the registry. */
518 /* All user customized values are stored in the registry by SetLocaleInfo */
519 if ( !NoUserOverride && (pacKey = GetLocaleSubkeyName(LCType)) )
520 {
521 char acRealKey[128];
522 HKEY hKey;
523
524 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
525
526 if ( RegOpenKeyExA( HKEY_CURRENT_USER, acRealKey,
527 0, KEY_READ, &hKey) == ERROR_SUCCESS )
528 {
529 if ( RegQueryValueExA( hKey, NULL, NULL, NULL, (LPBYTE)acBuffer,
530 &dwBufferSize ) == ERROR_SUCCESS )
531 {
532 retString = acBuffer;
533 found = 1;
534 }
535 RegCloseKey(hKey);
536 }
537 }
538
539 /* If not in the registry, get it from the NLS entries. */
540 if(!found) {
541 WCHAR wcBuffer[128];
542 int res_size;
543
544 /* check if language is registered in the kernel32 resources */
545 if((res_size = NLS_LoadStringExW(GetModuleHandleA("KERNEL32"), LANGIDFROMLCID(lcid),
546 LCType, wcBuffer, sizeof(wcBuffer)/sizeof(wcBuffer[0])))) {
547 WideCharToMultiByte(CP_ACP, 0, wcBuffer, res_size, acBuffer, dwBufferSize, NULL, NULL);
548 retString = acBuffer;
549 found = 1;
550 }
551 }
552
553 /* if not found report a most descriptive error */
554 if(!found) {
555 retString=0;
556 /* If we are through all of this, retLen should not be zero anymore.
557 If it is, the value is not supported */
558 i=0;
559 while (locale_name2id[i].name!=NULL) {
560 if (LCType == locale_name2id[i].id) {
561 retString = locale_name2id[i].name;
562 break;
563 }
564 i++;
565 }
566 if(!retString)
567 FIXME("Unkown LC type %lX\n", LCType);
568 else
569 FIXME("'%s' is not defined for your language (%04X).\n"
570 "Please define it in dlls/kernel/nls/YourLanguage.nls\n"
571 "and submit patch for inclusion into the next Wine release.\n",
572 retString, LOWORD(lcid));
573 SetLastError(ERROR_INVALID_PARAMETER);
574 return 0;
575 }
576
577 /* a FONTSIGNATURE is not a string, just 6 DWORDs */
578 if (LCType == LOCALE_FONTSIGNATURE) {
579 if (len) {
580 len = (len < sizeof(FONTSIGNATURE)) ? len : sizeof(FONTSIGNATURE);
581 memcpy(buf, retString, len);
582 return len;
583 }
584 return sizeof(FONTSIGNATURE);
585 }
586 /* if len=0 return only the length, don't touch the buffer*/
587 if (len) {
588 lstrcpynA(buf,retString,len);
589 return strlen(buf) + 1;
590 }
591 return strlen(retString)+1;
592}
593
594/******************************************************************************
595 * GetLocaleInfoW (KERNEL32.@)
596 *
597 * NOTES
598 * MS documentation states that len "specifies the size, in bytes (ANSI version)
599 * or characters (Unicode version), of" wbuf. Thus the number returned is
600 * the same between GetLocaleInfoW and GetLocaleInfoA.
601 */
602INT WINAPI GetLocaleInfoW(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT len)
603{ WORD wlen;
604 LPSTR abuf;
605
606 if (len && (! wbuf) )
607 { SetLastError(ERROR_INSUFFICIENT_BUFFER);
608 return 0;
609 }
610
611 abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
612 wlen = GetLocaleInfoA(lcid, LCType, abuf, len);
613
614 if (wlen && len) /* if len=0 return only the length*/
615 MultiByteToWideChar( CP_ACP, 0, abuf, -1, wbuf, len );
616
617 HeapFree(GetProcessHeap(),0,abuf);
618 return wlen;
619}
620#endif //__WIN32OS2__
621
622/******************************************************************************
623 *
624 * GetLocaleSubkeyName [helper function]
625 *
626 * - For use with the registry.
627 * - Gets the registry subkey name for a given lctype.
628 */
629static char *GetLocaleSubkeyName( DWORD lctype )
630{
631 char *pacKey=NULL;
632
633 switch ( lctype )
634 {
635 /* These values are used by SetLocaleInfo and GetLocaleInfo, and
636 * the values are stored in the registry, confirmed under Windows,
637 * for the ones that actually assign pacKey. Cases that aren't finished
638 * have not been confirmed, so that must be done before they can be
639 * added.
640 */
641 case LOCALE_SDATE : /* The date separator. */
642 pacKey = "sDate";
643 break;
644 case LOCALE_ICURRDIGITS:
645 pacKey = "iCurrDigits";
646 break;
647 case LOCALE_SDECIMAL :
648 pacKey = "sDecimal";
649 break;
650 case LOCALE_ICURRENCY:
651 pacKey = "iCurrency";
652 break;
653 case LOCALE_SGROUPING :
654 pacKey = "sGrouping";
655 break;
656 case LOCALE_IDIGITS:
657 pacKey = "iDigits";
658 break;
659 case LOCALE_SLIST :
660 pacKey = "sList";
661 break;
662 /* case LOCALE_ICALENDARTYPE: */
663 /* case LOCALE_IFIRSTDAYOFWEEK: */
664#ifdef __WIN32OS2__
665 case LOCALE_IFIRSTDAYOFWEEK:
666 pacKey = "iFirstDayOfWeek";
667 break;
668#endif
669 /* case LOCALE_IFIRSTWEEKOFYEAR: */
670 /* case LOCALE_SYEARMONTH : */
671 /* case LOCALE_SPOSITIVESIGN : */
672 /* case LOCALE_IPAPERSIZE: */
673 /* break; */
674 case LOCALE_SLONGDATE :
675 pacKey = "sLongDate";
676 break;
677 case LOCALE_SMONDECIMALSEP :
678 pacKey = "sMonDecimalSep";
679 break;
680 case LOCALE_SMONGROUPING:
681 pacKey = "sMonGrouping";
682 break;
683 case LOCALE_IMEASURE:
684 pacKey = "iMeasure";
685 break;
686 case LOCALE_SMONTHOUSANDSEP :
687 pacKey = "sMonThousandSep";
688 break;
689 case LOCALE_INEGCURR:
690 pacKey = "iNegCurr";
691 break;
692 case LOCALE_SNEGATIVESIGN :
693 pacKey = "sNegativeSign";
694 break;
695 case LOCALE_INEGNUMBER:
696 pacKey = "iNegNumber";
697 break;
698 case LOCALE_SSHORTDATE :
699 pacKey = "sShortDate";
700 break;
701 case LOCALE_ILDATE: /* Long Date format ordering specifier. */
702 pacKey = "iLDate";
703 break;
704 case LOCALE_ILZERO:
705 pacKey = "iLZero";
706 break;
707 case LOCALE_ITLZERO:
708 pacKey = "iTLZero";
709 break;
710 case LOCALE_ITIME: /* Time format specifier. */
711 pacKey = "iTime";
712 break;
713 case LOCALE_STHOUSAND :
714 pacKey = "sThousand";
715 break;
716 case LOCALE_S1159: /* AM */
717 pacKey = "s1159";
718 break;
719 case LOCALE_STIME:
720 pacKey = "sTime";
721 break;
722 case LOCALE_S2359: /* PM */
723 pacKey = "s2359";
724 break;
725 case LOCALE_STIMEFORMAT :
726 pacKey = "sTimeFormat";
727 break;
728 case LOCALE_SCURRENCY:
729 pacKey = "sCurrency";
730 break;
731
732 /* The following are not listed under MSDN as supported,
733 * but seem to be used and also stored in the registry.
734 */
735
736 case LOCALE_IDATE:
737 pacKey = "iDate";
738 break;
739 case LOCALE_SCOUNTRY:
740 pacKey = "sCountry";
741 break;
742 case LOCALE_ICOUNTRY:
743 pacKey = "iCountry";
744 break;
745 case LOCALE_SLANGUAGE:
746 pacKey = "sLanguage";
747 break;
748
749 default:
750 break;
751 }
752
753 return( pacKey );
754}
755
756/******************************************************************************
757 * SetLocaleInfoA [KERNEL32.656]
758 */
759BOOL WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
760{
761 HKEY hKey;
762 char *pacKey;
763 char acRealKey[128];
764
765 if ( (pacKey = GetLocaleSubkeyName(lctype)) )
766 {
767 sprintf( acRealKey, "Control Panel\\International\\%s", pacKey );
768 if ( RegCreateKeyA( HKEY_CURRENT_USER, acRealKey,
769 &hKey ) == ERROR_SUCCESS )
770 {
771 if ( RegSetValueExA( hKey, NULL, 0, REG_SZ,
772#ifdef __WIN32OS2__
773 (LPBYTE)data, strlen(data)+1 ) != ERROR_SUCCESS )
774#else
775 data, strlen(data)+1 ) != ERROR_SUCCESS )
776#endif
777 {
778 ERR("SetLocaleInfoA: %s did not work\n", pacKey );
779 }
780 RegCloseKey( hKey );
781 }
782 }
783 else
784 {
785 FIXME("(%ld,%ld,%s): stub\n",lcid,lctype,data);
786 }
787 return TRUE;
788}
789
790#ifdef __WIN32OS2__
791/*****************************************************************************
792 * Name : BOOL SetLocaleInfoW
793 * Purpose : The SetLocaleInfoW function sets an item of locale information.
794 * It does so by making an entry in the process portion of the
795 * locale table. This setting only affects the user override portion
796 * of the locale settings; it does not set the system defaults.
797 * Only certain types of locale information, or LCTYPE values, can
798 * be set by this function. See the following Remarks section for a
799 * list of valid LCTYPE values.
800 * The locale information is always passed in as a null-terminated
801 * Unicode string in the Unicode (W) version of the function, and as
802 * a null-terminated ANSI string in the ANSI (A) version. No integers
803 * are allowed by this function; any numeric values must be specified
804 * as Unicode or ANSI text. Each LCTYPE has a particular format, as
805 * noted in Locale Identifiers.
806 * Parameters: LCID Locale locale identifier
807 * LCTYPE LCType type of information to set
808 * LPCTSTR lpLCData pointer to information to set
809 * Variables :
810 * Result : TRUE / FALSE
811 * Remark :
812 * Status : UNTESTED STUB
813 *
814 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
815 *****************************************************************************/
816
817BOOL WIN32API SetLocaleInfoW(LCID Locale,
818 LCTYPE LCType,
819 LPCWSTR lpLCData)
820{
821 dprintf(("KERNEL32: SetLocaleInfoW(%08xh,%08xh,%08xh) not implemented.\n",
822 Locale,
823 LCType,
824 lpLCData));
825
826 return (FALSE);
827}
828#endif
829
830/******************************************************************************
831 * IsValidLocale [KERNEL32.489]
832 */
833BOOL WINAPI IsValidLocale(LCID lcid,DWORD flags)
834{
835#ifdef __WIN32OS2__
836 //SvL/MN: code below doesn't work -> winhlp32 complains about different language helpfiles
837 dprintf(("KERNEL32: IsValidLocale, always returns TRUE\n"));
838 return TRUE;
839#else
840 /* check if language is registered in the kernel32 resources */
841 if(!FindResourceExW(GetModuleHandleA("KERNEL32"), RT_STRINGW, (LPCWSTR)LOCALE_ILANGUAGE, LOWORD(lcid)))
842 return FALSE;
843 else
844 return TRUE;
845#endif
846}
847
848static BOOL CALLBACK EnumResourceLanguagesProcW(HMODULE hModule, LPCWSTR type,
849 LPCWSTR name, WORD LangID, LONG lParam)
850{
851 CHAR bufA[20];
852 WCHAR bufW[20];
853 LOCALE_ENUMPROCW lpfnLocaleEnum = (LOCALE_ENUMPROCW)lParam;
854 sprintf(bufA, "%08X", (UINT)LangID);
855 MultiByteToWideChar(CP_ACP, 0, bufA, -1, bufW, sizeof(bufW)/sizeof(bufW[0]));
856 return lpfnLocaleEnum(bufW);
857}
858
859/******************************************************************************
860 * EnumSystemLocalesW [KERNEL32.209]
861 */
862BOOL WINAPI EnumSystemLocalesW( LOCALE_ENUMPROCW lpfnLocaleEnum,
863 DWORD flags )
864{
865 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
866
867 EnumResourceLanguagesW(GetModuleHandleA("KERNEL32"), RT_STRINGW,
868 (LPCWSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcW,
869 (LONG)lpfnLocaleEnum);
870
871 return TRUE;
872}
873
874static BOOL CALLBACK EnumResourceLanguagesProcA(HMODULE hModule, LPCSTR type,
875 LPCSTR name, WORD LangID, LONG lParam)
876{
877 CHAR bufA[20];
878 LOCALE_ENUMPROCA lpfnLocaleEnum = (LOCALE_ENUMPROCA)lParam;
879 sprintf(bufA, "%08X", (UINT)LangID);
880 return lpfnLocaleEnum(bufA);
881}
882
883/******************************************************************************
884 * EnumSystemLocalesA [KERNEL32.208]
885 */
886BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA lpfnLocaleEnum,
887 DWORD flags)
888{
889 TRACE("(%p,%08lx)\n", lpfnLocaleEnum,flags);
890
891 EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
892 (LPCSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcA,
893 (LONG)lpfnLocaleEnum);
894
895 return TRUE;
896}
897
898static const unsigned char CT_CType2_LUT[] = {
899 C2_NOTAPPLICABLE, /* - 0 */
900 C2_NOTAPPLICABLE, /* - 1 */
901 C2_NOTAPPLICABLE, /* - 2 */
902 C2_NOTAPPLICABLE, /* - 3 */
903 C2_NOTAPPLICABLE, /* - 4 */
904 C2_NOTAPPLICABLE, /* - 5 */
905 C2_NOTAPPLICABLE, /* - 6 */
906 C2_NOTAPPLICABLE, /* - 7 */
907 C2_NOTAPPLICABLE, /* - 8 */
908 C2_SEGMENTSEPARATOR, /* - 9 */
909 C2_NOTAPPLICABLE, /* - 10 */
910 C2_NOTAPPLICABLE, /* - 11 */
911 C2_NOTAPPLICABLE, /* - 12 */
912 C2_NOTAPPLICABLE, /* - 13 */
913 C2_NOTAPPLICABLE, /* - 14 */
914 C2_NOTAPPLICABLE, /* - 15 */
915 C2_NOTAPPLICABLE, /* - 16 */
916 C2_NOTAPPLICABLE, /* - 17 */
917 C2_NOTAPPLICABLE, /* - 18 */
918 C2_NOTAPPLICABLE, /* - 19 */
919 C2_NOTAPPLICABLE, /* - 20 */
920 C2_NOTAPPLICABLE, /* - 21 */
921 C2_NOTAPPLICABLE, /* - 22 */
922 C2_NOTAPPLICABLE, /* - 23 */
923 C2_NOTAPPLICABLE, /* - 24 */
924 C2_NOTAPPLICABLE, /* - 25 */
925 C2_NOTAPPLICABLE, /* - 26 */
926 C2_NOTAPPLICABLE, /* - 27 */
927 C2_NOTAPPLICABLE, /* - 28 */
928 C2_NOTAPPLICABLE, /* - 29 */
929 C2_NOTAPPLICABLE, /* - 30 */
930 C2_NOTAPPLICABLE, /* - 31 */
931 C2_WHITESPACE, /* - 32 */
932 C2_OTHERNEUTRAL, /* ! - 33 */
933 C2_OTHERNEUTRAL, /* " - 34 */ /* " */
934 C2_EUROPETERMINATOR, /* # - 35 */
935 C2_EUROPETERMINATOR, /* $ - 36 */
936 C2_EUROPETERMINATOR, /* % - 37 */
937 C2_LEFTTORIGHT, /* & - 38 */
938 C2_OTHERNEUTRAL, /* ' - 39 */
939 C2_OTHERNEUTRAL, /* ( - 40 */
940 C2_OTHERNEUTRAL, /* ) - 41 */
941 C2_OTHERNEUTRAL, /* * - 42 */
942 C2_EUROPETERMINATOR, /* + - 43 */
943 C2_COMMONSEPARATOR, /* , - 44 */
944 C2_EUROPETERMINATOR, /* - - 45 */
945 C2_EUROPESEPARATOR, /* . - 46 */
946 C2_EUROPESEPARATOR, /* / - 47 */
947 C2_EUROPENUMBER, /* 0 - 48 */
948 C2_EUROPENUMBER, /* 1 - 49 */
949 C2_EUROPENUMBER, /* 2 - 50 */
950 C2_EUROPENUMBER, /* 3 - 51 */
951 C2_EUROPENUMBER, /* 4 - 52 */
952 C2_EUROPENUMBER, /* 5 - 53 */
953 C2_EUROPENUMBER, /* 6 - 54 */
954 C2_EUROPENUMBER, /* 7 - 55 */
955 C2_EUROPENUMBER, /* 8 - 56 */
956 C2_EUROPENUMBER, /* 9 - 57 */
957 C2_COMMONSEPARATOR, /* : - 58 */
958 C2_OTHERNEUTRAL, /* ; - 59 */
959 C2_OTHERNEUTRAL, /* < - 60 */
960 C2_OTHERNEUTRAL, /* = - 61 */
961 C2_OTHERNEUTRAL, /* > - 62 */
962 C2_OTHERNEUTRAL, /* ? - 63 */
963 C2_LEFTTORIGHT, /* @ - 64 */
964 C2_LEFTTORIGHT, /* A - 65 */
965 C2_LEFTTORIGHT, /* B - 66 */
966 C2_LEFTTORIGHT, /* C - 67 */
967 C2_LEFTTORIGHT, /* D - 68 */
968 C2_LEFTTORIGHT, /* E - 69 */
969 C2_LEFTTORIGHT, /* F - 70 */
970 C2_LEFTTORIGHT, /* G - 71 */
971 C2_LEFTTORIGHT, /* H - 72 */
972 C2_LEFTTORIGHT, /* I - 73 */
973 C2_LEFTTORIGHT, /* J - 74 */
974 C2_LEFTTORIGHT, /* K - 75 */
975 C2_LEFTTORIGHT, /* L - 76 */
976 C2_LEFTTORIGHT, /* M - 77 */
977 C2_LEFTTORIGHT, /* N - 78 */
978 C2_LEFTTORIGHT, /* O - 79 */
979 C2_LEFTTORIGHT, /* P - 80 */
980 C2_LEFTTORIGHT, /* Q - 81 */
981 C2_LEFTTORIGHT, /* R - 82 */
982 C2_LEFTTORIGHT, /* S - 83 */
983 C2_LEFTTORIGHT, /* T - 84 */
984 C2_LEFTTORIGHT, /* U - 85 */
985 C2_LEFTTORIGHT, /* V - 86 */
986 C2_LEFTTORIGHT, /* W - 87 */
987 C2_LEFTTORIGHT, /* X - 88 */
988 C2_LEFTTORIGHT, /* Y - 89 */
989 C2_LEFTTORIGHT, /* Z - 90 */
990 C2_OTHERNEUTRAL, /* [ - 91 */
991 C2_OTHERNEUTRAL, /* \ - 92 */
992 C2_OTHERNEUTRAL, /* ] - 93 */
993 C2_OTHERNEUTRAL, /* ^ - 94 */
994 C2_OTHERNEUTRAL, /* _ - 95 */
995 C2_OTHERNEUTRAL, /* ` - 96 */
996 C2_LEFTTORIGHT, /* a - 97 */
997 C2_LEFTTORIGHT, /* b - 98 */
998 C2_LEFTTORIGHT, /* c - 99 */
999 C2_LEFTTORIGHT, /* d - 100 */
1000 C2_LEFTTORIGHT, /* e - 101 */
1001 C2_LEFTTORIGHT, /* f - 102 */
1002 C2_LEFTTORIGHT, /* g - 103 */
1003 C2_LEFTTORIGHT, /* h - 104 */
1004 C2_LEFTTORIGHT, /* i - 105 */
1005 C2_LEFTTORIGHT, /* j - 106 */
1006 C2_LEFTTORIGHT, /* k - 107 */
1007 C2_LEFTTORIGHT, /* l - 108 */
1008 C2_LEFTTORIGHT, /* m - 109 */
1009 C2_LEFTTORIGHT, /* n - 110 */
1010 C2_LEFTTORIGHT, /* o - 111 */
1011 C2_LEFTTORIGHT, /* p - 112 */
1012 C2_LEFTTORIGHT, /* q - 113 */
1013 C2_LEFTTORIGHT, /* r - 114 */
1014 C2_LEFTTORIGHT, /* s - 115 */
1015 C2_LEFTTORIGHT, /* t - 116 */
1016 C2_LEFTTORIGHT, /* u - 117 */
1017 C2_LEFTTORIGHT, /* v - 118 */
1018 C2_LEFTTORIGHT, /* w - 119 */
1019 C2_LEFTTORIGHT, /* x - 120 */
1020 C2_LEFTTORIGHT, /* y - 121 */
1021 C2_LEFTTORIGHT, /* z - 122 */
1022 C2_OTHERNEUTRAL, /* { - 123 */
1023 C2_OTHERNEUTRAL, /* | - 124 */
1024 C2_OTHERNEUTRAL, /* } - 125 */
1025 C2_OTHERNEUTRAL, /* ~ - 126 */
1026 C2_NOTAPPLICABLE, /*  - 127 */
1027 C2_NOTAPPLICABLE, /* € - 128 */
1028 C2_NOTAPPLICABLE, /*  - 129 */
1029 C2_OTHERNEUTRAL, /* ‚ - 130 */
1030 C2_LEFTTORIGHT, /* ƒ - 131 */
1031 C2_OTHERNEUTRAL, /* „ - 132 */
1032 C2_OTHERNEUTRAL, /* …
1033 - 133 */
1034 C2_OTHERNEUTRAL, /* † - 134 */
1035 C2_OTHERNEUTRAL, /* ‡ - 135 */
1036 C2_LEFTTORIGHT, /* ˆ - 136 */
1037 C2_EUROPETERMINATOR, /* ‰ - 137 */
1038 C2_LEFTTORIGHT, /* Š - 138 */
1039 C2_OTHERNEUTRAL, /* ‹ - 139 */
1040 C2_LEFTTORIGHT, /* Œ - 140 */
1041 C2_NOTAPPLICABLE, /*  - 141 */
1042 C2_NOTAPPLICABLE, /* Ž - 142 */
1043 C2_NOTAPPLICABLE, /*  - 143 */
1044 C2_NOTAPPLICABLE, /*  - 144 */
1045 C2_OTHERNEUTRAL, /* ‘ - 145 */
1046 C2_OTHERNEUTRAL, /* ’ - 146 */
1047 C2_OTHERNEUTRAL, /* “ - 147 */
1048 C2_OTHERNEUTRAL, /* ” - 148 */
1049 C2_OTHERNEUTRAL, /* • - 149 */
1050 C2_OTHERNEUTRAL, /* – - 150 */
1051 C2_OTHERNEUTRAL, /* — - 151 */
1052 C2_LEFTTORIGHT, /* ˜ - 152 */
1053 C2_OTHERNEUTRAL, /* ™ - 153 */
1054 C2_LEFTTORIGHT, /* š - 154 */
1055 C2_OTHERNEUTRAL, /* › - 155 */
1056 C2_LEFTTORIGHT, /* œ - 156 */
1057 C2_NOTAPPLICABLE, /*  - 157 */
1058 C2_NOTAPPLICABLE, /* ž - 158 */
1059 C2_LEFTTORIGHT, /* Ÿ - 159 */
1060 C2_WHITESPACE, /*   - 160 */
1061 C2_OTHERNEUTRAL, /* ¡ - 161 */
1062 C2_EUROPETERMINATOR, /* ¢ - 162 */
1063 C2_EUROPETERMINATOR, /* £ - 163 */
1064 C2_EUROPETERMINATOR, /* € - 164 */
1065 C2_EUROPETERMINATOR, /* ¥ - 165 */
1066 C2_OTHERNEUTRAL, /* Š - 166 */
1067 C2_OTHERNEUTRAL, /* § - 167 */
1068 C2_OTHERNEUTRAL, /* š - 168 */
1069 C2_OTHERNEUTRAL, /* © - 169 */
1070 C2_OTHERNEUTRAL, /* ª - 170 */
1071 C2_OTHERNEUTRAL, /* « - 171 */
1072 C2_OTHERNEUTRAL, /* ¬ - 172 */
1073 C2_OTHERNEUTRAL, /* ­ - 173 */
1074 C2_OTHERNEUTRAL, /* ® - 174 */
1075 C2_OTHERNEUTRAL, /* ¯ - 175 */
1076 C2_EUROPETERMINATOR, /* ° - 176 */
1077 C2_EUROPETERMINATOR, /* ± - 177 */
1078 C2_EUROPENUMBER, /* ² - 178 */
1079 C2_EUROPENUMBER, /* ³ - 179 */
1080 C2_OTHERNEUTRAL, /* Ž - 180 */
1081 C2_OTHERNEUTRAL, /* µ - 181 */
1082 C2_OTHERNEUTRAL, /* ¶ - 182 */
1083 C2_OTHERNEUTRAL, /* · - 183 */
1084 C2_OTHERNEUTRAL, /* ž - 184 */
1085 C2_EUROPENUMBER, /* ¹ - 185 */
1086 C2_OTHERNEUTRAL, /* º - 186 */
1087 C2_OTHERNEUTRAL, /* » - 187 */
1088 C2_OTHERNEUTRAL, /* Œ - 188 */
1089 C2_OTHERNEUTRAL, /* œ - 189 */
1090 C2_OTHERNEUTRAL, /* Ÿ - 190 */
1091 C2_OTHERNEUTRAL, /* ¿ - 191 */
1092 C2_LEFTTORIGHT, /* À - 192 */
1093 C2_LEFTTORIGHT, /* Á - 193 */
1094 C2_LEFTTORIGHT, /* Â - 194 */
1095 C2_LEFTTORIGHT, /* Ã - 195 */
1096 C2_LEFTTORIGHT, /* Ä - 196 */
1097 C2_LEFTTORIGHT, /* Å - 197 */
1098 C2_LEFTTORIGHT, /* Æ - 198 */
1099 C2_LEFTTORIGHT, /* Ç - 199 */
1100 C2_LEFTTORIGHT, /* È - 200 */
1101 C2_LEFTTORIGHT, /* É - 201 */
1102 C2_LEFTTORIGHT, /* Ê - 202 */
1103 C2_LEFTTORIGHT, /* Ë - 203 */
1104 C2_LEFTTORIGHT, /* Ì - 204 */
1105 C2_LEFTTORIGHT, /* Í - 205 */
1106 C2_LEFTTORIGHT, /* Î - 206 */
1107 C2_LEFTTORIGHT, /* Ï - 207 */
1108 C2_LEFTTORIGHT, /* Ð - 208 */
1109 C2_LEFTTORIGHT, /* Ñ - 209 */
1110 C2_LEFTTORIGHT, /* Ò - 210 */
1111 C2_LEFTTORIGHT, /* Ó - 211 */
1112 C2_LEFTTORIGHT, /* Ô - 212 */
1113 C2_LEFTTORIGHT, /* Õ - 213 */
1114 C2_LEFTTORIGHT, /* Ö - 214 */
1115 C2_OTHERNEUTRAL, /* × - 215 */
1116 C2_LEFTTORIGHT, /* Ø - 216 */
1117 C2_LEFTTORIGHT, /* Ù - 217 */
1118 C2_LEFTTORIGHT, /* Ú - 218 */
1119 C2_LEFTTORIGHT, /* Û - 219 */
1120 C2_LEFTTORIGHT, /* Ü - 220 */
1121 C2_LEFTTORIGHT, /* Ý - 221 */
1122 C2_LEFTTORIGHT, /* Þ - 222 */
1123 C2_LEFTTORIGHT, /* ß - 223 */
1124 C2_LEFTTORIGHT, /* à - 224 */
1125 C2_LEFTTORIGHT, /* á - 225 */
1126 C2_LEFTTORIGHT, /* â - 226 */
1127 C2_LEFTTORIGHT, /* ã - 227 */
1128 C2_LEFTTORIGHT, /* ä - 228 */
1129 C2_LEFTTORIGHT, /* å - 229 */
1130 C2_LEFTTORIGHT, /* æ - 230 */
1131 C2_LEFTTORIGHT, /* ç - 231 */
1132 C2_LEFTTORIGHT, /* è - 232 */
1133 C2_LEFTTORIGHT, /* é - 233 */
1134 C2_LEFTTORIGHT, /* ê - 234 */
1135 C2_LEFTTORIGHT, /* ë - 235 */
1136 C2_LEFTTORIGHT, /* ì - 236 */
1137 C2_LEFTTORIGHT, /* í - 237 */
1138 C2_LEFTTORIGHT, /* î - 238 */
1139 C2_LEFTTORIGHT, /* ï - 239 */
1140 C2_LEFTTORIGHT, /* ð - 240 */
1141 C2_LEFTTORIGHT, /* ñ - 241 */
1142 C2_LEFTTORIGHT, /* ò - 242 */
1143 C2_LEFTTORIGHT, /* ó - 243 */
1144 C2_LEFTTORIGHT, /* ô - 244 */
1145 C2_LEFTTORIGHT, /* õ - 245 */
1146 C2_LEFTTORIGHT, /* ö - 246 */
1147 C2_OTHERNEUTRAL, /* ÷ - 247 */
1148 C2_LEFTTORIGHT, /* ø - 248 */
1149 C2_LEFTTORIGHT, /* ù - 249 */
1150 C2_LEFTTORIGHT, /* ú - 250 */
1151 C2_LEFTTORIGHT, /* û - 251 */
1152 C2_LEFTTORIGHT, /* ü - 252 */
1153 C2_LEFTTORIGHT, /* ý - 253 */
1154 C2_LEFTTORIGHT, /* þ - 254 */
1155 C2_LEFTTORIGHT /* ÿ - 255 */
1156};
1157
1158const WORD OLE2NLS_CT_CType3_LUT[] = {
1159 0x0000, /* - 0 */
1160 0x0000, /* - 1 */
1161 0x0000, /* - 2 */
1162 0x0000, /* - 3 */
1163 0x0000, /* - 4 */
1164 0x0000, /* - 5 */
1165 0x0000, /* - 6 */
1166 0x0000, /* - 7 */
1167 0x0000, /* - 8 */
1168 0x0008, /* - 9 */
1169 0x0008, /* - 10 */
1170 0x0008, /* - 11 */
1171 0x0008, /* - 12 */
1172 0x0008, /* - 13 */
1173 0x0000, /* - 14 */
1174 0x0000, /* - 15 */
1175 0x0000, /* - 16 */
1176 0x0000, /* - 17 */
1177 0x0000, /* - 18 */
1178 0x0000, /* - 19 */
1179 0x0000, /* - 20 */
1180 0x0000, /* - 21 */
1181 0x0000, /* - 22 */
1182 0x0000, /* - 23 */
1183 0x0000, /* - 24 */
1184 0x0000, /* - 25 */
1185 0x0000, /* - 26 */
1186 0x0000, /* - 27 */
1187 0x0000, /* - 28 */
1188 0x0000, /* - 29 */
1189 0x0000, /* - 30 */
1190 0x0000, /* - 31 */
1191 0x0048, /* - 32 */
1192 0x0048, /* ! - 33 */
1193 0x0448, /* " - 34 */ /* " */
1194 0x0048, /* # - 35 */
1195 0x0448, /* $ - 36 */
1196 0x0048, /* % - 37 */
1197 0x0048, /* & - 38 */
1198 0x0440, /* ' - 39 */
1199 0x0048, /* ( - 40 */
1200 0x0048, /* ) - 41 */
1201 0x0048, /* * - 42 */
1202 0x0048, /* + - 43 */
1203 0x0048, /* , - 44 */
1204 0x0440, /* - - 45 */
1205 0x0048, /* . - 46 */
1206 0x0448, /* / - 47 */
1207 0x0040, /* 0 - 48 */
1208 0x0040, /* 1 - 49 */
1209 0x0040, /* 2 - 50 */
1210 0x0040, /* 3 - 51 */
1211 0x0040, /* 4 - 52 */
1212 0x0040, /* 5 - 53 */
1213 0x0040, /* 6 - 54 */
1214 0x0040, /* 7 - 55 */
1215 0x0040, /* 8 - 56 */
1216 0x0040, /* 9 - 57 */
1217 0x0048, /* : - 58 */
1218 0x0048, /* ; - 59 */
1219 0x0048, /* < - 60 */
1220 0x0448, /* = - 61 */
1221 0x0048, /* > - 62 */
1222 0x0048, /* ? - 63 */
1223 0x0448, /* @ - 64 */
1224 0x8040, /* A - 65 */
1225 0x8040, /* B - 66 */
1226 0x8040, /* C - 67 */
1227 0x8040, /* D - 68 */
1228 0x8040, /* E - 69 */
1229 0x8040, /* F - 70 */
1230 0x8040, /* G - 71 */
1231 0x8040, /* H - 72 */
1232 0x8040, /* I - 73 */
1233 0x8040, /* J - 74 */
1234 0x8040, /* K - 75 */
1235 0x8040, /* L - 76 */
1236 0x8040, /* M - 77 */
1237 0x8040, /* N - 78 */
1238 0x8040, /* O - 79 */
1239 0x8040, /* P - 80 */
1240 0x8040, /* Q - 81 */
1241 0x8040, /* R - 82 */
1242 0x8040, /* S - 83 */
1243 0x8040, /* T - 84 */
1244 0x8040, /* U - 85 */
1245 0x8040, /* V - 86 */
1246 0x8040, /* W - 87 */
1247 0x8040, /* X - 88 */
1248 0x8040, /* Y - 89 */
1249 0x8040, /* Z - 90 */
1250 0x0048, /* [ - 91 */
1251 0x0448, /* \ - 92 */
1252 0x0048, /* ] - 93 */
1253 0x0448, /* ^ - 94 */
1254 0x0448, /* _ - 95 */
1255 0x0448, /* ` - 96 */
1256 0x8040, /* a - 97 */
1257 0x8040, /* b - 98 */
1258 0x8040, /* c - 99 */
1259 0x8040, /* d - 100 */
1260 0x8040, /* e - 101 */
1261 0x8040, /* f - 102 */
1262 0x8040, /* g - 103 */
1263 0x8040, /* h - 104 */
1264 0x8040, /* i - 105 */
1265 0x8040, /* j - 106 */
1266 0x8040, /* k - 107 */
1267 0x8040, /* l - 108 */
1268 0x8040, /* m - 109 */
1269 0x8040, /* n - 110 */
1270 0x8040, /* o - 111 */
1271 0x8040, /* p - 112 */
1272 0x8040, /* q - 113 */
1273 0x8040, /* r - 114 */
1274 0x8040, /* s - 115 */
1275 0x8040, /* t - 116 */
1276 0x8040, /* u - 117 */
1277 0x8040, /* v - 118 */
1278 0x8040, /* w - 119 */
1279 0x8040, /* x - 120 */
1280 0x8040, /* y - 121 */
1281 0x8040, /* z - 122 */
1282 0x0048, /* { - 123 */
1283 0x0048, /* | - 124 */
1284 0x0048, /* } - 125 */
1285 0x0448, /* ~ - 126 */
1286 0x0000, /*  - 127 */
1287 0x0000, /* € - 128 */
1288 0x0000, /*  - 129 */
1289 0x0008, /* ‚ - 130 */
1290 0x8000, /* ƒ - 131 */
1291 0x0008, /* „ - 132 */
1292 0x0008, /* …
1293 - 133 */
1294 0x0008, /* † - 134 */
1295 0x0008, /* ‡ - 135 */
1296 0x0001, /* ˆ - 136 */
1297 0x0008, /* ‰ - 137 */
1298 0x8003, /* Š - 138 */
1299 0x0008, /* ‹ - 139 */
1300 0x8000, /* Œ - 140 */
1301 0x0000, /*  - 141 */
1302 0x0000, /* Ž - 142 */
1303 0x0000, /*  - 143 */
1304 0x0000, /*  - 144 */
1305 0x0088, /* ‘ - 145 */
1306 0x0088, /* ’ - 146 */
1307 0x0088, /* “ - 147 */
1308 0x0088, /* ” - 148 */
1309 0x0008, /* • - 149 */
1310 0x0400, /* – - 150 */
1311 0x0400, /* — - 151 */
1312 0x0408, /* ˜ - 152 */
1313 0x0000, /* ™ - 153 */
1314 0x8003, /* š - 154 */
1315 0x0008, /* › - 155 */
1316 0x8000, /* œ - 156 */
1317 0x0000, /*  - 157 */
1318 0x0000, /* ž - 158 */
1319 0x8003, /* Ÿ - 159 */
1320 0x0008, /*   - 160 */
1321 0x0008, /* ¡ - 161 */
1322 0x0048, /* ¢ - 162 */
1323 0x0048, /* £ - 163 */
1324 0x0008, /* € - 164 */
1325 0x0048, /* ¥ - 165 */
1326 0x0048, /* Š - 166 */
1327 0x0008, /* § - 167 */
1328 0x0408, /* š - 168 */
1329 0x0008, /* © - 169 */
1330 0x0400, /* ª - 170 */
1331 0x0008, /* « - 171 */
1332 0x0048, /* ¬ - 172 */
1333 0x0408, /* ­ - 173 */
1334 0x0008, /* ® - 174 */
1335 0x0448, /* ¯ - 175 */
1336 0x0008, /* ° - 176 */
1337 0x0008, /* ± - 177 */
1338 0x0000, /* ² - 178 */
1339 0x0000, /* ³ - 179 */
1340 0x0408, /* Ž - 180 */
1341 0x0008, /* µ - 181 */
1342 0x0008, /* ¶ - 182 */
1343 0x0008, /* · - 183 */
1344 0x0408, /* ž - 184 */
1345 0x0000, /* ¹ - 185 */
1346 0x0400, /* º - 186 */
1347 0x0008, /* » - 187 */
1348 0x0000, /* Œ - 188 */
1349 0x0000, /* œ - 189 */
1350 0x0000, /* Ÿ - 190 */
1351 0x0008, /* ¿ - 191 */
1352 0x8003, /* À - 192 */
1353 0x8003, /* Á - 193 */
1354 0x8003, /* Â - 194 */
1355 0x8003, /* Ã - 195 */
1356 0x8003, /* Ä - 196 */
1357 0x8003, /* Å - 197 */
1358 0x8000, /* Æ - 198 */
1359 0x8003, /* Ç - 199 */
1360 0x8003, /* È - 200 */
1361 0x8003, /* É - 201 */
1362 0x8003, /* Ê - 202 */
1363 0x8003, /* Ë - 203 */
1364 0x8003, /* Ì - 204 */
1365 0x8003, /* Í - 205 */
1366 0x8003, /* Î - 206 */
1367 0x8003, /* Ï - 207 */
1368 0x8000, /* Ð - 208 */
1369 0x8003, /* Ñ - 209 */
1370 0x8003, /* Ò - 210 */
1371 0x8003, /* Ó - 211 */
1372 0x8003, /* Ô - 212 */
1373 0x8003, /* Õ - 213 */
1374 0x8003, /* Ö - 214 */
1375 0x0008, /* × - 215 */
1376 0x8003, /* Ø - 216 */
1377 0x8003, /* Ù - 217 */
1378 0x8003, /* Ú - 218 */
1379 0x8003, /* Û - 219 */
1380 0x8003, /* Ü - 220 */
1381 0x8003, /* Ý - 221 */
1382 0x8000, /* Þ - 222 */
1383 0x8000, /* ß - 223 */
1384 0x8003, /* à - 224 */
1385 0x8003, /* á - 225 */
1386 0x8003, /* â - 226 */
1387 0x8003, /* ã - 227 */
1388 0x8003, /* ä - 228 */
1389 0x8003, /* å - 229 */
1390 0x8000, /* æ - 230 */
1391 0x8003, /* ç - 231 */
1392 0x8003, /* è - 232 */
1393 0x8003, /* é - 233 */
1394 0x8003, /* ê - 234 */
1395 0x8003, /* ë - 235 */
1396 0x8003, /* ì - 236 */
1397 0x8003, /* í - 237 */
1398 0x8003, /* î - 238 */
1399 0x8003, /* ï - 239 */
1400 0x8000, /* ð - 240 */
1401 0x8003, /* ñ - 241 */
1402 0x8003, /* ò - 242 */
1403 0x8003, /* ó - 243 */
1404 0x8003, /* ô - 244 */
1405 0x8003, /* õ - 245 */
1406 0x8003, /* ö - 246 */
1407 0x0008, /* ÷ - 247 */
1408 0x8003, /* ø - 248 */
1409 0x8003, /* ù - 249 */
1410 0x8003, /* ú - 250 */
1411 0x8003, /* û - 251 */
1412 0x8003, /* ü - 252 */
1413 0x8003, /* ý - 253 */
1414 0x8000, /* þ - 254 */
1415 0x8003 /* ÿ - 255 */
1416};
1417
1418/******************************************************************************
1419 * GetStringTypeA [KERNEL32.396]
1420 */
1421BOOL WINAPI GetStringTypeA(LCID locale,DWORD dwInfoType,LPCSTR src,
1422 INT cchSrc,LPWORD chartype)
1423{
1424 return GetStringTypeExA(locale,dwInfoType,src,cchSrc,chartype);
1425}
1426
1427/******************************************************************************
1428 * GetStringTypeExA [KERNEL32.397]
1429 *
1430 * FIXME: Ignores the locale.
1431 */
1432BOOL WINAPI GetStringTypeExA(LCID locale,DWORD dwInfoType,LPCSTR src,
1433 INT cchSrc,LPWORD chartype)
1434{
1435 int i;
1436
1437 if ((src==NULL) || (chartype==NULL) || (src==(LPSTR)chartype))
1438 {
1439 SetLastError(ERROR_INVALID_PARAMETER);
1440 return FALSE;
1441 }
1442
1443 if (cchSrc==-1)
1444 cchSrc=strlen(src)+1;
1445
1446 switch (dwInfoType) {
1447 case CT_CTYPE1:
1448 for (i=0;i<cchSrc;i++)
1449 {
1450 chartype[i] = 0;
1451 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1452 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1453 if (islower(src[i])) chartype[i]|=C1_LOWER;
1454 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1455 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1456 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1457 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1458/* FIXME: isblank() is a GNU extension */
1459/* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1460 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1461 /* C1_XDIGIT */
1462 }
1463 return TRUE;
1464
1465 case CT_CTYPE2:
1466 for (i=0;i<cchSrc;i++)
1467 {
1468 chartype[i]=(WORD)CT_CType2_LUT[i];
1469 }
1470 return TRUE;
1471
1472 case CT_CTYPE3:
1473 for (i=0;i<cchSrc;i++)
1474 {
1475 chartype[i]=OLE2NLS_CT_CType3_LUT[i];
1476 }
1477 return TRUE;
1478
1479 default:
1480 ERR("Unknown dwInfoType:%ld\n",dwInfoType);
1481 return FALSE;
1482 }
1483}
1484
1485/***********************************************************************
1486 * VerLanguageNameA [KERNEL32.709][VERSION.9]
1487 */
1488DWORD WINAPI VerLanguageNameA( UINT wLang, LPSTR szLang, UINT nSize )
1489{
1490 if(!szLang)
1491 return 0;
1492
1493 return GetLocaleInfoA(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1494}
1495
1496/***********************************************************************
1497 * VerLanguageNameW [KERNEL32.710][VERSION.10]
1498 */
1499DWORD WINAPI VerLanguageNameW( UINT wLang, LPWSTR szLang, UINT nSize )
1500{
1501 if(!szLang)
1502 return 0;
1503
1504 return GetLocaleInfoW(MAKELCID(wLang, SORT_DEFAULT), LOCALE_SENGLANGUAGE, szLang, nSize);
1505}
1506
1507
1508static const unsigned char LCM_Unicode_LUT[] = {
1509 6 , 3, /* - 1 */
1510 6 , 4, /* - 2 */
1511 6 , 5, /* - 3 */
1512 6 , 6, /* - 4 */
1513 6 , 7, /* - 5 */
1514 6 , 8, /* - 6 */
1515 6 , 9, /* - 7 */
1516 6 , 10, /* - 8 */
1517 7 , 5, /* - 9 */
1518 7 , 6, /* - 10 */
1519 7 , 7, /* - 11 */
1520 7 , 8, /* - 12 */
1521 7 , 9, /* - 13 */
1522 6 , 11, /* - 14 */
1523 6 , 12, /* - 15 */
1524 6 , 13, /* - 16 */
1525 6 , 14, /* - 17 */
1526 6 , 15, /* - 18 */
1527 6 , 16, /* - 19 */
1528 6 , 17, /* - 20 */
1529 6 , 18, /* - 21 */
1530 6 , 19, /* - 22 */
1531 6 , 20, /* - 23 */
1532 6 , 21, /* - 24 */
1533 6 , 22, /* - 25 */
1534 6 , 23, /* - 26 */
1535 6 , 24, /* - 27 */
1536 6 , 25, /* - 28 */
1537 6 , 26, /* - 29 */
1538 6 , 27, /* - 30 */
1539 6 , 28, /* - 31 */
1540 7 , 2, /* - 32 */
1541 7 , 28, /* ! - 33 */
1542 7 , 29, /* " - 34 */ /* " */
1543 7 , 31, /* # - 35 */
1544 7 , 33, /* $ - 36 */
1545 7 , 35, /* % - 37 */
1546 7 , 37, /* & - 38 */
1547 6 , 128, /* ' - 39 */
1548 7 , 39, /* ( - 40 */
1549 7 , 42, /* ) - 41 */
1550 7 , 45, /* * - 42 */
1551 8 , 3, /* + - 43 */
1552 7 , 47, /* , - 44 */
1553 6 , 130, /* - - 45 */
1554 7 , 51, /* . - 46 */
1555 7 , 53, /* / - 47 */
1556 12 , 3, /* 0 - 48 */
1557 12 , 33, /* 1 - 49 */
1558 12 , 51, /* 2 - 50 */
1559 12 , 70, /* 3 - 51 */
1560 12 , 88, /* 4 - 52 */
1561 12 , 106, /* 5 - 53 */
1562 12 , 125, /* 6 - 54 */
1563 12 , 144, /* 7 - 55 */
1564 12 , 162, /* 8 - 56 */
1565 12 , 180, /* 9 - 57 */
1566 7 , 55, /* : - 58 */
1567 7 , 58, /* ; - 59 */
1568 8 , 14, /* < - 60 */
1569 8 , 18, /* = - 61 */
1570 8 , 20, /* > - 62 */
1571 7 , 60, /* ? - 63 */
1572 7 , 62, /* @ - 64 */
1573 14 , 2, /* A - 65 */
1574 14 , 9, /* B - 66 */
1575 14 , 10, /* C - 67 */
1576 14 , 26, /* D - 68 */
1577 14 , 33, /* E - 69 */
1578 14 , 35, /* F - 70 */
1579 14 , 37, /* G - 71 */
1580 14 , 44, /* H - 72 */
1581 14 , 50, /* I - 73 */
1582 14 , 53, /* J - 74 */
1583 14 , 54, /* K - 75 */
1584 14 , 72, /* L - 76 */
1585 14 , 81, /* M - 77 */
1586 14 , 112, /* N - 78 */
1587 14 , 124, /* O - 79 */
1588 14 , 126, /* P - 80 */
1589 14 , 137, /* Q - 81 */
1590 14 , 138, /* R - 82 */
1591 14 , 145, /* S - 83 */
1592 14 , 153, /* T - 84 */
1593 14 , 159, /* U - 85 */
1594 14 , 162, /* V - 86 */
1595 14 , 164, /* W - 87 */
1596 14 , 166, /* X - 88 */
1597 14 , 167, /* Y - 89 */
1598 14 , 169, /* Z - 90 */
1599 7 , 63, /* [ - 91 */
1600 7 , 65, /* \ - 92 */
1601 7 , 66, /* ] - 93 */
1602 7 , 67, /* ^ - 94 */
1603 7 , 68, /* _ - 95 */
1604 7 , 72, /* ` - 96 */
1605 14 , 2, /* a - 97 */
1606 14 , 9, /* b - 98 */
1607 14 , 10, /* c - 99 */
1608 14 , 26, /* d - 100 */
1609 14 , 33, /* e - 101 */
1610 14 , 35, /* f - 102 */
1611 14 , 37, /* g - 103 */
1612 14 , 44, /* h - 104 */
1613 14 , 50, /* i - 105 */
1614 14 , 53, /* j - 106 */
1615 14 , 54, /* k - 107 */
1616 14 , 72, /* l - 108 */
1617 14 , 81, /* m - 109 */
1618 14 , 112, /* n - 110 */
1619 14 , 124, /* o - 111 */
1620 14 , 126, /* p - 112 */
1621 14 , 137, /* q - 113 */
1622 14 , 138, /* r - 114 */
1623 14 , 145, /* s - 115 */
1624 14 , 153, /* t - 116 */
1625 14 , 159, /* u - 117 */
1626 14 , 162, /* v - 118 */
1627 14 , 164, /* w - 119 */
1628 14 , 166, /* x - 120 */
1629 14 , 167, /* y - 121 */
1630 14 , 169, /* z - 122 */
1631 7 , 74, /* { - 123 */
1632 7 , 76, /* | - 124 */
1633 7 , 78, /* } - 125 */
1634 7 , 80, /* ~ - 126 */
1635 6 , 29, /*  - 127 */
1636 6 , 30, /* € - 128 */
1637 6 , 31, /*  - 129 */
1638 7 , 123, /* ‚ - 130 */
1639 14 , 35, /* ƒ - 131 */
1640 7 , 127, /* „ - 132 */
1641 10 , 21, /* …
1642 - 133 */
1643 10 , 15, /* † - 134 */
1644 10 , 16, /* ‡ - 135 */
1645 7 , 67, /* ˆ - 136 */
1646 10 , 22, /* ‰ - 137 */
1647 14 , 145, /* Š - 138 */
1648 7 , 136, /* ‹ - 139 */
1649 14 + 16 , 124, /* Œ - 140 */
1650 6 , 43, /*  - 141 */
1651 6 , 44, /* Ž - 142 */
1652 6 , 45, /*  - 143 */
1653 6 , 46, /*  - 144 */
1654 7 , 121, /* ‘ - 145 */
1655 7 , 122, /* ’ - 146 */
1656 7 , 125, /* “ - 147 */
1657 7 , 126, /* ” - 148 */
1658 10 , 17, /* • - 149 */
1659 6 , 137, /* – - 150 */
1660 6 , 139, /* — - 151 */
1661 7 , 93, /* ˜ - 152 */
1662 14 , 156, /* ™ - 153 */
1663 14 , 145, /* š - 154 */
1664 7 , 137, /* › - 155 */
1665 14 + 16 , 124, /* œ - 156 */
1666 6 , 59, /*  - 157 */
1667 6 , 60, /* ž - 158 */
1668 14 , 167, /* Ÿ - 159 */
1669 7 , 4, /*   - 160 */
1670 7 , 81, /* ¡ - 161 */
1671 10 , 2, /* ¢ - 162 */
1672 10 , 3, /* £ - 163 */
1673 10 , 4, /* € - 164 */
1674 10 , 5, /* ¥ - 165 */
1675 7 , 82, /* Š - 166 */
1676 10 , 6, /* § - 167 */
1677 7 , 83, /* š - 168 */
1678 10 , 7, /* © - 169 */
1679 14 , 2, /* ª - 170 */
1680 8 , 24, /* « - 171 */
1681 10 , 8, /* ¬ - 172 */
1682 6 , 131, /* ­ - 173 */
1683 10 , 9, /* ® - 174 */
1684 7 , 84, /* ¯ - 175 */
1685 10 , 10, /* ° - 176 */
1686 8 , 23, /* ± - 177 */
1687 12 , 51, /* ² - 178 */
1688 12 , 70, /* ³ - 179 */
1689 7 , 85, /* Ž - 180 */
1690 10 , 11, /* µ - 181 */
1691 10 , 12, /* ¶ - 182 */
1692 10 , 13, /* · - 183 */
1693 7 , 86, /* ž - 184 */
1694 12 , 33, /* ¹ - 185 */
1695 14 , 124, /* º - 186 */
1696 8 , 26, /* » - 187 */
1697 12 , 21, /* Œ - 188 */
1698 12 , 25, /* œ - 189 */
1699 12 , 29, /* Ÿ - 190 */
1700 7 , 87, /* ¿ - 191 */
1701 14 , 2, /* À - 192 */
1702 14 , 2, /* Á - 193 */
1703 14 , 2, /* Â - 194 */
1704 14 , 2, /* Ã - 195 */
1705 14 , 2, /* Ä - 196 */
1706 14 , 2, /* Å - 197 */
1707 14 + 16 , 2, /* Æ - 198 */
1708 14 , 10, /* Ç - 199 */
1709 14 , 33, /* È - 200 */
1710 14 , 33, /* É - 201 */
1711 14 , 33, /* Ê - 202 */
1712 14 , 33, /* Ë - 203 */
1713 14 , 50, /* Ì - 204 */
1714 14 , 50, /* Í - 205 */
1715 14 , 50, /* Î - 206 */
1716 14 , 50, /* Ï - 207 */
1717 14 , 26, /* Ð - 208 */
1718 14 , 112, /* Ñ - 209 */
1719 14 , 124, /* Ò - 210 */
1720 14 , 124, /* Ó - 211 */
1721 14 , 124, /* Ô - 212 */
1722 14 , 124, /* Õ - 213 */
1723 14 , 124, /* Ö - 214 */
1724 8 , 28, /* × - 215 */
1725 14 , 124, /* Ø - 216 */
1726 14 , 159, /* Ù - 217 */
1727 14 , 159, /* Ú - 218 */
1728 14 , 159, /* Û - 219 */
1729 14 , 159, /* Ü - 220 */
1730 14 , 167, /* Ý - 221 */
1731 14 + 32 , 153, /* Þ - 222 */
1732 14 + 48 , 145, /* ß - 223 */
1733 14 , 2, /* à - 224 */
1734 14 , 2, /* á - 225 */
1735 14 , 2, /* â - 226 */
1736 14 , 2, /* ã - 227 */
1737 14 , 2, /* ä - 228 */
1738 14 , 2, /* å - 229 */
1739 14 + 16 , 2, /* æ - 230 */
1740 14 , 10, /* ç - 231 */
1741 14 , 33, /* è - 232 */
1742 14 , 33, /* é - 233 */
1743 14 , 33, /* ê - 234 */
1744 14 , 33, /* ë - 235 */
1745 14 , 50, /* ì - 236 */
1746 14 , 50, /* í - 237 */
1747 14 , 50, /* î - 238 */
1748 14 , 50, /* ï - 239 */
1749 14 , 26, /* ð - 240 */
1750 14 , 112, /* ñ - 241 */
1751 14 , 124, /* ò - 242 */
1752 14 , 124, /* ó - 243 */
1753 14 , 124, /* ô - 244 */
1754 14 , 124, /* õ - 245 */
1755 14 , 124, /* ö - 246 */
1756 8 , 29, /* ÷ - 247 */
1757 14 , 124, /* ø - 248 */
1758 14 , 159, /* ù - 249 */
1759 14 , 159, /* ú - 250 */
1760 14 , 159, /* û - 251 */
1761 14 , 159, /* ü - 252 */
1762 14 , 167, /* ý - 253 */
1763 14 + 32 , 153, /* þ - 254 */
1764 14 , 167 /* ÿ - 255 */ };
1765
1766static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
1767
1768#define LCM_Diacritic_Start 131
1769
1770static const unsigned char LCM_Diacritic_LUT[] = {
1771123, /* ƒ - 131 */
1772 2, /* „ - 132 */
1773 2, /* …
1774 - 133 */
1775 2, /* † - 134 */
1776 2, /* ‡ - 135 */
1777 3, /* ˆ - 136 */
1778 2, /* ‰ - 137 */
1779 20, /* Š - 138 */
1780 2, /* ‹ - 139 */
1781 2, /* Œ - 140 */
1782 2, /*  - 141 */
1783 2, /* Ž - 142 */
1784 2, /*  - 143 */
1785 2, /*  - 144 */
1786 2, /* ‘ - 145 */
1787 2, /* ’ - 146 */
1788 2, /* “ - 147 */
1789 2, /* ” - 148 */
1790 2, /* • - 149 */
1791 2, /* – - 150 */
1792 2, /* — - 151 */
1793 2, /* ˜ - 152 */
1794 2, /* ™ - 153 */
1795 20, /* š - 154 */
1796 2, /* › - 155 */
1797 2, /* œ - 156 */
1798 2, /*  - 157 */
1799 2, /* ž - 158 */
1800 19, /* Ÿ - 159 */
1801 2, /*   - 160 */
1802 2, /* ¡ - 161 */
1803 2, /* ¢ - 162 */
1804 2, /* £ - 163 */
1805 2, /* € - 164 */
1806 2, /* ¥ - 165 */
1807 2, /* Š - 166 */
1808 2, /* § - 167 */
1809 2, /* š - 168 */
1810 2, /* © - 169 */
1811 3, /* ª - 170 */
1812 2, /* « - 171 */
1813 2, /* ¬ - 172 */
1814 2, /* ­ - 173 */
1815 2, /* ® - 174 */
1816 2, /* ¯ - 175 */
1817 2, /* ° - 176 */
1818 2, /* ± - 177 */
1819 2, /* ² - 178 */
1820 2, /* ³ - 179 */
1821 2, /* Ž - 180 */
1822 2, /* µ - 181 */
1823 2, /* ¶ - 182 */
1824 2, /* · - 183 */
1825 2, /* ž - 184 */
1826 2, /* ¹ - 185 */
1827 3, /* º - 186 */
1828 2, /* » - 187 */
1829 2, /* Œ - 188 */
1830 2, /* œ - 189 */
1831 2, /* Ÿ - 190 */
1832 2, /* ¿ - 191 */
1833 15, /* À - 192 */
1834 14, /* Á - 193 */
1835 18, /* Â - 194 */
1836 25, /* Ã - 195 */
1837 19, /* Ä - 196 */
1838 26, /* Å - 197 */
1839 2, /* Æ - 198 */
1840 28, /* Ç - 199 */
1841 15, /* È - 200 */
1842 14, /* É - 201 */
1843 18, /* Ê - 202 */
1844 19, /* Ë - 203 */
1845 15, /* Ì - 204 */
1846 14, /* Í - 205 */
1847 18, /* Î - 206 */
1848 19, /* Ï - 207 */
1849104, /* Ð - 208 */
1850 25, /* Ñ - 209 */
1851 15, /* Ò - 210 */
1852 14, /* Ó - 211 */
1853 18, /* Ô - 212 */
1854 25, /* Õ - 213 */
1855 19, /* Ö - 214 */
1856 2, /* × - 215 */
1857 33, /* Ø - 216 */
1858 15, /* Ù - 217 */
1859 14, /* Ú - 218 */
1860 18, /* Û - 219 */
1861 19, /* Ü - 220 */
1862 14, /* Ý - 221 */
1863 2, /* Þ - 222 */
1864 2, /* ß - 223 */
1865 15, /* à - 224 */
1866 14, /* á - 225 */
1867 18, /* â - 226 */
1868 25, /* ã - 227 */
1869 19, /* ä - 228 */
1870 26, /* å - 229 */
1871 2, /* æ - 230 */
1872 28, /* ç - 231 */
1873 15, /* è - 232 */
1874 14, /* é - 233 */
1875 18, /* ê - 234 */
1876 19, /* ë - 235 */
1877 15, /* ì - 236 */
1878 14, /* í - 237 */
1879 18, /* î - 238 */
1880 19, /* ï - 239 */
1881104, /* ð - 240 */
1882 25, /* ñ - 241 */
1883 15, /* ò - 242 */
1884 14, /* ó - 243 */
1885 18, /* ô - 244 */
1886 25, /* õ - 245 */
1887 19, /* ö - 246 */
1888 2, /* ÷ - 247 */
1889 33, /* ø - 248 */
1890 15, /* ù - 249 */
1891 14, /* ú - 250 */
1892 18, /* û - 251 */
1893 19, /* ü - 252 */
1894 14, /* ý - 253 */
1895 2, /* þ - 254 */
1896 19, /* ÿ - 255 */
1897} ;
1898
1899/******************************************************************************
1900 * OLE2NLS_isPunctuation [INTERNAL]
1901 */
1902static int OLE2NLS_isPunctuation(unsigned char c)
1903{
1904 /* "punctuation character" in this context is a character which is
1905 considered "less important" during word sort comparison.
1906 See LCMapString implementation for the precise definition
1907 of "less important". */
1908
1909 return (LCM_Unicode_LUT[-2+2*c]==6);
1910}
1911
1912/******************************************************************************
1913 * OLE2NLS_isNonSpacing [INTERNAL]
1914 */
1915static int OLE2NLS_isNonSpacing(unsigned char c)
1916{
1917 /* This function is used by LCMapStringA. Characters
1918 for which it returns true are ignored when mapping a
1919 string with NORM_IGNORENONSPACE */
1920 return ((c==136) || (c==170) || (c==186));
1921}
1922
1923/******************************************************************************
1924 * OLE2NLS_isSymbol [INTERNAL]
1925 */
1926static int OLE2NLS_isSymbol(unsigned char c)
1927{
1928 /* This function is used by LCMapStringA. Characters
1929 for which it returns true are ignored when mapping a
1930 string with NORM_IGNORESYMBOLS */
1931#ifdef __WIN32OS2__
1932 return ( (c!=0) && !iswalpha((wint_t)c) );
1933#else
1934 return ( (c!=0) && !IsCharAlphaNumericA(c) );
1935#endif
1936}
1937
1938/******************************************************************************
1939 * identity [Internal]
1940 */
1941#ifdef __WIN32OS2__
1942static int _Optlink identity(int c)
1943#else
1944static int identity(int c)
1945#endif
1946{
1947 return c;
1948}
1949
1950/*************************************************************************
1951 * LCMapStringA [KERNEL32.492]
1952 *
1953 * Convert a string, or generate a sort key from it.
1954 *
1955 * If (mapflags & LCMAP_SORTKEY), the function will generate
1956 * a sort key for the source string. Else, it will convert it
1957 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1958 *
1959 * RETURNS
1960 * Error : 0.
1961 * Success : length of the result string.
1962 *
1963 * NOTES
1964 * If called with scrlen = -1, the function will compute the length
1965 * of the 0-terminated string strsrc by itself.
1966 *
1967 * If called with dstlen = 0, returns the buffer length that
1968 * would be required.
1969 *
1970 * NORM_IGNOREWIDTH means to compare ASCII and wide characters
1971 * as if they are equal.
1972 * In the only code page implemented so far, there may not be
1973 * wide characters in strings passed to LCMapStringA,
1974 * so there is nothing to be done for this flag.
1975 */
1976#ifdef __WIN32OS2__
1977ODINFUNCTION6(INT, LCMapStringA,
1978 LCID, lcid, /* [in] locale identifier created with MAKELCID;
1979 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1980 predefined values. */
1981 DWORD, mapflags, /* [in] flags */
1982 LPCSTR, srcstr, /* [in] source buffer */
1983 INT, srclen, /* [in] source length */
1984 LPSTR, dststr, /* [out] destination buffer */
1985 INT, dstlen) /* [in] destination buffer length */
1986#else
1987INT WINAPI LCMapStringA(
1988 LCID lcid, /* [in] locale identifier created with MAKELCID;
1989 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1990 predefined values. */
1991 DWORD mapflags, /* [in] flags */
1992 LPCSTR srcstr, /* [in] source buffer */
1993 INT srclen, /* [in] source length */
1994 LPSTR dststr, /* [out] destination buffer */
1995 INT dstlen) /* [in] destination buffer length */
1996#endif
1997{
1998 int i;
1999
2000 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
2001 lcid,mapflags,srcstr,srclen,dststr,dstlen);
2002
2003 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2004 {
2005 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
2006 SetLastError(ERROR_INVALID_PARAMETER);
2007 return 0;
2008 }
2009 if (srclen == -1)
2010 srclen = strlen(srcstr) + 1 ; /* (include final '\0') */
2011
2012#define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
2013 LCMAP_LOWERCASE | \
2014 LCMAP_SORTKEY | \
2015 NORM_IGNORECASE | \
2016 NORM_IGNORENONSPACE | \
2017 SORT_STRINGSORT | \
2018 NORM_IGNOREWIDTH | \
2019 NORM_IGNOREKANATYPE)
2020 /* FIXME: as long as we don't support Katakana nor Hiragana
2021 * characters, we can support NORM_IGNOREKANATYPE
2022 */
2023 if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
2024 {
2025 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
2026 "unimplemented flags: 0x%08lx\n",
2027 lcid,
2028 mapflags,
2029 srcstr,
2030 srclen,
2031 dststr,
2032 dstlen,
2033 mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
2034 );
2035 }
2036
2037 if ( !(mapflags & LCMAP_SORTKEY) )
2038 {
2039 int i,j;
2040#ifdef __WIN32OS2__
2041 int (* _Optlink f)(int) = identity;
2042#else
2043 int (* f)(int) = identity;
2044#endif
2045 int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
2046 int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
2047
2048 if (flag_ignorenonspace || flag_ignoresymbols)
2049 {
2050 /* For some values of mapflags, the length of the resulting
2051 string is not known at this point. Windows does map the string
2052 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
2053 these cases. */
2054 if (dstlen==0)
2055 {
2056 /* Compute required length */
2057 for (i=j=0; i < srclen; i++)
2058 {
2059 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
2060 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
2061 j++;
2062 }
2063 return j;
2064 }
2065 }
2066 else
2067 {
2068 if (dstlen==0)
2069 return srclen;
2070 if (dstlen<srclen)
2071 {
2072 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2073 return 0;
2074 }
2075 }
2076 if (mapflags & LCMAP_UPPERCASE)
2077 f = toupper;
2078 else if (mapflags & LCMAP_LOWERCASE)
2079 f = tolower;
2080 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
2081 for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
2082 {
2083 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
2084 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
2085 {
2086 dststr[j] = (CHAR) f(srcstr[i]);
2087 j++;
2088 }
2089 }
2090 return j;
2091 }
2092
2093 /* FIXME: This function completely ignores the "lcid" parameter. */
2094 /* else ... (mapflags & LCMAP_SORTKEY) */
2095 {
2096 int unicode_len=0;
2097 int case_len=0;
2098 int diacritic_len=0;
2099 int delayed_punctuation_len=0;
2100 char *case_component;
2101 char *diacritic_component;
2102 char *delayed_punctuation_component;
2103 int room,count;
2104 int flag_stringsort = mapflags & SORT_STRINGSORT;
2105
2106 /* compute how much room we will need */
2107 for (i=0;i<srclen;i++)
2108 {
2109 int ofs;
2110 unsigned char source_char = srcstr[i];
2111 if (source_char!='\0')
2112 {
2113 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
2114 {
2115 unicode_len++;
2116 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
2117 unicode_len++; /* double letter */
2118 }
2119 else
2120 {
2121 delayed_punctuation_len++;
2122 }
2123 }
2124
2125 if (isupper(source_char))
2126 case_len=unicode_len;
2127
2128 ofs = source_char - LCM_Diacritic_Start;
2129 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
2130 diacritic_len=unicode_len;
2131 }
2132
2133 if (mapflags & NORM_IGNORECASE)
2134 case_len=0;
2135 if (mapflags & NORM_IGNORENONSPACE)
2136 diacritic_len=0;
2137
2138 room = 2 * unicode_len /* "unicode" component */
2139 + diacritic_len /* "diacritic" component */
2140 + case_len /* "case" component */
2141 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
2142 + 4 /* four '\1' separators */
2143 + 1 ; /* terminal '\0' */
2144 if (dstlen==0)
2145 return room;
2146 else if (dstlen<room)
2147 {
2148 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2149 return 0;
2150 }
2151#if 0
2152 /*FIXME the Pointercheck should not be nessesary */
2153 if (IsBadWritePtr (dststr,room))
2154 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
2155 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2156 return 0;
2157 }
2158#endif
2159 /* locate each component, write separators */
2160 diacritic_component = dststr + 2*unicode_len ;
2161 *diacritic_component++ = '\1';
2162 case_component = diacritic_component + diacritic_len ;
2163 *case_component++ = '\1';
2164 delayed_punctuation_component = case_component + case_len ;
2165 *delayed_punctuation_component++ = '\1';
2166 *delayed_punctuation_component++ = '\1';
2167
2168 /* read source string char by char, write
2169 corresponding weight in each component. */
2170 for (i=0,count=0;i<srclen;i++)
2171 {
2172 unsigned char source_char=srcstr[i];
2173 if (source_char!='\0')
2174 {
2175 int type,longcode;
2176 type = LCM_Unicode_LUT[-2+2*source_char];
2177 longcode = type >> 4;
2178 type &= 15;
2179 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
2180 {
2181 WORD encrypted_location = (1<<15) + 7 + 4*count;
2182 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
2183 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
2184 /* big-endian is used here because it lets string comparison be
2185 compatible with numerical comparison */
2186
2187 *delayed_punctuation_component++ = type;
2188 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
2189 /* assumption : a punctuation character is never a
2190 double or accented letter */
2191 }
2192 else
2193 {
2194 dststr[2*count] = type;
2195 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
2196 if (longcode)
2197 {
2198 if (count<case_len)
2199 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2200 if (count<diacritic_len)
2201 diacritic_component[count] = 2; /* assumption: a double letter
2202 is never accented */
2203 count++;
2204
2205 dststr[2*count] = type;
2206 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
2207 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
2208 32 in the first column of LCM_Unicode_LUT --> longcode = 2
2209 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
2210 }
2211
2212 if (count<case_len)
2213 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
2214 if (count<diacritic_len)
2215 {
2216 int ofs = source_char - LCM_Diacritic_Start;
2217 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
2218 }
2219 count++;
2220 }
2221 }
2222 }
2223 dststr[room-1] = '\0';
2224 return room;
2225 }
2226}
2227
2228/*************************************************************************
2229 * LCMapStringW [KERNEL32.493]
2230 *
2231 * Convert a string, or generate a sort key from it.
2232 *
2233 * NOTE
2234 *
2235 * See LCMapStringA for documentation
2236 */
2237#ifdef __WIN32OS2__
2238ODINFUNCTION6(INT, LCMapStringW,
2239 LCID, lcid,DWORD, mapflags,LPCWSTR, srcstr,INT, srclen,LPWSTR, dststr,
2240 INT, dstlen)
2241#else
2242INT WINAPI LCMapStringW(
2243 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
2244 INT dstlen)
2245#endif
2246{
2247 int i;
2248
2249 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
2250 lcid, mapflags, srcstr, srclen, dststr, dstlen);
2251
2252 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
2253 {
2254 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
2255 SetLastError(ERROR_INVALID_PARAMETER);
2256 return 0;
2257 }
2258 if (srclen==-1)
2259 srclen = strlenW(srcstr)+1;
2260
2261 /* FIXME: Both this function and it's companion LCMapStringA()
2262 * completely ignore the "lcid" parameter. In place of the "lcid"
2263 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
2264 * environment variable prior to invoking this function. */
2265 if (mapflags & LCMAP_SORTKEY)
2266 {
2267 /* Possible values of LC_COLLATE. */
2268 char *lc_collate_default = 0; /* value prior to this function */
2269 char *lc_collate_env = 0; /* value retrieved from the environment */
2270
2271 /* General purpose index into strings of any type. */
2272 int str_idx = 0;
2273
2274 /* Lengths of various strings where the length is measured in
2275 * wide characters for wide character strings and in bytes for
2276 * native strings. The lengths include the NULL terminator. */
2277 size_t returned_len = 0;
2278 size_t src_native_len = 0;
2279 size_t dst_native_len = 0;
2280 size_t dststr_libc_len = 0;
2281
2282 /* Native (character set determined by locale) versions of the
2283 * strings source and destination strings. */
2284 LPSTR src_native = 0;
2285 LPSTR dst_native = 0;
2286
2287 /* Version of the source and destination strings using the
2288 * "wchar_t" Unicode data type needed by various libc functions. */
2289 wchar_t *srcstr_libc = 0;
2290 wchar_t *dststr_libc = 0;
2291
2292 if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2293 srclen * sizeof(wchar_t))))
2294 {
2295 ERR("Unable to allocate %d bytes for srcstr_libc\n",
2296 srclen * sizeof(wchar_t));
2297 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2298 return 0;
2299 }
2300
2301 /* Convert source string to a libc Unicode string. */
2302 for(str_idx = 0; str_idx < srclen; str_idx++)
2303 {
2304 srcstr_libc[str_idx] = srcstr[str_idx];
2305 }
2306
2307 /* src_native should contain at most 3 bytes for each
2308 * multibyte characters in the original srcstr string. */
2309 src_native_len = 3 * srclen;
2310 if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
2311 src_native_len)))
2312 {
2313 ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
2314 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2315 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2316 return 0;
2317 }
2318
2319 /* FIXME: Prior to to setting the LC_COLLATE locale category the
2320 * current value is backed up so it can be restored after the
2321 * last LC_COLLATE sensitive function returns.
2322 *
2323 * Even though the locale is adjusted for a minimum amount of
2324 * time a race condition exists where other threads may be
2325 * affected if they invoke LC_COLLATE sensitive functions. One
2326 * possible solution is to wrap all LC_COLLATE sensitive Wine
2327 * functions, like LCMapStringW(), in a mutex.
2328 *
2329 * Another enhancement to the following would be to set the
2330 * LC_COLLATE locale category as a function of the "lcid"
2331 * parameter instead of the "LC_COLLATE" environment variable. */
2332 if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
2333 {
2334 ERR("Unable to query the LC_COLLATE catagory\n");
2335 SetLastError(ERROR_INVALID_PARAMETER);
2336 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2337 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2338 return 0;
2339 }
2340
2341 if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
2342 {
2343 ERR("Unable to inherit the LC_COLLATE locale category from the "
2344 "environment. The \"LC_COLLATE\" environment variable is "
2345 "\"%s\".\n", getenv("LC_COLLATE") ?
2346 getenv("LC_COLLATE") : "<unset>");
2347 SetLastError(ERROR_INVALID_PARAMETER);
2348 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2349 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2350 return 0;
2351 }
2352
2353 TRACE("lc_collate_default = %s\n", lc_collate_default);
2354 TRACE("lc_collate_env = %s\n", lc_collate_env);
2355
2356 /* Convert the libc Unicode string to a native multibyte character
2357 * string. */
2358 returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
2359 if(returned_len == 0)
2360 {
2361 LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
2362 0, srcstr);
2363 ERR("wcstombs failed. The string specified (%s) may contains an "
2364 "invalid character.\n", srcstr_ascii);
2365 SetLastError(ERROR_INVALID_PARAMETER);
2366 if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
2367 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2368 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2369 setlocale(LC_COLLATE, lc_collate_default);
2370 return 0;
2371 }
2372 else if(returned_len > src_native_len)
2373 {
2374 src_native[src_native_len - 1] = 0;
2375 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
2376 "than expected (%d bytes).\n", src_native, returned_len,
2377 dst_native_len);
2378
2379 /* Since this is an internal error I'm not sure what the correct
2380 * error code is. */
2381 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2382
2383 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2384 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2385 setlocale(LC_COLLATE, lc_collate_default);
2386 return 0;
2387 }
2388 src_native_len = returned_len;
2389
2390 TRACE("src_native = %s src_native_len = %d\n",
2391 src_native, src_native_len);
2392
2393 /* dst_native seems to contain at most 4 bytes for each byte in
2394 * the original src_native string. Change if need be since this
2395 * isn't documented by the strxfrm() man page. */
2396 dst_native_len = 4 * src_native_len;
2397 if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
2398 {
2399 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
2400 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2401 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2402 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2403 setlocale(LC_COLLATE, lc_collate_default);
2404 return 0;
2405 }
2406
2407 /* The actual translation is done by the following call to
2408 * strxfrm(). The surrounding code could have been simplified
2409 * by calling wcsxfrm() instead except that wcsxfrm() is not
2410 * available on older Linux systems (RedHat 4.1 with
2411 * libc-5.3.12-17).
2412 *
2413 * Also, it is possible that the translation could be done by
2414 * various tables as it is done in LCMapStringA(). However, I'm
2415 * not sure what those tables are. */
2416 returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
2417
2418 if(returned_len > dst_native_len)
2419 {
2420 dst_native[dst_native_len - 1] = 0;
2421 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
2422 "than expected (%d bytes).\n", dst_native, returned_len,
2423 dst_native_len);
2424
2425 /* Since this is an internal error I'm not sure what the correct
2426 * error code is. */
2427 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2428
2429 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2430 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2431 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2432 setlocale(LC_COLLATE, lc_collate_default);
2433 return 0;
2434 }
2435 dst_native_len = returned_len;
2436
2437 TRACE("dst_native = %s dst_native_len = %d\n",
2438 dst_native, dst_native_len);
2439
2440 dststr_libc_len = dst_native_len;
2441 if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
2442 dststr_libc_len * sizeof(wchar_t))))
2443 {
2444 ERR("Unable to allocate %d bytes for dststr_libc\n",
2445 dststr_libc_len * sizeof(wchar_t));
2446 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
2447 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2448 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2449 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2450 setlocale(LC_COLLATE, lc_collate_default);
2451 return 0;
2452 }
2453
2454 /* Convert the native multibyte string to a libc Unicode string. */
2455 returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
2456
2457 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
2458 * function has returned. */
2459 setlocale(LC_COLLATE, lc_collate_default);
2460
2461 if(returned_len == 0)
2462 {
2463 ERR("mbstowcs failed. The native version of the translated string "
2464 "(%s) may contain an invalid character.\n", dst_native);
2465 SetLastError(ERROR_INVALID_PARAMETER);
2466 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2467 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2468 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2469 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2470 return 0;
2471 }
2472 if(dstlen)
2473 {
2474 if(returned_len > dstlen)
2475 {
2476 ERR("mbstowcs returned a string that was longer (%d chars) "
2477 "than the buffer provided (%d chars).\n", returned_len,
2478 dstlen);
2479 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2480 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2481 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2482 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2483 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2484 return 0;
2485 }
2486 dstlen = returned_len;
2487
2488 /* Convert a libc Unicode string to the destination string. */
2489 for(str_idx = 0; str_idx < dstlen; str_idx++)
2490 {
2491 dststr[str_idx] = dststr_libc[str_idx];
2492 }
2493 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
2494 *(((int *)dststr) + 0),
2495 *(((int *)dststr) + 1),
2496 *(((int *)dststr) + 2),
2497 *(((int *)dststr) + 3));
2498 }
2499 else
2500 {
2501 dstlen = returned_len;
2502 }
2503 TRACE("dstlen (return) = %d\n", dstlen);
2504 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
2505 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
2506 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
2507 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
2508 return dstlen;
2509 }
2510 else
2511 {
2512#ifdef __WIN32OS2__
2513 int (* _Optlink f)(int) = identity;
2514#else
2515 int (*f)(int)=identity;
2516#endif
2517
2518 if (dstlen==0)
2519 return srclen;
2520 if (dstlen<srclen)
2521 {
2522 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2523 return 0;
2524 }
2525
2526 if (mapflags & LCMAP_UPPERCASE)
2527 f = toupper;
2528 else if (mapflags & LCMAP_LOWERCASE)
2529 f = tolower;
2530 for (i=0; i < srclen; i++)
2531 dststr[i] = (WCHAR) f(srcstr[i]);
2532 return srclen;
2533 }
2534}
2535
2536
2537/***********************************************************************
2538 * OLE2NLS_EstimateMappingLength
2539 *
2540 * Estimates the number of characters required to hold the string
2541 * computed by LCMapStringA.
2542 *
2543 * The size is always over-estimated, with a fixed limit on the
2544 * amount of estimation error.
2545 *
2546 * Note that len == -1 is not permitted.
2547 */
2548static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
2549 LPCSTR str, DWORD len)
2550{
2551 /* Estimate only for small strings to keep the estimation error from
2552 * becoming too large. */
2553 if (len < 128) return len * 8 + 5;
2554 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
2555}
2556
2557/******************************************************************************
2558 * CompareStringA [KERNEL32.143]
2559 * Compares two strings using locale
2560 *
2561 * RETURNS
2562 *
2563 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
2564 * failure: 0
2565 *
2566 * NOTES
2567 *
2568 * Defaults to a word sort, but uses a string sort if
2569 * SORT_STRINGSORT is set.
2570 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
2571 *
2572 * BUGS
2573 *
2574 * This implementation ignores the locale
2575 *
2576 * FIXME
2577 *
2578 * Quite inefficient.
2579 */
2580UINT WINAPI CompareStringA(
2581 DWORD lcid, /* [in] locale ID */
2582 DWORD fdwStyle, /* [in] comparison-style options */
2583 LPCSTR s1, /* [in] first string */
2584 DWORD l1, /* [in] length of first string */
2585 LPCSTR s2, /* [in] second string */
2586 DWORD l2) /* [in] length of second string */
2587{
2588 int mapstring_flags;
2589 int len1,len2;
2590 int result;
2591 LPSTR sk1,sk2;
2592 TRACE("%s and %s\n",
2593 debugstr_a (s1), debugstr_a (s2));
2594
2595 if ( (s1==NULL) || (s2==NULL) )
2596 {
2597 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
2598 SetLastError(ERROR_INVALID_PARAMETER);
2599 return 0;
2600 }
2601
2602 if(fdwStyle & NORM_IGNORESYMBOLS)
2603 FIXME("IGNORESYMBOLS not supported\n");
2604
2605 if (l1 == -1) l1 = strlen(s1);
2606 if (l2 == -1) l2 = strlen(s2);
2607
2608 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2609 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
2610 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
2611
2612 if ((len1==0)||(len2==0))
2613 return 0; /* something wrong happened */
2614
2615 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2616 sk2 = sk1 + len1;
2617 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2618 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2619 {
2620 ERR("Bug in LCmapStringA.\n");
2621 result = 0;
2622 }
2623 else
2624 {
2625 /* strcmp doesn't necessarily return -1, 0, or 1 */
2626 result = strcmp(sk1,sk2);
2627 }
2628 HeapFree(GetProcessHeap(),0,sk1);
2629
2630 if (result < 0)
2631 return 1;
2632 if (result == 0)
2633 return 2;
2634
2635 /* must be greater, if we reach this point */
2636 return 3;
2637}
2638
2639/******************************************************************************
2640 * CompareStringW [KERNEL32.144]
2641 * This implementation ignores the locale
2642 * FIXME : Does only string sort. Should
2643 * be reimplemented the same way as CompareStringA.
2644 */
2645UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2646 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2647{
2648 int len,ret;
2649 if(fdwStyle & NORM_IGNORENONSPACE)
2650 FIXME("IGNORENONSPACE not supprted\n");
2651 if(fdwStyle & NORM_IGNORESYMBOLS)
2652 FIXME("IGNORESYMBOLS not supported\n");
2653
2654 /* Is strcmp defaulting to string sort or to word sort?? */
2655 /* FIXME: Handle NORM_STRINGSORT */
2656 l1 = (l1==-1)?strlenW(s1):l1;
2657 l2 = (l2==-1)?strlenW(s2):l2;
2658 len = l1<l2 ? l1:l2;
2659 ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
2660 /* not equal, return 1 or 3 */
2661 if(ret!=0) {
2662 /* need to translate result */
2663 return ((int)ret < 0) ? 1 : 3;
2664 }
2665 /* same len, return 2 */
2666 if(l1==l2) return 2;
2667 /* the longer one is lexically greater */
2668 return (l1<l2)? 1 : 3;
2669}
2670
2671/******************************************************************************
2672 * OLE_GetFormatA [Internal]
2673 *
2674 * FIXME
2675 * If datelen == 0, it should return the reguired string length.
2676 *
2677 This function implements stuff for GetDateFormat() and
2678 GetTimeFormat().
2679
2680 d single-digit (no leading zero) day (of month)
2681 dd two-digit day (of month)
2682 ddd short day-of-week name
2683 dddd long day-of-week name
2684 M single-digit month
2685 MM two-digit month
2686 MMM short month name
2687 MMMM full month name
2688 y two-digit year, no leading 0
2689 yy two-digit year
2690 yyyy four-digit year
2691 gg era string
2692 h hours with no leading zero (12-hour)
2693 hh hours with full two digits
2694 H hours with no leading zero (24-hour)
2695 HH hours with full two digits
2696 m minutes with no leading zero
2697 mm minutes with full two digits
2698 s seconds with no leading zero
2699 ss seconds with full two digits
2700 t time marker (A or P)
2701 tt time marker (AM, PM)
2702 '' used to quote literal characters
2703 '' (within a quoted string) indicates a literal '
2704
2705 These functions REQUIRE valid locale, date, and format.
2706 */
2707static INT OLE_GetFormatA(LCID locale,
2708 DWORD flags,
2709 DWORD tflags,
2710 LPSYSTEMTIME xtime,
2711 LPCSTR _format, /*in*/
2712 LPSTR date, /*out*/
2713 INT datelen)
2714{
2715 INT inpos, outpos;
2716 int count, type, inquote, Overflow;
2717 char buf[40];
2718 char format[40];
2719 char * pos;
2720 int buflen;
2721
2722 const char * _dgfmt[] = { "%d", "%02d" };
2723 const char ** dgfmt = _dgfmt - 1;
2724
2725 /* report, for debugging */
2726 TRACE("(0x%lx,0x%lx, 0x%lx, time(y=%d m=%d wd=%d d=%d,h=%d,m=%d,s=%d), fmt=%p \'%s\' , %p, len=%d)\n",
2727 locale, flags, tflags,
2728 xtime->wYear,xtime->wMonth,xtime->wDayOfWeek,xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2729 _format, _format, date, datelen);
2730
2731 if(datelen == 0) {
2732 FIXME("datelen = 0, returning 255\n");
2733 return 255;
2734 }
2735
2736 /* initalize state variables and output buffer */
2737 inpos = outpos = 0;
2738 count = 0; inquote = 0; Overflow = 0;
2739 type = '\0';
2740 date[0] = buf[0] = '\0';
2741
2742 strcpy(format,_format);
2743
2744 /* alter the formatstring, while it works for all languages now in wine
2745 its possible that it fails when the time looks like ss:mm:hh as example*/
2746 if (tflags & (TIME_NOMINUTESORSECONDS))
2747 { if ((pos = strstr ( format, ":mm")))
2748 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2749 }
2750 }
2751 if (tflags & (TIME_NOSECONDS))
2752 { if ((pos = strstr ( format, ":ss")))
2753 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2754 }
2755 }
2756
2757 for (inpos = 0;; inpos++) {
2758 /* TRACE("STATE inpos=%2d outpos=%2d count=%d inquote=%d type=%c buf,date = %c,%c\n", inpos, outpos, count, inquote, type, buf[inpos], date[outpos]); */
2759 if (inquote) {
2760 if (format[inpos] == '\'') {
2761 if (format[inpos+1] == '\'') {
2762 inpos += 1;
2763 date[outpos++] = '\'';
2764 } else {
2765 inquote = 0;
2766 continue; /* we did nothing to the output */
2767 }
2768 } else if (format[inpos] == '\0') {
2769 date[outpos++] = '\0';
2770 if (outpos > datelen) Overflow = 1;
2771 break;
2772 } else {
2773 date[outpos++] = format[inpos];
2774 if (outpos > datelen) {
2775 Overflow = 1;
2776 date[outpos-1] = '\0'; /* this is the last place where
2777 it's safe to write */
2778 break;
2779 }
2780 }
2781 } else if ( (count && (format[inpos] != type))
2782 || count == 4
2783 || (count == 2 && strchr("ghHmst", type)) ) {
2784 if (type == 'h' && (tflags & TIME_FORCE24HOURFORMAT)) type= 'H';
2785 if (type == 'd') {
2786 if (count == 4) {
2787 GetLocaleInfoA(locale,
2788 LOCALE_SDAYNAME1
2789 + (xtime->wDayOfWeek+6)%7,
2790 buf, sizeof(buf));
2791 } else if (count == 3) {
2792 GetLocaleInfoA(locale,
2793 LOCALE_SABBREVDAYNAME1
2794 + (xtime->wDayOfWeek+6)%7,
2795 buf, sizeof(buf));
2796 } else {
2797 sprintf(buf, dgfmt[count], xtime->wDay);
2798 }
2799 } else if (type == 'M') {
2800 if (count == 3) {
2801 GetLocaleInfoA(locale,
2802 LOCALE_SABBREVMONTHNAME1
2803 + xtime->wMonth - 1,
2804 buf, sizeof(buf));
2805 } else if (count == 4) {
2806 GetLocaleInfoA(locale,
2807 LOCALE_SMONTHNAME1
2808 + xtime->wMonth - 1,
2809 buf, sizeof(buf));
2810 } else {
2811 sprintf(buf, dgfmt[count], xtime->wMonth);
2812 }
2813 } else if (type == 'y') {
2814 if (count == 4) {
2815 sprintf(buf, "%d", xtime->wYear);
2816 } else if (count == 3) {
2817 strcpy(buf, "yyy");
2818 WARN("unknown format, c=%c, n=%d\n", type, count);
2819 } else {
2820 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2821 }
2822 } else if (type == 'g') {
2823 if (count == 2) {
2824 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2825 strcpy(buf, "AD");
2826 } else {
2827 strcpy(buf, "g");
2828 WARN("unknown format, c=%c, n=%d\n", type, count);
2829 }
2830 } else if (type == 'h') {
2831 /* gives us hours 1:00 -- 12:00 */
2832 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2833 } else if (type == 'H') {
2834 /* 24-hour time */
2835 sprintf(buf, dgfmt[count], xtime->wHour);
2836 } else if ( type == 'm') {
2837 sprintf(buf, dgfmt[count], xtime->wMinute);
2838 } else if ( type == 's') {
2839 sprintf(buf, dgfmt[count], xtime->wSecond);
2840 } else if (type == 't') {
2841 if ((tflags & TIME_NOTIMEMARKER))
2842 buf[0]='\0';
2843 else if (count == 1) {
2844 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2845 } else if (count == 2) {
2846 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2847 GetLocaleInfoA(locale,
2848 (xtime->wHour<12)
2849 ? LOCALE_S1159 : LOCALE_S2359,
2850 buf, sizeof(buf));
2851 }
2852 };
2853
2854 /* we need to check the next char in the format string
2855 again, no matter what happened */
2856 inpos--;
2857
2858 /* add the contents of buf to the output */
2859 buflen = strlen(buf);
2860 if (outpos + buflen < datelen) {
2861 date[outpos] = '\0'; /* for strcat to hook onto */
2862 strcat(date, buf);
2863 outpos += buflen;
2864 } else {
2865 date[outpos] = '\0';
2866 strncat(date, buf, datelen - outpos);
2867 date[datelen - 1] = '\0';
2868 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2869 WARN("insufficient buffer\n");
2870 return 0;
2871 }
2872
2873 /* reset the variables we used to keep track of this item */
2874 count = 0;
2875 type = '\0';
2876 } else if (format[inpos] == '\0') {
2877 /* we can't check for this at the loop-head, because
2878 that breaks the printing of the last format-item */
2879 date[outpos] = '\0';
2880 break;
2881 } else if (count) {
2882 /* continuing a code for an item */
2883 count +=1;
2884 continue;
2885 } else if (strchr("hHmstyMdg", format[inpos])) {
2886 type = format[inpos];
2887 count = 1;
2888 continue;
2889 } else if (format[inpos] == '\'') {
2890 inquote = 1;
2891 continue;
2892 } else {
2893 date[outpos++] = format[inpos];
2894 }
2895 /* now deal with a possible buffer overflow */
2896 if (outpos >= datelen) {
2897 date[datelen - 1] = '\0';
2898 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2899 return 0;
2900 }
2901 }
2902
2903 if (Overflow) {
2904 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2905 };
2906
2907 /* finish it off with a string terminator */
2908 outpos++;
2909 /* sanity check */
2910 if (outpos > datelen-1) outpos = datelen-1;
2911 date[outpos] = '\0';
2912
2913 TRACE("returns string '%s', len %d\n", date, outpos);
2914 return outpos;
2915}
2916
2917/******************************************************************************
2918 * OLE_GetFormatW [INTERNAL]
2919 */
2920static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2921 LPSYSTEMTIME xtime,
2922 LPCWSTR format,
2923 LPWSTR output, INT outlen)
2924{
2925 INT inpos, outpos;
2926 int count, type=0, inquote;
2927 int Overflow; /* loop check */
2928 char tmp[16];
2929 WCHAR buf[40];
2930 int buflen=0;
2931 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2932 WCHAR arg2[] = {'%','0','2','d',0};
2933 WCHAR *argarr[3];
2934 int datevars=0, timevars=0;
2935
2936 argarr[0] = arg0;
2937 argarr[1] = arg1;
2938 argarr[2] = arg2;
2939
2940 /* make a debug report */
2941 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2942 "%p with max len %d\n",
2943 locale, flags, tflags,
2944 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2945 debugstr_w(format), format, output, outlen);
2946
2947 if(outlen == 0) {
2948 FIXME("outlen = 0, returning 255\n");
2949 return 255;
2950 }
2951
2952 /* initialize state variables */
2953 inpos = outpos = 0;
2954 count = 0;
2955 inquote = Overflow = 0;
2956 /* this is really just a sanity check */
2957 output[0] = buf[0] = 0;
2958
2959 /* this loop is the core of the function */
2960 for (inpos = 0; /* we have several break points */ ; inpos++) {
2961 if (inquote) {
2962 if (format[inpos] == (WCHAR) '\'') {
2963 if (format[inpos+1] == '\'') {
2964 inpos++;
2965 output[outpos++] = '\'';
2966 } else {
2967 inquote = 0;
2968 continue;
2969 }
2970 } else if (format[inpos] == 0) {
2971 output[outpos++] = 0;
2972 if (outpos > outlen) Overflow = 1;
2973 break; /* normal exit (within a quote) */
2974 } else {
2975 output[outpos++] = format[inpos]; /* copy input */
2976 if (outpos > outlen) {
2977 Overflow = 1;
2978 output[outpos-1] = 0;
2979 break;
2980 }
2981 }
2982 } else if ( (count && (format[inpos] != type))
2983 || ( (count==4 && type =='y') ||
2984 (count==4 && type =='M') ||
2985 (count==4 && type =='d') ||
2986 (count==2 && type =='g') ||
2987 (count==2 && type =='h') ||
2988 (count==2 && type =='H') ||
2989 (count==2 && type =='m') ||
2990 (count==2 && type =='s') ||
2991 (count==2 && type =='t') ) ) {
2992 switch(type)
2993 {
2994 case 'd':
2995 if (count == 4) {
2996 GetLocaleInfoW(locale,
2997 LOCALE_SDAYNAME1 + (xtime->wDayOfWeek +6)%7,
2998 buf, sizeof(buf)/sizeof(WCHAR) );
2999 } else if (count == 3) {
3000 GetLocaleInfoW(locale,
3001 LOCALE_SABBREVDAYNAME1 +
3002 (xtime->wDayOfWeek +6)%7,
3003 buf, sizeof(buf)/sizeof(WCHAR) );
3004 } else {
3005 sprintf( tmp, "%.*d", count, xtime->wDay );
3006 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
3007 }
3008 break;
3009
3010 case 'M':
3011 if (count == 4) {
3012 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
3013 xtime->wMonth -1, buf,
3014 sizeof(buf)/sizeof(WCHAR) );
3015 } else if (count == 3) {
3016 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
3017 xtime->wMonth -1, buf,
3018 sizeof(buf)/sizeof(WCHAR) );
3019 } else {
3020 sprintf( tmp, "%.*d", count, xtime->wMonth );
3021 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
3022 }
3023 break;
3024 case 'y':
3025 if (count == 4) {
3026 sprintf( tmp, "%d", xtime->wYear );
3027 } else if (count == 3) {
3028 strcpy( tmp, "yyy" );
3029 } else {
3030 sprintf( tmp, "%.*d", count, xtime->wYear % 100 );
3031 }
3032 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
3033 break;
3034
3035 case 'g':
3036 if (count == 2) {
3037 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
3038 strcpy( tmp, "AD" );
3039 } else {
3040 /* Win API sez we copy it verbatim */
3041 strcpy( tmp, "g" );
3042 }
3043 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
3044 break;
3045
3046 case 'h':
3047 /* hours 1:00-12:00 --- is this right? */
3048 sprintf( tmp, "%.*d", count, (xtime->wHour-1)%12 +1);
3049 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
3050 break;
3051
3052 case 'H':
3053 sprintf( tmp, "%.*d", count, xtime->wHour );
3054 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
3055 break;
3056
3057 case 'm':
3058 sprintf( tmp, "%.*d", count, xtime->wMinute );
3059 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
3060 break;
3061
3062 case 's':
3063 sprintf( tmp, "%.*d", count, xtime->wSecond );
3064 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
3065 break;
3066
3067 case 't':
3068 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
3069 LOCALE_S1159 : LOCALE_S2359,
3070 buf, sizeof(buf) );
3071 if (count == 1) {
3072 buf[1] = 0;
3073 }
3074 break;
3075 }
3076
3077 /* no matter what happened, we need to check this next
3078 character the next time we loop through */
3079 inpos--;
3080
3081 /* cat buf onto the output */
3082 outlen = strlenW(buf);
3083 if (outpos + buflen < outlen) {
3084 strcpyW( output + outpos, buf );
3085 outpos += buflen;
3086 } else {
3087 lstrcpynW( output + outpos, buf, outlen - outpos );
3088 Overflow = 1;
3089 break; /* Abnormal exit */
3090 }
3091
3092 /* reset the variables we used this time */
3093 count = 0;
3094 type = '\0';
3095 } else if (format[inpos] == 0) {
3096 /* we can't check for this at the beginning, because that
3097 would keep us from printing a format spec that ended the
3098 string */
3099 output[outpos] = 0;
3100 break; /* NORMAL EXIT */
3101 } else if (count) {
3102 /* how we keep track of the middle of a format spec */
3103 count++;
3104 continue;
3105 } else if ( (datevars && (format[inpos]=='d' ||
3106 format[inpos]=='M' ||
3107 format[inpos]=='y' ||
3108 format[inpos]=='g') ) ||
3109 (timevars && (format[inpos]=='H' ||
3110 format[inpos]=='h' ||
3111 format[inpos]=='m' ||
3112 format[inpos]=='s' ||
3113 format[inpos]=='t') ) ) {
3114 type = format[inpos];
3115 count = 1;
3116 continue;
3117 } else if (format[inpos] == '\'') {
3118 inquote = 1;
3119 continue;
3120 } else {
3121 /* unquoted literals */
3122 output[outpos++] = format[inpos];
3123 }
3124 }
3125
3126 if (Overflow) {
3127 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3128 WARN(" buffer overflow\n");
3129 };
3130
3131 /* final string terminator and sanity check */
3132 outpos++;
3133 if (outpos > outlen-1) outpos = outlen-1;
3134 output[outpos] = '0';
3135
3136 TRACE(" returning %s\n", debugstr_w(output));
3137
3138 return (!Overflow) ? outlen : 0;
3139
3140}
3141
3142
3143/******************************************************************************
3144 * GetDateFormatA [KERNEL32.310]
3145 * Makes an ASCII string of the date
3146 *
3147 * This function uses format to format the date, or, if format
3148 * is NULL, uses the default for the locale. format is a string
3149 * of literal fields and characters as follows:
3150 *
3151 * - d single-digit (no leading zero) day (of month)
3152 * - dd two-digit day (of month)
3153 * - ddd short day-of-week name
3154 * - dddd long day-of-week name
3155 * - M single-digit month
3156 * - MM two-digit month
3157 * - MMM short month name
3158 * - MMMM full month name
3159 * - y two-digit year, no leading 0
3160 * - yy two-digit year
3161 * - yyyy four-digit year
3162 * - gg era string
3163 *
3164 */
3165INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
3166 LPSYSTEMTIME xtime,
3167 LPCSTR format, LPSTR date,INT datelen)
3168{
3169
3170 char format_buf[40];
3171 LPCSTR thisformat;
3172 SYSTEMTIME t;
3173 LPSYSTEMTIME thistime;
3174 LCID thislocale;
3175 INT ret;
3176 FILETIME ft;
3177 BOOL res;
3178
3179 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
3180 locale,flags,xtime,format,date,datelen);
3181
3182 if (!locale) {
3183 locale = LOCALE_SYSTEM_DEFAULT;
3184 };
3185
3186 if (locale == LOCALE_SYSTEM_DEFAULT) {
3187 thislocale = GetSystemDefaultLCID();
3188 } else if (locale == LOCALE_USER_DEFAULT) {
3189 thislocale = GetUserDefaultLCID();
3190 } else {
3191 thislocale = locale;
3192 };
3193
3194 if (xtime == NULL) {
3195 GetSystemTime(&t);
3196 } else {
3197 /* Silently correct wDayOfWeek by tranforming to FileTime and back again*/
3198 res=SystemTimeToFileTime(xtime,&ft);
3199 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error*/
3200 /*FIXME: SystemTimeToFileTime doesn't yet do that ckeck*/
3201 if(!res)
3202 {
3203 SetLastError(ERROR_INVALID_PARAMETER);
3204 return 0;
3205 }
3206 FileTimeToSystemTime(&ft,&t);
3207
3208 };
3209 thistime = &t;
3210
3211 if (format == NULL) {
3212 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
3213 ? LOCALE_SLONGDATE
3214 : LOCALE_SSHORTDATE),
3215 format_buf, sizeof(format_buf));
3216 thisformat = format_buf;
3217 } else {
3218 thisformat = format;
3219 };
3220
3221
3222 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
3223 date, datelen);
3224
3225
3226 TRACE(
3227 "GetDateFormatA() returning %d, with data=%s\n",
3228 ret, date);
3229 return ret;
3230}
3231
3232/******************************************************************************
3233 * GetDateFormatW [KERNEL32.311]
3234 * Makes a Unicode string of the date
3235 *
3236 * Acts the same as GetDateFormatA(), except that it's Unicode.
3237 * Accepts & returns sizes as counts of Unicode characters.
3238 *
3239 */
3240INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
3241 LPSYSTEMTIME xtime,
3242 LPCWSTR format,
3243 LPWSTR date, INT datelen)
3244{
3245 // convert "format" on passing in into ASCII
3246 LPSTR pszAsciiFormat = UnicodeToAsciiString((LPWSTR) format);
3247 LPSTR pszAsciiDate = (char *)alloca(datelen);
3248
3249 TRACE("Kernel32-ole2nls: GetDateFormatW(0x%04lx,0x%08lx,%p,%s,%p,%d) not yet complete\n",
3250 locale,flags,xtime,pszAsciiFormat,date,datelen);
3251
3252 // call ASCII variant
3253 int rc = GetDateFormatA(locale,
3254 flags,
3255 xtime,
3256 pszAsciiFormat,
3257 pszAsciiDate,
3258 datelen); // is in "characters", not bytes
3259
3260 FreeAsciiString(pszAsciiFormat);
3261
3262 // convert "date" on returning to UNICODE
3263 if (datelen != 0)
3264 {
3265 // in this case 'rc' holds the number of characters to convert
3266 lstrcpynAtoW(date, pszAsciiDate, rc);
3267 }
3268
3269 return rc;
3270
3271#if PH_OFF
3272 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
3273
3274 FIXME("STUB (should call OLE_GetFormatW)\n");
3275 lstrcpynW(date, datearr, datelen);
3276 return ( datelen < 9) ? datelen : 9;
3277#endif
3278}
3279
3280/**************************************************************************
3281 * EnumDateFormatsA (KERNEL32.198)
3282 */
3283BOOL WINAPI EnumDateFormatsA(
3284 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3285{
3286 LCID Loc = GetUserDefaultLCID();
3287 if(!lpDateFmtEnumProc)
3288 {
3289 SetLastError(ERROR_INVALID_PARAMETER);
3290 return FALSE;
3291 }
3292
3293 switch( Loc )
3294 {
3295
3296 case 0x00000407: /* (Loc,"de_DE") */
3297 {
3298 switch(dwFlags)
3299 {
3300 case DATE_SHORTDATE:
3301 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3302 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
3303 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3304 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3305 return TRUE;
3306 case DATE_LONGDATE:
3307 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
3308 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
3309 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
3310 return TRUE;
3311 default:
3312 FIXME("Unknown date format (%ld)\n", dwFlags);
3313 SetLastError(ERROR_INVALID_PARAMETER);
3314 return FALSE;
3315 }
3316 }
3317
3318 case 0x0000040c: /* (Loc,"fr_FR") */
3319 {
3320 switch(dwFlags)
3321 {
3322 case DATE_SHORTDATE:
3323 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3324 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
3325 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3326 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3327 return TRUE;
3328 case DATE_LONGDATE:
3329 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
3330 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
3331 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3332 return TRUE;
3333 default:
3334 FIXME("Unknown date format (%ld)\n", dwFlags);
3335 SetLastError(ERROR_INVALID_PARAMETER);
3336 return FALSE;
3337 }
3338 }
3339
3340 case 0x00000c0c: /* (Loc,"fr_CA") */
3341 {
3342 switch(dwFlags)
3343 {
3344 case DATE_SHORTDATE:
3345 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3346 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
3347 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
3348 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3349 return TRUE;
3350 case DATE_LONGDATE:
3351 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
3352 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
3353 return TRUE;
3354 default:
3355 FIXME("Unknown date format (%ld)\n", dwFlags);
3356 SetLastError(ERROR_INVALID_PARAMETER);
3357 return FALSE;
3358 }
3359 }
3360
3361 case 0x00000809: /* (Loc,"en_UK") */
3362 {
3363 switch(dwFlags)
3364 {
3365 case DATE_SHORTDATE:
3366 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3367 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3368 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3369 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3370 return TRUE;
3371 case DATE_LONGDATE:
3372 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3373 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3374 return TRUE;
3375 default:
3376 FIXME("Unknown date format (%ld)\n", dwFlags);
3377 SetLastError(ERROR_INVALID_PARAMETER);
3378 return FALSE;
3379 }
3380 }
3381
3382 case 0x00000c09: /* (Loc,"en_AU") */
3383 {
3384 switch(dwFlags)
3385 {
3386 case DATE_SHORTDATE:
3387 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3388 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3389 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3390 return TRUE;
3391 case DATE_LONGDATE:
3392 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
3393 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3394 return TRUE;
3395 default:
3396 FIXME("Unknown date format (%ld)\n", dwFlags);
3397 SetLastError(ERROR_INVALID_PARAMETER);
3398 return FALSE;
3399 }
3400 }
3401
3402 case 0x00001009: /* (Loc,"en_CA") */
3403 {
3404 switch(dwFlags)
3405 {
3406 case DATE_SHORTDATE:
3407 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3408 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3409 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
3410 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
3411 return TRUE;
3412 case DATE_LONGDATE:
3413 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
3414 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
3415 return TRUE;
3416 default:
3417 FIXME("Unknown date format (%ld)\n", dwFlags);
3418 SetLastError(ERROR_INVALID_PARAMETER);
3419 return FALSE;
3420 }
3421 }
3422
3423 case 0x00001409: /* (Loc,"en_NZ") */
3424 {
3425 switch(dwFlags)
3426 {
3427 case DATE_SHORTDATE:
3428 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
3429 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3430 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
3431 return TRUE;
3432 case DATE_LONGDATE:
3433 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3434 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
3435 return TRUE;
3436 default:
3437 FIXME("Unknown date format (%ld)\n", dwFlags);
3438 SetLastError(ERROR_INVALID_PARAMETER);
3439 return FALSE;
3440 }
3441 }
3442
3443 case 0x00001809: /* (Loc,"en_IE") */
3444 {
3445 switch(dwFlags)
3446 {
3447 case DATE_SHORTDATE:
3448 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
3449 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
3450 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
3451 return TRUE;
3452 case DATE_LONGDATE:
3453 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3454 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
3455 return TRUE;
3456 default:
3457 FIXME("Unknown date format (%ld)\n", dwFlags);
3458 SetLastError(ERROR_INVALID_PARAMETER);
3459 return FALSE;
3460 }
3461 }
3462
3463 case 0x00001c09: /* (Loc,"en_ZA") */
3464 {
3465 switch(dwFlags)
3466 {
3467 case DATE_SHORTDATE:
3468 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3469 return TRUE;
3470 case DATE_LONGDATE:
3471 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
3472 return TRUE;
3473 default:
3474 FIXME("Unknown date format (%ld)\n", dwFlags);
3475 SetLastError(ERROR_INVALID_PARAMETER);
3476 return FALSE;
3477 }
3478 }
3479
3480 case 0x00002009: /* (Loc,"en_JM") */
3481 {
3482 switch(dwFlags)
3483 {
3484 case DATE_SHORTDATE:
3485 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3486 return TRUE;
3487 case DATE_LONGDATE:
3488 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
3489 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
3490 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
3491 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
3492 return TRUE;
3493 default:
3494 FIXME("Unknown date format (%ld)\n", dwFlags);
3495 SetLastError(ERROR_INVALID_PARAMETER);
3496 return FALSE;
3497 }
3498 }
3499
3500 case 0x00002809: /* (Loc,"en_BZ") */
3501 case 0x00002c09: /* (Loc,"en_TT") */
3502 {
3503 switch(dwFlags)
3504 {
3505 case DATE_SHORTDATE:
3506 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
3507 return TRUE;
3508 case DATE_LONGDATE:
3509 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
3510 return TRUE;
3511 default:
3512 FIXME("Unknown date format (%ld)\n", dwFlags);
3513 SetLastError(ERROR_INVALID_PARAMETER);
3514 return FALSE;
3515 }
3516 }
3517
3518 default: /* default to US English "en_US" */
3519 {
3520 switch(dwFlags)
3521 {
3522 case DATE_SHORTDATE:
3523 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
3524 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
3525 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
3526 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
3527 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
3528 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
3529 return TRUE;
3530 case DATE_LONGDATE:
3531 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
3532 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
3533 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
3534 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
3535 return TRUE;
3536 default:
3537 FIXME("Unknown date format (%ld)\n", dwFlags);
3538 SetLastError(ERROR_INVALID_PARAMETER);
3539 return FALSE;
3540 }
3541 }
3542 }
3543}
3544
3545/**************************************************************************
3546 * EnumDateFormatsW (KERNEL32.199)
3547 */
3548BOOL WINAPI EnumDateFormatsW(
3549 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
3550{
3551 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
3552 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3553 return FALSE;
3554}
3555
3556/**************************************************************************
3557 * EnumTimeFormatsA (KERNEL32.210)
3558 */
3559BOOL WINAPI EnumTimeFormatsA(
3560 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3561{
3562 LCID Loc = GetUserDefaultLCID();
3563 if(!lpTimeFmtEnumProc)
3564 {
3565 SetLastError(ERROR_INVALID_PARAMETER);
3566 return FALSE;
3567 }
3568 if(dwFlags)
3569 {
3570 FIXME("Unknown time format (%ld)\n", dwFlags);
3571 }
3572
3573 switch( Loc )
3574 {
3575 case 0x00000407: /* (Loc,"de_DE") */
3576 {
3577 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3578 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3579 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3580 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
3581 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
3582 return TRUE;
3583 }
3584
3585 case 0x0000040c: /* (Loc,"fr_FR") */
3586 case 0x00000c0c: /* (Loc,"fr_CA") */
3587 {
3588 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
3589 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3590 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3591 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
3592 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
3593 return TRUE;
3594 }
3595
3596 case 0x00000809: /* (Loc,"en_UK") */
3597 case 0x00000c09: /* (Loc,"en_AU") */
3598 case 0x00001409: /* (Loc,"en_NZ") */
3599 case 0x00001809: /* (Loc,"en_IE") */
3600 {
3601 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3602 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3603 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3604 return TRUE;
3605 }
3606
3607 case 0x00001c09: /* (Loc,"en_ZA") */
3608 case 0x00002809: /* (Loc,"en_BZ") */
3609 case 0x00002c09: /* (Loc,"en_TT") */
3610 {
3611 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3612 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3613 return TRUE;
3614 }
3615
3616 default: /* default to US style "en_US" */
3617 {
3618 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3619 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3620 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3621 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3622 return TRUE;
3623 }
3624 }
3625}
3626
3627/**************************************************************************
3628 * EnumTimeFormatsW (KERNEL32.211)
3629 */
3630BOOL WINAPI EnumTimeFormatsW(
3631 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3632{
3633 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3634 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3635 return FALSE;
3636}
3637
3638/**************************************************************************
3639 * This function is used just locally !
3640 * Description: Inverts a string.
3641 */
3642static void OLE_InvertString(char* string)
3643{
3644 char sTmpArray[128];
3645 INT counter, i = 0;
3646
3647 for (counter = strlen(string); counter > 0; counter--)
3648 {
3649 memcpy(sTmpArray + i, string + counter-1, 1);
3650 i++;
3651 }
3652 memcpy(sTmpArray + i, "\0", 1);
3653 strcpy(string, sTmpArray);
3654}
3655
3656/***************************************************************************************
3657 * This function is used just locally !
3658 * Description: Test if the given string (psNumber) is valid or not.
3659 * The valid characters are the following:
3660 * - Characters '0' through '9'.
3661 * - One decimal point (dot) if the number is a floating-point value.
3662 * - A minus sign in the first character position if the number is
3663 * a negative value.
3664 * If the function succeeds, psBefore/psAfter will point to the string
3665 * on the right/left of the decimal symbol. pbNegative indicates if the
3666 * number is negative.
3667 */
3668static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3669{
3670char sNumberSet[] = "0123456789";
3671BOOL bInDecimal = FALSE;
3672
3673 /* Test if we do have a minus sign */
3674 if ( *pInput == '-' )
3675 {
3676 *pbNegative = TRUE;
3677 pInput++; /* Jump to the next character. */
3678 }
3679
3680 while(*pInput != '\0')
3681 {
3682 /* Do we have a valid numeric character */
3683 if ( strchr(sNumberSet, *pInput) != NULL )
3684 {
3685 if (bInDecimal == TRUE)
3686 *psAfter++ = *pInput;
3687 else
3688 *psBefore++ = *pInput;
3689 }
3690 else
3691 {
3692 /* Is this a decimal point (dot) */
3693 if ( *pInput == '.' )
3694 {
3695 /* Is it the first time we find it */
3696 if ((bInDecimal == FALSE))
3697 bInDecimal = TRUE;
3698 else
3699 return -1; /* ERROR: Invalid parameter */
3700 }
3701 else
3702 {
3703 /* It's neither a numeric character, nor a decimal point.
3704 * Thus, return an error.
3705 */
3706 return -1;
3707 }
3708 }
3709 pInput++;
3710 }
3711
3712 /* Add an End of Line character to the output buffers */
3713 *psBefore = '\0';
3714 *psAfter = '\0';
3715
3716 return 0;
3717}
3718
3719/**************************************************************************
3720 * This function is used just locally !
3721 * Description: A number could be formatted using different numbers
3722 * of "digits in group" (example: 4;3;2;0).
3723 * The first parameter of this function is an array
3724 * containing the rule to be used. It's format is the following:
3725 * |NDG|DG1|DG2|...|0|
3726 * where NDG is the number of used "digits in group" and DG1, DG2,
3727 * are the corresponding "digits in group".
3728 * Thus, this function returns the grouping value in the array
3729 * pointed by the second parameter.
3730 */
3731static INT OLE_GetGrouping(char* sRule, INT index)
3732{
3733 char sData[2], sRuleSize[2];
3734 INT nData, nRuleSize;
3735
3736 memcpy(sRuleSize, sRule, 1);
3737 memcpy(sRuleSize+1, "\0", 1);
3738 nRuleSize = atoi(sRuleSize);
3739
3740 if (index > 0 && index < nRuleSize)
3741 {
3742 memcpy(sData, sRule+index, 1);
3743 memcpy(sData+1, "\0", 1);
3744 nData = atoi(sData);
3745 }
3746
3747 else
3748 {
3749 memcpy(sData, sRule+nRuleSize-1, 1);
3750 memcpy(sData+1, "\0", 1);
3751 nData = atoi(sData);
3752 }
3753
3754 return nData;
3755}
3756
3757/**************************************************************************
3758 * GetNumberFormatA (KERNEL32.355)
3759 */
3760INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3761 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3762 LPSTR lpNumberStr, int cchNumber)
3763{
3764 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3765 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3766 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3767 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3768 char *pStr = NULL, *pTmpStr = NULL;
3769 LCID systemDefaultLCID;
3770 BOOL bNegative = FALSE;
3771 enum Operations
3772 {
3773 USE_PARAMETER,
3774 USE_LOCALEINFO,
3775 USE_SYSTEMDEFAULT,
3776 RETURN_ERROR
3777 } used_operation;
3778
3779 strncpy(sNumber, lpvalue, 128);
3780 sNumber[127] = '\0';
3781
3782 /* Make sure we have a valid input string, get the number
3783 * of digits before and after the decimal symbol, and check
3784 * if this is a negative number.
3785 */
3786 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
3787 {
3788 nNumberDecimal = strlen(sDigitsBeforeDecimal);
3789 nDigits = strlen(sDigitsAfterDecimal);
3790 }
3791 else
3792 {
3793 SetLastError(ERROR_INVALID_PARAMETER);
3794 return 0;
3795 }
3796
3797 /* Which source will we use to format the string */
3798 used_operation = RETURN_ERROR;
3799 if (lpFormat != NULL)
3800 {
3801 if (dwflags == 0)
3802 used_operation = USE_PARAMETER;
3803 }
3804 else
3805 {
3806 if (dwflags & LOCALE_NOUSEROVERRIDE)
3807 used_operation = USE_LOCALEINFO;
3808 else
3809 used_operation = USE_SYSTEMDEFAULT;
3810 }
3811
3812 /* Load the fields we need */
3813 switch(used_operation)
3814 {
3815 case USE_LOCALEINFO:
3816 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3817 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3818 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3819 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3820 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3821 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3822 break;
3823 case USE_PARAMETER:
3824 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
3825 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
3826 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
3827 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
3828 sprintf(sILZero, "%d",lpFormat->LeadingZero);
3829 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
3830 break;
3831 case USE_SYSTEMDEFAULT:
3832 systemDefaultLCID = GetSystemDefaultLCID();
3833 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3834 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3835 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3836 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3837 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3838 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3839 break;
3840 default:
3841 SetLastError(ERROR_INVALID_PARAMETER);
3842 return 0;
3843 }
3844
3845 nNumberDigits = atoi(sNumberDigits);
3846
3847 /* Remove the ";" */
3848 i=0;
3849 j = 1;
3850 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
3851 {
3852 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
3853 {
3854 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
3855 i++;
3856 j++;
3857 }
3858 }
3859 sprintf(sBuffer, "%d", i);
3860 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3861 memcpy(sRule + j, "\0", 1);
3862
3863 /* First, format the digits before the decimal. */
3864 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
3865 {
3866 /* Working on an inverted string is easier ! */
3867 OLE_InvertString(sDigitsBeforeDecimal);
3868
3869 nStep = nCounter = i = j = 0;
3870 nRuleIndex = 1;
3871 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3872
3873 /* Here, we will loop until we reach the end of the string.
3874 * An internal counter (j) is used in order to know when to
3875 * insert the "digit group symbol".
3876 */
3877 while (nNumberDecimal > 0)
3878 {
3879 i = nCounter + nStep;
3880 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
3881 nCounter++;
3882 j++;
3883 if (j >= nGrouping)
3884 {
3885 j = 0;
3886 if (nRuleIndex < sRule[0])
3887 nRuleIndex++;
3888 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3889 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
3890 nStep+= strlen(sDigitGroupSymbol);
3891 }
3892
3893 nNumberDecimal--;
3894 }
3895
3896 memcpy(sDestination + i+1, "\0", 1);
3897 /* Get the string in the right order ! */
3898 OLE_InvertString(sDestination);
3899 }
3900 else
3901 {
3902 nLZ = atoi(sILZero);
3903 if (nLZ != 0)
3904 {
3905 /* Use 0.xxx instead of .xxx */
3906 memcpy(sDestination, "0", 1);
3907 memcpy(sDestination+1, "\0", 1);
3908 }
3909 else
3910 memcpy(sDestination, "\0", 1);
3911
3912 }
3913
3914 /* Second, format the digits after the decimal. */
3915 j = 0;
3916 nCounter = nNumberDigits;
3917 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
3918 {
3919 i = strlen(sNumber) - strlen(pStr) + 1;
3920 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
3921 j = strlen(sDigitsAfterDecimal);
3922 if (j < nNumberDigits)
3923 nCounter = nNumberDigits-j;
3924 }
3925 for (i=0;i<nCounter;i++)
3926 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
3927 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
3928
3929 i = strlen(sDestination);
3930 j = strlen(sDigitsAfterDecimal);
3931 /* Finally, construct the resulting formatted string. */
3932
3933 for (nCounter=0; nCounter<i; nCounter++)
3934 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
3935
3936 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
3937
3938 for (i=0; i<j; i++)
3939 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
3940 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
3941
3942 /* Is it a negative number */
3943 if (bNegative == TRUE)
3944 {
3945 i = atoi(sNegNumber);
3946 pStr = sDestination;
3947 pTmpStr = sNumber;
3948 switch (i)
3949 {
3950 case 0:
3951 *pStr++ = '(';
3952 while (*sNumber != '\0')
3953 *pStr++ = *pTmpStr++;
3954 *pStr++ = ')';
3955 break;
3956 case 1:
3957 *pStr++ = '-';
3958 while (*pTmpStr != '\0')
3959 *pStr++ = *pTmpStr++;
3960 break;
3961 case 2:
3962 *pStr++ = '-';
3963 *pStr++ = ' ';
3964 while (*pTmpStr != '\0')
3965 *pStr++ = *pTmpStr++;
3966 break;
3967 case 3:
3968 while (*pTmpStr != '\0')
3969 *pStr++ = *pTmpStr++;
3970 *pStr++ = '-';
3971 break;
3972 case 4:
3973 while (*pTmpStr != '\0')
3974 *pStr++ = *pTmpStr++;
3975 *pStr++ = ' ';
3976 *pStr++ = '-';
3977 break;
3978 default:
3979 while (*pTmpStr != '\0')
3980 *pStr++ = *pTmpStr++;
3981 break;
3982 }
3983 }
3984 else
3985 strcpy(sDestination, sNumber);
3986
3987 /* If cchNumber is zero, then returns the number of bytes or characters
3988 * required to hold the formatted number string
3989 */
3990 if (cchNumber==0)
3991 retVal = strlen(sDestination) + 1;
3992 else
3993 {
3994 strncpy (lpNumberStr, sDestination, cchNumber-1);
3995 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
3996 retVal = strlen(lpNumberStr);
3997 }
3998
3999 return retVal;
4000}
4001
4002/**************************************************************************
4003 * GetNumberFormatW (KERNEL32.@)
4004 */
4005INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
4006 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
4007 LPWSTR lpNumberStr, int cchNumber)
4008{
4009 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
4010
4011 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
4012 return cchNumber? strlenW( lpNumberStr ) : 0;
4013}
4014
4015/**************************************************************************
4016 * GetCurrencyFormatA (KERNEL32.302)
4017 */
4018INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
4019 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
4020 LPSTR lpCurrencyStr, int cchCurrency)
4021{
4022 UINT nPosOrder, nNegOrder;
4023 INT retVal;
4024 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
4025 char *pDestination = sDestination;
4026 char sNumberFormated[128];
4027 char *pNumberFormated = sNumberFormated;
4028 LCID systemDefaultLCID;
4029 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
4030 enum Operations
4031 {
4032 USE_PARAMETER,
4033 USE_LOCALEINFO,
4034 USE_SYSTEMDEFAULT,
4035 RETURN_ERROR
4036 } used_operation;
4037
4038 NUMBERFMTA numberFmt;
4039
4040 /* Which source will we use to format the string */
4041 used_operation = RETURN_ERROR;
4042 if (lpFormat != NULL)
4043 {
4044 if (dwflags == 0)
4045 used_operation = USE_PARAMETER;
4046 }
4047 else
4048 {
4049 if (dwflags & LOCALE_NOUSEROVERRIDE)
4050 used_operation = USE_LOCALEINFO;
4051 else
4052 used_operation = USE_SYSTEMDEFAULT;
4053 }
4054
4055 /* Load the fields we need */
4056 switch(used_operation)
4057 {
4058 case USE_LOCALEINFO:
4059 /* Specific to CURRENCYFMTA*/
4060 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
4061 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
4062 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
4063
4064 nPosOrder = atoi(sPosOrder);
4065 nNegOrder = atoi(sNegOrder);
4066 break;
4067 case USE_PARAMETER:
4068 /* Specific to CURRENCYFMTA*/
4069 nNegOrder = lpFormat->NegativeOrder;
4070 nPosOrder = lpFormat->PositiveOrder;
4071 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
4072 break;
4073 case USE_SYSTEMDEFAULT:
4074 systemDefaultLCID = GetSystemDefaultLCID();
4075 /* Specific to CURRENCYFMTA*/
4076 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
4077 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
4078 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
4079
4080 nPosOrder = atoi(sPosOrder);
4081 nNegOrder = atoi(sNegOrder);
4082 break;
4083 default:
4084 SetLastError(ERROR_INVALID_PARAMETER);
4085 return 0;
4086 }
4087
4088 /* Construct a temporary number format structure */
4089 if (lpFormat != NULL)
4090 {
4091 numberFmt.NumDigits = lpFormat->NumDigits;
4092 numberFmt.LeadingZero = lpFormat->LeadingZero;
4093 numberFmt.Grouping = lpFormat->Grouping;
4094 numberFmt.NegativeOrder = 0;
4095 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
4096 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
4097 bValidFormat = TRUE;
4098 }
4099
4100 /* Make a call to GetNumberFormatA() */
4101 if (*lpvalue == '-')
4102 {
4103 bIsPositive = FALSE;
4104 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
4105 }
4106 else
4107 {
4108 bIsPositive = TRUE;
4109 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
4110 }
4111
4112 if (retVal == 0)
4113 return 0;
4114
4115 /* construct the formatted string */
4116 if (bIsPositive)
4117 {
4118 switch (nPosOrder)
4119 {
4120 case 0: /* Prefix, no separation */
4121 strcpy (pDestination, sCurrencySymbol);
4122 strcat (pDestination, pNumberFormated);
4123 break;
4124 case 1: /* Suffix, no separation */
4125 strcpy (pDestination, pNumberFormated);
4126 strcat (pDestination, sCurrencySymbol);
4127 break;
4128 case 2: /* Prefix, 1 char separation */
4129 strcpy (pDestination, sCurrencySymbol);
4130 strcat (pDestination, " ");
4131 strcat (pDestination, pNumberFormated);
4132 break;
4133 case 3: /* Suffix, 1 char separation */
4134 strcpy (pDestination, pNumberFormated);
4135 strcat (pDestination, " ");
4136 strcat (pDestination, sCurrencySymbol);
4137 break;
4138 default:
4139 SetLastError(ERROR_INVALID_PARAMETER);
4140 return 0;
4141 }
4142 }
4143 else /* negative number */
4144 {
4145 switch (nNegOrder)
4146 {
4147 case 0: /* format: ($1.1) */
4148 strcpy (pDestination, "(");
4149 strcat (pDestination, sCurrencySymbol);
4150 strcat (pDestination, pNumberFormated);
4151 strcat (pDestination, ")");
4152 break;
4153 case 1: /* format: -$1.1 */
4154 strcpy (pDestination, "-");
4155 strcat (pDestination, sCurrencySymbol);
4156 strcat (pDestination, pNumberFormated);
4157 break;
4158 case 2: /* format: $-1.1 */
4159 strcpy (pDestination, sCurrencySymbol);
4160 strcat (pDestination, "-");
4161 strcat (pDestination, pNumberFormated);
4162 break;
4163 case 3: /* format: $1.1- */
4164 strcpy (pDestination, sCurrencySymbol);
4165 strcat (pDestination, pNumberFormated);
4166 strcat (pDestination, "-");
4167 break;
4168 case 4: /* format: (1.1$) */
4169 strcpy (pDestination, "(");
4170 strcat (pDestination, pNumberFormated);
4171 strcat (pDestination, sCurrencySymbol);
4172 strcat (pDestination, ")");
4173 break;
4174 case 5: /* format: -1.1$ */
4175 strcpy (pDestination, "-");
4176 strcat (pDestination, pNumberFormated);
4177 strcat (pDestination, sCurrencySymbol);
4178 break;
4179 case 6: /* format: 1.1-$ */
4180 strcpy (pDestination, pNumberFormated);
4181 strcat (pDestination, "-");
4182 strcat (pDestination, sCurrencySymbol);
4183 break;
4184 case 7: /* format: 1.1$- */
4185 strcpy (pDestination, pNumberFormated);
4186 strcat (pDestination, sCurrencySymbol);
4187 strcat (pDestination, "-");
4188 break;
4189 case 8: /* format: -1.1 $ */
4190 strcpy (pDestination, "-");
4191 strcat (pDestination, pNumberFormated);
4192 strcat (pDestination, " ");
4193 strcat (pDestination, sCurrencySymbol);
4194 break;
4195 case 9: /* format: -$ 1.1 */
4196 strcpy (pDestination, "-");
4197 strcat (pDestination, sCurrencySymbol);
4198 strcat (pDestination, " ");
4199 strcat (pDestination, pNumberFormated);
4200 break;
4201 case 10: /* format: 1.1 $- */
4202 strcpy (pDestination, pNumberFormated);
4203 strcat (pDestination, " ");
4204 strcat (pDestination, sCurrencySymbol);
4205 strcat (pDestination, "-");
4206 break;
4207 case 11: /* format: $ 1.1- */
4208 strcpy (pDestination, sCurrencySymbol);
4209 strcat (pDestination, " ");
4210 strcat (pDestination, pNumberFormated);
4211 strcat (pDestination, "-");
4212 break;
4213 case 12: /* format: $ -1.1 */
4214 strcpy (pDestination, sCurrencySymbol);
4215 strcat (pDestination, " ");
4216 strcat (pDestination, "-");
4217 strcat (pDestination, pNumberFormated);
4218 break;
4219 case 13: /* format: 1.1- $ */
4220 strcpy (pDestination, pNumberFormated);
4221 strcat (pDestination, "-");
4222 strcat (pDestination, " ");
4223 strcat (pDestination, sCurrencySymbol);
4224 break;
4225 case 14: /* format: ($ 1.1) */
4226 strcpy (pDestination, "(");
4227 strcat (pDestination, sCurrencySymbol);
4228 strcat (pDestination, " ");
4229 strcat (pDestination, pNumberFormated);
4230 strcat (pDestination, ")");
4231 break;
4232 case 15: /* format: (1.1 $) */
4233 strcpy (pDestination, "(");
4234 strcat (pDestination, pNumberFormated);
4235 strcat (pDestination, " ");
4236 strcat (pDestination, sCurrencySymbol);
4237 strcat (pDestination, ")");
4238 break;
4239 default:
4240 SetLastError(ERROR_INVALID_PARAMETER);
4241 return 0;
4242 }
4243 }
4244
4245 if (cchCurrency == 0)
4246 return strlen(pDestination) + 1;
4247
4248 else
4249 {
4250 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
4251 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
4252 return strlen(lpCurrencyStr);
4253 }
4254}
4255
4256/**************************************************************************
4257 * GetCurrencyFormatW (KERNEL32.303)
4258 */
4259INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
4260 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
4261 LPWSTR lpCurrencyStr, int cchCurrency)
4262{
4263 FIXME("This API function is NOT implemented !\n");
4264 return 0;
4265}
4266
4267/******************************************************************************
4268 * OLE2NLS_CheckLocale [intern]
4269 */
4270static LCID OLE2NLS_CheckLocale (LCID locale)
4271{
4272 if (!locale)
4273 { locale = LOCALE_SYSTEM_DEFAULT;
4274 }
4275
4276 if (locale == LOCALE_SYSTEM_DEFAULT)
4277 { return GetSystemDefaultLCID();
4278 }
4279 else if (locale == LOCALE_USER_DEFAULT)
4280 { return GetUserDefaultLCID();
4281 }
4282 else
4283 { return locale;
4284 }
4285}
4286/******************************************************************************
4287 * GetTimeFormatA [KERNEL32.422]
4288 * Makes an ASCII string of the time
4289 *
4290 * Formats date according to format, or locale default if format is
4291 * NULL. The format consists of literal characters and fields as follows:
4292 *
4293 * h hours with no leading zero (12-hour)
4294 * hh hours with full two digits
4295 * H hours with no leading zero (24-hour)
4296 * HH hours with full two digits
4297 * m minutes with no leading zero
4298 * mm minutes with full two digits
4299 * s seconds with no leading zero
4300 * ss seconds with full two digits
4301 * t time marker (A or P)
4302 * tt time marker (AM, PM)
4303 *
4304 */
4305INT WINAPI
4306GetTimeFormatA(LCID locale, /* [in] */
4307 DWORD flags, /* [in] */
4308 LPSYSTEMTIME xtime, /* [in] */
4309 LPCSTR format, /* [in] */
4310 LPSTR timestr, /* [out] */
4311 INT timelen /* [in] */)
4312{ char format_buf[40];
4313 LPCSTR thisformat;
4314 SYSTEMTIME t;
4315 LPSYSTEMTIME thistime;
4316 LCID thislocale=0;
4317 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4318 INT ret;
4319
4320 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
4321
4322 thislocale = OLE2NLS_CheckLocale ( locale );
4323
4324 if (format == NULL)
4325 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4326 { thislocale = GetSystemDefaultLCID();
4327 }
4328 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
4329 thisformat = format_buf;
4330 }
4331 else
4332 { thisformat = format;
4333 }
4334
4335 if (xtime == NULL) /* NULL means use the current local time*/
4336 { GetLocalTime(&t);
4337 thistime = &t;
4338 }
4339 else
4340 { thistime = xtime;
4341 /* Check that hour,min and sec is in range */
4342 }
4343 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
4344 timestr, timelen);
4345 return ret;
4346}
4347
4348
4349/******************************************************************************
4350 * GetTimeFormatW [KERNEL32.423]
4351 * Makes a Unicode string of the time
4352 */
4353INT WINAPI
4354GetTimeFormatW(LCID locale, /* [in] */
4355 DWORD flags, /* [in] */
4356 LPSYSTEMTIME xtime, /* [in] */
4357 LPCWSTR format, /* [in] */
4358 LPWSTR timestr, /* [out] */
4359 INT timelen /* [in] */)
4360{ WCHAR format_buf[40];
4361 LPCWSTR thisformat;
4362 SYSTEMTIME t;
4363 LPSYSTEMTIME thistime;
4364 LCID thislocale=0;
4365 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
4366 INT ret;
4367
4368 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
4369 xtime,debugstr_w(format),timestr,timelen);
4370
4371 thislocale = OLE2NLS_CheckLocale ( locale );
4372
4373 if (format == NULL)
4374 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
4375 { thislocale = GetSystemDefaultLCID();
4376 }
4377 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
4378 thisformat = format_buf;
4379 }
4380 else
4381 { thisformat = format;
4382 }
4383
4384 if (xtime == NULL) /* NULL means use the current local time*/
4385 { GetLocalTime(&t);
4386 thistime = &t;
4387 }
4388 else
4389 { thistime = xtime;
4390 }
4391
4392 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
4393 timestr, timelen);
4394 return ret;
4395}
4396
4397/******************************************************************************
4398 * EnumCalendarInfoA [KERNEL32.196]
4399 */
4400BOOL WINAPI EnumCalendarInfoA(
4401 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
4402) {
4403 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);
4404 return FALSE;
4405}
4406
4407#ifdef __WIN32OS2__
4408/*****************************************************************************
4409 * Name : BOOL WIN32API EnumCalendarInfoW
4410 * Purpose : The EnumCalendarInfoW function enumerates calendar information
4411 * for a specified locale. The CalType parameter specifies the type
4412 * of calendar information to enumerate. The function returns the
4413 * specified calendar information for all applicable calendars for
4414 * the locale, or for a single requested calendar, depending on the
4415 * value of the Calendar parameter.
4416 * The EnumCalendarInfo function enumerates the calendar information
4417 * by calling an application-defined callback function. It passes
4418 * the callback function a pointer to a string buffer containing
4419 * the requested calendar information. This continues until either
4420 * the last applicable calendar is found or the callback function
4421 * returns FALSE.
4422 * Parameters: CALINFO_ENUMPROCW lpCalInfoEnumProc pointer to enumeration
4423 * callback function
4424 * LCID Locale locale whose calendar information is of interest
4425 * CALID Calendar calendar whose information is of interest
4426 * CALTYPE CalType type of calendar information of interest
4427 * Variables :
4428 * Result : If the function succeeds, the return value is nonzero.
4429 * If the function fails, the return value is zero
4430 * Remark :
4431 * Status : UNTESTED STUB
4432 *
4433 * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
4434 *****************************************************************************/
4435
4436BOOL WIN32API EnumCalendarInfoW(CALINFO_ENUMPROCW lpCalInfoEnumProc,
4437 LCID Locale,
4438 CALID Calendar,
4439 CALTYPE CalType)
4440{
4441
4442 dprintf(("KERNEL32: EnumCalendarInfoW(%08x,%08x,%08x,%08x)not implemented\n",
4443 lpCalInfoEnumProc,
4444 Locale,
4445 Calendar,
4446 CalType
4447 ));
4448
4449 return (FALSE);
4450}
4451#endif
Note: See TracBrowser for help on using the repository browser.