2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
15 /******************************************************************************
16 * GetACP [KERNEL32.276] Gets current ANSI code-page identifier.
19 * Current ANSI code-page identifier, default if no current defined
21 UINT32 WINAPI
GetACP(void)
23 /* This introduces too many messages */
24 /* FIXME(win32, "(void): stub\n"); */
25 return 1252; /* Windows 3.1 ISO Latin */
29 /***********************************************************************
30 * GetCPInfo (KERNEL32.154)
32 BOOL32 WINAPI
GetCPInfo( UINT32 codepage
, LPCPINFO cpinfo
)
34 cpinfo
->DefaultChar
[0] = '?';
37 case 932 : /* Shift JIS (japan) */
38 cpinfo
->MaxCharSize
= 2;
39 cpinfo
->LeadByte
[0]= 0x81; cpinfo
->LeadByte
[1] = 0x9F;
40 cpinfo
->LeadByte
[2]= 0xE0; cpinfo
->LeadByte
[3] = 0xFC;
41 cpinfo
->LeadByte
[4]= 0x00; cpinfo
->LeadByte
[5] = 0x00;
43 case 936 : /* GB2312 (Chinese) */
44 case 949 : /* KSC5601-1987 (Korean) */
45 case 950 : /* BIG5 (Chinese) */
46 cpinfo
->MaxCharSize
= 2;
47 cpinfo
->LeadByte
[0]= 0x81; cpinfo
->LeadByte
[1] = 0xFE;
48 cpinfo
->LeadByte
[2]= 0x00; cpinfo
->LeadByte
[3] = 0x00;
50 case 1361 : /* Johab (Korean) */
51 cpinfo
->MaxCharSize
= 2;
52 cpinfo
->LeadByte
[0]= 0x84; cpinfo
->LeadByte
[1] = 0xD3;
53 cpinfo
->LeadByte
[2]= 0xD8; cpinfo
->LeadByte
[3] = 0xDE;
54 cpinfo
->LeadByte
[4]= 0xE0; cpinfo
->LeadByte
[5] = 0xF9;
55 cpinfo
->LeadByte
[6]= 0x00; cpinfo
->LeadByte
[7] = 0x00;
58 cpinfo
->MaxCharSize
= 1;
59 cpinfo
->LeadByte
[0]= 0x00; cpinfo
->LeadByte
[1] = 0x00;
65 /***********************************************************************
66 * GetOEMCP (KERNEL32.248)
68 UINT32 WINAPI
GetOEMCP(void)
70 return 437; /* MS-DOS United States */
73 /***********************************************************************
74 * IsValidCodePage (KERNEL32.360)
76 BOOL32 WINAPI
IsValidCodePage(UINT32 CodePage
)
89 /***********************************************************************
90 * MultiByteToWideChar (KERNEL32.534)
93 * page [in] Codepage character set to convert from
94 * flags [in] Character mapping flags
95 * src [in] Source string buffer
96 * srclen [in] Length of source string buffer
97 * dst [in] Destination buffer
98 * dstlen [in] Length of destination buffer
101 * The returned length includes the null terminator character.
104 * Success: If dstlen > 0, number of characters written to destination
105 * buffer. If dstlen == 0, number of characters needed to do
107 * Failure: 0. Occurs if not enough space is available.
110 * ERROR_INSUFFICIENT_BUFFER
111 * ERROR_INVALID_FLAGS (not yet implemented)
112 * ERROR_INVALID_PARAMETER (not yet implemented)
115 * Does not properly handle codepage conversions.
116 * Does not properly handle flags.
119 INT32 WINAPI
MultiByteToWideChar(UINT32 page
, DWORD flags
,
120 LPCSTR src
, INT32 srclen
,
121 LPWSTR dst
, INT32 dstlen
)
126 srclen
= lstrlen32A(src
)+1;
131 while (srclen
&& dstlen
) {
132 *dst
= (WCHAR
)(unsigned char)*src
;
136 if (!dstlen
&& srclen
) {
137 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
143 /***********************************************************************
144 * WideCharToMultiByte (KERNEL32.727)
147 * page [in] Codepage character set to convert to
148 * flags [in] Character mapping flags
149 * src [in] Source string buffer
150 * srclen [in] Length of source string buffer
151 * dst [in] Destination buffer
152 * dstlen [in] Length of destination buffer
153 * defchar [in] Default character to use for conversion if no exact
154 * conversion can be made
155 * used [out] Set if default character was used in the conversion
158 * The returned length includes the null terminator character.
161 * Success: If dstlen > 0, number of characters written to destination
162 * buffer. If dstlen == 0, number of characters needed to do
164 * Failure: 0. Occurs if not enough space is available.
167 * ERROR_INSUFFICIENT_BUFFER
168 * ERROR_INVALID_FLAGS (not yet implemented)
171 * Does not properly handle codepage conversions.
172 * Does not properly handle flags.
175 INT32 WINAPI
WideCharToMultiByte(UINT32 page
, DWORD flags
, LPCWSTR src
,
176 INT32 srclen
,LPSTR dst
, INT32 dstlen
,
177 LPCSTR defchar
, BOOL32
*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
);
197 srclen
= lstrlen32W(src
)+1;
198 while(srclen
&& (dont_copy
|| dstlen
))
205 /* ??? The WC_DEFAULTCHAR flag only gets used in
206 * combination with the WC_COMPOSITECHECK flag or at
207 * least this is what it seems from using the function
208 * on NT4.0 in combination with reading the documentation.
210 *dst
= defchar
? *defchar
: '?';
227 if (!eos
&& srclen
> 0) {
228 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
235 /***********************************************************************
236 * IsDBCSLeadByteEx (KERNEL32.359)
238 BOOL32 WINAPI
IsDBCSLeadByteEx( UINT32 codepage
, BYTE testchar
)
243 GetCPInfo(codepage
, &cpinfo
);
244 for (i
= 0 ; i
< sizeof(cpinfo
.LeadByte
)/sizeof(cpinfo
.LeadByte
[0]); i
+=2)
246 if (cpinfo
.LeadByte
[i
] == 0)
248 if (cpinfo
.LeadByte
[i
] <= testchar
&& testchar
<= cpinfo
.LeadByte
[i
+1])
255 /***********************************************************************
256 * IsDBCSLeadByte16 (KERNEL.207)
258 BOOL16 WINAPI
IsDBCSLeadByte16( BYTE testchar
)
260 return IsDBCSLeadByteEx(GetACP(), testchar
);
264 /***********************************************************************
265 * IsDBCSLeadByte32 (KERNEL32.358)
267 BOOL32 WINAPI
IsDBCSLeadByte32( BYTE testchar
)
269 return IsDBCSLeadByteEx(GetACP(), testchar
);
273 /***********************************************************************
274 * EnumSystemCodePages32A (KERNEL32.92)
276 BOOL32 WINAPI
EnumSystemCodePages32A(CODEPAGE_ENUMPROC32A lpfnCodePageEnum
,DWORD flags
)
278 TRACE(win32
,"(%p,%08lx)\n",lpfnCodePageEnum
,flags
);
279 lpfnCodePageEnum("437");
283 /***********************************************************************
284 * EnumSystemCodePages32W (KERNEL32.93)
286 BOOL32 WINAPI
EnumSystemCodePages32W( CODEPAGE_ENUMPROC32W lpfnCodePageEnum
,
290 TRACE(win32
,"(%p,%08lx)\n",lpfnCodePageEnum
,flags
);
292 cp
= HEAP_strdupAtoW( GetProcessHeap(), 0, "437" );
293 lpfnCodePageEnum(cp
);
294 HeapFree( GetProcessHeap(), 0, cp
);