source: trunk/src/kernel32/ole2nls.c@ 21302

Last change on this file since 21302 was 21302, checked in by ydario, 16 years ago

Kernel32 updates.

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