2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
11 #include "debugtools.h"
13 DEFAULT_DEBUG_CHANNEL(win32
)
16 /******************************************************************************
17 * GetACP [KERNEL32.276] Gets current ANSI code-page identifier.
20 * Current ANSI code-page identifier, default if no current defined
22 UINT WINAPI
GetACP(void)
24 /* This introduces too many messages */
25 /* FIXME(win32, "(void): stub\n"); */
26 return 1252; /* Windows 3.1 ISO Latin */
30 /***********************************************************************
31 * GetCPInfo (KERNEL32.154)
33 BOOL WINAPI
GetCPInfo( UINT codepage
, LPCPINFO cpinfo
)
35 cpinfo
->DefaultChar
[0] = '?';
38 case 932 : /* Shift JIS (japan) */
39 cpinfo
->MaxCharSize
= 2;
40 cpinfo
->LeadByte
[0]= 0x81; cpinfo
->LeadByte
[1] = 0x9F;
41 cpinfo
->LeadByte
[2]= 0xE0; cpinfo
->LeadByte
[3] = 0xFC;
42 cpinfo
->LeadByte
[4]= 0x00; cpinfo
->LeadByte
[5] = 0x00;
44 case 936 : /* GB2312 (Chinese) */
45 case 949 : /* KSC5601-1987 (Korean) */
46 case 950 : /* BIG5 (Chinese) */
47 cpinfo
->MaxCharSize
= 2;
48 cpinfo
->LeadByte
[0]= 0x81; cpinfo
->LeadByte
[1] = 0xFE;
49 cpinfo
->LeadByte
[2]= 0x00; cpinfo
->LeadByte
[3] = 0x00;
51 case 1361 : /* Johab (Korean) */
52 cpinfo
->MaxCharSize
= 2;
53 cpinfo
->LeadByte
[0]= 0x84; cpinfo
->LeadByte
[1] = 0xD3;
54 cpinfo
->LeadByte
[2]= 0xD8; cpinfo
->LeadByte
[3] = 0xDE;
55 cpinfo
->LeadByte
[4]= 0xE0; cpinfo
->LeadByte
[5] = 0xF9;
56 cpinfo
->LeadByte
[6]= 0x00; cpinfo
->LeadByte
[7] = 0x00;
59 cpinfo
->MaxCharSize
= 1;
60 cpinfo
->LeadByte
[0]= 0x00; cpinfo
->LeadByte
[1] = 0x00;
66 /***********************************************************************
67 * GetOEMCP (KERNEL32.248)
69 UINT WINAPI
GetOEMCP(void)
71 return 437; /* MS-DOS United States */
74 /***********************************************************************
75 * IsValidCodePage (KERNEL32.360)
77 BOOL WINAPI
IsValidCodePage(UINT CodePage
)
90 /***********************************************************************
91 * MultiByteToWideChar (KERNEL32.534)
94 * page [in] Codepage character set to convert from
95 * flags [in] Character mapping flags
96 * src [in] Source string buffer
97 * srclen [in] Length of source string buffer
98 * dst [in] Destination buffer
99 * dstlen [in] Length of destination buffer
102 * The returned length includes the null terminator character.
105 * Success: If dstlen > 0, number of characters written to destination
106 * buffer. If dstlen == 0, number of characters needed to do
108 * Failure: 0. Occurs if not enough space is available.
111 * ERROR_INSUFFICIENT_BUFFER
112 * ERROR_INVALID_FLAGS (not yet implemented)
113 * ERROR_INVALID_PARAMETER (not yet implemented)
116 * Does not properly handle codepage conversions.
117 * Does not properly handle flags.
120 INT WINAPI
MultiByteToWideChar(UINT page
, DWORD flags
,
121 LPCSTR src
, INT srclen
,
122 LPWSTR dst
, INT dstlen
)
127 srclen
= lstrlenA(src
)+1;
132 while (srclen
&& dstlen
) {
133 *dst
= (WCHAR
)(unsigned char)*src
;
137 if (!dstlen
&& srclen
) {
138 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
144 /***********************************************************************
145 * WideCharToMultiByte (KERNEL32.727)
148 * page [in] Codepage character set to convert to
149 * flags [in] Character mapping flags
150 * src [in] Source string buffer
151 * srclen [in] Length of source string buffer
152 * dst [in] Destination buffer
153 * dstlen [in] Length of destination buffer
154 * defchar [in] Default character to use for conversion if no exact
155 * conversion can be made
156 * used [out] Set if default character was used in the conversion
159 * The returned length includes the null terminator character.
162 * Success: If dstlen > 0, number of characters written to destination
163 * buffer. If dstlen == 0, number of characters needed to do
165 * Failure: 0. Occurs if not enough space is available.
168 * ERROR_INSUFFICIENT_BUFFER
169 * ERROR_INVALID_FLAGS (not yet implemented)
172 * Does not properly handle codepage conversions.
173 * Does not properly handle flags.
176 INT WINAPI
WideCharToMultiByte(UINT page
, DWORD flags
, LPCWSTR src
,
177 INT srclen
,LPSTR dst
, INT dstlen
,
178 LPCSTR defchar
, BOOL
*used
)
183 int dont_copy
= (dstlen
==0);
185 if ((!src
) || ((!dst
) && (!dont_copy
)) )
186 { SetLastError(ERROR_INVALID_PARAMETER
);
190 if (page
!=GetACP() && page
!=CP_OEMCP
&& page
!=CP_ACP
)
191 FIXME("Conversion in CP %d not supported\n",page
);
194 FIXME("flags %lx not supported\n",flags
);
200 srclen
= lstrlenW(src
)+1;
203 while(srclen
&& (dont_copy
|| dstlen
))
210 /* ??? The WC_DEFAULTCHAR flag only gets used in
211 * combination with the WC_COMPOSITECHECK flag or at
212 * least this is what it seems from using the function
213 * on NT4.0 in combination with reading the documentation.
215 *dst
= defchar
? *defchar
: '?';
223 if((!*src
) && care_for_eos
) {
232 if (!eos
&& srclen
> 0) {
233 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
240 /***********************************************************************
241 * IsDBCSLeadByteEx (KERNEL32.359)
243 BOOL WINAPI
IsDBCSLeadByteEx( UINT codepage
, BYTE testchar
)
248 GetCPInfo(codepage
, &cpinfo
);
249 for (i
= 0 ; i
< sizeof(cpinfo
.LeadByte
)/sizeof(cpinfo
.LeadByte
[0]); i
+=2)
251 if (cpinfo
.LeadByte
[i
] == 0)
253 if (cpinfo
.LeadByte
[i
] <= testchar
&& testchar
<= cpinfo
.LeadByte
[i
+1])
260 /***********************************************************************
261 * IsDBCSLeadByte16 (KERNEL.207)
263 BOOL16 WINAPI
IsDBCSLeadByte16( BYTE testchar
)
265 return IsDBCSLeadByteEx(GetACP(), testchar
);
269 /***********************************************************************
270 * IsDBCSLeadByte32 (KERNEL32.358)
272 BOOL WINAPI
IsDBCSLeadByte( BYTE testchar
)
274 return IsDBCSLeadByteEx(GetACP(), testchar
);
278 /***********************************************************************
279 * EnumSystemCodePages32A (KERNEL32.92)
281 BOOL WINAPI
EnumSystemCodePagesA(CODEPAGE_ENUMPROCA lpfnCodePageEnum
,DWORD flags
)
283 TRACE("(%p,%08lx)\n",lpfnCodePageEnum
,flags
);
284 lpfnCodePageEnum("437");
288 /***********************************************************************
289 * EnumSystemCodePages32W (KERNEL32.93)
291 BOOL WINAPI
EnumSystemCodePagesW( CODEPAGE_ENUMPROCW lpfnCodePageEnum
,
295 TRACE("(%p,%08lx)\n",lpfnCodePageEnum
,flags
);
297 cp
= HEAP_strdupAtoW( GetProcessHeap(), 0, "437" );
298 lpfnCodePageEnum(cp
);
299 HeapFree( GetProcessHeap(), 0, cp
);