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

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

WINE NLS sync

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