2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
14 /******************************************************************************
15 * GetACP [KERNEL32.276] Gets current ANSI code-page identifier.
18 * Current ANSI code-page identifier, default if no current defined
20 UINT WINAPI
GetACP(void)
22 /* This introduces too many messages */
23 /* FIXME(win32, "(void): stub\n"); */
24 return 1252; /* Windows 3.1 ISO Latin */
28 /***********************************************************************
29 * GetCPInfo (KERNEL32.154)
31 BOOL WINAPI
GetCPInfo( UINT codepage
, LPCPINFO cpinfo
)
33 cpinfo
->DefaultChar
[0] = '?';
36 case 932 : /* Shift JIS (japan) */
37 cpinfo
->MaxCharSize
= 2;
38 cpinfo
->LeadByte
[0]= 0x81; cpinfo
->LeadByte
[1] = 0x9F;
39 cpinfo
->LeadByte
[2]= 0xE0; cpinfo
->LeadByte
[3] = 0xFC;
40 cpinfo
->LeadByte
[4]= 0x00; cpinfo
->LeadByte
[5] = 0x00;
42 case 936 : /* GB2312 (Chinese) */
43 case 949 : /* KSC5601-1987 (Korean) */
44 case 950 : /* BIG5 (Chinese) */
45 cpinfo
->MaxCharSize
= 2;
46 cpinfo
->LeadByte
[0]= 0x81; cpinfo
->LeadByte
[1] = 0xFE;
47 cpinfo
->LeadByte
[2]= 0x00; cpinfo
->LeadByte
[3] = 0x00;
49 case 1361 : /* Johab (Korean) */
50 cpinfo
->MaxCharSize
= 2;
51 cpinfo
->LeadByte
[0]= 0x84; cpinfo
->LeadByte
[1] = 0xD3;
52 cpinfo
->LeadByte
[2]= 0xD8; cpinfo
->LeadByte
[3] = 0xDE;
53 cpinfo
->LeadByte
[4]= 0xE0; cpinfo
->LeadByte
[5] = 0xF9;
54 cpinfo
->LeadByte
[6]= 0x00; cpinfo
->LeadByte
[7] = 0x00;
57 cpinfo
->MaxCharSize
= 1;
58 cpinfo
->LeadByte
[0]= 0x00; cpinfo
->LeadByte
[1] = 0x00;
64 /***********************************************************************
65 * GetOEMCP (KERNEL32.248)
67 UINT WINAPI
GetOEMCP(void)
69 return 437; /* MS-DOS United States */
72 /***********************************************************************
73 * IsValidCodePage (KERNEL32.360)
75 BOOL WINAPI
IsValidCodePage(UINT CodePage
)
88 /***********************************************************************
89 * MultiByteToWideChar (KERNEL32.534)
92 * page [in] Codepage character set to convert from
93 * flags [in] Character mapping flags
94 * src [in] Source string buffer
95 * srclen [in] Length of source string buffer
96 * dst [in] Destination buffer
97 * dstlen [in] Length of destination buffer
100 * The returned length includes the null terminator character.
103 * Success: If dstlen > 0, number of characters written to destination
104 * buffer. If dstlen == 0, number of characters needed to do
106 * Failure: 0. Occurs if not enough space is available.
109 * ERROR_INSUFFICIENT_BUFFER
110 * ERROR_INVALID_FLAGS (not yet implemented)
111 * ERROR_INVALID_PARAMETER (not yet implemented)
114 * Does not properly handle codepage conversions.
115 * Does not properly handle flags.
118 INT WINAPI
MultiByteToWideChar(UINT page
, DWORD flags
,
119 LPCSTR src
, INT srclen
,
120 LPWSTR dst
, INT dstlen
)
125 srclen
= lstrlenA(src
)+1;
130 while (srclen
&& dstlen
) {
131 *dst
= (WCHAR
)(unsigned char)*src
;
135 if (!dstlen
&& srclen
) {
136 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
142 /***********************************************************************
143 * WideCharToMultiByte (KERNEL32.727)
146 * page [in] Codepage character set to convert to
147 * flags [in] Character mapping flags
148 * src [in] Source string buffer
149 * srclen [in] Length of source string buffer
150 * dst [in] Destination buffer
151 * dstlen [in] Length of destination buffer
152 * defchar [in] Default character to use for conversion if no exact
153 * conversion can be made
154 * used [out] Set if default character was used in the conversion
157 * The returned length includes the null terminator character.
160 * Success: If dstlen > 0, number of characters written to destination
161 * buffer. If dstlen == 0, number of characters needed to do
163 * Failure: 0. Occurs if not enough space is available.
166 * ERROR_INSUFFICIENT_BUFFER
167 * ERROR_INVALID_FLAGS (not yet implemented)
170 * Does not properly handle codepage conversions.
171 * Does not properly handle flags.
174 INT WINAPI
WideCharToMultiByte(UINT page
, DWORD flags
, LPCWSTR src
,
175 INT srclen
,LPSTR dst
, INT dstlen
,
176 LPCSTR defchar
, BOOL
*used
)
181 int dont_copy
= (dstlen
==0);
183 if ((!src
) | ((!dst
) && (!dont_copy
)) )
184 { SetLastError(ERROR_INVALID_PARAMETER
);
188 if (page
!=GetACP() && page
!=CP_OEMCP
&& page
!=CP_ACP
)
189 FIXME(win32
,"Conversion in CP %d not supported\n",page
);
192 FIXME(win32
,"flags %lx not supported\n",flags
);
198 srclen
= lstrlenW(src
)+1;
201 while(srclen
&& (dont_copy
|| dstlen
))
208 /* ??? The WC_DEFAULTCHAR flag only gets used in
209 * combination with the WC_COMPOSITECHECK flag or at
210 * least this is what it seems from using the function
211 * on NT4.0 in combination with reading the documentation.
213 *dst
= defchar
? *defchar
: '?';
221 if((!*src
) && care_for_eos
) {
230 if (!eos
&& srclen
> 0) {
231 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
238 /***********************************************************************
239 * IsDBCSLeadByteEx (KERNEL32.359)
241 BOOL WINAPI
IsDBCSLeadByteEx( UINT codepage
, BYTE testchar
)
246 GetCPInfo(codepage
, &cpinfo
);
247 for (i
= 0 ; i
< sizeof(cpinfo
.LeadByte
)/sizeof(cpinfo
.LeadByte
[0]); i
+=2)
249 if (cpinfo
.LeadByte
[i
] == 0)
251 if (cpinfo
.LeadByte
[i
] <= testchar
&& testchar
<= cpinfo
.LeadByte
[i
+1])
258 /***********************************************************************
259 * IsDBCSLeadByte16 (KERNEL.207)
261 BOOL16 WINAPI
IsDBCSLeadByte16( BYTE testchar
)
263 return IsDBCSLeadByteEx(GetACP(), testchar
);
267 /***********************************************************************
268 * IsDBCSLeadByte32 (KERNEL32.358)
270 BOOL WINAPI
IsDBCSLeadByte( BYTE testchar
)
272 return IsDBCSLeadByteEx(GetACP(), testchar
);
276 /***********************************************************************
277 * EnumSystemCodePages32A (KERNEL32.92)
279 BOOL WINAPI
EnumSystemCodePagesA(CODEPAGE_ENUMPROCA lpfnCodePageEnum
,DWORD flags
)
281 TRACE(win32
,"(%p,%08lx)\n",lpfnCodePageEnum
,flags
);
282 lpfnCodePageEnum("437");
286 /***********************************************************************
287 * EnumSystemCodePages32W (KERNEL32.93)
289 BOOL WINAPI
EnumSystemCodePagesW( CODEPAGE_ENUMPROCW lpfnCodePageEnum
,
293 TRACE(win32
,"(%p,%08lx)\n",lpfnCodePageEnum
,flags
);
295 cp
= HEAP_strdupAtoW( GetProcessHeap(), 0, "437" );
296 lpfnCodePageEnum(cp
);
297 HeapFree( GetProcessHeap(), 0, cp
);