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

Last change on this file since 5737 was 5737, checked in by sandervl, 24 years ago

Fixed FS corruption in LCMapStringA/W + ole2nls resync

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