Release 980726
[wine/multimedia.git] / ole / ole2nls.c
blob7d18e99736e75acf71ecc42ba51d1986fe18a581
1 /*
2 * OLE2NLS library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1998 David Lee Lambert
6 */
8 #include <string.h>
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include "windows.h"
12 #include "heap.h"
13 #include "ole.h"
14 #include "options.h"
15 #include "winnls.h"
16 #include "winreg.h"
17 #include "winerror.h"
18 #include "debug.h"
20 /* Locale name to id map. used by EnumSystemLocales, GetLocalInfoA
21 * MUST contain all #defines from winnls.h
22 * last entry has NULL name, 0 id.
23 */
24 #define LOCALE_ENTRY(x) {#x,LOCALE_##x}
25 static struct tagLOCALE_NAME2ID {
26 char *name;
27 DWORD id;
28 } locale_name2id[]= {
29 LOCALE_ENTRY(ILANGUAGE),
30 LOCALE_ENTRY(SLANGUAGE),
31 LOCALE_ENTRY(SENGLANGUAGE),
32 LOCALE_ENTRY(SABBREVLANGNAME),
33 LOCALE_ENTRY(SNATIVELANGNAME),
34 LOCALE_ENTRY(ICOUNTRY),
35 LOCALE_ENTRY(SCOUNTRY),
36 LOCALE_ENTRY(SENGCOUNTRY),
37 LOCALE_ENTRY(SABBREVCTRYNAME),
38 LOCALE_ENTRY(SNATIVECTRYNAME),
39 LOCALE_ENTRY(IDEFAULTLANGUAGE),
40 LOCALE_ENTRY(IDEFAULTCOUNTRY),
41 LOCALE_ENTRY(IDEFAULTCODEPAGE),
42 LOCALE_ENTRY(IDEFAULTANSICODEPAGE),
43 LOCALE_ENTRY(SLIST),
44 LOCALE_ENTRY(IMEASURE),
45 LOCALE_ENTRY(SDECIMAL),
46 LOCALE_ENTRY(STHOUSAND),
47 LOCALE_ENTRY(SGROUPING),
48 LOCALE_ENTRY(IDIGITS),
49 LOCALE_ENTRY(ILZERO),
50 LOCALE_ENTRY(INEGNUMBER),
51 LOCALE_ENTRY(SNATIVEDIGITS),
52 LOCALE_ENTRY(SCURRENCY),
53 LOCALE_ENTRY(SINTLSYMBOL),
54 LOCALE_ENTRY(SMONDECIMALSEP),
55 LOCALE_ENTRY(SMONTHOUSANDSEP),
56 LOCALE_ENTRY(SMONGROUPING),
57 LOCALE_ENTRY(ICURRDIGITS),
58 LOCALE_ENTRY(IINTLCURRDIGITS),
59 LOCALE_ENTRY(ICURRENCY),
60 LOCALE_ENTRY(INEGCURR),
61 LOCALE_ENTRY(SDATE),
62 LOCALE_ENTRY(STIME),
63 LOCALE_ENTRY(SSHORTDATE),
64 LOCALE_ENTRY(SLONGDATE),
65 LOCALE_ENTRY(STIMEFORMAT),
66 LOCALE_ENTRY(IDATE),
67 LOCALE_ENTRY(ILDATE),
68 LOCALE_ENTRY(ITIME),
69 LOCALE_ENTRY(ITIMEMARKPOSN),
70 LOCALE_ENTRY(ICENTURY),
71 LOCALE_ENTRY(ITLZERO),
72 LOCALE_ENTRY(IDAYLZERO),
73 LOCALE_ENTRY(IMONLZERO),
74 LOCALE_ENTRY(S1159),
75 LOCALE_ENTRY(S2359),
76 LOCALE_ENTRY(ICALENDARTYPE),
77 LOCALE_ENTRY(IOPTIONALCALENDAR),
78 LOCALE_ENTRY(IFIRSTDAYOFWEEK),
79 LOCALE_ENTRY(IFIRSTWEEKOFYEAR),
80 LOCALE_ENTRY(SDAYNAME1),
81 LOCALE_ENTRY(SDAYNAME2),
82 LOCALE_ENTRY(SDAYNAME3),
83 LOCALE_ENTRY(SDAYNAME4),
84 LOCALE_ENTRY(SDAYNAME5),
85 LOCALE_ENTRY(SDAYNAME6),
86 LOCALE_ENTRY(SDAYNAME7),
87 LOCALE_ENTRY(SABBREVDAYNAME1),
88 LOCALE_ENTRY(SABBREVDAYNAME2),
89 LOCALE_ENTRY(SABBREVDAYNAME3),
90 LOCALE_ENTRY(SABBREVDAYNAME4),
91 LOCALE_ENTRY(SABBREVDAYNAME5),
92 LOCALE_ENTRY(SABBREVDAYNAME6),
93 LOCALE_ENTRY(SABBREVDAYNAME7),
94 LOCALE_ENTRY(SMONTHNAME1),
95 LOCALE_ENTRY(SMONTHNAME2),
96 LOCALE_ENTRY(SMONTHNAME3),
97 LOCALE_ENTRY(SMONTHNAME4),
98 LOCALE_ENTRY(SMONTHNAME5),
99 LOCALE_ENTRY(SMONTHNAME6),
100 LOCALE_ENTRY(SMONTHNAME7),
101 LOCALE_ENTRY(SMONTHNAME8),
102 LOCALE_ENTRY(SMONTHNAME9),
103 LOCALE_ENTRY(SMONTHNAME10),
104 LOCALE_ENTRY(SMONTHNAME11),
105 LOCALE_ENTRY(SMONTHNAME12),
106 LOCALE_ENTRY(SMONTHNAME13),
107 LOCALE_ENTRY(SABBREVMONTHNAME1),
108 LOCALE_ENTRY(SABBREVMONTHNAME2),
109 LOCALE_ENTRY(SABBREVMONTHNAME3),
110 LOCALE_ENTRY(SABBREVMONTHNAME4),
111 LOCALE_ENTRY(SABBREVMONTHNAME5),
112 LOCALE_ENTRY(SABBREVMONTHNAME6),
113 LOCALE_ENTRY(SABBREVMONTHNAME7),
114 LOCALE_ENTRY(SABBREVMONTHNAME8),
115 LOCALE_ENTRY(SABBREVMONTHNAME9),
116 LOCALE_ENTRY(SABBREVMONTHNAME10),
117 LOCALE_ENTRY(SABBREVMONTHNAME11),
118 LOCALE_ENTRY(SABBREVMONTHNAME12),
119 LOCALE_ENTRY(SABBREVMONTHNAME13),
120 LOCALE_ENTRY(SPOSITIVESIGN),
121 LOCALE_ENTRY(SNEGATIVESIGN),
122 LOCALE_ENTRY(IPOSSIGNPOSN),
123 LOCALE_ENTRY(INEGSIGNPOSN),
124 LOCALE_ENTRY(IPOSSYMPRECEDES),
125 LOCALE_ENTRY(IPOSSEPBYSPACE),
126 LOCALE_ENTRY(INEGSYMPRECEDES),
127 LOCALE_ENTRY(INEGSEPBYSPACE),
128 /* LOCALE_ENTRY(FONTSIGNATURE),*/
129 {NULL,0},
132 const struct map_lcid2str {
133 LCID langid;
134 const char *langname;
135 } languages[]={
136 {0x0401,"Arabisch"},
137 {0x0402,"Bulgarisch"},
138 {0x0403,"Katalanisch"},
139 {0x0404,"Traditionales Chinesisch"},
140 {0x0405,"Tschecisch"},
141 {0x0406,"Dänisch"},
142 {0x0407,"Deutsch"},
143 {0x0408,"Griechisch"},
144 {0x0409,"Amerikanisches Englisch"},
145 {0x040A,"Kastilisches Spanisch"},
146 {0x040B,"Finnisch"},
147 {0x040C,"Franzvsisch"},
148 {0x040D,"Hebrdisch"},
149 {0x040E,"Ungarisch"},
150 {0x040F,"Isldndisch"},
151 {0x0410,"Italienisch"},
152 {0x0411,"Japanisch"},
153 {0x0412,"Koreanisch"},
154 {0x0413,"Niederldndisch"},
155 {0x0414,"Norwegisch-Bokmal"},
156 {0x0415,"Polnisch"},
157 {0x0416,"Brasilianisches Portugiesisch"},
158 {0x0417,"Rdtoromanisch"},
159 {0x0418,"Rumdnisch"},
160 {0x0419,"Russisch"},
161 {0x041A,"Kroatoserbisch (lateinisch)"},
162 {0x041B,"Slowenisch"},
163 {0x041C,"Albanisch"},
164 {0x041D,"Schwedisch"},
165 {0x041E,"Thai"},
166 {0x041F,"T|rkisch"},
167 {0x0420,"Urdu"},
168 {0x0421,"Bahasa"},
169 {0x0804,"Vereinfachtes Chinesisch"},
170 {0x0807,"Schweizerdeutsch"},
171 {0x0809,"Britisches Englisch"},
172 {0x080A,"Mexikanisches Spanisch"},
173 {0x080C,"Belgisches Franzvsisch"},
174 {0x0810,"Schweizerisches Italienisch"},
175 {0x0813,"Belgisches Niederldndisch"},
176 {0x0814,"Norgwegisch-Nynorsk"},
177 {0x0816,"Portugiesisch"},
178 {0x081A,"Serbokratisch (kyrillisch)"},
179 {0x0C1C,"Kanadisches Franzvsisch"},
180 {0x100C,"Schweizerisches Franzvsisch"},
181 {0x0000,"Unbekannt"},
184 /***********************************************************************
185 * GetUserDefaultLCID (OLE2NLS.1)
187 LCID WINAPI GetUserDefaultLCID()
189 /* Default sorting, neutral sublanguage */
190 switch(Options.language)
192 /* case LANG_Bu: return 0x02; */ /* Bulgarian */
193 /* case LANG_Ch: return 0x04; */ /* Chinese */
194 case LANG_Cz: return 0x05; /* Czech */
195 case LANG_Da: return 0x06; /* Danish */
196 case LANG_De: return 0x07; /* German */
197 /* case LANG_Gr: return 0x08; */ /* Greek */
198 case LANG_En: return 0x09; /* English */
199 case LANG_Es: return 0x0a; /* Spanish */
200 case LANG_Fi: return 0x0b; /* Finnish */
201 case LANG_Fr: return 0x0c; /* French */
202 case LANG_Hu: return 0x0e; /* Hungarian */
203 /* case LANG_Ic: return 0x0f; */ /* Icelandic */
204 case LANG_It: return 0x10; /* Italian */
205 /* case LANG_Jp: return 0x11; */ /* Japanese */
206 case LANG_Ko: return 0x12; /* Korean */
207 /* case LANG_Du: return 0x13; */ /* Dutch */
208 case LANG_No: return 0x14; /* Norwegian */
209 case LANG_Pl: return 0x15; /* Polish */
210 case LANG_Po: return 0x16; /* Portuguese */
211 /* case LANG_Ro: return 0x18; */ /* Romanian */
212 /* case LANG_Ru: return 0x19; */ /* Russian */
213 /* case LANG_Cr: return 0x1a; */ /* Croatian */
214 /* case LANG_Sl: return 0x1b; */ /* Slovak */
215 case LANG_Sw: return 0x1d; /* Swedish */
216 /* case LANG_Tu: return 0x1f; */ /* Turkish */
217 /* case LANG_Sv: return 0x24; */ /* Slovenian */
218 case LANG_Eo: return 0x25; /* Esperanto (not official) */
219 case LANG_Ca: return 0x26; /* Catalan */
221 default:
222 return 0x00; /* Neutral language */
226 /***********************************************************************
227 * GetSystemDefaultLCID (OLE2NLS.2)
229 LCID WINAPI GetSystemDefaultLCID()
231 return GetUserDefaultLCID();
234 /***********************************************************************
235 * GetUserDefaultLangID (OLE2NLS.3)
237 LANGID WINAPI GetUserDefaultLangID()
239 return (WORD)GetUserDefaultLCID();
242 /***********************************************************************
243 * GetSystemDefaultLangID (OLE2NLS.4)
245 LANGID WINAPI GetSystemDefaultLangID()
247 return GetUserDefaultLangID();
250 /***********************************************************************
251 * GetLocaleInfoA (OLE2NLS.5)
252 * Is the last parameter really WORD for Win16?
254 INT16 WINAPI GetLocaleInfo16(LCID lcid,LCTYPE LCType,LPSTR buf,INT16 len)
256 return GetLocaleInfo32A(lcid,LCType,buf,len);
259 INT32 WINAPI GetLocaleInfo32A(LCID lcid,LCTYPE LCType,LPSTR buf,INT32 len)
261 char *retString;
262 int found,i;
264 TRACE(ole,"(%8lX,%8lX,%p,%4X)\n",
265 lcid,LCType,buf,len);
267 LCType &= ~(LOCALE_NOUSEROVERRIDE|LOCALE_USE_CP_ACP);
269 /* As an option, we could obtain the value from win.ini.
270 This would not match the Wine compile-time option.
271 Also, not all identifiers are available from win.ini */
272 retString=0;
273 /* If we are through all of this, retLen should not be zero anymore.
274 If it is, the value is not supported */
275 i=0;
276 while (locale_name2id[i].name!=NULL) {
277 if (LCType == locale_name2id[i].id) {
278 retString = locale_name2id[i].name;
279 break;
281 i++;
283 if (!retString) {
284 WARN(ole,"Unkown LC type %lX\n",LCType);
285 return 0;
288 #define LOCVAL(type,value) case type:retString=value;break;
290 /* Now, the language specific definitions. They don't have to be
291 complete */
292 found=1;
293 switch(Options.language)
295 case LANG_De:
296 switch (LCType) {
297 #include "nls/deu.nls"
298 default: found=0;break;
300 break; /* LANG(De) */
302 case LANG_Da:
303 switch (LCType) {
304 #include "nls/dnk.nls"
305 default: found=0;break;
307 break; /* LANG(Da) */
309 case LANG_En:
310 switch (LCType) {
311 #include "nls/enu.nls"
312 default: found=0;break;
314 break; /* LANG(En) */
316 case LANG_Eo:
317 switch (LCType) {
318 #include "nls/esperanto.nls"
319 default: found=0;break;
321 break; /* LANG(Eo) */
323 case LANG_Fi:
324 switch (LCType) {
325 #include "nls/fin.nls"
326 default: found=0;break;
328 break; /* LANG(Fi) */
330 case LANG_It:
331 switch (LCType) {
332 #include "nls/ita.nls"
333 default: found=0;break;
335 break; /* LANG(It) */
337 case 0x0809:
338 switch (LCType) {
339 #include "nls/eng.nls"
340 default: found=0;break;
342 break; /* LANG(0x0809) (U.K. English) */
344 case LANG_Ko: /* string using codepage 949 */
345 switch (LCType) {
346 #include "nls/kor.nls"
347 default: found=0;break;
349 break; /* LANG(Ko) */
351 case LANG_Hu:
352 switch (LCType) {
353 #include "nls/hun.nls"
354 default: found=0;break;
356 break; /* LANG(En) */
358 case LANG_Pl:
359 switch (LCType) {
360 #include "nls/plk.nls"
361 default: found=0;break;
363 break; /* LANG(Pl) */
365 case LANG_Po:
366 switch (LCType) {
367 #include "nls/ptb.nls"
368 default: found=0;break;
370 break; /* LANG(Po) */
372 case LANG_Sw:
373 switch (LCType) {
374 #include "nls/sve.nls"
375 default: found=0;break;
377 break; /* LANG(Sw) */
379 /*Insert other languages here*/
381 default:
382 found=0;
383 break;
384 } /* switch */
386 if(!found) {
387 ERR(ole,"'%s' not supported for your language.\n",
388 retString);
389 retString = "<WINE-NLS-unknown>";
390 /*return 0;*/
392 if (buf)
393 lstrcpyn32A(buf,retString,len);
394 return strlen(retString)+1;
397 /***********************************************************************
398 * GetLocaleInfo32W (KERNEL32.230)
399 * Is the last parameter really WORD for Win16?
401 INT32 WINAPI GetLocaleInfo32W(LCID lcid,LCTYPE LCType,LPWSTR wbuf,INT32 len)
403 LPSTR abuf = (LPSTR)HeapAlloc(GetProcessHeap(),0,len);
405 INT32 n = GetLocaleInfo32A(lcid, LCType, abuf, len);
406 if (wbuf)
407 lstrcpynAtoW(wbuf,abuf,len);
408 HeapFree(GetProcessHeap(),0,abuf);
409 return n;
412 /***********************************************************************
413 * SetLocaleInfoA [KERNEL32.499]
415 BOOL16 WINAPI SetLocaleInfoA(DWORD lcid, DWORD lctype, LPCSTR data)
417 FIXME(ole,"(%ld,%ld,%s): stub\n",lcid,lctype,data);
418 return TRUE;
421 /***********************************************************************
422 * IsValidLocale [KERNEL32.361]
424 BOOL32 WINAPI IsValidLocale(LCID lcid,DWORD flags)
426 /* we support ANY language. Well, at least say that...*/
427 return TRUE;
430 /***********************************************************************
431 * EnumSystemLocales32W [KERNEL32.93]
433 BOOL32 WINAPI EnumSystemLocales32W( LOCALE_ENUMPROC32W lpfnLocaleEnum,
434 DWORD flags )
436 int i;
437 BOOL32 ret;
438 WCHAR buffer[200];
439 HKEY xhkey;
441 TRACE(win32,"(%p,%08lx)\n",lpfnLocaleEnum,flags );
442 /* see if we can reuse the Win95 registry entries.... */
443 if (ERROR_SUCCESS==RegOpenKey32A(HKEY_LOCAL_MACHINE,"\\System\\CurrentControlSet\\control\\Nls\\Locale\\",&xhkey)) {
444 i=0;
445 while (1) {
446 if (ERROR_SUCCESS!=RegEnumKey32W(xhkey,i,buffer,sizeof(buffer)))
447 break;
448 if (!lpfnLocaleEnum(buffer))
449 break;
450 i++;
452 RegCloseKey(xhkey);
453 return TRUE;
456 i=0;
457 while (languages[i].langname!=NULL)
459 LPWSTR cp;
460 char xbuffer[10];
462 sprintf(xbuffer,"%08lx",(DWORD)languages[i].langid);
464 cp = HEAP_strdupAtoW( GetProcessHeap(), 0, xbuffer );
465 ret = lpfnLocaleEnum(cp);
466 HeapFree( GetProcessHeap(), 0, cp );
467 if (!ret) break;
468 i++;
470 return TRUE;
473 /***********************************************************************
474 * EnumSystemLocales32A [KERNEL32.92]
476 BOOL32 WINAPI EnumSystemLocales32A(LOCALE_ENUMPROC32A lpfnLocaleEnum,
477 DWORD flags)
479 int i;
480 CHAR buffer[200];
481 HKEY xhkey;
483 TRACE(win32,"(%p,%08lx)\n",
484 lpfnLocaleEnum,flags
486 if (ERROR_SUCCESS==RegOpenKey32A(HKEY_LOCAL_MACHINE,"\\System\\CurrentControlSet\\control\\Nls\\Locale\\",&xhkey)) {
487 i=0;
488 while (1) {
489 if (ERROR_SUCCESS!=RegEnumKey32A(xhkey,i,buffer,sizeof(buffer)))
490 break;
491 if (!lpfnLocaleEnum(buffer))
492 break;
493 i++;
495 RegCloseKey(xhkey);
496 return TRUE;
498 i=0;
499 while (languages[i].langname!=NULL) {
500 sprintf(buffer,"%08lx",(DWORD)languages[i].langid);
501 if (!lpfnLocaleEnum(buffer))
502 break;
503 i++;
505 return TRUE;
508 static const unsigned char CT_CType2_LUT[] = {
509 C2_NOTAPPLICABLE, /* - 0 */
510 C2_NOTAPPLICABLE, /* - 1 */
511 C2_NOTAPPLICABLE, /* - 2 */
512 C2_NOTAPPLICABLE, /* - 3 */
513 C2_NOTAPPLICABLE, /* - 4 */
514 C2_NOTAPPLICABLE, /* - 5 */
515 C2_NOTAPPLICABLE, /* - 6 */
516 C2_NOTAPPLICABLE, /* - 7 */
517 C2_NOTAPPLICABLE, /* - 8 */
518 C2_SEGMENTSEPARATOR, /* - 9 */
519 C2_NOTAPPLICABLE, /* - 10 */
520 C2_NOTAPPLICABLE, /* - 11 */
521 C2_NOTAPPLICABLE, /* - 12 */
522 C2_NOTAPPLICABLE, /* - 13 */
523 C2_NOTAPPLICABLE, /* - 14 */
524 C2_NOTAPPLICABLE, /* - 15 */
525 C2_NOTAPPLICABLE, /* - 16 */
526 C2_NOTAPPLICABLE, /* - 17 */
527 C2_NOTAPPLICABLE, /* - 18 */
528 C2_NOTAPPLICABLE, /* - 19 */
529 C2_NOTAPPLICABLE, /* - 20 */
530 C2_NOTAPPLICABLE, /* - 21 */
531 C2_NOTAPPLICABLE, /* - 22 */
532 C2_NOTAPPLICABLE, /* - 23 */
533 C2_NOTAPPLICABLE, /* - 24 */
534 C2_NOTAPPLICABLE, /* - 25 */
535 C2_NOTAPPLICABLE, /* - 26 */
536 C2_NOTAPPLICABLE, /* - 27 */
537 C2_NOTAPPLICABLE, /* - 28 */
538 C2_NOTAPPLICABLE, /* - 29 */
539 C2_NOTAPPLICABLE, /* - 30 */
540 C2_NOTAPPLICABLE, /* - 31 */
541 C2_WHITESPACE, /* - 32 */
542 C2_OTHERNEUTRAL, /* ! - 33 */
543 C2_OTHERNEUTRAL, /* " - 34 */ /* " */
544 C2_EUROPETERMINATOR, /* # - 35 */
545 C2_EUROPETERMINATOR, /* $ - 36 */
546 C2_EUROPETERMINATOR, /* % - 37 */
547 C2_LEFTTORIGHT, /* & - 38 */
548 C2_OTHERNEUTRAL, /* ' - 39 */
549 C2_OTHERNEUTRAL, /* ( - 40 */
550 C2_OTHERNEUTRAL, /* ) - 41 */
551 C2_OTHERNEUTRAL, /* * - 42 */
552 C2_EUROPETERMINATOR, /* + - 43 */
553 C2_COMMONSEPARATOR, /* , - 44 */
554 C2_EUROPETERMINATOR, /* - - 45 */
555 C2_EUROPESEPARATOR, /* . - 46 */
556 C2_EUROPESEPARATOR, /* / - 47 */
557 C2_EUROPENUMBER, /* 0 - 48 */
558 C2_EUROPENUMBER, /* 1 - 49 */
559 C2_EUROPENUMBER, /* 2 - 50 */
560 C2_EUROPENUMBER, /* 3 - 51 */
561 C2_EUROPENUMBER, /* 4 - 52 */
562 C2_EUROPENUMBER, /* 5 - 53 */
563 C2_EUROPENUMBER, /* 6 - 54 */
564 C2_EUROPENUMBER, /* 7 - 55 */
565 C2_EUROPENUMBER, /* 8 - 56 */
566 C2_EUROPENUMBER, /* 9 - 57 */
567 C2_COMMONSEPARATOR, /* : - 58 */
568 C2_OTHERNEUTRAL, /* ; - 59 */
569 C2_OTHERNEUTRAL, /* < - 60 */
570 C2_OTHERNEUTRAL, /* = - 61 */
571 C2_OTHERNEUTRAL, /* > - 62 */
572 C2_OTHERNEUTRAL, /* ? - 63 */
573 C2_LEFTTORIGHT, /* @ - 64 */
574 C2_LEFTTORIGHT, /* A - 65 */
575 C2_LEFTTORIGHT, /* B - 66 */
576 C2_LEFTTORIGHT, /* C - 67 */
577 C2_LEFTTORIGHT, /* D - 68 */
578 C2_LEFTTORIGHT, /* E - 69 */
579 C2_LEFTTORIGHT, /* F - 70 */
580 C2_LEFTTORIGHT, /* G - 71 */
581 C2_LEFTTORIGHT, /* H - 72 */
582 C2_LEFTTORIGHT, /* I - 73 */
583 C2_LEFTTORIGHT, /* J - 74 */
584 C2_LEFTTORIGHT, /* K - 75 */
585 C2_LEFTTORIGHT, /* L - 76 */
586 C2_LEFTTORIGHT, /* M - 77 */
587 C2_LEFTTORIGHT, /* N - 78 */
588 C2_LEFTTORIGHT, /* O - 79 */
589 C2_LEFTTORIGHT, /* P - 80 */
590 C2_LEFTTORIGHT, /* Q - 81 */
591 C2_LEFTTORIGHT, /* R - 82 */
592 C2_LEFTTORIGHT, /* S - 83 */
593 C2_LEFTTORIGHT, /* T - 84 */
594 C2_LEFTTORIGHT, /* U - 85 */
595 C2_LEFTTORIGHT, /* V - 86 */
596 C2_LEFTTORIGHT, /* W - 87 */
597 C2_LEFTTORIGHT, /* X - 88 */
598 C2_LEFTTORIGHT, /* Y - 89 */
599 C2_LEFTTORIGHT, /* Z - 90 */
600 C2_OTHERNEUTRAL, /* [ - 91 */
601 C2_OTHERNEUTRAL, /* \ - 92 */
602 C2_OTHERNEUTRAL, /* ] - 93 */
603 C2_OTHERNEUTRAL, /* ^ - 94 */
604 C2_OTHERNEUTRAL, /* _ - 95 */
605 C2_OTHERNEUTRAL, /* ` - 96 */
606 C2_LEFTTORIGHT, /* a - 97 */
607 C2_LEFTTORIGHT, /* b - 98 */
608 C2_LEFTTORIGHT, /* c - 99 */
609 C2_LEFTTORIGHT, /* d - 100 */
610 C2_LEFTTORIGHT, /* e - 101 */
611 C2_LEFTTORIGHT, /* f - 102 */
612 C2_LEFTTORIGHT, /* g - 103 */
613 C2_LEFTTORIGHT, /* h - 104 */
614 C2_LEFTTORIGHT, /* i - 105 */
615 C2_LEFTTORIGHT, /* j - 106 */
616 C2_LEFTTORIGHT, /* k - 107 */
617 C2_LEFTTORIGHT, /* l - 108 */
618 C2_LEFTTORIGHT, /* m - 109 */
619 C2_LEFTTORIGHT, /* n - 110 */
620 C2_LEFTTORIGHT, /* o - 111 */
621 C2_LEFTTORIGHT, /* p - 112 */
622 C2_LEFTTORIGHT, /* q - 113 */
623 C2_LEFTTORIGHT, /* r - 114 */
624 C2_LEFTTORIGHT, /* s - 115 */
625 C2_LEFTTORIGHT, /* t - 116 */
626 C2_LEFTTORIGHT, /* u - 117 */
627 C2_LEFTTORIGHT, /* v - 118 */
628 C2_LEFTTORIGHT, /* w - 119 */
629 C2_LEFTTORIGHT, /* x - 120 */
630 C2_LEFTTORIGHT, /* y - 121 */
631 C2_LEFTTORIGHT, /* z - 122 */
632 C2_OTHERNEUTRAL, /* { - 123 */
633 C2_OTHERNEUTRAL, /* | - 124 */
634 C2_OTHERNEUTRAL, /* } - 125 */
635 C2_OTHERNEUTRAL, /* ~ - 126 */
636 C2_NOTAPPLICABLE, /* \x7f - 127 */
637 C2_NOTAPPLICABLE, /* € - 128 */
638 C2_NOTAPPLICABLE, /* � - 129 */
639 C2_OTHERNEUTRAL, /* ‚ - 130 */
640 C2_LEFTTORIGHT, /* ƒ - 131 */
641 C2_OTHERNEUTRAL, /* „ - 132 */
642 C2_OTHERNEUTRAL, /* … - 133 */
643 C2_OTHERNEUTRAL, /* † - 134 */
644 C2_OTHERNEUTRAL, /* ‡ - 135 */
645 C2_LEFTTORIGHT, /* ˆ - 136 */
646 C2_EUROPETERMINATOR, /* ‰ - 137 */
647 C2_LEFTTORIGHT, /* Š - 138 */
648 C2_OTHERNEUTRAL, /* ‹ - 139 */
649 C2_LEFTTORIGHT, /* Π- 140 */
650 C2_NOTAPPLICABLE, /* � - 141 */
651 C2_NOTAPPLICABLE, /* Ž - 142 */
652 C2_NOTAPPLICABLE, /* � - 143 */
653 C2_NOTAPPLICABLE, /* � - 144 */
654 C2_OTHERNEUTRAL, /* ‘ - 145 */
655 C2_OTHERNEUTRAL, /* ’ - 146 */
656 C2_OTHERNEUTRAL, /* “ - 147 */
657 C2_OTHERNEUTRAL, /* ” - 148 */
658 C2_OTHERNEUTRAL, /* • - 149 */
659 C2_OTHERNEUTRAL, /* – - 150 */
660 C2_OTHERNEUTRAL, /* — - 151 */
661 C2_LEFTTORIGHT, /* ˜ - 152 */
662 C2_OTHERNEUTRAL, /* ™ - 153 */
663 C2_LEFTTORIGHT, /* š - 154 */
664 C2_OTHERNEUTRAL, /* › - 155 */
665 C2_LEFTTORIGHT, /* œ - 156 */
666 C2_NOTAPPLICABLE, /* � - 157 */
667 C2_NOTAPPLICABLE, /* ž - 158 */
668 C2_LEFTTORIGHT, /* Ÿ - 159 */
669 C2_WHITESPACE, /*   - 160 */
670 C2_OTHERNEUTRAL, /* ¡ - 161 */
671 C2_EUROPETERMINATOR, /* ¢ - 162 */
672 C2_EUROPETERMINATOR, /* £ - 163 */
673 C2_EUROPETERMINATOR, /* ¤ - 164 */
674 C2_EUROPETERMINATOR, /* ¥ - 165 */
675 C2_OTHERNEUTRAL, /* ¦ - 166 */
676 C2_OTHERNEUTRAL, /* § - 167 */
677 C2_OTHERNEUTRAL, /* ¨ - 168 */
678 C2_OTHERNEUTRAL, /* © - 169 */
679 C2_OTHERNEUTRAL, /* ª - 170 */
680 C2_OTHERNEUTRAL, /* « - 171 */
681 C2_OTHERNEUTRAL, /* ¬ - 172 */
682 C2_OTHERNEUTRAL, /* ­ - 173 */
683 C2_OTHERNEUTRAL, /* ® - 174 */
684 C2_OTHERNEUTRAL, /* ¯ - 175 */
685 C2_EUROPETERMINATOR, /* ° - 176 */
686 C2_EUROPETERMINATOR, /* ± - 177 */
687 C2_EUROPENUMBER, /* ² - 178 */
688 C2_EUROPENUMBER, /* ³ - 179 */
689 C2_OTHERNEUTRAL, /* ´ - 180 */
690 C2_OTHERNEUTRAL, /* µ - 181 */
691 C2_OTHERNEUTRAL, /* ¶ - 182 */
692 C2_OTHERNEUTRAL, /* · - 183 */
693 C2_OTHERNEUTRAL, /* ¸ - 184 */
694 C2_EUROPENUMBER, /* ¹ - 185 */
695 C2_OTHERNEUTRAL, /* º - 186 */
696 C2_OTHERNEUTRAL, /* » - 187 */
697 C2_OTHERNEUTRAL, /* ¼ - 188 */
698 C2_OTHERNEUTRAL, /* ½ - 189 */
699 C2_OTHERNEUTRAL, /* ¾ - 190 */
700 C2_OTHERNEUTRAL, /* ¿ - 191 */
701 C2_LEFTTORIGHT, /* À - 192 */
702 C2_LEFTTORIGHT, /* Á - 193 */
703 C2_LEFTTORIGHT, /* Â - 194 */
704 C2_LEFTTORIGHT, /* Ã - 195 */
705 C2_LEFTTORIGHT, /* Ä - 196 */
706 C2_LEFTTORIGHT, /* Å - 197 */
707 C2_LEFTTORIGHT, /* Æ - 198 */
708 C2_LEFTTORIGHT, /* Ç - 199 */
709 C2_LEFTTORIGHT, /* È - 200 */
710 C2_LEFTTORIGHT, /* É - 201 */
711 C2_LEFTTORIGHT, /* Ê - 202 */
712 C2_LEFTTORIGHT, /* Ë - 203 */
713 C2_LEFTTORIGHT, /* Ì - 204 */
714 C2_LEFTTORIGHT, /* Í - 205 */
715 C2_LEFTTORIGHT, /* Î - 206 */
716 C2_LEFTTORIGHT, /* Ï - 207 */
717 C2_LEFTTORIGHT, /* Ð - 208 */
718 C2_LEFTTORIGHT, /* Ñ - 209 */
719 C2_LEFTTORIGHT, /* Ò - 210 */
720 C2_LEFTTORIGHT, /* Ó - 211 */
721 C2_LEFTTORIGHT, /* Ô - 212 */
722 C2_LEFTTORIGHT, /* Õ - 213 */
723 C2_LEFTTORIGHT, /* Ö - 214 */
724 C2_OTHERNEUTRAL, /* × - 215 */
725 C2_LEFTTORIGHT, /* Ø - 216 */
726 C2_LEFTTORIGHT, /* Ù - 217 */
727 C2_LEFTTORIGHT, /* Ú - 218 */
728 C2_LEFTTORIGHT, /* Û - 219 */
729 C2_LEFTTORIGHT, /* Ü - 220 */
730 C2_LEFTTORIGHT, /* Ý - 221 */
731 C2_LEFTTORIGHT, /* Þ - 222 */
732 C2_LEFTTORIGHT, /* ß - 223 */
733 C2_LEFTTORIGHT, /* à - 224 */
734 C2_LEFTTORIGHT, /* á - 225 */
735 C2_LEFTTORIGHT, /* â - 226 */
736 C2_LEFTTORIGHT, /* ã - 227 */
737 C2_LEFTTORIGHT, /* ä - 228 */
738 C2_LEFTTORIGHT, /* å - 229 */
739 C2_LEFTTORIGHT, /* æ - 230 */
740 C2_LEFTTORIGHT, /* ç - 231 */
741 C2_LEFTTORIGHT, /* è - 232 */
742 C2_LEFTTORIGHT, /* é - 233 */
743 C2_LEFTTORIGHT, /* ê - 234 */
744 C2_LEFTTORIGHT, /* ë - 235 */
745 C2_LEFTTORIGHT, /* ì - 236 */
746 C2_LEFTTORIGHT, /* í - 237 */
747 C2_LEFTTORIGHT, /* î - 238 */
748 C2_LEFTTORIGHT, /* ï - 239 */
749 C2_LEFTTORIGHT, /* ð - 240 */
750 C2_LEFTTORIGHT, /* ñ - 241 */
751 C2_LEFTTORIGHT, /* ò - 242 */
752 C2_LEFTTORIGHT, /* ó - 243 */
753 C2_LEFTTORIGHT, /* ô - 244 */
754 C2_LEFTTORIGHT, /* õ - 245 */
755 C2_LEFTTORIGHT, /* ö - 246 */
756 C2_OTHERNEUTRAL, /* ÷ - 247 */
757 C2_LEFTTORIGHT, /* ø - 248 */
758 C2_LEFTTORIGHT, /* ù - 249 */
759 C2_LEFTTORIGHT, /* ú - 250 */
760 C2_LEFTTORIGHT, /* û - 251 */
761 C2_LEFTTORIGHT, /* ü - 252 */
762 C2_LEFTTORIGHT, /* ý - 253 */
763 C2_LEFTTORIGHT, /* þ - 254 */
764 C2_LEFTTORIGHT /* ÿ - 255 */
767 static const WORD CT_CType3_LUT[] = {
768 0x0000, /* - 0 */
769 0x0000, /* - 1 */
770 0x0000, /* - 2 */
771 0x0000, /* - 3 */
772 0x0000, /* - 4 */
773 0x0000, /* - 5 */
774 0x0000, /* - 6 */
775 0x0000, /* - 7 */
776 0x0000, /* - 8 */
777 0x0008, /* - 9 */
778 0x0008, /* - 10 */
779 0x0008, /* - 11 */
780 0x0008, /* - 12 */
781 0x0008, /* - 13 */
782 0x0000, /* - 14 */
783 0x0000, /* - 15 */
784 0x0000, /* - 16 */
785 0x0000, /* - 17 */
786 0x0000, /* - 18 */
787 0x0000, /* - 19 */
788 0x0000, /* - 20 */
789 0x0000, /* - 21 */
790 0x0000, /* - 22 */
791 0x0000, /* - 23 */
792 0x0000, /* - 24 */
793 0x0000, /* - 25 */
794 0x0000, /* - 26 */
795 0x0000, /* - 27 */
796 0x0000, /* - 28 */
797 0x0000, /* - 29 */
798 0x0000, /* - 30 */
799 0x0000, /* - 31 */
800 0x0048, /* - 32 */
801 0x0048, /* ! - 33 */
802 0x0448, /* " - 34 */ /* " */
803 0x0048, /* # - 35 */
804 0x0448, /* $ - 36 */
805 0x0048, /* % - 37 */
806 0x0048, /* & - 38 */
807 0x0440, /* ' - 39 */
808 0x0048, /* ( - 40 */
809 0x0048, /* ) - 41 */
810 0x0048, /* * - 42 */
811 0x0048, /* + - 43 */
812 0x0048, /* , - 44 */
813 0x0440, /* - - 45 */
814 0x0048, /* . - 46 */
815 0x0448, /* / - 47 */
816 0x0040, /* 0 - 48 */
817 0x0040, /* 1 - 49 */
818 0x0040, /* 2 - 50 */
819 0x0040, /* 3 - 51 */
820 0x0040, /* 4 - 52 */
821 0x0040, /* 5 - 53 */
822 0x0040, /* 6 - 54 */
823 0x0040, /* 7 - 55 */
824 0x0040, /* 8 - 56 */
825 0x0040, /* 9 - 57 */
826 0x0048, /* : - 58 */
827 0x0048, /* ; - 59 */
828 0x0048, /* < - 60 */
829 0x0448, /* = - 61 */
830 0x0048, /* > - 62 */
831 0x0048, /* ? - 63 */
832 0x0448, /* @ - 64 */
833 0x8040, /* A - 65 */
834 0x8040, /* B - 66 */
835 0x8040, /* C - 67 */
836 0x8040, /* D - 68 */
837 0x8040, /* E - 69 */
838 0x8040, /* F - 70 */
839 0x8040, /* G - 71 */
840 0x8040, /* H - 72 */
841 0x8040, /* I - 73 */
842 0x8040, /* J - 74 */
843 0x8040, /* K - 75 */
844 0x8040, /* L - 76 */
845 0x8040, /* M - 77 */
846 0x8040, /* N - 78 */
847 0x8040, /* O - 79 */
848 0x8040, /* P - 80 */
849 0x8040, /* Q - 81 */
850 0x8040, /* R - 82 */
851 0x8040, /* S - 83 */
852 0x8040, /* T - 84 */
853 0x8040, /* U - 85 */
854 0x8040, /* V - 86 */
855 0x8040, /* W - 87 */
856 0x8040, /* X - 88 */
857 0x8040, /* Y - 89 */
858 0x8040, /* Z - 90 */
859 0x0048, /* [ - 91 */
860 0x0448, /* \ - 92 */
861 0x0048, /* ] - 93 */
862 0x0448, /* ^ - 94 */
863 0x0448, /* _ - 95 */
864 0x0448, /* ` - 96 */
865 0x8040, /* a - 97 */
866 0x8040, /* b - 98 */
867 0x8040, /* c - 99 */
868 0x8040, /* d - 100 */
869 0x8040, /* e - 101 */
870 0x8040, /* f - 102 */
871 0x8040, /* g - 103 */
872 0x8040, /* h - 104 */
873 0x8040, /* i - 105 */
874 0x8040, /* j - 106 */
875 0x8040, /* k - 107 */
876 0x8040, /* l - 108 */
877 0x8040, /* m - 109 */
878 0x8040, /* n - 110 */
879 0x8040, /* o - 111 */
880 0x8040, /* p - 112 */
881 0x8040, /* q - 113 */
882 0x8040, /* r - 114 */
883 0x8040, /* s - 115 */
884 0x8040, /* t - 116 */
885 0x8040, /* u - 117 */
886 0x8040, /* v - 118 */
887 0x8040, /* w - 119 */
888 0x8040, /* x - 120 */
889 0x8040, /* y - 121 */
890 0x8040, /* z - 122 */
891 0x0048, /* { - 123 */
892 0x0048, /* | - 124 */
893 0x0048, /* } - 125 */
894 0x0448, /* ~ - 126 */
895 0x0000, /* \x7f - 127 */
896 0x0000, /* € - 128 */
897 0x0000, /* � - 129 */
898 0x0008, /* ‚ - 130 */
899 0x8000, /* ƒ - 131 */
900 0x0008, /* „ - 132 */
901 0x0008, /* … - 133 */
902 0x0008, /* † - 134 */
903 0x0008, /* ‡ - 135 */
904 0x0001, /* ˆ - 136 */
905 0x0008, /* ‰ - 137 */
906 0x8003, /* Š - 138 */
907 0x0008, /* ‹ - 139 */
908 0x8000, /* Π- 140 */
909 0x0000, /* � - 141 */
910 0x0000, /* Ž - 142 */
911 0x0000, /* � - 143 */
912 0x0000, /* � - 144 */
913 0x0088, /* ‘ - 145 */
914 0x0088, /* ’ - 146 */
915 0x0088, /* “ - 147 */
916 0x0088, /* ” - 148 */
917 0x0008, /* • - 149 */
918 0x0400, /* – - 150 */
919 0x0400, /* — - 151 */
920 0x0408, /* ˜ - 152 */
921 0x0000, /* ™ - 153 */
922 0x8003, /* š - 154 */
923 0x0008, /* › - 155 */
924 0x8000, /* œ - 156 */
925 0x0000, /* � - 157 */
926 0x0000, /* ž - 158 */
927 0x8003, /* Ÿ - 159 */
928 0x0008, /*   - 160 */
929 0x0008, /* ¡ - 161 */
930 0x0048, /* ¢ - 162 */
931 0x0048, /* £ - 163 */
932 0x0008, /* ¤ - 164 */
933 0x0048, /* ¥ - 165 */
934 0x0048, /* ¦ - 166 */
935 0x0008, /* § - 167 */
936 0x0408, /* ¨ - 168 */
937 0x0008, /* © - 169 */
938 0x0400, /* ª - 170 */
939 0x0008, /* « - 171 */
940 0x0048, /* ¬ - 172 */
941 0x0408, /* ­ - 173 */
942 0x0008, /* ® - 174 */
943 0x0448, /* ¯ - 175 */
944 0x0008, /* ° - 176 */
945 0x0008, /* ± - 177 */
946 0x0000, /* ² - 178 */
947 0x0000, /* ³ - 179 */
948 0x0408, /* ´ - 180 */
949 0x0008, /* µ - 181 */
950 0x0008, /* ¶ - 182 */
951 0x0008, /* · - 183 */
952 0x0408, /* ¸ - 184 */
953 0x0000, /* ¹ - 185 */
954 0x0400, /* º - 186 */
955 0x0008, /* » - 187 */
956 0x0000, /* ¼ - 188 */
957 0x0000, /* ½ - 189 */
958 0x0000, /* ¾ - 190 */
959 0x0008, /* ¿ - 191 */
960 0x8003, /* À - 192 */
961 0x8003, /* Á - 193 */
962 0x8003, /* Â - 194 */
963 0x8003, /* Ã - 195 */
964 0x8003, /* Ä - 196 */
965 0x8003, /* Å - 197 */
966 0x8000, /* Æ - 198 */
967 0x8003, /* Ç - 199 */
968 0x8003, /* È - 200 */
969 0x8003, /* É - 201 */
970 0x8003, /* Ê - 202 */
971 0x8003, /* Ë - 203 */
972 0x8003, /* Ì - 204 */
973 0x8003, /* Í - 205 */
974 0x8003, /* Î - 206 */
975 0x8003, /* Ï - 207 */
976 0x8000, /* Ð - 208 */
977 0x8003, /* Ñ - 209 */
978 0x8003, /* Ò - 210 */
979 0x8003, /* Ó - 211 */
980 0x8003, /* Ô - 212 */
981 0x8003, /* Õ - 213 */
982 0x8003, /* Ö - 214 */
983 0x0008, /* × - 215 */
984 0x8003, /* Ø - 216 */
985 0x8003, /* Ù - 217 */
986 0x8003, /* Ú - 218 */
987 0x8003, /* Û - 219 */
988 0x8003, /* Ü - 220 */
989 0x8003, /* Ý - 221 */
990 0x8000, /* Þ - 222 */
991 0x8000, /* ß - 223 */
992 0x8003, /* à - 224 */
993 0x8003, /* á - 225 */
994 0x8003, /* â - 226 */
995 0x8003, /* ã - 227 */
996 0x8003, /* ä - 228 */
997 0x8003, /* å - 229 */
998 0x8000, /* æ - 230 */
999 0x8003, /* ç - 231 */
1000 0x8003, /* è - 232 */
1001 0x8003, /* é - 233 */
1002 0x8003, /* ê - 234 */
1003 0x8003, /* ë - 235 */
1004 0x8003, /* ì - 236 */
1005 0x8003, /* í - 237 */
1006 0x8003, /* î - 238 */
1007 0x8003, /* ï - 239 */
1008 0x8000, /* ð - 240 */
1009 0x8003, /* ñ - 241 */
1010 0x8003, /* ò - 242 */
1011 0x8003, /* ó - 243 */
1012 0x8003, /* ô - 244 */
1013 0x8003, /* õ - 245 */
1014 0x8003, /* ö - 246 */
1015 0x0008, /* ÷ - 247 */
1016 0x8003, /* ø - 248 */
1017 0x8003, /* ù - 249 */
1018 0x8003, /* ú - 250 */
1019 0x8003, /* û - 251 */
1020 0x8003, /* ü - 252 */
1021 0x8003, /* ý - 253 */
1022 0x8000, /* þ - 254 */
1023 0x8003 /* ÿ - 255 */
1026 /***********************************************************************
1027 * GetStringTypeA [OLE2NLS.7]
1029 BOOL16 WINAPI GetStringType16(LCID locale,DWORD dwInfoType,LPCSTR src,
1030 INT16 cchSrc,LPWORD chartype)
1032 return GetStringTypeEx32A(locale,dwInfoType,src,cchSrc,chartype);
1034 /***********************************************************************
1035 * GetStringTypeA [KERNEL32.277]
1037 BOOL32 WINAPI GetStringType32A(LCID locale,DWORD dwInfoType,LPCSTR src,
1038 INT32 cchSrc,LPWORD chartype)
1040 return GetStringTypeEx32A(locale,dwInfoType,src,cchSrc,chartype);
1043 /***********************************************************************
1044 * GetStringTypeExA [KERNEL32.276]
1046 * FIXME: Ignores the locale.
1048 BOOL32 WINAPI GetStringTypeEx32A(LCID locale,DWORD dwInfoType,LPCSTR src,
1049 INT32 cchSrc,LPWORD chartype)
1051 int i;
1053 if ((src==NULL) || (chartype==NULL) || (src==(LPSTR)chartype))
1055 SetLastError(ERROR_INVALID_PARAMETER);
1056 return FALSE;
1059 if (cchSrc==-1)
1060 cchSrc=lstrlen32A(src)+1;
1062 switch (dwInfoType) {
1063 case CT_CTYPE1:
1064 for (i=0;i<cchSrc;i++)
1066 chartype[i] = 0;
1067 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1068 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1069 if (islower(src[i])) chartype[i]|=C1_LOWER;
1070 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1071 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1072 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1073 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1074 /* FIXME: isblank() is a GNU extension */
1075 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1076 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1077 /* C1_XDIGIT */
1079 return TRUE;
1081 case CT_CTYPE2:
1082 for (i=0;i<cchSrc;i++)
1084 chartype[i]=(WORD)CT_CType2_LUT[i];
1086 return TRUE;
1088 case CT_CTYPE3:
1089 for (i=0;i<cchSrc;i++)
1091 chartype[i]=CT_CType3_LUT[i];
1093 return TRUE;
1095 default:
1096 ERR(ole,"Unknown dwInfoType:%ld\n",dwInfoType);
1097 return FALSE;
1101 /*********************************************************************
1102 * GetStringTypeW [KERNEL32.279]
1104 * NOTES
1105 * Yes, this is missing LCID locale. MS fault.
1107 BOOL32 WINAPI GetStringType32W(DWORD dwInfoType,LPCWSTR src,INT32 cchSrc,
1108 LPWORD chartype)
1110 return GetStringTypeEx32W(0/*defaultlocale*/,dwInfoType,src,cchSrc,chartype);
1113 /*********************************************************************
1114 * GetStringTypeW [KERNEL32.278]
1115 * FIXME: unicode chars are assumed chars
1117 BOOL32 WINAPI GetStringTypeEx32W(LCID locale,DWORD dwInfoType,LPCWSTR src,
1118 INT32 cchSrc,LPWORD chartype)
1120 int i;
1123 if (cchSrc==-1)
1124 cchSrc=lstrlen32W(src)+1;
1126 switch (dwInfoType) {
1127 case CT_CTYPE2:
1128 FIXME(ole,"CT_CTYPE2 not supported.\n");
1129 return FALSE;
1130 case CT_CTYPE3:
1131 FIXME(ole,"CT_CTYPE3 not supported.\n");
1132 return FALSE;
1133 default:break;
1135 for (i=0;i<cchSrc;i++) {
1136 chartype[i] = 0;
1137 if (isdigit(src[i])) chartype[i]|=C1_DIGIT;
1138 if (isalpha(src[i])) chartype[i]|=C1_ALPHA;
1139 if (islower(src[i])) chartype[i]|=C1_LOWER;
1140 if (isupper(src[i])) chartype[i]|=C1_UPPER;
1141 if (isspace(src[i])) chartype[i]|=C1_SPACE;
1142 if (ispunct(src[i])) chartype[i]|=C1_PUNCT;
1143 if (iscntrl(src[i])) chartype[i]|=C1_CNTRL;
1144 /* FIXME: isblank() is a GNU extension */
1145 /* if (isblank(src[i])) chartype[i]|=C1_BLANK; */
1146 if ((src[i] == ' ') || (src[i] == '\t')) chartype[i]|=C1_BLANK;
1147 /* C1_XDIGIT */
1149 return TRUE;
1152 /*****************************************************************
1153 * VerLanguageName16 [VER.10]
1155 DWORD WINAPI VerLanguageName16(UINT16 langid,LPSTR langname,UINT16 langnamelen)
1157 int i;
1158 DWORD result;
1159 char buffer[80];
1161 TRACE(ver,"(%d,%p,%d)\n",langid,langname,langnamelen);
1162 /* First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
1163 * from the registry.
1165 sprintf(buffer,
1166 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
1167 langid);
1168 result = RegQueryValue16(HKEY_LOCAL_MACHINE, buffer, langname,
1169 (LPDWORD)&langnamelen);
1170 if (result == ERROR_SUCCESS) {
1171 langname[langnamelen-1]='\0';
1172 return langnamelen;
1174 /* if that fails, use the internal table */
1175 for (i=0;languages[i].langid!=0;i++)
1176 if (langid==languages[i].langid)
1177 break;
1178 strncpy(langname,languages[i].langname,langnamelen);
1179 langname[langnamelen-1]='\0';
1180 return strlen(languages[i].langname);
1183 /*****************************************************************
1184 * VerLanguageName32A [VERSION.9]
1186 DWORD WINAPI VerLanguageName32A(UINT32 langid,LPSTR langname,
1187 UINT32 langnamelen)
1189 return VerLanguageName16(langid,langname,langnamelen);
1192 /*****************************************************************
1193 * VerLanguageName32W [VERSION.10]
1195 DWORD WINAPI VerLanguageName32W(UINT32 langid,LPWSTR langname,
1196 UINT32 langnamelen)
1198 int i;
1199 LPWSTR keyname;
1200 DWORD result;
1201 char buffer[80];
1203 /* First, check \System\CurrentControlSet\control\Nls\Locale\<langid>
1204 * from the registry.
1206 sprintf(buffer,
1207 "\\System\\CurrentControlSet\\control\\Nls\\Locale\\%08x",
1208 langid);
1209 keyname = HEAP_strdupAtoW( GetProcessHeap(), 0, buffer );
1210 result = RegQueryValue32W(HKEY_LOCAL_MACHINE, keyname, langname,
1211 (LPDWORD)&langnamelen);
1212 HeapFree( GetProcessHeap(), 0, keyname );
1213 if (result != ERROR_SUCCESS) {
1214 /* if that fails, use the internal table */
1215 for (i=0;languages[i].langid!=0;i++)
1216 if (langid==languages[i].langid)
1217 break;
1218 lstrcpyAtoW( langname, languages[i].langname );
1219 langnamelen = strlen(languages[i].langname);
1220 /* same as strlenW(langname); */
1222 return langnamelen;
1225 static const unsigned char LCM_Unicode_LUT[] = {
1226 6 , 3, /* - 1 */
1227 6 , 4, /* - 2 */
1228 6 , 5, /* - 3 */
1229 6 , 6, /* - 4 */
1230 6 , 7, /* - 5 */
1231 6 , 8, /* - 6 */
1232 6 , 9, /* - 7 */
1233 6 , 10, /* - 8 */
1234 7 , 5, /* - 9 */
1235 7 , 6, /* - 10 */
1236 7 , 7, /* - 11 */
1237 7 , 8, /* - 12 */
1238 7 , 9, /* - 13 */
1239 6 , 11, /* - 14 */
1240 6 , 12, /* - 15 */
1241 6 , 13, /* - 16 */
1242 6 , 14, /* - 17 */
1243 6 , 15, /* - 18 */
1244 6 , 16, /* - 19 */
1245 6 , 17, /* - 20 */
1246 6 , 18, /* - 21 */
1247 6 , 19, /* - 22 */
1248 6 , 20, /* - 23 */
1249 6 , 21, /* - 24 */
1250 6 , 22, /* - 25 */
1251 6 , 23, /* - 26 */
1252 6 , 24, /* - 27 */
1253 6 , 25, /* - 28 */
1254 6 , 26, /* - 29 */
1255 6 , 27, /* - 30 */
1256 6 , 28, /* - 31 */
1257 7 , 2, /* - 32 */
1258 7 , 28, /* ! - 33 */
1259 7 , 29, /* " - 34 */ /* " */
1260 7 , 31, /* # - 35 */
1261 7 , 33, /* $ - 36 */
1262 7 , 35, /* % - 37 */
1263 7 , 37, /* & - 38 */
1264 6 , 128, /* ' - 39 */
1265 7 , 39, /* ( - 40 */
1266 7 , 42, /* ) - 41 */
1267 7 , 45, /* * - 42 */
1268 8 , 3, /* + - 43 */
1269 7 , 47, /* , - 44 */
1270 6 , 130, /* - - 45 */
1271 7 , 51, /* . - 46 */
1272 7 , 53, /* / - 47 */
1273 12 , 3, /* 0 - 48 */
1274 12 , 33, /* 1 - 49 */
1275 12 , 51, /* 2 - 50 */
1276 12 , 70, /* 3 - 51 */
1277 12 , 88, /* 4 - 52 */
1278 12 , 106, /* 5 - 53 */
1279 12 , 125, /* 6 - 54 */
1280 12 , 144, /* 7 - 55 */
1281 12 , 162, /* 8 - 56 */
1282 12 , 180, /* 9 - 57 */
1283 7 , 55, /* : - 58 */
1284 7 , 58, /* ; - 59 */
1285 8 , 14, /* < - 60 */
1286 8 , 18, /* = - 61 */
1287 8 , 20, /* > - 62 */
1288 7 , 60, /* ? - 63 */
1289 7 , 62, /* @ - 64 */
1290 14 , 2, /* A - 65 */
1291 14 , 9, /* B - 66 */
1292 14 , 10, /* C - 67 */
1293 14 , 26, /* D - 68 */
1294 14 , 33, /* E - 69 */
1295 14 , 35, /* F - 70 */
1296 14 , 37, /* G - 71 */
1297 14 , 44, /* H - 72 */
1298 14 , 50, /* I - 73 */
1299 14 , 53, /* J - 74 */
1300 14 , 54, /* K - 75 */
1301 14 , 72, /* L - 76 */
1302 14 , 81, /* M - 77 */
1303 14 , 112, /* N - 78 */
1304 14 , 124, /* O - 79 */
1305 14 , 126, /* P - 80 */
1306 14 , 137, /* Q - 81 */
1307 14 , 138, /* R - 82 */
1308 14 , 145, /* S - 83 */
1309 14 , 153, /* T - 84 */
1310 14 , 159, /* U - 85 */
1311 14 , 162, /* V - 86 */
1312 14 , 164, /* W - 87 */
1313 14 , 166, /* X - 88 */
1314 14 , 167, /* Y - 89 */
1315 14 , 169, /* Z - 90 */
1316 7 , 63, /* [ - 91 */
1317 7 , 65, /* \ - 92 */
1318 7 , 66, /* ] - 93 */
1319 7 , 67, /* ^ - 94 */
1320 7 , 68, /* _ - 95 */
1321 7 , 72, /* ` - 96 */
1322 14 , 2, /* a - 97 */
1323 14 , 9, /* b - 98 */
1324 14 , 10, /* c - 99 */
1325 14 , 26, /* d - 100 */
1326 14 , 33, /* e - 101 */
1327 14 , 35, /* f - 102 */
1328 14 , 37, /* g - 103 */
1329 14 , 44, /* h - 104 */
1330 14 , 50, /* i - 105 */
1331 14 , 53, /* j - 106 */
1332 14 , 54, /* k - 107 */
1333 14 , 72, /* l - 108 */
1334 14 , 81, /* m - 109 */
1335 14 , 112, /* n - 110 */
1336 14 , 124, /* o - 111 */
1337 14 , 126, /* p - 112 */
1338 14 , 137, /* q - 113 */
1339 14 , 138, /* r - 114 */
1340 14 , 145, /* s - 115 */
1341 14 , 153, /* t - 116 */
1342 14 , 159, /* u - 117 */
1343 14 , 162, /* v - 118 */
1344 14 , 164, /* w - 119 */
1345 14 , 166, /* x - 120 */
1346 14 , 167, /* y - 121 */
1347 14 , 169, /* z - 122 */
1348 7 , 74, /* { - 123 */
1349 7 , 76, /* | - 124 */
1350 7 , 78, /* } - 125 */
1351 7 , 80, /* ~ - 126 */
1352 6 , 29, /* \x7f - 127 */
1353 6 , 30, /* € - 128 */
1354 6 , 31, /* � - 129 */
1355 7 , 123, /* ‚ - 130 */
1356 14 , 35, /* ƒ - 131 */
1357 7 , 127, /* „ - 132 */
1358 10 , 21, /* … - 133 */
1359 10 , 15, /* † - 134 */
1360 10 , 16, /* ‡ - 135 */
1361 7 , 67, /* ˆ - 136 */
1362 10 , 22, /* ‰ - 137 */
1363 14 , 145, /* Š - 138 */
1364 7 , 136, /* ‹ - 139 */
1365 14 + 16 , 124, /* Π- 140 */
1366 6 , 43, /* � - 141 */
1367 6 , 44, /* Ž - 142 */
1368 6 , 45, /* � - 143 */
1369 6 , 46, /* � - 144 */
1370 7 , 121, /* ‘ - 145 */
1371 7 , 122, /* ’ - 146 */
1372 7 , 125, /* “ - 147 */
1373 7 , 126, /* ” - 148 */
1374 10 , 17, /* • - 149 */
1375 6 , 137, /* – - 150 */
1376 6 , 139, /* — - 151 */
1377 7 , 93, /* ˜ - 152 */
1378 14 , 156, /* ™ - 153 */
1379 14 , 145, /* š - 154 */
1380 7 , 137, /* › - 155 */
1381 14 + 16 , 124, /* œ - 156 */
1382 6 , 59, /* � - 157 */
1383 6 , 60, /* ž - 158 */
1384 14 , 167, /* Ÿ - 159 */
1385 7 , 4, /*   - 160 */
1386 7 , 81, /* ¡ - 161 */
1387 10 , 2, /* ¢ - 162 */
1388 10 , 3, /* £ - 163 */
1389 10 , 4, /* ¤ - 164 */
1390 10 , 5, /* ¥ - 165 */
1391 7 , 82, /* ¦ - 166 */
1392 10 , 6, /* § - 167 */
1393 7 , 83, /* ¨ - 168 */
1394 10 , 7, /* © - 169 */
1395 14 , 2, /* ª - 170 */
1396 8 , 24, /* « - 171 */
1397 10 , 8, /* ¬ - 172 */
1398 6 , 131, /* ­ - 173 */
1399 10 , 9, /* ® - 174 */
1400 7 , 84, /* ¯ - 175 */
1401 10 , 10, /* ° - 176 */
1402 8 , 23, /* ± - 177 */
1403 12 , 51, /* ² - 178 */
1404 12 , 70, /* ³ - 179 */
1405 7 , 85, /* ´ - 180 */
1406 10 , 11, /* µ - 181 */
1407 10 , 12, /* ¶ - 182 */
1408 10 , 13, /* · - 183 */
1409 7 , 86, /* ¸ - 184 */
1410 12 , 33, /* ¹ - 185 */
1411 14 , 124, /* º - 186 */
1412 8 , 26, /* » - 187 */
1413 12 , 21, /* ¼ - 188 */
1414 12 , 25, /* ½ - 189 */
1415 12 , 29, /* ¾ - 190 */
1416 7 , 87, /* ¿ - 191 */
1417 14 , 2, /* À - 192 */
1418 14 , 2, /* Á - 193 */
1419 14 , 2, /* Â - 194 */
1420 14 , 2, /* Ã - 195 */
1421 14 , 2, /* Ä - 196 */
1422 14 , 2, /* Å - 197 */
1423 14 + 16 , 2, /* Æ - 198 */
1424 14 , 10, /* Ç - 199 */
1425 14 , 33, /* È - 200 */
1426 14 , 33, /* É - 201 */
1427 14 , 33, /* Ê - 202 */
1428 14 , 33, /* Ë - 203 */
1429 14 , 50, /* Ì - 204 */
1430 14 , 50, /* Í - 205 */
1431 14 , 50, /* Î - 206 */
1432 14 , 50, /* Ï - 207 */
1433 14 , 26, /* Ð - 208 */
1434 14 , 112, /* Ñ - 209 */
1435 14 , 124, /* Ò - 210 */
1436 14 , 124, /* Ó - 211 */
1437 14 , 124, /* Ô - 212 */
1438 14 , 124, /* Õ - 213 */
1439 14 , 124, /* Ö - 214 */
1440 8 , 28, /* × - 215 */
1441 14 , 124, /* Ø - 216 */
1442 14 , 159, /* Ù - 217 */
1443 14 , 159, /* Ú - 218 */
1444 14 , 159, /* Û - 219 */
1445 14 , 159, /* Ü - 220 */
1446 14 , 167, /* Ý - 221 */
1447 14 + 32 , 153, /* Þ - 222 */
1448 14 + 48 , 145, /* ß - 223 */
1449 14 , 2, /* à - 224 */
1450 14 , 2, /* á - 225 */
1451 14 , 2, /* â - 226 */
1452 14 , 2, /* ã - 227 */
1453 14 , 2, /* ä - 228 */
1454 14 , 2, /* å - 229 */
1455 14 + 16 , 2, /* æ - 230 */
1456 14 , 10, /* ç - 231 */
1457 14 , 33, /* è - 232 */
1458 14 , 33, /* é - 233 */
1459 14 , 33, /* ê - 234 */
1460 14 , 33, /* ë - 235 */
1461 14 , 50, /* ì - 236 */
1462 14 , 50, /* í - 237 */
1463 14 , 50, /* î - 238 */
1464 14 , 50, /* ï - 239 */
1465 14 , 26, /* ð - 240 */
1466 14 , 112, /* ñ - 241 */
1467 14 , 124, /* ò - 242 */
1468 14 , 124, /* ó - 243 */
1469 14 , 124, /* ô - 244 */
1470 14 , 124, /* õ - 245 */
1471 14 , 124, /* ö - 246 */
1472 8 , 29, /* ÷ - 247 */
1473 14 , 124, /* ø - 248 */
1474 14 , 159, /* ù - 249 */
1475 14 , 159, /* ú - 250 */
1476 14 , 159, /* û - 251 */
1477 14 , 159, /* ü - 252 */
1478 14 , 167, /* ý - 253 */
1479 14 + 32 , 153, /* þ - 254 */
1480 14 , 167 /* ÿ - 255 */ };
1482 static const unsigned char LCM_Unicode_LUT_2[] = { 33, 44, 145 };
1484 #define LCM_Diacritic_Start 131
1486 static const unsigned char LCM_Diacritic_LUT[] = {
1487 123, /* ƒ - 131 */
1488 2, /* „ - 132 */
1489 2, /* … - 133 */
1490 2, /* † - 134 */
1491 2, /* ‡ - 135 */
1492 3, /* ˆ - 136 */
1493 2, /* ‰ - 137 */
1494 20, /* Š - 138 */
1495 2, /* ‹ - 139 */
1496 2, /* Π- 140 */
1497 2, /* � - 141 */
1498 2, /* Ž - 142 */
1499 2, /* � - 143 */
1500 2, /* � - 144 */
1501 2, /* ‘ - 145 */
1502 2, /* ’ - 146 */
1503 2, /* “ - 147 */
1504 2, /* ” - 148 */
1505 2, /* • - 149 */
1506 2, /* – - 150 */
1507 2, /* — - 151 */
1508 2, /* ˜ - 152 */
1509 2, /* ™ - 153 */
1510 20, /* š - 154 */
1511 2, /* › - 155 */
1512 2, /* œ - 156 */
1513 2, /* � - 157 */
1514 2, /* ž - 158 */
1515 19, /* Ÿ - 159 */
1516 2, /*   - 160 */
1517 2, /* ¡ - 161 */
1518 2, /* ¢ - 162 */
1519 2, /* £ - 163 */
1520 2, /* ¤ - 164 */
1521 2, /* ¥ - 165 */
1522 2, /* ¦ - 166 */
1523 2, /* § - 167 */
1524 2, /* ¨ - 168 */
1525 2, /* © - 169 */
1526 3, /* ª - 170 */
1527 2, /* « - 171 */
1528 2, /* ¬ - 172 */
1529 2, /* ­ - 173 */
1530 2, /* ® - 174 */
1531 2, /* ¯ - 175 */
1532 2, /* ° - 176 */
1533 2, /* ± - 177 */
1534 2, /* ² - 178 */
1535 2, /* ³ - 179 */
1536 2, /* ´ - 180 */
1537 2, /* µ - 181 */
1538 2, /* ¶ - 182 */
1539 2, /* · - 183 */
1540 2, /* ¸ - 184 */
1541 2, /* ¹ - 185 */
1542 3, /* º - 186 */
1543 2, /* » - 187 */
1544 2, /* ¼ - 188 */
1545 2, /* ½ - 189 */
1546 2, /* ¾ - 190 */
1547 2, /* ¿ - 191 */
1548 15, /* À - 192 */
1549 14, /* Á - 193 */
1550 18, /* Â - 194 */
1551 25, /* Ã - 195 */
1552 19, /* Ä - 196 */
1553 26, /* Å - 197 */
1554 2, /* Æ - 198 */
1555 28, /* Ç - 199 */
1556 15, /* È - 200 */
1557 14, /* É - 201 */
1558 18, /* Ê - 202 */
1559 19, /* Ë - 203 */
1560 15, /* Ì - 204 */
1561 14, /* Í - 205 */
1562 18, /* Î - 206 */
1563 19, /* Ï - 207 */
1564 104, /* Ð - 208 */
1565 25, /* Ñ - 209 */
1566 15, /* Ò - 210 */
1567 14, /* Ó - 211 */
1568 18, /* Ô - 212 */
1569 25, /* Õ - 213 */
1570 19, /* Ö - 214 */
1571 2, /* × - 215 */
1572 33, /* Ø - 216 */
1573 15, /* Ù - 217 */
1574 14, /* Ú - 218 */
1575 18, /* Û - 219 */
1576 19, /* Ü - 220 */
1577 14, /* Ý - 221 */
1578 2, /* Þ - 222 */
1579 2, /* ß - 223 */
1580 15, /* à - 224 */
1581 14, /* á - 225 */
1582 18, /* â - 226 */
1583 25, /* ã - 227 */
1584 19, /* ä - 228 */
1585 26, /* å - 229 */
1586 2, /* æ - 230 */
1587 28, /* ç - 231 */
1588 15, /* è - 232 */
1589 14, /* é - 233 */
1590 18, /* ê - 234 */
1591 19, /* ë - 235 */
1592 15, /* ì - 236 */
1593 14, /* í - 237 */
1594 18, /* î - 238 */
1595 19, /* ï - 239 */
1596 104, /* ð - 240 */
1597 25, /* ñ - 241 */
1598 15, /* ò - 242 */
1599 14, /* ó - 243 */
1600 18, /* ô - 244 */
1601 25, /* õ - 245 */
1602 19, /* ö - 246 */
1603 2, /* ÷ - 247 */
1604 33, /* ø - 248 */
1605 15, /* ù - 249 */
1606 14, /* ú - 250 */
1607 18, /* û - 251 */
1608 19, /* ü - 252 */
1609 14, /* ý - 253 */
1610 2, /* þ - 254 */
1611 19, /* ÿ - 255 */
1614 static int is_punctuation(unsigned char c)
1616 /* "punctuation character" in this context is a character which is
1617 considered "less important" during word sort comparison.
1618 See LCMapString implementation for the precise definition
1619 of "less important". */
1621 return (LCM_Unicode_LUT[-2+2*c]==6);
1624 static int identity(int c)
1626 return c;
1629 /*************************************************************************
1630 * LCMapString32A [KERNEL32.492]
1632 * Convert a string, or generate a sort key from it.
1634 * If (mapflags & LCMAP_SORTKEY), the function will generate
1635 * a sort key for the source string. Else, it will convert it
1636 * accordingly to the flags LCMAP_UPPERCASE, LCMAP_LOWERCASE,...
1638 * RETURNS
1639 * Error : 0.
1640 * Success : length of the result string.
1642 * REMARKS
1643 * If called with scrlen = -1, the function will compute the length
1644 * of the 0-terminated string strsrc by itself.
1646 * If called with dstlen = 0, returns the buffer length that
1647 * would be required.
1649 INT32 WINAPI LCMapString32A(
1650 LCID lcid /* locale identifier created with MAKELCID;
1651 LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT are predefined
1652 values. */,
1653 DWORD mapflags /* flags */,
1654 LPCSTR srcstr /* source buffer */,
1655 INT32 srclen /* source length */,
1656 LPSTR dststr /* destination buffer */,
1657 INT32 dstlen /* destination buffer length */)
1659 int i;
1661 TRACE(string,"(0x%04lx,0x%08lx,%s,%d,%p,%d)\n",
1662 lcid,mapflags,srcstr,srclen,dststr,dstlen);
1664 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1666 SetLastError(ERROR_INVALID_PARAMETER);
1667 return 0;
1669 if (srclen==-1)
1670 srclen = lstrlen32A(srcstr) + 1 ; /* (include final '\0') */
1672 if (mapflags & ~ ( LCMAP_UPPERCASE | LCMAP_LOWERCASE | LCMAP_SORTKEY |
1673 NORM_IGNORECASE | NORM_IGNORENONSPACE | SORT_STRINGSORT) )
1675 FIXME(string,"(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1676 "unimplemented flags: 0x%08lx\n",
1677 lcid,mapflags,srcstr,srclen,dststr,dstlen,mapflags);
1680 if ( !(mapflags & LCMAP_SORTKEY) )
1682 int (*f)(int)=identity;
1684 if (dstlen==0)
1685 return srclen; /* dstlen=0 means "do nothing but return required length" */
1686 if (dstlen<srclen)
1687 srclen=dstlen; /* No, this case is not an error under Windows 95.
1688 And no '\0' gets written. */
1689 if (mapflags & LCMAP_UPPERCASE)
1690 f = toupper;
1691 else if (mapflags & LCMAP_LOWERCASE)
1692 f = tolower;
1693 for (i=0; i < srclen; i++)
1694 dststr[i] = (CHAR) f(srcstr[i]);
1695 return srclen;
1698 /* else ... (mapflags & LCMAP_SORTKEY) */
1700 int unicode_len=0;
1701 int case_len=0;
1702 int diacritic_len=0;
1703 int delayed_punctuation_len=0;
1704 char *case_component;
1705 char *diacritic_component;
1706 char *delayed_punctuation_component;
1707 int room,count;
1708 int flag_stringsort = mapflags & SORT_STRINGSORT;
1710 /* compute how much room we will need */
1711 for (i=0;i<srclen;i++)
1713 int ofs;
1714 unsigned char source_char = srcstr[i];
1715 if (source_char!='\0')
1717 if (flag_stringsort || !is_punctuation(source_char))
1719 unicode_len++;
1720 if ( LCM_Unicode_LUT[-2+2*source_char] & ~15 )
1721 unicode_len++; /* double letter */
1723 else
1725 delayed_punctuation_len++;
1729 if (isupper(source_char))
1730 case_len=unicode_len;
1732 ofs = source_char - LCM_Diacritic_Start;
1733 if ((ofs>=0) && (LCM_Diacritic_LUT[ofs]!=2))
1734 diacritic_len=unicode_len;
1737 if (mapflags & NORM_IGNORECASE)
1738 case_len=0;
1739 if (mapflags & NORM_IGNORENONSPACE)
1740 diacritic_len=0;
1742 room = 2 * unicode_len /* "unicode" component */
1743 + diacritic_len /* "diacritic" component */
1744 + case_len /* "case" component */
1745 + 4 * delayed_punctuation_len /* punctuation in word sort mode */
1746 + 4 /* four '\1' separators */
1747 + 1 ; /* terminal '\0' */
1748 if (dstlen==0)
1749 return room;
1750 else if (dstlen<room)
1752 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1753 return 0;
1756 /*FIXME the Pointercheck should not be nessesary */
1757 if (IsBadWritePtr32 (dststr,room))
1758 { ERR (string,"bad destination buffer (dststr) : %p,%d\n",dststr,dstlen);
1759 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1760 return 0;
1763 /* locate each component, write separators */
1764 diacritic_component = dststr + 2*unicode_len ;
1765 *diacritic_component++ = '\1';
1766 case_component = diacritic_component + diacritic_len ;
1767 *case_component++ = '\1';
1768 delayed_punctuation_component = case_component + case_len ;
1769 *delayed_punctuation_component++ = '\1';
1770 *delayed_punctuation_component++ = '\1';
1772 /* read source string char by char, write
1773 corresponding weight in each component. */
1774 for (i=0,count=0;i<srclen;i++)
1776 unsigned char source_char=srcstr[i];
1777 if (source_char!='\0')
1779 int type,longcode;
1780 type = LCM_Unicode_LUT[-2+2*source_char];
1781 longcode = type >> 4;
1782 type &= 15;
1783 if (!flag_stringsort && is_punctuation(source_char))
1785 UINT16 encrypted_location = (1<<15) + 7 + 4*count;
1786 *delayed_punctuation_component++ = (unsigned char) (encrypted_location>>8);
1787 *delayed_punctuation_component++ = (unsigned char) (encrypted_location&255);
1788 /* big-endian is used here because it lets string comparison be
1789 compatible with numerical comparison */
1791 *delayed_punctuation_component++ = type;
1792 *delayed_punctuation_component++ = LCM_Unicode_LUT[-1+2*source_char];
1793 /* assumption : a punctuation character is never a
1794 double or accented letter */
1796 else
1798 dststr[2*count] = type;
1799 dststr[2*count+1] = LCM_Unicode_LUT[-1+2*source_char];
1800 if (longcode)
1802 if (count<case_len)
1803 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1804 if (count<diacritic_len)
1805 diacritic_component[count] = 2; /* assumption: a double letter
1806 is never accented */
1807 count++;
1809 dststr[2*count] = type;
1810 dststr[2*count+1] = *(LCM_Unicode_LUT_2 - 1 + longcode);
1811 /* 16 in the first column of LCM_Unicode_LUT --> longcode = 1
1812 32 in the first column of LCM_Unicode_LUT --> longcode = 2
1813 48 in the first column of LCM_Unicode_LUT --> longcode = 3 */
1816 if (count<case_len)
1817 case_component[count] = ( isupper(source_char) ? 18 : 2 ) ;
1818 if (count<diacritic_len)
1820 int ofs = source_char - LCM_Diacritic_Start;
1821 diacritic_component[count] = (ofs>=0 ? LCM_Diacritic_LUT[ofs] : 2);
1823 count++;
1827 dststr[room-1] = '\0';
1828 return room;
1832 INT32 WINAPI LCMapString32W(
1833 LCID lcid,DWORD mapflags,LPCWSTR srcstr,INT32 srclen,LPWSTR dststr,
1834 INT32 dstlen)
1836 int i;
1838 TRACE(string,"(0x%04lx,0x%08lx,%p,%d,%p,%d)\n",
1839 lcid,mapflags,srcstr,srclen,dststr,dstlen);
1841 if ( ((dstlen!=0) && (dststr==NULL)) || (srcstr==NULL) )
1843 SetLastError(ERROR_INVALID_PARAMETER);
1844 return 0;
1846 if (srclen==-1)
1847 srclen = lstrlen32W(srcstr)+1;
1848 if (mapflags & LCMAP_SORTKEY)
1850 FIXME(string,"(0x%04lx,0x%08lx,%p,%d,%p,%d): "
1851 "unimplemented flags: 0x%08lx\n",
1852 lcid,mapflags,srcstr,srclen,dststr,dstlen,mapflags);
1853 return 0;
1855 else
1857 int (*f)(int)=identity;
1859 if (dstlen==0)
1860 return srclen;
1861 if (dstlen<srclen)
1862 return 0;
1863 if (mapflags & LCMAP_UPPERCASE)
1864 f = toupper;
1865 else if (mapflags & LCMAP_LOWERCASE)
1866 f = tolower;
1867 for (i=0; i < srclen; i++)
1868 dststr[i] = (WCHAR) f(srcstr[i]);
1869 return srclen;
1873 /***********************************************************************
1874 * CompareString16 (OLE2NLS.8)
1876 UINT16 WINAPI CompareString16(DWORD lcid,DWORD fdwStyle,
1877 LPCSTR s1,DWORD l1,LPCSTR s2,DWORD l2)
1879 return (UINT16)CompareString32A(lcid,fdwStyle,s1,l1,s2,l2);
1882 /***********************************************************************
1883 * CompareString32A (KERNEL32.29)
1884 * This implementation ignores the locale
1885 * FIXME
1886 * Moreover it is quite inefficient. FIXME too!
1888 UINT32 WINAPI CompareString32A(DWORD lcid, DWORD fdwStyle,
1889 LPCSTR s1, DWORD l1, LPCSTR s2,DWORD l2)
1891 int mapstring_flags;
1892 int len1,len2;
1893 int result;
1894 LPSTR sk1,sk2;
1895 TRACE(ole,"%s and %s\n",
1896 debugstr_a (s1), debugstr_a (s2));
1898 if ( (s1==NULL) || (s2==NULL) )
1900 SetLastError(ERROR_INVALID_PARAMETER);
1901 return 0;
1904 if(fdwStyle & NORM_IGNORESYMBOLS)
1905 FIXME(ole, "IGNORESYMBOLS not supported\n");
1907 mapstring_flags = LCMAP_SORTKEY | fdwStyle ;
1908 len1 = LCMapString32A(lcid,mapstring_flags,s1,l1,NULL,0);
1909 len2 = LCMapString32A(lcid,mapstring_flags,s2,l2,NULL,0);
1911 if ((len1==0)||(len2==0))
1912 return 0; /* something wrong happened */
1914 sk1 = (LPSTR)HeapAlloc(GetProcessHeap(),0,len1);
1915 sk2 = (LPSTR)HeapAlloc(GetProcessHeap(),0,len2);
1916 if ( (!LCMapString32A(lcid,mapstring_flags,s1,l1,sk1,len1))
1917 || (!LCMapString32A(lcid,mapstring_flags,s2,l2,sk2,len2)) )
1918 { ERR(ole,"Bug in LCmapString32A.\n");
1919 result = 0;
1921 else
1922 { result = strcmp(sk1,sk2)+2;
1924 HeapFree(GetProcessHeap(),0,sk1);
1925 HeapFree(GetProcessHeap(),0,sk2);
1926 return result;
1929 /***********************************************************************
1930 * CompareString32W (KERNEL32.30)
1931 * This implementation ignores the locale
1932 * FIXME : Does only string sort. Should
1933 * be reimplemented the same way as CompareString32A.
1935 UINT32 WINAPI CompareString32W(DWORD lcid, DWORD fdwStyle,
1936 LPCWSTR s1, DWORD l1, LPCWSTR s2,DWORD l2)
1938 int len,ret;
1939 if(fdwStyle & NORM_IGNORENONSPACE)
1940 FIXME(ole,"IGNORENONSPACE not supprted\n");
1941 if(fdwStyle & NORM_IGNORESYMBOLS)
1942 FIXME(ole,"IGNORESYMBOLS not supported\n");
1944 /* Is strcmp defaulting to string sort or to word sort?? */
1945 /* FIXME: Handle NORM_STRINGSORT */
1946 l1 = (l1==-1)?lstrlen32W(s1):l1;
1947 l2 = (l2==-1)?lstrlen32W(s2):l2;
1948 len = l1<l2 ? l1:l2;
1949 ret = (fdwStyle & NORM_IGNORECASE) ?
1950 lstrncmpi32W(s1,s2,len) : lstrncmp32W(s1,s2,len);
1951 /* not equal, return 1 or 3 */
1952 if(ret!=0) return ret+2;
1953 /* same len, return 2 */
1954 if(l1==l2) return 2;
1955 /* the longer one is lexically greater */
1956 return (l1<l2)? 1 : 3;
1959 /*****************************************************************
1961 * OLE_GetFormatA() [internal]
1964 This function implements stuff for GetDateFormat() and
1965 GetTimeFormat().
1967 d single-digit (no leading zero) day (of month)
1968 dd two-digit day (of month)
1969 ddd short day-of-week name
1970 dddd long day-of-week name
1971 M single-digit month
1972 MM two-digit month
1973 MMM short month name
1974 MMMM full month name
1975 y two-digit year, no leading 0
1976 yy two-digit year
1977 yyyy four-digit year
1978 gg era string
1979 h hours with no leading zero (12-hour)
1980 hh hours with full two digits
1981 H hours with no leading zero (24-hour)
1982 HH hours with full two digits
1983 m minutes with no leading zero
1984 mm minutes with full two digits
1985 s seconds with no leading zero
1986 ss seconds with full two digits
1987 t time marker (A or P)
1988 tt time marker (AM, PM)
1989 '' used to quote literal characters
1990 '' (within a quoted string) indicates a literal '
1992 These functions REQUIRE valid locale, date, and format.
1996 INT32 WINAPI OLE_GetFormatA(LCID locale,
1997 DWORD flags,
1998 LPSYSTEMTIME xtime,
1999 LPCSTR format,
2000 LPSTR date, INT32 datelen)
2002 INT32 inpos, outpos;
2003 int count, type, inquote, Overflow;
2004 char buf[40];
2005 int buflen;
2007 const char * _dgfmt[] = { "%d", "%02d" };
2008 const char ** dgfmt = _dgfmt - 1;
2010 /* report, for debugging */
2011 TRACE(ole, "func(%8lx,%8lx, time(d=%d,h=%d,m=%d,s=%d), fmt:\'%s\' (at %p), %p (%9s), len=%d)\n", locale, flags,
2012 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2013 format, format, date, date, datelen);
2015 /* initalize state variables and output buffer */
2016 inpos = outpos = 0;
2017 count = 0; inquote = 0; Overflow = 0;
2018 type = '\0';
2019 date[0] = buf[0] = '\0';
2021 for (inpos = 0;; inpos++) {
2022 /* TRACE(ole, "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]); */
2023 if (inquote) {
2024 if (format[inpos] == '\'') {
2025 if (format[inpos+1] == '\'') {
2026 inpos += 1;
2027 date[outpos++] = '\'';
2028 } else {
2029 inquote = 0;
2030 continue; /* we did nothing to the output */
2032 } else if (format[inpos] == '\0') {
2033 date[outpos++] = '\0';
2034 if (outpos > datelen) Overflow = 1;
2035 break;
2036 } else {
2037 date[outpos++] = format[inpos];
2038 if (outpos > datelen) {
2039 Overflow = 1;
2040 date[outpos-1] = '\0'; /* this is the last place where
2041 it's safe to write */
2042 break;
2045 } else if ( (count && (format[inpos] != type))
2046 || count == 4
2047 || (count == 2 && strchr("ghHmst", type)) )
2049 if (type == 'd') {
2050 if (count == 4) {
2051 GetLocaleInfo32A(locale,
2052 LOCALE_SDAYNAME1
2053 + xtime->wDayOfWeek - 1,
2054 buf, sizeof(buf));
2055 } else if (count == 3) {
2056 GetLocaleInfo32A(locale,
2057 LOCALE_SABBREVDAYNAME1
2058 + xtime->wDayOfWeek - 1,
2059 buf, sizeof(buf));
2060 } else {
2061 sprintf(buf, dgfmt[count], xtime->wDay);
2063 } else if (type == 'M') {
2064 if (count == 3) {
2065 GetLocaleInfo32A(locale,
2066 LOCALE_SABBREVMONTHNAME1
2067 + xtime->wMonth - 1,
2068 buf, sizeof(buf));
2069 } else if (count == 4) {
2070 GetLocaleInfo32A(locale,
2071 LOCALE_SMONTHNAME1
2072 + xtime->wMonth - 1,
2073 buf, sizeof(buf));
2074 } else {
2075 sprintf(buf, dgfmt[count], xtime->wMonth);
2077 } else if (type == 'y') {
2078 if (count == 4) {
2079 sprintf(buf, "%d", xtime->wYear);
2080 } else if (count == 3) {
2081 strcpy(buf, "yyy");
2082 WARN(ole,
2083 "unknown format,\
2084 c=%c, n=%d\n", type, count);
2085 } else {
2086 sprintf(buf, dgfmt[count], xtime->wYear % 100);
2088 } else if (type == 'g') {
2089 if (count == 2) {
2090 FIXME(ole, "LOCALE_ICALENDARTYPE unimp.\n");
2091 strcpy(buf, "AD");
2092 } else {
2093 strcpy(buf, "g");
2094 WARN(ole,
2095 "unknown format, \
2096 c=%c, n=%d\n", type, count);
2098 } else if (type == 'h') {
2099 /* gives us hours 1:00 -- 12:00 */
2100 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
2101 } else if (type == 'H') {
2102 /* 24-hour time */
2103 sprintf(buf, dgfmt[count], xtime->wHour);
2104 } else if (type == 'm') {
2105 sprintf(buf, dgfmt[count], xtime->wMinute);
2106 } else if (type == 's') {
2107 sprintf(buf, dgfmt[count], xtime->wSecond);
2108 } else if (type == 't') {
2109 if (count == 1) {
2110 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
2111 } else if (count == 2) {
2112 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
2113 GetLocaleInfo32A(locale,
2114 (xtime->wHour<12)
2115 ? LOCALE_S1159 : LOCALE_S2359,
2116 buf, sizeof(buf));
2120 /* we need to check the next char in the format string
2121 again, no matter what happened */
2122 inpos--;
2124 /* add the contents of buf to the output */
2125 buflen = strlen(buf);
2126 if (outpos + buflen < datelen) {
2127 date[outpos] = '\0'; /* for strcat to hook onto */
2128 strcat(date, buf);
2129 outpos += buflen;
2130 } else {
2131 date[outpos] = '\0';
2132 strncat(date, buf, datelen - outpos);
2133 date[datelen - 1] = '\0';
2134 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2135 WARN(ole, "insufficient buffer\n");
2136 return 0;
2139 /* reset the variables we used to keep track of this item */
2140 count = 0;
2141 type = '\0';
2142 } else if (format[inpos] == '\0') {
2143 /* we can't check for this at the loop-head, because
2144 that breaks the printing of the last format-item */
2145 date[outpos] = '\0';
2146 break;
2147 } else if (count) {
2148 /* continuing a code for an item */
2149 count +=1;
2150 continue;
2151 } else if (strchr("hHmstyMdg", format[inpos])) {
2152 type = format[inpos];
2153 count = 1;
2154 continue;
2155 } else if (format[inpos] == '\'') {
2156 inquote = 1;
2157 continue;
2158 } else {
2159 date[outpos++] = format[inpos];
2161 /* now deal with a possible buffer overflow */
2162 if (outpos >= datelen) {
2163 date[datelen - 1] = '\0';
2164 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2165 return 0;
2169 if (Overflow) {
2170 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2173 /* finish it off with a string terminator */
2174 outpos++;
2175 /* sanity check */
2176 if (outpos > datelen-1) outpos = datelen-1;
2177 date[outpos] = '\0';
2179 TRACE(ole, "OLE_GetFormatA returns string '%s', len %d\n",
2180 date, outpos);
2181 return outpos;
2184 /**************************************************************
2185 * OLE_GetFormatW [internal]
2187 INT32 WINAPI OLE_GetFormatW(LCID locale, DWORD flags,
2188 LPSYSTEMTIME xtime,
2189 LPCWSTR format,
2190 LPWSTR output, INT32 outlen)
2192 INT32 inpos, outpos;
2193 int count, type=0, inquote;
2194 int Overflow; /* loop check */
2195 int usedate, usetime;
2196 WCHAR buf[40];
2197 int buflen=0;
2198 char abuf[40];
2199 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
2200 WCHAR arg2[] = {'%','0','2','d',0};
2201 WCHAR *argarr[] = {arg0, arg1, arg2};
2202 int datevars=0, timevars=0;
2204 /* make a debug report */
2205 lstrcpynWtoA(abuf, format, sizeof(format));
2206 TRACE(ole, "args: %8lx, %8lx, time(d=%d,h=%d,m=%d,s=%d), fmt:\'%s\' (at %p), %p with max len %d\n",
2207 locale, flags,
2208 xtime->wDay, xtime->wHour, xtime->wMinute, xtime->wSecond,
2209 abuf, format, output, outlen);
2212 /* initialize state variables */
2213 inpos = outpos = 0;
2214 count = 0;
2215 inquote = Overflow = 0;
2216 /* this is really just a sanity check */
2217 output[0] = buf[0] = 0;
2218 abuf[0] = '\0';
2219 /* for compatibility with official Windows behavior */
2220 usedate = flags & DATE_DATEVARSONLY;
2221 usetime = flags & TIME_TIMEVARSONLY;
2223 /* this loop is the core of the function */
2224 for (inpos = 0; /* we have several break points */ ; inpos++) {
2225 if (inquote) {
2226 if (format[inpos] == (WCHAR) '\'') {
2227 if (format[inpos+1] == '\'') {
2228 inpos++;
2229 output[outpos++] = '\'';
2230 } else {
2231 inquote = 0;
2232 continue;
2234 } else if (format[inpos] == 0) {
2235 output[outpos++] = 0;
2236 if (outpos > outlen) Overflow = 1;
2237 break; /* normal exit (within a quote) */
2238 } else {
2239 output[outpos++] = format[inpos]; /* copy input */
2240 if (outpos > outlen) {
2241 Overflow = 1;
2242 output[outpos-1] = 0;
2243 break;
2246 } else if ( (count && (format[inpos] != type))
2247 || ( (count==4 && type =='y') ||
2248 (count==4 && type =='M') ||
2249 (count==4 && type =='d') ||
2250 (count==2 && type =='g') ||
2251 (count==2 && type =='h') ||
2252 (count==2 && type =='H') ||
2253 (count==2 && type =='m') ||
2254 (count==2 && type =='s') ||
2255 (count==2 && type =='t') ) ) {
2256 if (type == 'd') {
2257 if (count == 3) {
2258 GetLocaleInfo32W(locale,
2259 LOCALE_SDAYNAME1 + xtime->wDayOfWeek -1,
2260 buf, sizeof(buf)/sizeof(WCHAR) );
2261 } else if (count == 3) {
2262 GetLocaleInfo32W(locale,
2263 LOCALE_SABBREVDAYNAME1 +
2264 xtime->wDayOfWeek -1,
2265 buf, sizeof(buf)/sizeof(WCHAR) );
2266 } else {
2267 wsnprintf32W(buf, 5, argarr[count], xtime->wDay );
2269 } else if (type == 'M') {
2270 if (count == 4) {
2271 GetLocaleInfo32W(locale, LOCALE_SMONTHNAME1 +
2272 xtime->wMonth -1, buf,
2273 sizeof(buf)/sizeof(WCHAR) );
2274 } else if (count == 3) {
2275 GetLocaleInfo32W(locale, LOCALE_SABBREVMONTHNAME1 +
2276 xtime->wMonth -1, buf,
2277 sizeof(buf)/sizeof(WCHAR) );
2278 } else {
2279 wsnprintf32W(buf, 5, argarr[count], xtime->wMonth);
2281 } else if (type == 'y') {
2282 if (count == 4) {
2283 wsnprintf32W(buf, 6, argarr[1] /* "%d" */,
2284 xtime->wYear);
2285 } else if (count == 3) {
2286 lstrcpynAtoW(buf, "yyy", 5);
2287 } else {
2288 wsnprintf32W(buf, 6, argarr[count],
2289 xtime->wYear % 100);
2291 } else if (type == 'g') {
2292 if (count == 2) {
2293 FIXME(ole, "LOCALE_ICALENDARTYPE unimplemented\n");
2294 lstrcpynAtoW(buf, "AD", 5);
2295 } else {
2296 /* Win API sez we copy it verbatim */
2297 lstrcpynAtoW(buf, "g", 5);
2299 } else if (type == 'h') {
2300 /* hours 1:00-12:00 --- is this right? */
2301 wsnprintf32W(buf, 5, argarr[count],
2302 (xtime->wHour-1)%12 +1);
2303 } else if (type == 'H') {
2304 wsnprintf32W(buf, 5, argarr[count],
2305 xtime->wHour);
2306 } else if (type == 'm') {
2307 wsnprintf32W(buf, 5, argarr[count],
2308 xtime->wMinute);
2309 } else if (type == 's') {
2310 wsnprintf32W(buf, 5, argarr[count],
2311 xtime->wSecond);
2312 } else if (type == 't') {
2313 GetLocaleInfo32W(locale, (xtime->wHour < 12) ?
2314 LOCALE_S1159 : LOCALE_S2359,
2315 buf, sizeof(buf) );
2316 if (count == 1) {
2317 buf[1] = 0;
2321 /* no matter what happened, we need to check this next
2322 character the next time we loop through */
2323 inpos--;
2325 /* cat buf onto the output */
2326 outlen = lstrlen32W(buf);
2327 if (outpos + buflen < outlen) {
2328 output[outpos] = 0; /* a "hook" for strcat */
2329 lstrcat32W(output, buf);
2330 outpos += buflen;
2331 } else {
2332 output[outpos] = 0;
2333 lstrcatn32W(output, buf, outlen - outpos);
2334 output[outlen - 1] = 0;
2335 Overflow = 1;
2336 break; /* Abnormal exit */
2339 /* reset the variables we used this time */
2340 count = 0;
2341 type = '\0';
2342 } else if (format[inpos] == 0) {
2343 /* we can't check for this at the beginning, because that
2344 would keep us from printing a format spec that ended the
2345 string */
2346 output[outpos] = 0;
2347 break; /* NORMAL EXIT */
2348 } else if (count) {
2349 /* how we keep track of the middle of a format spec */
2350 count++;
2351 continue;
2352 } else if ( (datevars && (format[inpos]=='d' ||
2353 format[inpos]=='M' ||
2354 format[inpos]=='y' ||
2355 format[inpos]=='g') ) ||
2356 (timevars && (format[inpos]=='H' ||
2357 format[inpos]=='h' ||
2358 format[inpos]=='m' ||
2359 format[inpos]=='s' ||
2360 format[inpos]=='t') ) ) {
2361 type = format[inpos];
2362 count = 1;
2363 continue;
2364 } else if (format[inpos] == '\'') {
2365 inquote = 1;
2366 continue;
2367 } else {
2368 /* unquoted literals */
2369 output[outpos++] = format[inpos];
2373 if (Overflow) {
2374 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2375 WARN(ole, " buffer overflow\n");
2378 /* final string terminator and sanity check */
2379 outpos++;
2380 if (outpos > outlen-1) outpos = outlen-1;
2381 output[outpos] = '0';
2383 lstrcpynWtoA(abuf, output, sizeof(abuf) );
2384 TRACE(ole, " returning string \'%s\'\n", abuf);
2386 return (!Overflow) ? outlen : 0;
2391 /*****************************************************************
2392 * GetDateFormat32A() [KERNEL32.310] Makes an ASCII string of the date
2394 * This function uses format to format the date, or, if format
2395 * is NULL, uses the default for the locale. format is a string
2396 * of literal fields and characters as follows:
2398 * - d single-digit (no leading zero) day (of month)
2399 * - dd two-digit day (of month)
2400 * - ddd short day-of-week name
2401 * - dddd long day-of-week name
2402 * - M single-digit month
2403 * - MM two-digit month
2404 * - MMM short month name
2405 * - MMMM full month name
2406 * - y two-digit year, no leading 0
2407 * - yy two-digit year
2408 * - yyyy four-digit year
2409 * - gg era string
2413 INT32 WINAPI GetDateFormat32A(LCID locale,DWORD flags,
2414 LPSYSTEMTIME xtime,
2415 LPCSTR format, LPSTR date,INT32 datelen)
2418 char format_buf[40];
2419 LPCSTR thisformat;
2420 SYSTEMTIME t;
2421 LPSYSTEMTIME thistime;
2422 LCID thislocale;
2424 INT32 ret;
2426 TRACE(ole,"(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",
2427 locale,flags,xtime,format,date,datelen);
2429 if (!locale) {
2430 locale = LOCALE_SYSTEM_DEFAULT;
2433 if (locale == LOCALE_SYSTEM_DEFAULT) {
2434 thislocale = GetSystemDefaultLCID();
2435 } else if (locale == LOCALE_USER_DEFAULT) {
2436 thislocale = GetUserDefaultLCID();
2437 } else {
2438 thislocale = locale;
2441 if (xtime == NULL) {
2442 GetSystemTime(&t);
2443 thistime = &t;
2444 } else {
2445 thistime = xtime;
2448 if (format == NULL) {
2449 GetLocaleInfo32A(thislocale, ((flags&DATE_LONGDATE)
2450 ? LOCALE_SLONGDATE
2451 : LOCALE_SSHORTDATE),
2452 format_buf, sizeof(format_buf));
2453 thisformat = format_buf;
2454 } else {
2455 thisformat = format;
2459 ret = OLE_GetFormatA(thislocale, flags, thistime, thisformat,
2460 date, datelen);
2463 TRACE(ole,
2464 "GetDateFormat32A() returning %d, with data=%s\n",
2465 ret, date);
2466 return ret;
2469 /* ****************************************************************
2470 * GetDateFormat32W() [KERNEL32.311] Makes a Unicode string of the date
2472 * Acts the same as GetDateFormat32A(), except that it's Unicode.
2473 * Accepts & returns sizes as counts of Unicode characters.
2476 INT32 WINAPI GetDateFormat32W(LCID locale,DWORD flags,
2477 LPSYSTEMTIME xtime,
2478 LPCWSTR format,
2479 LPWSTR date, INT32 datelen)
2481 short datearr[] = {'1','9','9','4','-','1','-','1',0};
2483 FIXME(ole, "STUB (should call OLE_GetFormatW)\n");
2484 lstrcpyn32W(date, datearr, datelen);
2485 return ( datelen < 9) ? datelen : 9;
2491 /**************************************************************************
2492 * GetNumberFormat32A (KERNEL32.355)
2493 * NOTE: type of lpFormat should be CONST NUMBERFORMAT
2495 INT32 WINAPI GetNumberFormat32A(LCID locale, DWORD dwflags,
2496 LPCSTR lpvalue, char *lpFormat,
2497 LPSTR lpNumberStr, int cchNumber)
2499 int n;
2501 FIXME(file,"%s: stub, no reformating done\n",lpvalue);
2503 n = strlen(lpvalue);
2504 if (cchNumber) {
2505 strncpy(lpNumberStr,lpvalue,cchNumber);
2506 if (cchNumber <= n) {
2507 lpNumberStr[cchNumber-1] = 0;
2508 n = cchNumber-1;
2511 return n;
2516 /*****************************************************************
2518 * GetTimeFormat32A() [KERNEL32.422] Makes an ASCII string of the time
2520 * Formats date according to format, or locale default if format is
2521 * NULL. The format consists of literal characters and fields as follows:
2523 * h hours with no leading zero (12-hour)
2524 * hh hours with full two digits
2525 * H hours with no leading zero (24-hour)
2526 * HH hours with full two digits
2527 * m minutes with no leading zero
2528 * mm minutes with full two digits
2529 * s seconds with no leading zero
2530 * ss seconds with full two digits
2531 * t time marker (A or P)
2532 * tt time marker (AM, PM)
2536 INT32 WINAPI
2537 GetTimeFormat32A(LCID locale, /* in */
2538 DWORD flags, /* in */
2539 LPSYSTEMTIME xtime, /* in */
2540 LPCSTR format, /* in */
2541 LPSTR timestr, /* out */
2542 INT32 timelen /* in */)
2543 { char format_buf[40];
2544 LPCSTR thisformat;
2545 SYSTEMTIME t;
2546 LPSYSTEMTIME thistime;
2547 LCID thislocale=0;
2548 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */;
2550 TRACE(ole,"GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
2551 if (!locale)
2552 { locale = LOCALE_SYSTEM_DEFAULT;
2555 if (locale == LOCALE_SYSTEM_DEFAULT)
2556 { thislocale = GetSystemDefaultLCID();
2558 else if (locale == LOCALE_USER_DEFAULT)
2559 { thislocale = GetUserDefaultLCID();
2561 else
2562 { thislocale = locale;
2564 if (format == NULL)
2565 { if (flags&LOCALE_NOUSEROVERRIDE) /*use system default*/
2566 { thislocale = GetSystemDefaultLCID();
2568 switch (flags)
2569 { case TIME_NOSECONDS:
2570 FIXME(ole,"TIME_NOSECONDS not yet implemented");
2571 break;
2572 case TIME_NOMINUTESORSECONDS:
2573 FIXME(ole,"TIME_NOMINUTESORSECONDS not yet implemented");
2574 break;
2576 GetLocaleInfo32A(thislocale, thisflags, format_buf,sizeof(format_buf));
2577 thisformat = format_buf;
2579 else
2580 { thisformat = format;
2583 if (!locale)
2584 { locale = GetSystemDefaultLCID();
2586 if (xtime == NULL) /* NULL means use the current local time*/
2587 { GetSystemTime(&t);
2588 thistime = &t;
2590 else
2591 { thistime = xtime;
2593 return OLE_GetFormatA(thislocale, thisflags, thistime, thisformat,timestr, timelen);
2597 /* ****************************************************************
2598 * GetTimeFormat32W() [KERNEL32.423] Makes a Unicode string of the time
2603 INT32 WINAPI
2604 GetTimeFormat32W(LCID locale,DWORD flags,
2605 LPSYSTEMTIME xtime,
2606 LPCWSTR format,
2607 LPWSTR timestr,INT32 timelen)
2609 char debugbuf[40];
2610 WCHAR buf[20];
2611 LPCWSTR realformat=0;
2612 SYSTEMTIME t;
2613 LPSYSTEMTIME realtime;
2614 WCHAR * fmt_buf = NULL;
2615 int fmt_buf_size = 0; /* units of WCHARs */
2616 INT32 retval;
2618 lstrcpynWtoA(debugbuf, format, (sizeof(buf))/2);
2619 TRACE(ole, "GetTimeFormatW len %d flags 0x%lX format >%s<\n",
2620 timelen, flags, debugbuf);
2622 /* Enforce the Windows behavior */
2623 flags |= ~LOCALE_TIMEDATEBOTH;
2624 flags |= TIME_TIMEVARSONLY;
2626 /* take care of the format or locale not being given */
2627 if (format) {
2628 realformat = format;
2629 } else if (locale) {
2630 /* allocate memory */
2631 retval = ERROR_INSUFFICIENT_BUFFER;
2632 fmt_buf = malloc((fmt_buf_size+=7) * sizeof(WCHAR));
2633 if (!fmt_buf)
2634 goto out_nomem;
2636 while(!GetLocaleInfo32W(locale, LOCALE_STIMEFORMAT,
2637 fmt_buf, fmt_buf_size)) {
2638 retval = ERROR_OUTOFMEMORY;
2639 fmt_buf = realloc(fmt_buf,
2640 (fmt_buf_size += 10) * sizeof(WCHAR));
2641 if (!fmt_buf)
2642 goto out_nomem;
2644 realformat = fmt_buf;
2645 } else {
2646 FIXME(ole, "caller gave no locale, no format; what should we do?\n");
2647 SetLastError(ERROR_BAD_FORMAT);
2649 if (!locale)
2650 locale = GetSystemDefaultLCID();
2652 realtime = xtime;
2653 if (!realtime) {
2654 realtime = &t;
2655 GetSystemTime(realtime);
2658 retval = OLE_GetFormatW(locale, flags, realtime, realformat, timestr, timelen);
2659 if (fmt_buf)
2660 free(fmt_buf);
2661 return retval;
2663 out_nomem:
2664 SetLastError(retval);
2665 WARN(ole, "could not allocate %d chars of memory\n", fmt_buf_size);
2666 return 0;