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

Last change on this file since 7334 was 7334, checked in by phaller, 24 years ago

replaced heap alloc by stack alloc

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