Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

oemxlate.c

Go to the documentation of this file.
00001 /**************************** Module Header ********************************\ 00002 * Module Name: oemxlate.c 00003 * 00004 * Copyright (c) 1985 - 1999, Microsoft Corporation 00005 * 00006 * ANSI/UNICODE(U+00--) to/from OEM translation routines for CP 437 00007 * 00008 * The goal of this module is to translate strings from ANSI/U+00-- to Oem 00009 * character set or the opposite. If there is no equivalent character 00010 * we use the followings rules: 00011 * 00012 * 1) we put a similar character (e.g. character without accent) 00013 * 2) In OemToChar, graphics vertical, horizontal, and junction characters 00014 * are usually translated to '|', '-', and '+' characters, as appropriate, 00015 * unless the ANSI set is expanded to include such graphics. 00016 * 3) Otherwise we put underscore "_". 00017 * 00018 * History: 00019 * IanJa 4/10/91 from Win3.1 \\pucus\win31ro!drivers\keyboard\xlat*.* 00020 \***************************************************************************/ 00021 00022 #include "precomp.h" 00023 #pragma hdrstop 00024 00025 /***************************************************************************\ 00026 * CharToOemA 00027 * 00028 * CharToOemA(pSrc, pDst) - Translates the ANSI string at pSrc into 00029 * the OEM string at pDst. pSrc == pDst is legal. 00030 * Always returns TRUE 00031 * 00032 \***************************************************************************/ 00033 BOOL WINAPI CharToOemA( 00034 LPCSTR pSrc, 00035 LPSTR pDst) 00036 { 00037 UserAssert(gpsi); 00038 00039 if (pSrc == NULL || pDst == NULL) { 00040 return FALSE; 00041 } 00042 00043 do { 00044 *pDst++ = gpsi->acAnsiToOem[(UCHAR)*pSrc]; 00045 } while (*pSrc++); 00046 00047 return TRUE; 00048 } 00049 00050 /***************************************************************************\ 00051 * CharToOemBuffA 00052 * 00053 * CharToOemBuffA(pSrc, pDst, nLength) - Translates nLength characters from 00054 * the ANSI string at pSrc into OEM characters in the buffer at pDst. 00055 * pSrc == pDst is legal. 00056 * 00057 * History: 00058 \***************************************************************************/ 00059 BOOL WINAPI CharToOemBuffA( 00060 LPCSTR pSrc, 00061 LPSTR pDst, 00062 DWORD nLength) 00063 { 00064 UserAssert(gpsi); 00065 00066 if (pSrc == NULL || pDst == NULL) { 00067 return FALSE; 00068 } 00069 00070 while (nLength--) { 00071 *pDst++ = gpsi->acAnsiToOem[(UCHAR)*pSrc++]; 00072 } 00073 00074 return TRUE; 00075 } 00076 00077 00078 /***************************************************************************\ 00079 * OemToCharA 00080 * 00081 * OemToCharA(pSrc, pDst) - Translates the OEM string at pSrc into 00082 * the ANSI string at pDst. pSrc == pDst is legal. 00083 * 00084 * Always returns TRUE 00085 * 00086 * History: 00087 \***************************************************************************/ 00088 BOOL WINAPI OemToCharA( 00089 LPCSTR pSrc, 00090 LPSTR pDst) 00091 { 00092 UserAssert(gpsi); 00093 00094 if (pSrc == NULL || pDst == NULL) { 00095 return FALSE; 00096 } 00097 00098 do { 00099 *pDst++ = gpsi->acOemToAnsi[(UCHAR)*pSrc]; 00100 } while (*pSrc++); 00101 00102 return TRUE; 00103 } 00104 00105 00106 /***************************************************************************\ 00107 * OemToCharBuffA 00108 * 00109 * OemToCharBuffA(pSrc, pDst, nLength) - Translates nLength OEM characters from 00110 * the buffer at pSrc into ANSI characters in the buffer at pDst. 00111 * pSrc == pDst is legal. 00112 * 00113 * Always returns TRUE 00114 * 00115 * History: 00116 \***************************************************************************/ 00117 BOOL WINAPI OemToCharBuffA( 00118 LPCSTR pSrc, 00119 LPSTR pDst, 00120 DWORD nLength) 00121 { 00122 UserAssert(gpsi); 00123 00124 if (pSrc == NULL || pDst == NULL) { 00125 return FALSE; 00126 } 00127 00128 while (nLength--) { 00129 *pDst++ = gpsi->acOemToAnsi[(UCHAR)*pSrc++]; 00130 } 00131 00132 return TRUE; 00133 } 00134 00135 00136 /***************************************************************************\ 00137 * CharToOemW 00138 * 00139 * CharToOemW(pSrc, pDst) - Translates the Unicode string at pSrc into 00140 * the OEM string at pDst. pSrc == pDst is legal. 00141 * 00142 * History: 00143 \***************************************************************************/ 00144 BOOL WINAPI CharToOemW( 00145 LPCWSTR pSrc, 00146 LPSTR pDst) 00147 { 00148 int cch; 00149 if (pSrc == NULL || pDst == NULL) { 00150 return FALSE; 00151 } else if (pSrc == (LPCWSTR)pDst) { 00152 /* 00153 * WideCharToMultiByte() requires pSrc != pDst: fail this call. 00154 * LATER: Is this really true? 00155 */ 00156 return FALSE; 00157 } 00158 00159 cch = wcslen(pSrc) + 1; 00160 00161 WideCharToMultiByte( 00162 CP_OEMCP, // Unicode -> OEM 00163 0, // gives best visual match 00164 (LPWSTR)pSrc, cch, // source & length 00165 pDst, // dest 00166 cch * 2, // max poss.length (DBCS may * 2) 00167 "_", // default char 00168 NULL); // (don't care whether defaulted) 00169 00170 return TRUE; 00171 } 00172 00173 /***************************************************************************\ 00174 * CharToOemBuffW 00175 * 00176 * CharToOemBuffW(pSrc, pDst, nLength) - Translates nLength characters from 00177 * the Unicode string at pSrc into OEM characters in the buffer at pDst. 00178 * pSrc == pDst is legal. 00179 * 00180 * History: 00181 \***************************************************************************/ 00182 BOOL WINAPI CharToOemBuffW( 00183 LPCWSTR pSrc, 00184 LPSTR pDst, 00185 DWORD nLength) 00186 { 00187 if (pSrc == NULL || pDst == NULL) { 00188 return FALSE; 00189 } else if (pSrc == (LPCWSTR)pDst) { 00190 /* 00191 * WideCharToMultiByte() requires pSrc != pDst: fail this call. 00192 * LATER: Is this really true? 00193 */ 00194 return FALSE; 00195 } 00196 00197 WideCharToMultiByte( 00198 CP_OEMCP, // Unicode -> OEM 00199 0, // gives best visual match 00200 (LPWSTR)pSrc, (int)nLength, // source & length 00201 pDst, // dest 00202 (int)nLength * 2, // max poss. length (DBCS may * 2) 00203 "_", // default char 00204 NULL); // (don't care whether defaulted) 00205 00206 return TRUE; 00207 } 00208 00209 /***************************************************************************\ 00210 * OemToCharW 00211 * 00212 * OemToCharW(pSrc, pDst) - Translates the OEM string at pSrc into 00213 * the Unicode string at pDst. pSrc == pDst is not legal. 00214 * 00215 * History: 00216 \***************************************************************************/ 00217 BOOL WINAPI OemToCharW( 00218 LPCSTR pSrc, 00219 LPWSTR pDst) 00220 { 00221 int cch; 00222 if (pSrc == NULL || pDst == NULL) { 00223 return FALSE; 00224 } else if (pSrc == (LPCSTR)pDst) { 00225 /* 00226 * MultiByteToWideChar() requires pSrc != pDst: fail this call. 00227 * LATER: Is this really true? 00228 */ 00229 return FALSE; 00230 } 00231 00232 cch = strlen(pSrc) + 1; 00233 00234 MultiByteToWideChar( 00235 CP_OEMCP, // Unicode -> OEM 00236 MB_PRECOMPOSED | MB_USEGLYPHCHARS, // visual map to precomposed 00237 (LPSTR)pSrc, cch, // source & length 00238 pDst, // destination 00239 cch); // max poss. precomposed length 00240 00241 return TRUE; 00242 } 00243 00244 /***************************************************************************\ 00245 * OemToCharBuffW 00246 * 00247 * OemToCharBuffW(pSrc, pDst, nLength) - Translates nLength OEM characters from 00248 * the buffer at pSrc into Unicode characters in the buffer at pDst. 00249 * pSrc == pDst is not legal. 00250 * 00251 * History: 00252 \***************************************************************************/ 00253 BOOL WINAPI OemToCharBuffW( 00254 LPCSTR pSrc, 00255 LPWSTR pDst, 00256 DWORD nLength) 00257 { 00258 if (pSrc == NULL || pDst == NULL) { 00259 return FALSE; 00260 } else if (pSrc == (LPCSTR)pDst) { 00261 /* 00262 * MultiByteToWideChar() requires pSrc != pDst: fail this call. 00263 * LATER: Is this really true? 00264 */ 00265 return FALSE; 00266 } 00267 00268 MultiByteToWideChar( 00269 CP_OEMCP, // Unicode -> OEM 00270 MB_PRECOMPOSED | MB_USEGLYPHCHARS, // visual map to precomposed 00271 (LPSTR)pSrc, nLength, // source & length 00272 pDst, // destination 00273 nLength); // max poss. precomposed length 00274 00275 return TRUE; 00276 } 00277 00278 /***************************************************************************\ 00279 * OemKeyScan (API) 00280 * 00281 * Converts an OEM character into a scancode plus shift state, returning 00282 * scancode in low byte, shift state in high byte. 00283 * 00284 * Returns -1 on error. 00285 * 00286 \***************************************************************************/ 00287 00288 DWORD WINAPI OemKeyScan( 00289 WORD wOemChar) 00290 { 00291 WCHAR wchOem; 00292 SHORT sVk; 00293 UINT dwRet; 00294 00295 #ifdef FE_SB // OemKeyScan() 00296 /* 00297 * Return 0xFFFFFFFF for DBCS LeadByte character. 00298 */ 00299 if (IsDBCSLeadByte(LOBYTE(wOemChar))) { 00300 return 0xFFFFFFFF; 00301 } 00302 #endif // FE_SB 00303 00304 if (!OemToCharBuffW((LPCSTR)&wOemChar, &wchOem, 1)) { 00305 return 0xFFFFFFFF; 00306 } 00307 00308 sVk = VkKeyScanW(wchOem); 00309 if ((dwRet = MapVirtualKeyW(LOBYTE(sVk), 0)) == 0) { 00310 return 0xFFFFFFFF; 00311 } 00312 return dwRet | ((sVk & 0xFF00) << 8); 00313 }

Generated on Sat May 15 19:41:06 2004 for test by doxygen 1.3.7