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

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

DT: IFIRSTDAYOFWEEK changes/fixes

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