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

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

codepage, getlocaleinfo + thread tib updates

File size: 119.6 KB
Line 
1/* $Id: ole2nls.c,v 1.1 2002-02-07 16:34:53 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 */
1372#ifdef __WIN32OS2__
1373ODINFUNCTION6(INT, LCMapStringA,
1374 LCID, lcid, /* [in] locale identifier created with MAKELCID;
1375 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1376 predefined values. */
1377 DWORD, mapflags, /* [in] flags */
1378 LPCSTR, srcstr, /* [in] source buffer */
1379 INT, srclen, /* [in] source length */
1380 LPSTR, dststr, /* [out] destination buffer */
1381 INT, dstlen) /* [in] destination buffer length */
1382{
1383 int i;
1384#else
1385INT WINAPI LCMapStringA(
1386 LCID lcid, /* [in] locale identifier created with MAKELCID;
1387 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are
1388 predefined values. */
1389 DWORD mapflags, /* [in] flags */
1390 LPCSTR srcstr, /* [in] source buffer */
1391 INT srclen, /* [in] source length */
1392 LPSTR dststr, /* [out] destination buffer */
1393 INT dstlen) /* [in] destination buffer length */
1394{
1395 int i;
1396
1397 TRACE("(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1398 lcid,mapflags,srcstr,srclen,dststr,dstlen);
1399#endif
1400
1401 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1402 {
1403 ERR("(src=%s,dest=%s): Invalid NULL string\n", srcstr, dststr);
1404 SetLastError(ERROR_INVALID_PARAMETER);
1405 return 0;
1406 }
1407 if (srclen == -1)
1408 srclen = strlen(srcstr) + 1 ; /* (include final '\0') */
1409
1410#define LCMAPSTRINGA_SUPPORTED_FLAGS (LCMAP_UPPERCASE | \
1411 LCMAP_LOWERCASE | \
1412 LCMAP_SORTKEY | \
1413 NORM_IGNORECASE | \
1414 NORM_IGNORENONSPACE | \
1415 SORT_STRINGSORT | \
1416 NORM_IGNOREWIDTH | \
1417 NORM_IGNOREKANATYPE)
1418 /* FIXME: as long as we don't support Katakana nor Hiragana
1419 * characters, we can support NORM_IGNOREKANATYPE
1420 */
1421#ifdef DEBUG
1422 if (mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS)
1423 {
1424 FIXME("(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1425 "unimplemented flags: 0x%08lx\n",
1426 lcid,
1427 mapflags,
1428 srcstr,
1429 srclen,
1430 dststr,
1431 dstlen,
1432 mapflags & ~LCMAPSTRINGA_SUPPORTED_FLAGS
1433 );
1434 }
1435#endif
1436
1437 if ( !(mapflags & LCMAP_SORTKEY) )
1438 {
1439 int i,j;
1440 int (* f)(int) = identity;
1441
1442 int flag_ignorenonspace = mapflags & NORM_IGNORENONSPACE;
1443 int flag_ignoresymbols = mapflags & NORM_IGNORESYMBOLS;
1444
1445 if (flag_ignorenonspace || flag_ignoresymbols)
1446 {
1447 /* For some values of mapflags, the length of the resulting
1448 string is not known at this point. Windows does map the string
1449 and does not SetLastError ERROR_INSUFFICIENT_BUFFER in
1450 these cases. */
1451 if (dstlen==0)
1452 {
1453 /* Compute required length */
1454 for (i=j=0; i < srclen; i++)
1455 {
1456 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1457 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1458 j++;
1459 }
1460 return j;
1461 }
1462 }
1463 else
1464 {
1465 if (dstlen==0)
1466 return srclen;
1467 if (dstlen<srclen)
1468 {
1469 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1470 return 0;
1471 }
1472 }
1473 if (mapflags & LCMAP_UPPERCASE)
1474 f = toupper;
1475 else if (mapflags & LCMAP_LOWERCASE)
1476 f = tolower;
1477 /* FIXME: NORM_IGNORENONSPACE requires another conversion */
1478 for (i=j=0; (i<srclen) && (j<dstlen) ; i++)
1479 {
1480 if ( !(flag_ignorenonspace && OLE2NLS_isNonSpacing(srcstr[i]))
1481 && !(flag_ignoresymbols && OLE2NLS_isSymbol(srcstr[i])) )
1482 {
1483 dststr[j] = (CHAR) f(srcstr[i]);
1484 j++;
1485 }
1486 }
1487 return j;
1488 }
1489
1490 /* FIXME: This function completely ignores the "lcid" parameter. */
1491 /* else ... (mapflags & LCMAP_SORTKEY) */
1492 {
1493 int unicode_len=0;
1494 int case_len=0;
1495 int diacritic_len=0;
1496 int delayed_punctuation_len=0;
1497 char *case_component;
1498 char *diacritic_component;
1499 char *delayed_punctuation_component;
1500 int room,count;
1501 int flag_stringsort = mapflags & SORT_STRINGSORT;
1502
1503 /* compute how much room we will need */
1504 for (i=0;i<srclen;i++)
1505 {
1506 int ofs;
1507 unsigned char source_char = srcstr[i];
1508 if (source_char!='\0')
1509 {
1510 if (flag_stringsort || !OLE2NLS_isPunctuation(source_char))
1511 {
1512 unicode_len++;
1513 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
1514 unicode_len++; /* double letter */
1515 }
1516 else
1517 {
1518 delayed_punctuation_len++;
1519 }
1520 }
1521
1522 if (isupper(source_char))
1523 case_len=unicode_len;
1524
1525 ofs = source_char - LCM_Diacritic_Start;
1526 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
1527 diacritic_len=unicode_len;
1528 }
1529
1530 if (mapflags & NORM_IGNORECASE)
1531 case_len=0;
1532 if (mapflags & NORM_IGNORENONSPACE)
1533 diacritic_len=0;
1534
1535 room = 2 * unicode_len /* "unicode" component */
1536 + diacritic_len /* "diacritic" component */
1537 + case_len /* "case" component */
1538 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
1539 + 4 /* four '\1' separators */
1540 + 1 ; /* terminal '\0' */
1541 if (dstlen==0)
1542 return room;
1543 else if (dstlen<room)
1544 {
1545 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1546 return 0;
1547 }
1548#if 0
1549 /*FIXME the Pointercheck should not be nessesary */
1550 if (IsBadWritePtr (dststr,room))
1551 { ERR("bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
1552 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1553 return 0;
1554 }
1555#endif
1556 /* locate each component, write separators */
1557 diacritic_component = dststr + 2*unicode_len ;
1558 *diacritic_component++ = '\1';
1559 case_component = diacritic_component + diacritic_len ;
1560 *case_component++ = '\1';
1561 delayed_punctuation_component = case_component + case_len ;
1562 *delayed_punctuation_component++ = '\1';
1563 *delayed_punctuation_component++ = '\1';
1564
1565 /* read source string char by char, write
1566 corresponding weight in each component. */
1567 for (i=0,count=0;i<srclen;i++)
1568 {
1569 unsigned char source_char=srcstr[i];
1570 if (source_char!='\0')
1571 {
1572 int type,longcode;
1573 type = LCM_Unicode_LUT[-2+2*source_char];
1574 longcode = type >> 4;
1575 type &= 15;
1576 if (!flag_stringsort && OLE2NLS_isPunctuation(source_char))
1577 {
1578 WORD encrypted_location = (1<<15) + 7 + 4*count;
1579 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
1580 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
1581 /* big-endian is used here because it lets string comparison be
1582 compatible with numerical comparison */
1583
1584 *delayed_punctuation_component++ = type;
1585 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
1586 /* assumption : a punctuation character is never a
1587 double or accented letter */
1588 }
1589 else
1590 {
1591 dststr[2*count] = type;
1592 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
1593 if (longcode)
1594 {
1595 if (count<case_len)
1596 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1597 if (count<diacritic_len)
1598 diacritic_component[count] = 2; /* assumption: a double letter
1599 is never accented */
1600 count++;
1601
1602 dststr[2*count] = type;
1603 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
1604 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1605 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1606 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1607 }
1608
1609 if (count<case_len)
1610 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1611 if (count<diacritic_len)
1612 {
1613 int ofs = source_char - LCM_Diacritic_Start;
1614 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
1615 }
1616 count++;
1617 }
1618 }
1619 }
1620 dststr[room-1] = '\0';
1621 return room;
1622 }
1623}
1624
1625/*************************************************************************
1626 * LCMapStringW [KERNEL32.493]
1627 *
1628 * Convert a string, or generate a sort key from it.
1629 *
1630 * NOTE
1631 *
1632 * See LCMapStringA for documentation
1633 */
1634#ifdef __WIN32OS2__
1635ODINFUNCTION6(INT, LCMapStringW,
1636 LCID, lcid,DWORD, mapflags,LPCWSTR, srcstr,INT, srclen,LPWSTR, dststr,
1637 INT, dstlen)
1638{
1639 int i;
1640
1641#else
1642INT WINAPI LCMapStringW(
1643 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT srclen,LPWSTR dststr,
1644 INT dstlen)
1645{
1646 int i;
1647
1648 TRACE("(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
1649 lcid, mapflags, srcstr, srclen, dststr, dstlen);
1650#endif
1651
1652 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1653 {
1654 ERR("(src=%p,dst=%p): Invalid NULL string\n", srcstr, dststr);
1655 SetLastError(ERROR_INVALID_PARAMETER);
1656 return 0;
1657 }
1658 if (srclen==-1)
1659 srclen = strlenW(srcstr)+1;
1660
1661 /* FIXME: Both this function and it's companion LCMapStringA()
1662 * completely ignore the "lcid" parameter. In place of the "lcid"
1663 * parameter the application must set the "LC_COLLATE" or "LC_ALL"
1664 * environment variable prior to invoking this function. */
1665 if (mapflags & LCMAP_SORTKEY)
1666 {
1667 /* Possible values of LC_COLLATE. */
1668 char *lc_collate_default = 0; /* value prior to this function */
1669 char *lc_collate_env = 0; /* value retrieved from the environment */
1670
1671 /* General purpose index into strings of any type. */
1672 int str_idx = 0;
1673
1674 /* Lengths of various strings where the length is measured in
1675 * wide characters for wide character strings and in bytes for
1676 * native strings. The lengths include the NULL terminator. */
1677 size_t returned_len = 0;
1678 size_t src_native_len = 0;
1679 size_t dst_native_len = 0;
1680 size_t dststr_libc_len = 0;
1681
1682 /* Native (character set determined by locale) versions of the
1683 * strings source and destination strings. */
1684 LPSTR src_native = 0;
1685 LPSTR dst_native = 0;
1686
1687 /* Version of the source and destination strings using the
1688 * "wchar_t" Unicode data type needed by various libc functions. */
1689 wchar_t *srcstr_libc = 0;
1690 wchar_t *dststr_libc = 0;
1691
1692 if(!(srcstr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1693 srclen * sizeof(wchar_t))))
1694 {
1695 ERR("Unable to allocate %d bytes for srcstr_libc\n",
1696 srclen * sizeof(wchar_t));
1697 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1698 return 0;
1699 }
1700
1701 /* Convert source string to a libc Unicode string. */
1702 for(str_idx = 0; str_idx < srclen; str_idx++)
1703 {
1704 srcstr_libc[str_idx] = srcstr[str_idx];
1705 }
1706
1707 /* src_native should contain at most 3 bytes for each
1708 * multibyte characters in the original srcstr string. */
1709 src_native_len = 3 * srclen;
1710 if(!(src_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0,
1711 src_native_len)))
1712 {
1713 ERR("Unable to allocate %d bytes for src_native\n", src_native_len);
1714 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1715 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1716 return 0;
1717 }
1718
1719 /* FIXME: Prior to to setting the LC_COLLATE locale category the
1720 * current value is backed up so it can be restored after the
1721 * last LC_COLLATE sensitive function returns.
1722 *
1723 * Even though the locale is adjusted for a minimum amount of
1724 * time a race condition exists where other threads may be
1725 * affected if they invoke LC_COLLATE sensitive functions. One
1726 * possible solution is to wrap all LC_COLLATE sensitive Wine
1727 * functions, like LCMapStringW(), in a mutex.
1728 *
1729 * Another enhancement to the following would be to set the
1730 * LC_COLLATE locale category as a function of the "lcid"
1731 * parameter instead of the "LC_COLLATE" environment variable. */
1732 if(!(lc_collate_default = setlocale(LC_COLLATE, NULL)))
1733 {
1734 ERR("Unable to query the LC_COLLATE catagory\n");
1735 SetLastError(ERROR_INVALID_PARAMETER);
1736 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1737 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1738 return 0;
1739 }
1740
1741 if(!(lc_collate_env = setlocale(LC_COLLATE, "")))
1742 {
1743 ERR("Unable to inherit the LC_COLLATE locale category from the "
1744 "environment. The \"LC_COLLATE\" environment variable is "
1745 "\"%s\".\n", getenv("LC_COLLATE") ?
1746 getenv("LC_COLLATE") : "<unset>");
1747 SetLastError(ERROR_INVALID_PARAMETER);
1748 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1749 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1750 return 0;
1751 }
1752
1753 TRACE("lc_collate_default = %s\n", lc_collate_default);
1754 TRACE("lc_collate_env = %s\n", lc_collate_env);
1755
1756 /* Convert the libc Unicode string to a native multibyte character
1757 * string. */
1758 returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1;
1759 if(returned_len == 0)
1760 {
1761 LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(),
1762 0, srcstr);
1763 ERR("wcstombs failed. The string specified (%s) may contains an "
1764 "invalid character.\n", srcstr_ascii);
1765 SetLastError(ERROR_INVALID_PARAMETER);
1766 if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii);
1767 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1768 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1769 setlocale(LC_COLLATE, lc_collate_default);
1770 return 0;
1771 }
1772 else if(returned_len > src_native_len)
1773 {
1774 src_native[src_native_len - 1] = 0;
1775 ERR("wcstombs returned a string (%s) that was longer (%d bytes) "
1776 "than expected (%d bytes).\n", src_native, returned_len,
1777 dst_native_len);
1778
1779 /* Since this is an internal error I'm not sure what the correct
1780 * error code is. */
1781 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1782
1783 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1784 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1785 setlocale(LC_COLLATE, lc_collate_default);
1786 return 0;
1787 }
1788 src_native_len = returned_len;
1789
1790 TRACE("src_native = %s src_native_len = %d\n",
1791 src_native, src_native_len);
1792
1793 /* dst_native seems to contain at most 4 bytes for each byte in
1794 * the original src_native string. Change if need be since this
1795 * isn't documented by the strxfrm() man page. */
1796 dst_native_len = 4 * src_native_len;
1797 if(!(dst_native = (LPSTR)HeapAlloc(GetProcessHeap(), 0, dst_native_len)))
1798 {
1799 ERR("Unable to allocate %d bytes for dst_native\n", dst_native_len);
1800 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1801 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1802 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1803 setlocale(LC_COLLATE, lc_collate_default);
1804 return 0;
1805 }
1806
1807 /* The actual translation is done by the following call to
1808 * strxfrm(). The surrounding code could have been simplified
1809 * by calling wcsxfrm() instead except that wcsxfrm() is not
1810 * available on older Linux systems (RedHat 4.1 with
1811 * libc-5.3.12-17).
1812 *
1813 * Also, it is possible that the translation could be done by
1814 * various tables as it is done in LCMapStringA(). However, I'm
1815 * not sure what those tables are. */
1816 returned_len = strxfrm(dst_native, src_native, dst_native_len) + 1;
1817
1818 if(returned_len > dst_native_len)
1819 {
1820 dst_native[dst_native_len - 1] = 0;
1821 ERR("strxfrm returned a string (%s) that was longer (%d bytes) "
1822 "than expected (%d bytes).\n", dst_native, returned_len,
1823 dst_native_len);
1824
1825 /* Since this is an internal error I'm not sure what the correct
1826 * error code is. */
1827 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1828
1829 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1830 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1831 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
1832 setlocale(LC_COLLATE, lc_collate_default);
1833 return 0;
1834 }
1835 dst_native_len = returned_len;
1836
1837 TRACE("dst_native = %s dst_native_len = %d\n",
1838 dst_native, dst_native_len);
1839
1840 dststr_libc_len = dst_native_len;
1841 if(!(dststr_libc = (wchar_t *)HeapAlloc(GetProcessHeap(), 0,
1842 dststr_libc_len * sizeof(wchar_t))))
1843 {
1844 ERR("Unable to allocate %d bytes for dststr_libc\n",
1845 dststr_libc_len * sizeof(wchar_t));
1846 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1847 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1848 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1849 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
1850 setlocale(LC_COLLATE, lc_collate_default);
1851 return 0;
1852 }
1853
1854 /* Convert the native multibyte string to a libc Unicode string. */
1855 returned_len = mbstowcs(dststr_libc, dst_native, dst_native_len) + 1;
1856
1857 /* Restore LC_COLLATE now that the last LC_COLLATE sensitive
1858 * function has returned. */
1859 setlocale(LC_COLLATE, lc_collate_default);
1860
1861 if(returned_len == 0)
1862 {
1863 ERR("mbstowcs failed. The native version of the translated string "
1864 "(%s) may contain an invalid character.\n", dst_native);
1865 SetLastError(ERROR_INVALID_PARAMETER);
1866 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1867 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1868 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
1869 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
1870 return 0;
1871 }
1872 if(dstlen)
1873 {
1874 if(returned_len > dstlen)
1875 {
1876 ERR("mbstowcs returned a string that was longer (%d chars) "
1877 "than the buffer provided (%d chars).\n", returned_len,
1878 dstlen);
1879 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1880 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1881 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1882 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
1883 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
1884 return 0;
1885 }
1886 dstlen = returned_len;
1887
1888 /* Convert a libc Unicode string to the destination string. */
1889 for(str_idx = 0; str_idx < dstlen; str_idx++)
1890 {
1891 dststr[str_idx] = dststr_libc[str_idx];
1892 }
1893 TRACE("1st 4 int sized chunks of dststr = %x %x %x %x\n",
1894 *(((int *)dststr) + 0),
1895 *(((int *)dststr) + 1),
1896 *(((int *)dststr) + 2),
1897 *(((int *)dststr) + 3));
1898 }
1899 else
1900 {
1901 dstlen = returned_len;
1902 }
1903 TRACE("dstlen (return) = %d\n", dstlen);
1904 if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc);
1905 if(src_native) HeapFree(GetProcessHeap(), 0, src_native);
1906 if(dst_native) HeapFree(GetProcessHeap(), 0, dst_native);
1907 if(dststr_libc) HeapFree(GetProcessHeap(), 0, dststr_libc);
1908 return dstlen;
1909 }
1910 else
1911 {
1912 int (*f)(int)=identity;
1913
1914 if (dstlen==0)
1915 return srclen;
1916 if (dstlen<srclen)
1917 {
1918 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1919 return 0;
1920 }
1921
1922 if (mapflags & LCMAP_UPPERCASE)
1923 f = toupper;
1924 else if (mapflags & LCMAP_LOWERCASE)
1925 f = tolower;
1926 for (i=0; i < srclen; i++)
1927 dststr[i] = (WCHAR) f(srcstr[i]);
1928 return srclen;
1929 }
1930}
1931
1932
1933/***********************************************************************
1934 * OLE2NLS_EstimateMappingLength
1935 *
1936 * Estimates the number of characters required to hold the string
1937 * computed by LCMapStringA.
1938 *
1939 * The size is always over-estimated, with a fixed limit on the
1940 * amount of estimation error.
1941 *
1942 * Note that len == -1 is not permitted.
1943 */
1944static inline int OLE2NLS_EstimateMappingLength(LCID lcid, DWORD dwMapFlags,
1945 LPCSTR str, DWORD len)
1946{
1947 /* Estimate only for small strings to keep the estimation error from
1948 * becoming too large. */
1949 if (len < 128) return len * 8 + 5;
1950 else return LCMapStringA(lcid, dwMapFlags, str, len, NULL, 0);
1951}
1952
1953/******************************************************************************
1954 * CompareStringA [KERNEL32.143]
1955 * Compares two strings using locale
1956 *
1957 * RETURNS
1958 *
1959 * success: CSTR_LESS_THAN, CSTR_EQUAL, CSTR_GREATER_THAN
1960 * failure: 0
1961 *
1962 * NOTES
1963 *
1964 * Defaults to a word sort, but uses a string sort if
1965 * SORT_STRINGSORT is set.
1966 * Calls SetLastError for ERROR_INVALID_FLAGS, ERROR_INVALID_PARAMETER.
1967 *
1968 * BUGS
1969 *
1970 * This implementation ignores the locale
1971 *
1972 * FIXME
1973 *
1974 * Quite inefficient.
1975 */
1976UINT WINAPI CompareStringA(
1977 DWORD lcid, /* [in] locale ID */
1978 DWORD fdwStyle, /* [in] comparison-style options */
1979 LPCSTR s1, /* [in] first string */
1980 DWORD l1, /* [in] length of first string */
1981 LPCSTR s2, /* [in] second string */
1982 DWORD l2) /* [in] length of second string */
1983{
1984 int mapstring_flags;
1985 int len1,len2;
1986 int result;
1987 LPSTR sk1,sk2;
1988 TRACE("%s and %s\n",
1989 debugstr_a (s1), debugstr_a (s2));
1990
1991 if ( (s1==NULL) || (s2==NULL) )
1992 {
1993 ERR("(s1=%s,s2=%s): Invalid NULL string\n", s1, s2);
1994 SetLastError(ERROR_INVALID_PARAMETER);
1995 return 0;
1996 }
1997
1998 if(fdwStyle & NORM_IGNORESYMBOLS)
1999 FIXME("IGNORESYMBOLS not supported\n");
2000
2001 if (l1 == -1) l1 = strlen(s1);
2002 if (l2 == -1) l2 = strlen(s2);
2003
2004 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
2005 len1 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s1, l1);
2006 len2 = OLE2NLS_EstimateMappingLength(lcid, mapstring_flags, s2, l2);
2007
2008 if ((len1==0)||(len2==0))
2009 return 0; /* something wrong happened */
2010
2011 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len1 + len2);
2012 sk2 = sk1 + len1;
2013 if ( (!LCMapStringA(lcid,mapstring_flags,s1,l1,sk1,len1))
2014 || (!LCMapStringA(lcid,mapstring_flags,s2,l2,sk2,len2)) )
2015 {
2016 ERR("Bug in LCmapStringA.\n");
2017 result = 0;
2018 }
2019 else
2020 {
2021 /* strcmp doesn't necessarily return -1, 0, or 1 */
2022 result = strcmp(sk1,sk2);
2023 }
2024 HeapFree(GetProcessHeap(),0,sk1);
2025
2026 if (result < 0)
2027 return 1;
2028 if (result == 0)
2029 return 2;
2030
2031 /* must be greater, if we reach this point */
2032 return 3;
2033}
2034
2035/******************************************************************************
2036 * CompareStringW [KERNEL32.144]
2037 * This implementation ignores the locale
2038 * FIXME : Does only string sort. Should
2039 * be reimplemented the same way as CompareStringA.
2040 */
2041UINT WINAPI CompareStringW(DWORD lcid, DWORD fdwStyle,
2042 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
2043{
2044 int len,ret;
2045 if(fdwStyle & NORM_IGNORENONSPACE)
2046 FIXME("IGNORENONSPACE not supprted\n");
2047 if(fdwStyle & NORM_IGNORESYMBOLS)
2048 FIXME("IGNORESYMBOLS not supported\n");
2049
2050 /* Is strcmp defaulting to string sort or to word sort?? */
2051 /* FIXME: Handle NORM_STRINGSORT */
2052 l1 = (l1==-1)?strlenW(s1):l1;
2053 l2 = (l2==-1)?strlenW(s2):l2;
2054 len = l1<l2 ? l1:l2;
2055 ret = (fdwStyle & NORM_IGNORECASE) ? strncmpiW(s1,s2,len) : strncmpW(s1,s2,len);
2056 /* not equal, return 1 or 3 */
2057 if(ret!=0) {
2058 /* need to translate result */
2059 return ((int)ret < 0) ? 1 : 3;
2060 }
2061 /* same len, return 2 */
2062 if(l1==l2) return 2;
2063 /* the longer one is lexically greater */
2064 return (l1<l2)? 1 : 3;
2065}
2066
2067/******************************************************************************
2068 * OLE_GetFormatA [Internal]
2069 *
2070 * FIXME
2071 * If datelen == 0, it should return the reguired string length.
2072 *
2073 This function implements stuff for GetDateFormat() and
2074 GetTimeFormat().
2075
2076 d single-digit (no leading zero) day (of month)
2077 dd two-digit day (of month)
2078 ddd short day-of-week name
2079 dddd long day-of-week name
2080 M single-digit month
2081 MM two-digit month
2082 MMM short month name
2083 MMMM full month name
2084 y two-digit year, no leading 0
2085 yy two-digit year
2086 yyyy four-digit year
2087 gg era string
2088 h hours with no leading zero (12-hour)
2089 hh hours with full two digits
2090 H hours with no leading zero (24-hour)
2091 HH hours with full two digits
2092 m minutes with no leading zero
2093 mm minutes with full two digits
2094 s seconds with no leading zero
2095 ss seconds with full two digits
2096 t time marker (A or P)
2097 tt time marker (AM, PM)
2098 '' used to quote literal characters
2099 '' (within a quoted string) indicates a literal '
2100
2101 These functions REQUIRE valid locale, date, and format.
2102 */
2103static INT OLE_GetFormatA(LCID locale,
2104 DWORD flags,
2105 DWORD tflags,
2106 LPSYSTEMTIME xtime,
2107 LPCSTR _format, /*in*/
2108 LPSTR date, /*out*/
2109 INT datelen)
2110{
2111 INT inpos, outpos;
2112 int count, type, inquote, Overflow;
2113 char buf[40];
2114 char format[40];
2115 char * pos;
2116 int buflen;
2117
2118 const char * _dgfmt[] = { "%d", "%02d" };
2119 const char ** dgfmt = _dgfmt - 1;
2120
2121 /* report, for debugging */
2122 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",
2123 locale, flags, tflags,
2124 xtime->wYear,xtime->wMonth,xtime->wDayOfWeek,xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2125 _format, _format, date, datelen);
2126
2127 if(datelen == 0) {
2128 FIXME("datelen = 0, returning 255\n");
2129 return 255;
2130 }
2131
2132 /* initalize state variables and output buffer */
2133 inpos = outpos = 0;
2134 count = 0; inquote = 0; Overflow = 0;
2135 type = '\0';
2136 date[0] = buf[0] = '\0';
2137
2138 strcpy(format,_format);
2139
2140 /* alter the formatstring, while it works for all languages now in wine
2141 its possible that it fails when the time looks like ss:mm:hh as example*/
2142 if (tflags & (TIME_NOMINUTESORSECONDS))
2143 { if ((pos = strstr ( format, ":mm")))
2144 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2145 }
2146 }
2147 if (tflags & (TIME_NOSECONDS))
2148 { if ((pos = strstr ( format, ":ss")))
2149 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
2150 }
2151 }
2152
2153 for (inpos = 0;; inpos++) {
2154 /* 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]); */
2155 if (inquote) {
2156 if (format[inpos] == '\'') {
2157 if (format[inpos+1] == '\'') {
2158 inpos += 1;
2159 date[outpos++] = '\'';
2160 } else {
2161 inquote = 0;
2162 continue; /* we did nothing to the output */
2163 }
2164 } else if (format[inpos] == '\0') {
2165 date[outpos++] = '\0';
2166 if (outpos > datelen) Overflow = 1;
2167 break;
2168 } else {
2169 date[outpos++] = format[inpos];
2170 if (outpos > datelen) {
2171 Overflow = 1;
2172 date[outpos-1] = '\0'; /* this is the last place where
2173 it's safe to write */
2174 break;
2175 }
2176 }
2177 } else if ( (count && (format[inpos] != type))
2178 || count == 4
2179 || (count == 2 && strchr("ghHmst", type)) ) {
2180 if (type == 'h' && (tflags & TIME_FORCE24HOURFORMAT)) type= 'H';
2181 if (type == 'd') {
2182 if (count == 4) {
2183 GetLocaleInfoA(locale,
2184 LOCALE_SDAYNAME1
2185 + (xtime->wDayOfWeek+6)%7,
2186 buf, sizeof(buf));
2187 } else if (count == 3) {
2188 GetLocaleInfoA(locale,
2189 LOCALE_SABBREVDAYNAME1
2190 + (xtime->wDayOfWeek+6)%7,
2191 buf, sizeof(buf));
2192 } else {
2193 sprintf(buf, dgfmt[count], xtime->wDay);
2194 }
2195 } else if (type == 'M') {
2196 if (count == 3) {
2197 GetLocaleInfoA(locale,
2198 LOCALE_SABBREVMONTHNAME1
2199 + xtime->wMonth - 1,
2200 buf, sizeof(buf));
2201 } else if (count == 4) {
2202 GetLocaleInfoA(locale,
2203 LOCALE_SMONTHNAME1
2204 + xtime->wMonth - 1,
2205 buf, sizeof(buf));
2206 } else {
2207 sprintf(buf, dgfmt[count], xtime->wMonth);
2208 }
2209 } else if (type == 'y') {
2210 if (count == 4) {
2211 sprintf(buf, "%d", xtime->wYear);
2212 } else if (count == 3) {
2213 strcpy(buf, "yyy");
2214 WARN("unknown format, c=%c, n=%d\n", type, count);
2215 } else {
2216 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2217 }
2218 } else if (type == 'g') {
2219 if (count == 2) {
2220 FIXME("LOCALE_ICALENDARTYPE unimp.\n");
2221 strcpy(buf, "AD");
2222 } else {
2223 strcpy(buf, "g");
2224 WARN("unknown format, c=%c, n=%d\n", type, count);
2225 }
2226 } else if (type == 'h') {
2227 /* gives us hours 1:00 -- 12:00 */
2228 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2229 } else if (type == 'H') {
2230 /* 24-hour time */
2231 sprintf(buf, dgfmt[count], xtime->wHour);
2232 } else if ( type == 'm') {
2233 sprintf(buf, dgfmt[count], xtime->wMinute);
2234 } else if ( type == 's') {
2235 sprintf(buf, dgfmt[count], xtime->wSecond);
2236 } else if (type == 't') {
2237 if ((tflags & TIME_NOTIMEMARKER))
2238 buf[0]='\0';
2239 else if (count == 1) {
2240 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2241 } else if (count == 2) {
2242 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2243 GetLocaleInfoA(locale,
2244 (xtime->wHour<12)
2245 ? LOCALE_S1159 : LOCALE_S2359,
2246 buf, sizeof(buf));
2247 }
2248 };
2249
2250 /* we need to check the next char in the format string
2251 again, no matter what happened */
2252 inpos--;
2253
2254 /* add the contents of buf to the output */
2255 buflen = strlen(buf);
2256 if (outpos + buflen < datelen) {
2257 date[outpos] = '\0'; /* for strcat to hook onto */
2258 strcat(date, buf);
2259 outpos += buflen;
2260 } else {
2261 date[outpos] = '\0';
2262 strncat(date, buf, datelen - outpos);
2263 date[datelen - 1] = '\0';
2264 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2265 WARN("insufficient buffer\n");
2266 return 0;
2267 }
2268
2269 /* reset the variables we used to keep track of this item */
2270 count = 0;
2271 type = '\0';
2272 } else if (format[inpos] == '\0') {
2273 /* we can't check for this at the loop-head, because
2274 that breaks the printing of the last format-item */
2275 date[outpos] = '\0';
2276 break;
2277 } else if (count) {
2278 /* continuing a code for an item */
2279 count +=1;
2280 continue;
2281 } else if (strchr("hHmstyMdg", format[inpos])) {
2282 type = format[inpos];
2283 count = 1;
2284 continue;
2285 } else if (format[inpos] == '\'') {
2286 inquote = 1;
2287 continue;
2288 } else {
2289 date[outpos++] = format[inpos];
2290 }
2291 /* now deal with a possible buffer overflow */
2292 if (outpos >= datelen) {
2293 date[datelen - 1] = '\0';
2294 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2295 return 0;
2296 }
2297 }
2298
2299 if (Overflow) {
2300 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2301 };
2302
2303 /* finish it off with a string terminator */
2304 outpos++;
2305 /* sanity check */
2306 if (outpos > datelen-1) outpos = datelen-1;
2307 date[outpos] = '\0';
2308
2309 TRACE("returns string '%s', len %d\n", date, outpos);
2310 return outpos;
2311}
2312
2313/******************************************************************************
2314 * OLE_GetFormatW [INTERNAL]
2315 */
2316static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
2317 LPSYSTEMTIME xtime,
2318 LPCWSTR format,
2319 LPWSTR output, INT outlen)
2320{
2321 INT inpos, outpos;
2322 int count, type=0, inquote;
2323 int Overflow; /* loop check */
2324 char tmp[16];
2325 WCHAR buf[40];
2326 int buflen=0;
2327 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2328 WCHAR arg2[] = {'%','0','2','d',0};
2329 WCHAR *argarr[3];
2330 int datevars=0, timevars=0;
2331
2332 argarr[0] = arg0;
2333 argarr[1] = arg1;
2334 argarr[2] = arg2;
2335
2336 /* make a debug report */
2337 TRACE("args: 0x%lx, 0x%lx, 0x%lx, time(d=%d,h=%d,m=%d,s=%d), fmt:%s (at %p), "
2338 "%p with max len %d\n",
2339 locale, flags, tflags,
2340 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2341 debugstr_w(format), format, output, outlen);
2342
2343 if(outlen == 0) {
2344 FIXME("outlen = 0, returning 255\n");
2345 return 255;
2346 }
2347
2348 /* initialize state variables */
2349 inpos = outpos = 0;
2350 count = 0;
2351 inquote = Overflow = 0;
2352 /* this is really just a sanity check */
2353 output[0] = buf[0] = 0;
2354
2355 /* this loop is the core of the function */
2356 for (inpos = 0; /* we have several break points */ ; inpos++) {
2357 if (inquote) {
2358 if (format[inpos] == (WCHAR) '\'') {
2359 if (format[inpos+1] == '\'') {
2360 inpos++;
2361 output[outpos++] = '\'';
2362 } else {
2363 inquote = 0;
2364 continue;
2365 }
2366 } else if (format[inpos] == 0) {
2367 output[outpos++] = 0;
2368 if (outpos > outlen) Overflow = 1;
2369 break; /* normal exit (within a quote) */
2370 } else {
2371 output[outpos++] = format[inpos]; /* copy input */
2372 if (outpos > outlen) {
2373 Overflow = 1;
2374 output[outpos-1] = 0;
2375 break;
2376 }
2377 }
2378 } else if ( (count && (format[inpos] != type))
2379 || ( (count==4 && type =='y') ||
2380 (count==4 && type =='M') ||
2381 (count==4 && type =='d') ||
2382 (count==2 && type =='g') ||
2383 (count==2 && type =='h') ||
2384 (count==2 && type =='H') ||
2385 (count==2 && type =='m') ||
2386 (count==2 && type =='s') ||
2387 (count==2 && type =='t') ) ) {
2388 switch(type)
2389 {
2390 case 'd':
2391 if (count == 4) {
2392 GetLocaleInfoW(locale,
2393 LOCALE_SDAYNAME1 + (xtime->wDayOfWeek +6)%7,
2394 buf, sizeof(buf)/sizeof(WCHAR) );
2395 } else if (count == 3) {
2396 GetLocaleInfoW(locale,
2397 LOCALE_SABBREVDAYNAME1 +
2398 (xtime->wDayOfWeek +6)%7,
2399 buf, sizeof(buf)/sizeof(WCHAR) );
2400 } else {
2401 sprintf( tmp, "%.*d", count, xtime->wDay );
2402 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2403 }
2404 break;
2405
2406 case 'M':
2407 if (count == 4) {
2408 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
2409 xtime->wMonth -1, buf,
2410 sizeof(buf)/sizeof(WCHAR) );
2411 } else if (count == 3) {
2412 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
2413 xtime->wMonth -1, buf,
2414 sizeof(buf)/sizeof(WCHAR) );
2415 } else {
2416 sprintf( tmp, "%.*d", count, xtime->wMonth );
2417 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2418 }
2419 break;
2420 case 'y':
2421 if (count == 4) {
2422 sprintf( tmp, "%d", xtime->wYear );
2423 } else if (count == 3) {
2424 strcpy( tmp, "yyy" );
2425 } else {
2426 sprintf( tmp, "%.*d", count, xtime->wYear % 100 );
2427 }
2428 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2429 break;
2430
2431 case 'g':
2432 if (count == 2) {
2433 FIXME("LOCALE_ICALENDARTYPE unimplemented\n");
2434 strcpy( tmp, "AD" );
2435 } else {
2436 /* Win API sez we copy it verbatim */
2437 strcpy( tmp, "g" );
2438 }
2439 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2440 break;
2441
2442 case 'h':
2443 /* hours 1:00-12:00 --- is this right? */
2444 sprintf( tmp, "%.*d", count, (xtime->wHour-1)%12 +1);
2445 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2446 break;
2447
2448 case 'H':
2449 sprintf( tmp, "%.*d", count, xtime->wHour );
2450 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2451 break;
2452
2453 case 'm':
2454 sprintf( tmp, "%.*d", count, xtime->wMinute );
2455 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2456 break;
2457
2458 case 's':
2459 sprintf( tmp, "%.*d", count, xtime->wSecond );
2460 MultiByteToWideChar( CP_ACP, 0, tmp, -1, buf, sizeof(buf)/sizeof(WCHAR) );
2461 break;
2462
2463 case 't':
2464 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
2465 LOCALE_S1159 : LOCALE_S2359,
2466 buf, sizeof(buf) );
2467 if (count == 1) {
2468 buf[1] = 0;
2469 }
2470 break;
2471 }
2472
2473 /* no matter what happened, we need to check this next
2474 character the next time we loop through */
2475 inpos--;
2476
2477 /* cat buf onto the output */
2478 outlen = strlenW(buf);
2479 if (outpos + buflen < outlen) {
2480 strcpyW( output + outpos, buf );
2481 outpos += buflen;
2482 } else {
2483 lstrcpynW( output + outpos, buf, outlen - outpos );
2484 Overflow = 1;
2485 break; /* Abnormal exit */
2486 }
2487
2488 /* reset the variables we used this time */
2489 count = 0;
2490 type = '\0';
2491 } else if (format[inpos] == 0) {
2492 /* we can't check for this at the beginning, because that
2493 would keep us from printing a format spec that ended the
2494 string */
2495 output[outpos] = 0;
2496 break; /* NORMAL EXIT */
2497 } else if (count) {
2498 /* how we keep track of the middle of a format spec */
2499 count++;
2500 continue;
2501 } else if ( (datevars && (format[inpos]=='d' ||
2502 format[inpos]=='M' ||
2503 format[inpos]=='y' ||
2504 format[inpos]=='g') ) ||
2505 (timevars && (format[inpos]=='H' ||
2506 format[inpos]=='h' ||
2507 format[inpos]=='m' ||
2508 format[inpos]=='s' ||
2509 format[inpos]=='t') ) ) {
2510 type = format[inpos];
2511 count = 1;
2512 continue;
2513 } else if (format[inpos] == '\'') {
2514 inquote = 1;
2515 continue;
2516 } else {
2517 /* unquoted literals */
2518 output[outpos++] = format[inpos];
2519 }
2520 }
2521
2522 if (Overflow) {
2523 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2524 WARN(" buffer overflow\n");
2525 };
2526
2527 /* final string terminator and sanity check */
2528 outpos++;
2529 if (outpos > outlen-1) outpos = outlen-1;
2530 output[outpos] = '0';
2531
2532 TRACE(" returning %s\n", debugstr_w(output));
2533
2534 return (!Overflow) ? outlen : 0;
2535
2536}
2537
2538
2539/******************************************************************************
2540 * GetDateFormatA [KERNEL32.310]
2541 * Makes an ASCII string of the date
2542 *
2543 * This function uses format to format the date, or, if format
2544 * is NULL, uses the default for the locale. format is a string
2545 * of literal fields and characters as follows:
2546 *
2547 * - d single-digit (no leading zero) day (of month)
2548 * - dd two-digit day (of month)
2549 * - ddd short day-of-week name
2550 * - dddd long day-of-week name
2551 * - M single-digit month
2552 * - MM two-digit month
2553 * - MMM short month name
2554 * - MMMM full month name
2555 * - y two-digit year, no leading 0
2556 * - yy two-digit year
2557 * - yyyy four-digit year
2558 * - gg era string
2559 *
2560 */
2561INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
2562 LPSYSTEMTIME xtime,
2563 LPCSTR format, LPSTR date,INT datelen)
2564{
2565
2566 char format_buf[40];
2567 LPCSTR thisformat;
2568 SYSTEMTIME t;
2569 LPSYSTEMTIME thistime;
2570 LCID thislocale;
2571 INT ret;
2572 FILETIME ft;
2573 BOOL res;
2574
2575 TRACE("(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2576 locale,flags,xtime,format,date,datelen);
2577
2578 if (!locale) {
2579 locale = LOCALE_SYSTEM_DEFAULT;
2580 };
2581
2582 if (locale == LOCALE_SYSTEM_DEFAULT) {
2583 thislocale = GetSystemDefaultLCID();
2584 } else if (locale == LOCALE_USER_DEFAULT) {
2585 thislocale = GetUserDefaultLCID();
2586 } else {
2587 thislocale = locale;
2588 };
2589
2590 if (xtime == NULL) {
2591 GetSystemTime(&t);
2592 } else {
2593 /* Silently correct wDayOfWeek by tranforming to FileTime and back again*/
2594 res=SystemTimeToFileTime(xtime,&ft);
2595 /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error*/
2596 /*FIXME: SystemTimeToFileTime doesn't yet do that ckeck*/
2597 if(!res)
2598 {
2599 SetLastError(ERROR_INVALID_PARAMETER);
2600 return 0;
2601 }
2602 FileTimeToSystemTime(&ft,&t);
2603
2604 };
2605 thistime = &t;
2606
2607 if (format == NULL) {
2608 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
2609 ? LOCALE_SLONGDATE
2610 : LOCALE_SSHORTDATE),
2611 format_buf, sizeof(format_buf));
2612 thisformat = format_buf;
2613 } else {
2614 thisformat = format;
2615 };
2616
2617
2618 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
2619 date, datelen);
2620
2621
2622 TRACE(
2623 "GetDateFormatA() returning %d, with data=%s\n",
2624 ret, date);
2625 return ret;
2626}
2627
2628/******************************************************************************
2629 * GetDateFormatW [KERNEL32.311]
2630 * Makes a Unicode string of the date
2631 *
2632 * Acts the same as GetDateFormatA(), except that it's Unicode.
2633 * Accepts & returns sizes as counts of Unicode characters.
2634 *
2635 */
2636INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
2637 LPSYSTEMTIME xtime,
2638 LPCWSTR format,
2639 LPWSTR date, INT datelen)
2640{
2641#ifdef __WIN32OS2__
2642 // convert "format" on passing in into ASCII
2643 LPSTR pszAsciiFormat = UnicodeToAsciiString((LPWSTR) format);
2644 LPSTR pszAsciiDate = (char *)alloca(datelen);
2645 int rc;
2646
2647 TRACE("Kernel32-ole2nls: GetDateFormatW(0x%04lx,0x%08lx,%p,%s,%p,%d) not yet complete\n",
2648 locale,flags,xtime,pszAsciiFormat,date,datelen);
2649
2650 // call ASCII variant
2651 rc = GetDateFormatA(locale,
2652 flags,
2653 xtime,
2654 pszAsciiFormat,
2655 pszAsciiDate,
2656 datelen); // is in "characters", not bytes
2657
2658 FreeAsciiString(pszAsciiFormat);
2659
2660 // convert "date" on returning to UNICODE
2661 if (datelen != 0)
2662 {
2663 // in this case 'rc' holds the number of characters to convert
2664 lstrcpynAtoW(date, pszAsciiDate, rc);
2665 }
2666
2667 return rc;
2668
2669#else
2670 unsigned short datearr[] = {'1','9','9','4','-','1','-','1',0};
2671
2672 FIXME("STUB (should call OLE_GetFormatW)\n");
2673 lstrcpynW(date, datearr, datelen);
2674 return ( datelen < 9) ? datelen : 9;
2675#endif
2676}
2677
2678/**************************************************************************
2679 * EnumDateFormatsA (KERNEL32.198)
2680 */
2681BOOL WINAPI EnumDateFormatsA(
2682 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2683{
2684 LCID Loc = GetUserDefaultLCID();
2685 if(!lpDateFmtEnumProc)
2686 {
2687 SetLastError(ERROR_INVALID_PARAMETER);
2688 return FALSE;
2689 }
2690
2691 switch( Loc )
2692 {
2693
2694 case 0x00000407: /* (Loc,"de_DE") */
2695 {
2696 switch(dwFlags)
2697 {
2698 case DATE_SHORTDATE:
2699 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
2700 if(!(*lpDateFmtEnumProc)("d.M.yyyy")) return TRUE;
2701 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
2702 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
2703 return TRUE;
2704 case DATE_LONGDATE:
2705 if(!(*lpDateFmtEnumProc)("dddd,d. MMMM yyyy")) return TRUE;
2706 if(!(*lpDateFmtEnumProc)("d. MMMM yyyy")) return TRUE;
2707 if(!(*lpDateFmtEnumProc)("d. MMM yyyy")) return TRUE;
2708 return TRUE;
2709 default:
2710 FIXME("Unknown date format (%ld)\n", dwFlags);
2711 SetLastError(ERROR_INVALID_PARAMETER);
2712 return FALSE;
2713 }
2714 }
2715
2716 case 0x0000040c: /* (Loc,"fr_FR") */
2717 {
2718 switch(dwFlags)
2719 {
2720 case DATE_SHORTDATE:
2721 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2722 if(!(*lpDateFmtEnumProc)("dd.MM.yy")) return TRUE;
2723 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
2724 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2725 return TRUE;
2726 case DATE_LONGDATE:
2727 if(!(*lpDateFmtEnumProc)("dddd d MMMM yyyy")) return TRUE;
2728 if(!(*lpDateFmtEnumProc)("d MMM yy")) return TRUE;
2729 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2730 return TRUE;
2731 default:
2732 FIXME("Unknown date format (%ld)\n", dwFlags);
2733 SetLastError(ERROR_INVALID_PARAMETER);
2734 return FALSE;
2735 }
2736 }
2737
2738 case 0x00000c0c: /* (Loc,"fr_CA") */
2739 {
2740 switch(dwFlags)
2741 {
2742 case DATE_SHORTDATE:
2743 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
2744 if(!(*lpDateFmtEnumProc)("dd-MM-yy")) return TRUE;
2745 if(!(*lpDateFmtEnumProc)("yy MM dd")) return TRUE;
2746 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2747 return TRUE;
2748 case DATE_LONGDATE:
2749 if(!(*lpDateFmtEnumProc)("d MMMM, yyyy")) return TRUE;
2750 if(!(*lpDateFmtEnumProc)("d MMM yyyy")) return TRUE;
2751 return TRUE;
2752 default:
2753 FIXME("Unknown date format (%ld)\n", dwFlags);
2754 SetLastError(ERROR_INVALID_PARAMETER);
2755 return FALSE;
2756 }
2757 }
2758
2759 case 0x00000809: /* (Loc,"en_UK") */
2760 {
2761 switch(dwFlags)
2762 {
2763 case DATE_SHORTDATE:
2764 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2765 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2766 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2767 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
2768 return TRUE;
2769 case DATE_LONGDATE:
2770 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
2771 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2772 return TRUE;
2773 default:
2774 FIXME("Unknown date format (%ld)\n", dwFlags);
2775 SetLastError(ERROR_INVALID_PARAMETER);
2776 return FALSE;
2777 }
2778 }
2779
2780 case 0x00000c09: /* (Loc,"en_AU") */
2781 {
2782 switch(dwFlags)
2783 {
2784 case DATE_SHORTDATE:
2785 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
2786 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2787 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2788 return TRUE;
2789 case DATE_LONGDATE:
2790 if(!(*lpDateFmtEnumProc)("dddd,d MMMM yyyy")) return TRUE;
2791 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2792 return TRUE;
2793 default:
2794 FIXME("Unknown date format (%ld)\n", dwFlags);
2795 SetLastError(ERROR_INVALID_PARAMETER);
2796 return FALSE;
2797 }
2798 }
2799
2800 case 0x00001009: /* (Loc,"en_CA") */
2801 {
2802 switch(dwFlags)
2803 {
2804 case DATE_SHORTDATE:
2805 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2806 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2807 if(!(*lpDateFmtEnumProc)("yy-MM-dd")) return TRUE;
2808 if(!(*lpDateFmtEnumProc)("M/dd/yy")) return TRUE;
2809 return TRUE;
2810 case DATE_LONGDATE:
2811 if(!(*lpDateFmtEnumProc)("d-MMM-yy")) return TRUE;
2812 if(!(*lpDateFmtEnumProc)("MMMM d, yyyy")) return TRUE;
2813 return TRUE;
2814 default:
2815 FIXME("Unknown date format (%ld)\n", dwFlags);
2816 SetLastError(ERROR_INVALID_PARAMETER);
2817 return FALSE;
2818 }
2819 }
2820
2821 case 0x00001409: /* (Loc,"en_NZ") */
2822 {
2823 switch(dwFlags)
2824 {
2825 case DATE_SHORTDATE:
2826 if(!(*lpDateFmtEnumProc)("d/MM/yy")) return TRUE;
2827 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2828 if(!(*lpDateFmtEnumProc)("d.MM.yy")) return TRUE;
2829 return TRUE;
2830 case DATE_LONGDATE:
2831 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2832 if(!(*lpDateFmtEnumProc)("dddd, d MMMM yyyy")) return TRUE;
2833 return TRUE;
2834 default:
2835 FIXME("Unknown date format (%ld)\n", dwFlags);
2836 SetLastError(ERROR_INVALID_PARAMETER);
2837 return FALSE;
2838 }
2839 }
2840
2841 case 0x00001809: /* (Loc,"en_IE") */
2842 {
2843 switch(dwFlags)
2844 {
2845 case DATE_SHORTDATE:
2846 if(!(*lpDateFmtEnumProc)("dd/MM/yy")) return TRUE;
2847 if(!(*lpDateFmtEnumProc)("d/M/yy")) return TRUE;
2848 if(!(*lpDateFmtEnumProc)("d.M.yy")) return TRUE;
2849 return TRUE;
2850 case DATE_LONGDATE:
2851 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
2852 if(!(*lpDateFmtEnumProc)("d MMMM yyyy")) return TRUE;
2853 return TRUE;
2854 default:
2855 FIXME("Unknown date format (%ld)\n", dwFlags);
2856 SetLastError(ERROR_INVALID_PARAMETER);
2857 return FALSE;
2858 }
2859 }
2860
2861 case 0x00001c09: /* (Loc,"en_ZA") */
2862 {
2863 switch(dwFlags)
2864 {
2865 case DATE_SHORTDATE:
2866 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
2867 return TRUE;
2868 case DATE_LONGDATE:
2869 if(!(*lpDateFmtEnumProc)("dd MMMM yyyy")) return TRUE;
2870 return TRUE;
2871 default:
2872 FIXME("Unknown date format (%ld)\n", dwFlags);
2873 SetLastError(ERROR_INVALID_PARAMETER);
2874 return FALSE;
2875 }
2876 }
2877
2878 case 0x00002009: /* (Loc,"en_JM") */
2879 {
2880 switch(dwFlags)
2881 {
2882 case DATE_SHORTDATE:
2883 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2884 return TRUE;
2885 case DATE_LONGDATE:
2886 if(!(*lpDateFmtEnumProc)("dddd,MMMM dd,yyyy")) return TRUE;
2887 if(!(*lpDateFmtEnumProc)("MMMM dd,yyyy")) return TRUE;
2888 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM,yyyy")) return TRUE;
2889 if(!(*lpDateFmtEnumProc)("dd MMMM,yyyy")) return TRUE;
2890 return TRUE;
2891 default:
2892 FIXME("Unknown date format (%ld)\n", dwFlags);
2893 SetLastError(ERROR_INVALID_PARAMETER);
2894 return FALSE;
2895 }
2896 }
2897
2898 case 0x00002809: /* (Loc,"en_BZ") */
2899 case 0x00002c09: /* (Loc,"en_TT") */
2900 {
2901 switch(dwFlags)
2902 {
2903 case DATE_SHORTDATE:
2904 if(!(*lpDateFmtEnumProc)("dd/MM/yyyy")) return TRUE;
2905 return TRUE;
2906 case DATE_LONGDATE:
2907 if(!(*lpDateFmtEnumProc)("dddd,dd MMMM yyyy")) return TRUE;
2908 return TRUE;
2909 default:
2910 FIXME("Unknown date format (%ld)\n", dwFlags);
2911 SetLastError(ERROR_INVALID_PARAMETER);
2912 return FALSE;
2913 }
2914 }
2915
2916 default: /* default to US English "en_US" */
2917 {
2918 switch(dwFlags)
2919 {
2920 case DATE_SHORTDATE:
2921 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
2922 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
2923 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
2924 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
2925 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
2926 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
2927 return TRUE;
2928 case DATE_LONGDATE:
2929 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
2930 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
2931 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
2932 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
2933 return TRUE;
2934 default:
2935 FIXME("Unknown date format (%ld)\n", dwFlags);
2936 SetLastError(ERROR_INVALID_PARAMETER);
2937 return FALSE;
2938 }
2939 }
2940 }
2941}
2942
2943/**************************************************************************
2944 * EnumDateFormatsW (KERNEL32.199)
2945 */
2946BOOL WINAPI EnumDateFormatsW(
2947 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
2948{
2949 FIXME("(%p, %ld, %ld): stub\n", lpDateFmtEnumProc, Locale, dwFlags);
2950 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2951 return FALSE;
2952}
2953
2954/**************************************************************************
2955 * EnumTimeFormatsA (KERNEL32.210)
2956 */
2957BOOL WINAPI EnumTimeFormatsA(
2958 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
2959{
2960 LCID Loc = GetUserDefaultLCID();
2961 if(!lpTimeFmtEnumProc)
2962 {
2963 SetLastError(ERROR_INVALID_PARAMETER);
2964 return FALSE;
2965 }
2966 if(dwFlags)
2967 {
2968 FIXME("Unknown time format (%ld)\n", dwFlags);
2969 }
2970
2971 switch( Loc )
2972 {
2973 case 0x00000407: /* (Loc,"de_DE") */
2974 {
2975 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
2976 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
2977 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
2978 if(!(*lpTimeFmtEnumProc)("H.mm")) return TRUE;
2979 if(!(*lpTimeFmtEnumProc)("H.mm'Uhr'")) return TRUE;
2980 return TRUE;
2981 }
2982
2983 case 0x0000040c: /* (Loc,"fr_FR") */
2984 case 0x00000c0c: /* (Loc,"fr_CA") */
2985 {
2986 if(!(*lpTimeFmtEnumProc)("H:mm")) return TRUE;
2987 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
2988 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
2989 if(!(*lpTimeFmtEnumProc)("HH.mm")) return TRUE;
2990 if(!(*lpTimeFmtEnumProc)("HH'h'mm")) return TRUE;
2991 return TRUE;
2992 }
2993
2994 case 0x00000809: /* (Loc,"en_UK") */
2995 case 0x00000c09: /* (Loc,"en_AU") */
2996 case 0x00001409: /* (Loc,"en_NZ") */
2997 case 0x00001809: /* (Loc,"en_IE") */
2998 {
2999 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3000 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3001 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3002 return TRUE;
3003 }
3004
3005 case 0x00001c09: /* (Loc,"en_ZA") */
3006 case 0x00002809: /* (Loc,"en_BZ") */
3007 case 0x00002c09: /* (Loc,"en_TT") */
3008 {
3009 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3010 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3011 return TRUE;
3012 }
3013
3014 default: /* default to US style "en_US" */
3015 {
3016 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
3017 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
3018 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
3019 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
3020 return TRUE;
3021 }
3022 }
3023}
3024
3025/**************************************************************************
3026 * EnumTimeFormatsW (KERNEL32.211)
3027 */
3028BOOL WINAPI EnumTimeFormatsW(
3029 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
3030{
3031 FIXME("(%p,%ld,%ld): stub\n", lpTimeFmtEnumProc, Locale, dwFlags);
3032 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
3033 return FALSE;
3034}
3035
3036/**************************************************************************
3037 * This function is used just locally !
3038 * Description: Inverts a string.
3039 */
3040static void OLE_InvertString(char* string)
3041{
3042 char sTmpArray[128];
3043 INT counter, i = 0;
3044
3045 for (counter = strlen(string); counter > 0; counter--)
3046 {
3047 memcpy(sTmpArray + i, string + counter-1, 1);
3048 i++;
3049 }
3050 memcpy(sTmpArray + i, "\0", 1);
3051 strcpy(string, sTmpArray);
3052}
3053
3054/***************************************************************************************
3055 * This function is used just locally !
3056 * Description: Test if the given string (psNumber) is valid or not.
3057 * The valid characters are the following:
3058 * - Characters '0' through '9'.
3059 * - One decimal point (dot) if the number is a floating-point value.
3060 * - A minus sign in the first character position if the number is
3061 * a negative value.
3062 * If the function succeeds, psBefore/psAfter will point to the string
3063 * on the right/left of the decimal symbol. pbNegative indicates if the
3064 * number is negative.
3065 */
3066static INT OLE_GetNumberComponents(char* pInput, char* psBefore, char* psAfter, BOOL* pbNegative)
3067{
3068char sNumberSet[] = "0123456789";
3069BOOL bInDecimal = FALSE;
3070
3071 /* Test if we do have a minus sign */
3072 if ( *pInput == '-' )
3073 {
3074 *pbNegative = TRUE;
3075 pInput++; /* Jump to the next character. */
3076 }
3077
3078 while(*pInput != '\0')
3079 {
3080 /* Do we have a valid numeric character */
3081 if ( strchr(sNumberSet, *pInput) != NULL )
3082 {
3083 if (bInDecimal == TRUE)
3084 *psAfter++ = *pInput;
3085 else
3086 *psBefore++ = *pInput;
3087 }
3088 else
3089 {
3090 /* Is this a decimal point (dot) */
3091 if ( *pInput == '.' )
3092 {
3093 /* Is it the first time we find it */
3094 if ((bInDecimal == FALSE))
3095 bInDecimal = TRUE;
3096 else
3097 return -1; /* ERROR: Invalid parameter */
3098 }
3099 else
3100 {
3101 /* It's neither a numeric character, nor a decimal point.
3102 * Thus, return an error.
3103 */
3104 return -1;
3105 }
3106 }
3107 pInput++;
3108 }
3109
3110 /* Add an End of Line character to the output buffers */
3111 *psBefore = '\0';
3112 *psAfter = '\0';
3113
3114 return 0;
3115}
3116
3117/**************************************************************************
3118 * This function is used just locally !
3119 * Description: A number could be formatted using different numbers
3120 * of "digits in group" (example: 4;3;2;0).
3121 * The first parameter of this function is an array
3122 * containing the rule to be used. It's format is the following:
3123 * |NDG|DG1|DG2|...|0|
3124 * where NDG is the number of used "digits in group" and DG1, DG2,
3125 * are the corresponding "digits in group".
3126 * Thus, this function returns the grouping value in the array
3127 * pointed by the second parameter.
3128 */
3129static INT OLE_GetGrouping(char* sRule, INT index)
3130{
3131 char sData[2], sRuleSize[2];
3132 INT nData, nRuleSize;
3133
3134 memcpy(sRuleSize, sRule, 1);
3135 memcpy(sRuleSize+1, "\0", 1);
3136 nRuleSize = atoi(sRuleSize);
3137
3138 if (index > 0 && index < nRuleSize)
3139 {
3140 memcpy(sData, sRule+index, 1);
3141 memcpy(sData+1, "\0", 1);
3142 nData = atoi(sData);
3143 }
3144
3145 else
3146 {
3147 memcpy(sData, sRule+nRuleSize-1, 1);
3148 memcpy(sData+1, "\0", 1);
3149 nData = atoi(sData);
3150 }
3151
3152 return nData;
3153}
3154
3155/**************************************************************************
3156 * GetNumberFormatA (KERNEL32.355)
3157 */
3158INT WINAPI GetNumberFormatA(LCID locale, DWORD dwflags,
3159 LPCSTR lpvalue, const NUMBERFMTA * lpFormat,
3160 LPSTR lpNumberStr, int cchNumber)
3161{
3162 char sNumberDigits[3], sDecimalSymbol[5], sDigitsInGroup[11], sDigitGroupSymbol[5], sILZero[2];
3163 INT nNumberDigits, nNumberDecimal, i, j, nCounter, nStep, nRuleIndex, nGrouping, nDigits, retVal, nLZ;
3164 char sNumber[128], sDestination[128], sDigitsAfterDecimal[10], sDigitsBeforeDecimal[128];
3165 char sRule[10], sSemiColumn[]=";", sBuffer[5], sNegNumber[2];
3166 char *pStr = NULL, *pTmpStr = NULL;
3167 LCID systemDefaultLCID;
3168 BOOL bNegative = FALSE;
3169 enum Operations
3170 {
3171 USE_PARAMETER,
3172 USE_LOCALEINFO,
3173 USE_SYSTEMDEFAULT,
3174 RETURN_ERROR
3175 } used_operation;
3176
3177 strncpy(sNumber, lpvalue, 128);
3178 sNumber[127] = '\0';
3179
3180 /* Make sure we have a valid input string, get the number
3181 * of digits before and after the decimal symbol, and check
3182 * if this is a negative number.
3183 */
3184 if ( OLE_GetNumberComponents(sNumber, sDigitsBeforeDecimal, sDigitsAfterDecimal, &bNegative) != -1)
3185 {
3186 nNumberDecimal = strlen(sDigitsBeforeDecimal);
3187 nDigits = strlen(sDigitsAfterDecimal);
3188 }
3189 else
3190 {
3191 SetLastError(ERROR_INVALID_PARAMETER);
3192 return 0;
3193 }
3194
3195 /* Which source will we use to format the string */
3196 used_operation = RETURN_ERROR;
3197 if (lpFormat != NULL)
3198 {
3199 if (dwflags == 0)
3200 used_operation = USE_PARAMETER;
3201 }
3202 else
3203 {
3204 if (dwflags & LOCALE_NOUSEROVERRIDE)
3205 used_operation = USE_LOCALEINFO;
3206 else
3207 used_operation = USE_SYSTEMDEFAULT;
3208 }
3209
3210 /* Load the fields we need */
3211 switch(used_operation)
3212 {
3213 case USE_LOCALEINFO:
3214 GetLocaleInfoA(locale, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3215 GetLocaleInfoA(locale, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3216 GetLocaleInfoA(locale, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3217 GetLocaleInfoA(locale, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3218 GetLocaleInfoA(locale, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3219 GetLocaleInfoA(locale, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3220 break;
3221 case USE_PARAMETER:
3222 sprintf(sNumberDigits, "%d",lpFormat->NumDigits);
3223 strcpy(sDecimalSymbol, lpFormat->lpDecimalSep);
3224 sprintf(sDigitsInGroup, "%d;0",lpFormat->Grouping);
3225 strcpy(sDigitGroupSymbol, lpFormat->lpThousandSep);
3226 sprintf(sILZero, "%d",lpFormat->LeadingZero);
3227 sprintf(sNegNumber, "%d",lpFormat->NegativeOrder);
3228 break;
3229 case USE_SYSTEMDEFAULT:
3230 systemDefaultLCID = GetSystemDefaultLCID();
3231 GetLocaleInfoA(systemDefaultLCID, LOCALE_IDIGITS, sNumberDigits, sizeof(sNumberDigits));
3232 GetLocaleInfoA(systemDefaultLCID, LOCALE_SDECIMAL, sDecimalSymbol, sizeof(sDecimalSymbol));
3233 GetLocaleInfoA(systemDefaultLCID, LOCALE_SGROUPING, sDigitsInGroup, sizeof(sDigitsInGroup));
3234 GetLocaleInfoA(systemDefaultLCID, LOCALE_STHOUSAND, sDigitGroupSymbol, sizeof(sDigitGroupSymbol));
3235 GetLocaleInfoA(systemDefaultLCID, LOCALE_ILZERO, sILZero, sizeof(sILZero));
3236 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGNUMBER, sNegNumber, sizeof(sNegNumber));
3237 break;
3238 default:
3239 SetLastError(ERROR_INVALID_PARAMETER);
3240 return 0;
3241 }
3242
3243 nNumberDigits = atoi(sNumberDigits);
3244
3245 /* Remove the ";" */
3246 i=0;
3247 j = 1;
3248 for (nCounter=0; nCounter<strlen(sDigitsInGroup); nCounter++)
3249 {
3250 if ( memcmp(sDigitsInGroup + nCounter, sSemiColumn, 1) != 0 )
3251 {
3252 memcpy(sRule + j, sDigitsInGroup + nCounter, 1);
3253 i++;
3254 j++;
3255 }
3256 }
3257 sprintf(sBuffer, "%d", i);
3258 memcpy(sRule, sBuffer, 1); /* Number of digits in the groups ( used by OLE_GetGrouping() ) */
3259 memcpy(sRule + j, "\0", 1);
3260
3261 /* First, format the digits before the decimal. */
3262 if ((nNumberDecimal>0) && (atoi(sDigitsBeforeDecimal) != 0))
3263 {
3264 /* Working on an inverted string is easier ! */
3265 OLE_InvertString(sDigitsBeforeDecimal);
3266
3267 nStep = nCounter = i = j = 0;
3268 nRuleIndex = 1;
3269 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3270
3271 /* Here, we will loop until we reach the end of the string.
3272 * An internal counter (j) is used in order to know when to
3273 * insert the "digit group symbol".
3274 */
3275 while (nNumberDecimal > 0)
3276 {
3277 i = nCounter + nStep;
3278 memcpy(sDestination + i, sDigitsBeforeDecimal + nCounter, 1);
3279 nCounter++;
3280 j++;
3281 if (j >= nGrouping)
3282 {
3283 j = 0;
3284 if (nRuleIndex < sRule[0])
3285 nRuleIndex++;
3286 nGrouping = OLE_GetGrouping(sRule, nRuleIndex);
3287 memcpy(sDestination + i+1, sDigitGroupSymbol, strlen(sDigitGroupSymbol));
3288 nStep+= strlen(sDigitGroupSymbol);
3289 }
3290
3291 nNumberDecimal--;
3292 }
3293
3294 memcpy(sDestination + i+1, "\0", 1);
3295 /* Get the string in the right order ! */
3296 OLE_InvertString(sDestination);
3297 }
3298 else
3299 {
3300 nLZ = atoi(sILZero);
3301 if (nLZ != 0)
3302 {
3303 /* Use 0.xxx instead of .xxx */
3304 memcpy(sDestination, "0", 1);
3305 memcpy(sDestination+1, "\0", 1);
3306 }
3307 else
3308 memcpy(sDestination, "\0", 1);
3309
3310 }
3311
3312 /* Second, format the digits after the decimal. */
3313 j = 0;
3314 nCounter = nNumberDigits;
3315 if ( (nDigits>0) && (pStr = strstr (sNumber, ".")) )
3316 {
3317 i = strlen(sNumber) - strlen(pStr) + 1;
3318 strncpy ( sDigitsAfterDecimal, sNumber + i, nNumberDigits);
3319 j = strlen(sDigitsAfterDecimal);
3320 if (j < nNumberDigits)
3321 nCounter = nNumberDigits-j;
3322 }
3323 for (i=0;i<nCounter;i++)
3324 memcpy(sDigitsAfterDecimal+i+j, "0", 1);
3325 memcpy(sDigitsAfterDecimal + nNumberDigits, "\0", 1);
3326
3327 i = strlen(sDestination);
3328 j = strlen(sDigitsAfterDecimal);
3329 /* Finally, construct the resulting formatted string. */
3330
3331 for (nCounter=0; nCounter<i; nCounter++)
3332 memcpy(sNumber + nCounter, sDestination + nCounter, 1);
3333
3334 memcpy(sNumber + nCounter, sDecimalSymbol, strlen(sDecimalSymbol));
3335
3336 for (i=0; i<j; i++)
3337 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), sDigitsAfterDecimal + i, 1);
3338 memcpy(sNumber + nCounter+i+strlen(sDecimalSymbol), "\0", 1);
3339
3340 /* Is it a negative number */
3341 if (bNegative == TRUE)
3342 {
3343 i = atoi(sNegNumber);
3344 pStr = sDestination;
3345 pTmpStr = sNumber;
3346 switch (i)
3347 {
3348 case 0:
3349 *pStr++ = '(';
3350 while (*sNumber != '\0')
3351 *pStr++ = *pTmpStr++;
3352 *pStr++ = ')';
3353 break;
3354 case 1:
3355 *pStr++ = '-';
3356 while (*pTmpStr != '\0')
3357 *pStr++ = *pTmpStr++;
3358 break;
3359 case 2:
3360 *pStr++ = '-';
3361 *pStr++ = ' ';
3362 while (*pTmpStr != '\0')
3363 *pStr++ = *pTmpStr++;
3364 break;
3365 case 3:
3366 while (*pTmpStr != '\0')
3367 *pStr++ = *pTmpStr++;
3368 *pStr++ = '-';
3369 break;
3370 case 4:
3371 while (*pTmpStr != '\0')
3372 *pStr++ = *pTmpStr++;
3373 *pStr++ = ' ';
3374 *pStr++ = '-';
3375 break;
3376 default:
3377 while (*pTmpStr != '\0')
3378 *pStr++ = *pTmpStr++;
3379 break;
3380 }
3381 }
3382 else
3383 strcpy(sDestination, sNumber);
3384
3385 /* If cchNumber is zero, then returns the number of bytes or characters
3386 * required to hold the formatted number string
3387 */
3388 if (cchNumber==0)
3389 retVal = strlen(sDestination) + 1;
3390 else
3391 {
3392 strncpy (lpNumberStr, sDestination, cchNumber-1);
3393 *(lpNumberStr+cchNumber-1) = '\0'; /* ensure we got a NULL at the end */
3394 retVal = strlen(lpNumberStr);
3395 }
3396
3397 return retVal;
3398}
3399
3400/**************************************************************************
3401 * GetNumberFormatW (KERNEL32.@)
3402 */
3403INT WINAPI GetNumberFormatW(LCID locale, DWORD dwflags,
3404 LPCWSTR lpvalue, const NUMBERFMTW * lpFormat,
3405 LPWSTR lpNumberStr, int cchNumber)
3406{
3407 FIXME("%s: stub, no reformating done\n",debugstr_w(lpvalue));
3408
3409 lstrcpynW( lpNumberStr, lpvalue, cchNumber );
3410 return cchNumber? strlenW( lpNumberStr ) : 0;
3411}
3412
3413/**************************************************************************
3414 * GetCurrencyFormatA (KERNEL32.302)
3415 */
3416INT WINAPI GetCurrencyFormatA(LCID locale, DWORD dwflags,
3417 LPCSTR lpvalue, const CURRENCYFMTA * lpFormat,
3418 LPSTR lpCurrencyStr, int cchCurrency)
3419{
3420 UINT nPosOrder, nNegOrder;
3421 INT retVal;
3422 char sDestination[128], sNegOrder[8], sPosOrder[8], sCurrencySymbol[8];
3423 char *pDestination = sDestination;
3424 char sNumberFormated[128];
3425 char *pNumberFormated = sNumberFormated;
3426 LCID systemDefaultLCID;
3427 BOOL bIsPositive = FALSE, bValidFormat = FALSE;
3428 enum Operations
3429 {
3430 USE_PARAMETER,
3431 USE_LOCALEINFO,
3432 USE_SYSTEMDEFAULT,
3433 RETURN_ERROR
3434 } used_operation;
3435
3436 NUMBERFMTA numberFmt;
3437
3438 /* Which source will we use to format the string */
3439 used_operation = RETURN_ERROR;
3440 if (lpFormat != NULL)
3441 {
3442 if (dwflags == 0)
3443 used_operation = USE_PARAMETER;
3444 }
3445 else
3446 {
3447 if (dwflags & LOCALE_NOUSEROVERRIDE)
3448 used_operation = USE_LOCALEINFO;
3449 else
3450 used_operation = USE_SYSTEMDEFAULT;
3451 }
3452
3453 /* Load the fields we need */
3454 switch(used_operation)
3455 {
3456 case USE_LOCALEINFO:
3457 /* Specific to CURRENCYFMTA*/
3458 GetLocaleInfoA(locale, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3459 GetLocaleInfoA(locale, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3460 GetLocaleInfoA(locale, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3461
3462 nPosOrder = atoi(sPosOrder);
3463 nNegOrder = atoi(sNegOrder);
3464 break;
3465 case USE_PARAMETER:
3466 /* Specific to CURRENCYFMTA*/
3467 nNegOrder = lpFormat->NegativeOrder;
3468 nPosOrder = lpFormat->PositiveOrder;
3469 strcpy(sCurrencySymbol, lpFormat->lpCurrencySymbol);
3470 break;
3471 case USE_SYSTEMDEFAULT:
3472 systemDefaultLCID = GetSystemDefaultLCID();
3473 /* Specific to CURRENCYFMTA*/
3474 GetLocaleInfoA(systemDefaultLCID, LOCALE_INEGCURR, sNegOrder, sizeof(sNegOrder));
3475 GetLocaleInfoA(systemDefaultLCID, LOCALE_ICURRENCY, sPosOrder, sizeof(sPosOrder));
3476 GetLocaleInfoA(systemDefaultLCID, LOCALE_SCURRENCY, sCurrencySymbol, sizeof(sCurrencySymbol));
3477
3478 nPosOrder = atoi(sPosOrder);
3479 nNegOrder = atoi(sNegOrder);
3480 break;
3481 default:
3482 SetLastError(ERROR_INVALID_PARAMETER);
3483 return 0;
3484 }
3485
3486 /* Construct a temporary number format structure */
3487 if (lpFormat != NULL)
3488 {
3489 numberFmt.NumDigits = lpFormat->NumDigits;
3490 numberFmt.LeadingZero = lpFormat->LeadingZero;
3491 numberFmt.Grouping = lpFormat->Grouping;
3492 numberFmt.NegativeOrder = 0;
3493 numberFmt.lpDecimalSep = lpFormat->lpDecimalSep;
3494 numberFmt.lpThousandSep = lpFormat->lpThousandSep;
3495 bValidFormat = TRUE;
3496 }
3497
3498 /* Make a call to GetNumberFormatA() */
3499 if (*lpvalue == '-')
3500 {
3501 bIsPositive = FALSE;
3502 retVal = GetNumberFormatA(locale,0,lpvalue+1,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3503 }
3504 else
3505 {
3506 bIsPositive = TRUE;
3507 retVal = GetNumberFormatA(locale,0,lpvalue,(bValidFormat)?&numberFmt:NULL,pNumberFormated,128);
3508 }
3509
3510 if (retVal == 0)
3511 return 0;
3512
3513 /* construct the formatted string */
3514 if (bIsPositive)
3515 {
3516 switch (nPosOrder)
3517 {
3518 case 0: /* Prefix, no separation */
3519 strcpy (pDestination, sCurrencySymbol);
3520 strcat (pDestination, pNumberFormated);
3521 break;
3522 case 1: /* Suffix, no separation */
3523 strcpy (pDestination, pNumberFormated);
3524 strcat (pDestination, sCurrencySymbol);
3525 break;
3526 case 2: /* Prefix, 1 char separation */
3527 strcpy (pDestination, sCurrencySymbol);
3528 strcat (pDestination, " ");
3529 strcat (pDestination, pNumberFormated);
3530 break;
3531 case 3: /* Suffix, 1 char separation */
3532 strcpy (pDestination, pNumberFormated);
3533 strcat (pDestination, " ");
3534 strcat (pDestination, sCurrencySymbol);
3535 break;
3536 default:
3537 SetLastError(ERROR_INVALID_PARAMETER);
3538 return 0;
3539 }
3540 }
3541 else /* negative number */
3542 {
3543 switch (nNegOrder)
3544 {
3545 case 0: /* format: ($1.1) */
3546 strcpy (pDestination, "(");
3547 strcat (pDestination, sCurrencySymbol);
3548 strcat (pDestination, pNumberFormated);
3549 strcat (pDestination, ")");
3550 break;
3551 case 1: /* format: -$1.1 */
3552 strcpy (pDestination, "-");
3553 strcat (pDestination, sCurrencySymbol);
3554 strcat (pDestination, pNumberFormated);
3555 break;
3556 case 2: /* format: $-1.1 */
3557 strcpy (pDestination, sCurrencySymbol);
3558 strcat (pDestination, "-");
3559 strcat (pDestination, pNumberFormated);
3560 break;
3561 case 3: /* format: $1.1- */
3562 strcpy (pDestination, sCurrencySymbol);
3563 strcat (pDestination, pNumberFormated);
3564 strcat (pDestination, "-");
3565 break;
3566 case 4: /* format: (1.1$) */
3567 strcpy (pDestination, "(");
3568 strcat (pDestination, pNumberFormated);
3569 strcat (pDestination, sCurrencySymbol);
3570 strcat (pDestination, ")");
3571 break;
3572 case 5: /* format: -1.1$ */
3573 strcpy (pDestination, "-");
3574 strcat (pDestination, pNumberFormated);
3575 strcat (pDestination, sCurrencySymbol);
3576 break;
3577 case 6: /* format: 1.1-$ */
3578 strcpy (pDestination, pNumberFormated);
3579 strcat (pDestination, "-");
3580 strcat (pDestination, sCurrencySymbol);
3581 break;
3582 case 7: /* format: 1.1$- */
3583 strcpy (pDestination, pNumberFormated);
3584 strcat (pDestination, sCurrencySymbol);
3585 strcat (pDestination, "-");
3586 break;
3587 case 8: /* format: -1.1 $ */
3588 strcpy (pDestination, "-");
3589 strcat (pDestination, pNumberFormated);
3590 strcat (pDestination, " ");
3591 strcat (pDestination, sCurrencySymbol);
3592 break;
3593 case 9: /* format: -$ 1.1 */
3594 strcpy (pDestination, "-");
3595 strcat (pDestination, sCurrencySymbol);
3596 strcat (pDestination, " ");
3597 strcat (pDestination, pNumberFormated);
3598 break;
3599 case 10: /* format: 1.1 $- */
3600 strcpy (pDestination, pNumberFormated);
3601 strcat (pDestination, " ");
3602 strcat (pDestination, sCurrencySymbol);
3603 strcat (pDestination, "-");
3604 break;
3605 case 11: /* format: $ 1.1- */
3606 strcpy (pDestination, sCurrencySymbol);
3607 strcat (pDestination, " ");
3608 strcat (pDestination, pNumberFormated);
3609 strcat (pDestination, "-");
3610 break;
3611 case 12: /* format: $ -1.1 */
3612 strcpy (pDestination, sCurrencySymbol);
3613 strcat (pDestination, " ");
3614 strcat (pDestination, "-");
3615 strcat (pDestination, pNumberFormated);
3616 break;
3617 case 13: /* format: 1.1- $ */
3618 strcpy (pDestination, pNumberFormated);
3619 strcat (pDestination, "-");
3620 strcat (pDestination, " ");
3621 strcat (pDestination, sCurrencySymbol);
3622 break;
3623 case 14: /* format: ($ 1.1) */
3624 strcpy (pDestination, "(");
3625 strcat (pDestination, sCurrencySymbol);
3626 strcat (pDestination, " ");
3627 strcat (pDestination, pNumberFormated);
3628 strcat (pDestination, ")");
3629 break;
3630 case 15: /* format: (1.1 $) */
3631 strcpy (pDestination, "(");
3632 strcat (pDestination, pNumberFormated);
3633 strcat (pDestination, " ");
3634 strcat (pDestination, sCurrencySymbol);
3635 strcat (pDestination, ")");
3636 break;
3637 default:
3638 SetLastError(ERROR_INVALID_PARAMETER);
3639 return 0;
3640 }
3641 }
3642
3643 if (cchCurrency == 0)
3644 return strlen(pDestination) + 1;
3645
3646 else
3647 {
3648 strncpy (lpCurrencyStr, pDestination, cchCurrency-1);
3649 *(lpCurrencyStr+cchCurrency-1) = '\0'; /* ensure we got a NULL at the end */
3650 return strlen(lpCurrencyStr);
3651 }
3652}
3653
3654/**************************************************************************
3655 * GetCurrencyFormatW (KERNEL32.303)
3656 */
3657INT WINAPI GetCurrencyFormatW(LCID locale, DWORD dwflags,
3658 LPCWSTR lpvalue, const CURRENCYFMTW * lpFormat,
3659 LPWSTR lpCurrencyStr, int cchCurrency)
3660{
3661 FIXME("This API function is NOT implemented !\n");
3662 return 0;
3663}
3664
3665/******************************************************************************
3666 * OLE2NLS_CheckLocale [intern]
3667 */
3668static LCID OLE2NLS_CheckLocale (LCID locale)
3669{
3670 if (!locale)
3671 { locale = LOCALE_SYSTEM_DEFAULT;
3672 }
3673
3674 if (locale == LOCALE_SYSTEM_DEFAULT)
3675 { return GetSystemDefaultLCID();
3676 }
3677 else if (locale == LOCALE_USER_DEFAULT)
3678 { return GetUserDefaultLCID();
3679 }
3680 else
3681 { return locale;
3682 }
3683}
3684/******************************************************************************
3685 * GetTimeFormatA [KERNEL32.422]
3686 * Makes an ASCII string of the time
3687 *
3688 * Formats date according to format, or locale default if format is
3689 * NULL. The format consists of literal characters and fields as follows:
3690 *
3691 * h hours with no leading zero (12-hour)
3692 * hh hours with full two digits
3693 * H hours with no leading zero (24-hour)
3694 * HH hours with full two digits
3695 * m minutes with no leading zero
3696 * mm minutes with full two digits
3697 * s seconds with no leading zero
3698 * ss seconds with full two digits
3699 * t time marker (A or P)
3700 * tt time marker (AM, PM)
3701 *
3702 */
3703INT WINAPI
3704GetTimeFormatA(LCID locale, /* [in] */
3705 DWORD flags, /* [in] */
3706 LPSYSTEMTIME xtime, /* [in] */
3707 LPCSTR format, /* [in] */
3708 LPSTR timestr, /* [out] */
3709 INT timelen /* [in] */)
3710{ char format_buf[40];
3711 LPCSTR thisformat;
3712 SYSTEMTIME t;
3713 LPSYSTEMTIME thistime;
3714 LCID thislocale=0;
3715 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
3716 INT ret;
3717
3718 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
3719
3720 thislocale = OLE2NLS_CheckLocale ( locale );
3721
3722 if (format == NULL)
3723 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
3724 { thislocale = GetSystemDefaultLCID();
3725 }
3726 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
3727 thisformat = format_buf;
3728 }
3729 else
3730 { thisformat = format;
3731 }
3732
3733 if (xtime == NULL) /* NULL means use the current local time*/
3734 { GetLocalTime(&t);
3735 thistime = &t;
3736 }
3737 else
3738 { thistime = xtime;
3739 /* Check that hour,min and sec is in range */
3740 }
3741 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
3742 timestr, timelen);
3743 return ret;
3744}
3745
3746
3747/******************************************************************************
3748 * GetTimeFormatW [KERNEL32.423]
3749 * Makes a Unicode string of the time
3750 */
3751INT WINAPI
3752GetTimeFormatW(LCID locale, /* [in] */
3753 DWORD flags, /* [in] */
3754 LPSYSTEMTIME xtime, /* [in] */
3755 LPCWSTR format, /* [in] */
3756 LPWSTR timestr, /* [out] */
3757 INT timelen /* [in] */)
3758{ WCHAR format_buf[40];
3759 LPCWSTR thisformat;
3760 SYSTEMTIME t;
3761 LPSYSTEMTIME thistime;
3762 LCID thislocale=0;
3763 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
3764 INT ret;
3765
3766 TRACE("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
3767 xtime,debugstr_w(format),timestr,timelen);
3768
3769 thislocale = OLE2NLS_CheckLocale ( locale );
3770
3771 if (format == NULL)
3772 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
3773 { thislocale = GetSystemDefaultLCID();
3774 }
3775 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
3776 thisformat = format_buf;
3777 }
3778 else
3779 { thisformat = format;
3780 }
3781
3782 if (xtime == NULL) /* NULL means use the current local time*/
3783 { GetLocalTime(&t);
3784 thistime = &t;
3785 }
3786 else
3787 { thistime = xtime;
3788 }
3789
3790 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
3791 timestr, timelen);
3792 return ret;
3793}
3794
3795/******************************************************************************
3796 * EnumCalendarInfoA [KERNEL32.196]
3797 */
3798BOOL WINAPI EnumCalendarInfoA(
3799 CALINFO_ENUMPROCA calinfoproc,LCID locale,CALID calendar,CALTYPE caltype
3800) {
3801 FIXME("(%p,0x%04lx,0x%08lx,0x%08lx),stub!\n",calinfoproc,locale,calendar,caltype);
3802 return FALSE;
3803}
3804
3805#ifdef __WIN32OS2__
3806/*****************************************************************************
3807 * Name : BOOL WIN32API EnumCalendarInfoW
3808 * Purpose : The EnumCalendarInfoW function enumerates calendar information
3809 * for a specified locale. The CalType parameter specifies the type
3810 * of calendar information to enumerate. The function returns the
3811 * specified calendar information for all applicable calendars for
3812 * the locale, or for a single requested calendar, depending on the
3813 * value of the Calendar parameter.
3814 * The EnumCalendarInfo function enumerates the calendar information
3815 * by calling an application-defined callback function. It passes
3816 * the callback function a pointer to a string buffer containing
3817 * the requested calendar information. This continues until either
3818 * the last applicable calendar is found or the callback function
3819 * returns FALSE.
3820 * Parameters: CALINFO_ENUMPROCW lpCalInfoEnumProc pointer to enumeration
3821 * callback function
3822 * LCID Locale locale whose calendar information is of interest
3823 * CALID Calendar calendar whose information is of interest
3824 * CALTYPE CalType type of calendar information of interest
3825 * Variables :
3826 * Result : If the function succeeds, the return value is nonzero.
3827 * If the function fails, the return value is zero
3828 * Remark :
3829 * Status : UNTESTED STUB
3830 *
3831 * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
3832 *****************************************************************************/
3833
3834BOOL WIN32API EnumCalendarInfoW(CALINFO_ENUMPROCW lpCalInfoEnumProc,
3835 LCID Locale,
3836 CALID Calendar,
3837 CALTYPE CalType)
3838{
3839
3840 dprintf(("KERNEL32: EnumCalendarInfoW(%08x,%08x,%08x,%08x)not implemented\n",
3841 lpCalInfoEnumProc,
3842 Locale,
3843 Calendar,
3844 CalType
3845 ));
3846
3847 return (FALSE);
3848}
3849#endif
Note: See TracBrowser for help on using the repository browser.