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

Last change on this file since 5155 was 5155, checked in by sandervl, 25 years ago

YD: header changes

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