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

Last change on this file since 4310 was 4214, checked in by phaller, 25 years ago

Fixes for Netscape

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