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