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

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

rewrote string functions with new unicode code

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