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

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

logging updates

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