You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
743 lines
19 KiB
743 lines
19 KiB
|
|
/**************************************************************************\
|
|
* Module Name: kcodecnv.c
|
|
*
|
|
* Copyright (c) 1985 - 1999, Microsoft Corporation
|
|
*
|
|
* This module contains all the code for the Korean code conversion functions.
|
|
*
|
|
* History:
|
|
* 15-Jul-1995
|
|
* 22-Feb-1996 bklee
|
|
\**************************************************************************/
|
|
#include "precomp.h"
|
|
#pragma hdrstop
|
|
|
|
#define IDD_2BEOL 100
|
|
#define IDD_3BEOL1 101
|
|
#define IDD_3BEOL2 102
|
|
|
|
#define lpSource(lpks) (LPSTR)((LPSTR)lpks+lpks->dchSource)
|
|
#define lpDest(lpks) (LPSTR)((LPSTR)lpks+lpks->dchDest)
|
|
|
|
#define JOHAB_CP 1361
|
|
#define WANSUNG_CP 949
|
|
#define TWO_BYTE 2
|
|
#define ONE_WORD 1
|
|
|
|
typedef struct tagHIGH_LOW // For high byte and low byte
|
|
{
|
|
BYTE low, high;
|
|
} HIGH_LOW;
|
|
|
|
typedef union tagWANSUNG // For Wansung character code
|
|
{
|
|
HIGH_LOW e;
|
|
WORD w;
|
|
} WANSUNG;
|
|
|
|
/* Hanguel Mnemonic Table for 2 BeolSik and 3 BeolSik */
|
|
CONST WORD HMNTable[3][96] =
|
|
{
|
|
// For 2 Beolsik.
|
|
{
|
|
/* 20 SP */ 0xA1A1,
|
|
/* 21 ! */ 0xA3A1,
|
|
/* 22 " */ 0xA1A8,
|
|
/* 23 # */ 0xA3A3,
|
|
/* 24 $ */ 0xA3A4,
|
|
/* 25 % */ 0xA3A5,
|
|
/* 26 & */ 0xA3A6,
|
|
/* 27 ` */ 0xA1AE, /* A1AE ? AiA2 */
|
|
/* 28 ( */ 0xA3A8,
|
|
/* 29 ) */ 0xA3A9,
|
|
/* 2A * */ 0xA3AA,
|
|
/* 2B + */ 0xA3AB,
|
|
/* 2C ' */ 0xA3A7,
|
|
/* 2D - */ 0x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 0xA3DD,
|
|
/* 5E ^ */ 0xA3DE,
|
|
/* 5F _ */ 0xA3DF,
|
|
/* 60 ` */ 0xA1A2, /* A1AE ? AiA2 */
|
|
/* 61 a */ 0xA4B1,
|
|
/* 62 b */ 0xA4D0,
|
|
/* 63 c */ 0xA4BA,
|
|
/* 64 d */ 0xA4B7,
|
|
/* 65 e */ 0xA4A7,
|
|
/* 66 f */ 0xA4A9,
|
|
/* 67 g */ 0xA4BE,
|
|
/* 68 h */ 0xA4C7,
|
|
/* 69 i */ 0xA4C1,
|
|
/* 6A j */ 0xA4C3,
|
|
/* 6B k */ 0xA4BF,
|
|
/* 6C l */ 0xA4D3,
|
|
/* 6D m */ 0xA4D1,
|
|
/* 6E n */ 0xA4CC,
|
|
/* 6F o */ 0xA4C0,
|
|
/* 70 p */ 0xA4C4,
|
|
/* 71 q */ 0xA4B2,
|
|
/* 72 r */ 0xA4A1,
|
|
/* 73 s */ 0xA4A4,
|
|
/* 74 t */ 0xA4B5,
|
|
/* 75 u */ 0xA4C5,
|
|
/* 76 v */ 0xA4BD,
|
|
/* 77 w */ 0xA4B8,
|
|
/* 78 x */ 0xA4BC,
|
|
/* 79 y */ 0xA4CB,
|
|
/* 7A z */ 0xA4BB,
|
|
/* 7B { */ 0xA3FB,
|
|
/* 7C | */ 0xA3FC,
|
|
/* 7D } */ 0xA3FD,
|
|
/* 7E ~ */ 0xA1AD,
|
|
0x0000
|
|
},
|
|
// For KT390.
|
|
{
|
|
/* Hex Code KSC Code */
|
|
/* 20 SP */ 0xA1A1,
|
|
/* 21 ! */ 0xA4B8,
|
|
/* 22 " */ 0xA1A8,
|
|
/* 23 # */ 0xA3A3,
|
|
/* 24 $ */ 0xA3A4,
|
|
/* 25 % */ 0xA3A5,
|
|
/* 26 & */ 0xA3A6,
|
|
/* 27 ` */ 0xA1AE,
|
|
/* 28 ( */ 0xA3A8,
|
|
/* 29 ) */ 0xA3A9,
|
|
/* 2A * */ 0xA3AA,
|
|
/* 2B + */ 0x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3B5,
|
|
/* 5A Z */ 0xA4BA,
|
|
/* 5B [ */ 0xA3A8,
|
|
/* 5C \ */ 0xA3BA,
|
|
/* 5D ] */ 0xA1B4,
|
|
/* 5E ^ */ 0xA3BD,
|
|
/* 5F _ */ 0xA3BB,
|
|
/* 60 ` */ 0xA3AA,
|
|
/* 61 a */ 0xA4B7,
|
|
/* 62 b */ 0xA4CC,
|
|
/* 63 c */ 0xA4C4,
|
|
/* 64 d */ 0xA4D3,
|
|
/* 65 e */ 0xA4C5,
|
|
/* 66 f */ 0xA4BF,
|
|
/* 67 g */ 0xA4D1,
|
|
/* 68 h */ 0xA4A4,
|
|
/* 69 i */ 0xA4B1,
|
|
/* 6A j */ 0xA4B7,
|
|
/* 6B k */ 0xA4A1,
|
|
/* 6C l */ 0xA4B8,
|
|
/* 6D m */ 0xA4BE,
|
|
/* 6E n */ 0xA4B5,
|
|
/* 6F o */ 0xA4BA,
|
|
/* 70 p */ 0xA4BD,
|
|
/* 71 q */ 0xA4B5,
|
|
/* 72 r */ 0xA4C0,
|
|
/* 73 s */ 0xA4A4,
|
|
/* 74 t */ 0xA4C3,
|
|
/* 75 u */ 0xA4A7,
|
|
/* 76 v */ 0xA4C7,
|
|
/* 77 w */ 0xA4A9,
|
|
/* 78 x */ 0xA4A1,
|
|
/* 79 y */ 0xA4B1,
|
|
/* 7A z */ 0xA4B1,
|
|
/* 7B { */ 0xA3A5,
|
|
/* 7C | */ 0xA3CC,
|
|
/* 7D } */ 0xA3AF,
|
|
/* 7E ~ */ 0xA1AD,
|
|
0x0000
|
|
}
|
|
};
|
|
|
|
CONST WORD wKSCompCode[51] = // from 'GiYuk' to 'Yi'.
|
|
{
|
|
0x8841,0x8C41,0x8444,0x9041,0x8446,0x8447,0x9441,0x9841,0x9C41,0x844A,
|
|
0x844B,0x844C,0x844D,0x844E,0x844F,0x8450,0xA041,0xA441,0xA841,0x8454,
|
|
0xAC41,0xB041,0xB441,0xB841,0xBC41,0xC041,0xC441,0xC841,0xCC41,0xD041,
|
|
0x8461,0x8481,0x84A1,0x84C1,0x84E1,0x8541,0x8561,0x8581,0x85A1,0x85C1,
|
|
0x85E1,0x8641,0x8661,0x8681,0x86A1,0x86C1,0x86E1,0x8741,0x8761,0x8781,
|
|
0x87A1
|
|
};
|
|
|
|
CONST WORD wKSCompCode2[30] = // from 'GiYuk' to 'HiEut'.
|
|
{
|
|
0x8442,0x8443,0x8444,0x8445,0x8446,0x8447,0x8448,0x9841,0x8449,0x844A,
|
|
0x844B,0x844C,0x844D,0x844E,0x844F,0x8450,0x8451,0x8453,0xA841,0x8454,
|
|
0x8455,0x8456,0x8457,0x8458,0xBC41,0x8459,0x845A,0x845B,0x845C,0x845D
|
|
};
|
|
|
|
|
|
WORD
|
|
JunjaToBanja(
|
|
LPSTR lpSrc,
|
|
LPSTR lpDest
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Arguments:
|
|
|
|
Return Value:
|
|
|
|
--*/
|
|
|
|
{
|
|
WANSUNG wsCode;
|
|
WORD wCount = 0;
|
|
|
|
while (*lpSrc)
|
|
{
|
|
if ((BYTE)(*lpSrc) < (BYTE)0x80)
|
|
{
|
|
*lpDest++ = *lpSrc++;
|
|
wCount++;
|
|
}
|
|
else
|
|
{
|
|
wsCode.e.high = *lpSrc++;
|
|
wsCode.e.low = *lpSrc++;
|
|
if (wsCode.w == 0xA1A1)
|
|
{
|
|
*lpDest++ = ' ';
|
|
wCount++;
|
|
}
|
|
else if (wsCode.w >= 0xA3A1 && wsCode.w <= 0xA3FE)
|
|
{
|
|
*lpDest++ = wsCode.e.low - (BYTE)0x80;
|
|
wCount++;
|
|
}
|
|
else
|
|
{
|
|
*lpDest++ = wsCode.e.high;
|
|
*lpDest++ = wsCode.e.low;
|
|
wCount += 2;
|
|
}
|
|
}
|
|
}
|
|
*lpDest = '\0';
|
|
return (wCount);
|
|
}
|
|
|
|
WORD
|
|
BanjaToJunja(
|
|
LPSTR lpSrc,
|
|
LPSTR lpDest
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Arguments:
|
|
|
|
Return Value:
|
|
|
|
--*/
|
|
|
|
{
|
|
WORD wCount = 0;
|
|
|
|
while (*lpSrc)
|
|
{
|
|
if ((BYTE)(*lpSrc) < (BYTE)0x80)
|
|
{
|
|
if (*lpSrc++ == ' ')
|
|
{
|
|
*lpDest++ = (BYTE)0xA1;
|
|
*lpDest++ = (BYTE)0xA1;
|
|
wCount += 2;
|
|
}
|
|
else
|
|
{
|
|
*lpDest++ = (BYTE)0xA3;
|
|
*lpDest++ = *(lpSrc - 1) + (BYTE)0x80;
|
|
wCount += 2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
*lpDest++ = *lpSrc++;
|
|
*lpDest++ = *lpSrc++;
|
|
wCount += 2;
|
|
}
|
|
}
|
|
*lpDest = '\0';
|
|
return (wCount);
|
|
}
|
|
|
|
WORD
|
|
JohabToKs(
|
|
LPSTR lpSrc,
|
|
LPSTR lpDest
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Arguments:
|
|
|
|
Return Value:
|
|
|
|
--*/
|
|
|
|
{
|
|
WORD wCount = 0;
|
|
#if defined(OLD_CONV)
|
|
WANSUNG wsSCode, wsDCode;
|
|
int iHead = 0, iTail = 2349, iMid;
|
|
BYTE bCount;
|
|
#endif
|
|
|
|
while (*lpSrc)
|
|
{
|
|
if ((BYTE)(*lpSrc) < (BYTE)0x80)
|
|
{
|
|
*lpDest++ = *lpSrc++;
|
|
wCount++;
|
|
}
|
|
else
|
|
#if defined(OLD_CONV)
|
|
{
|
|
wsSCode.e.high = *lpSrc++;
|
|
wsSCode.e.low = *lpSrc++;
|
|
for (bCount = 0; bCount < 51 && wKSCompCode[bCount] != wsSCode.w; bCount++)
|
|
;
|
|
wsDCode.w = (bCount == 51)? 0: bCount + 0xA4A1;
|
|
if (wsDCode.w)
|
|
{
|
|
*lpDest++ = wsDCode.e.high;
|
|
*lpDest++ = wsDCode.e.low;
|
|
wCount += 2;
|
|
continue;
|
|
}
|
|
for (bCount = 0; bCount < 30 && wKSCompCode2[bCount] != wsSCode.w; bCount++)
|
|
;
|
|
wsDCode.w = (bCount == 30)? 0: bCount + 0xA4A1;
|
|
if (wsDCode.w)
|
|
{
|
|
*lpDest++ = wsDCode.e.high;
|
|
*lpDest++ = wsDCode.e.low;
|
|
wCount += 2;
|
|
continue;
|
|
}
|
|
while (iHead <= iTail && !wsDCode.w)
|
|
{
|
|
iMid = (iHead + iTail) / 2;
|
|
if (wKSCharCode[iMid] > wsSCode.w)
|
|
iTail = iMid - 1;
|
|
else if (wKSCharCode[iMid] < wsSCode.w)
|
|
iHead = iMid + 1;
|
|
else
|
|
wsDCode.w = ((iMid / 94 + 0xB0) << 8) | (iMid % 94 + 0xA1);
|
|
}
|
|
if (wsDCode.w)
|
|
{
|
|
*lpDest++ = wsDCode.e.high;
|
|
*lpDest++ = wsDCode.e.low;
|
|
wCount += 2;
|
|
}
|
|
else
|
|
{
|
|
*lpDest++ = wsSCode.e.high;
|
|
*lpDest++ = wsSCode.e.low;
|
|
wCount += 2;
|
|
}
|
|
}
|
|
#else
|
|
{
|
|
// for simple implementation, converting one character by character
|
|
// we have to change it string to string conversion.
|
|
WCHAR wUni;
|
|
CHAR chTmp[2];
|
|
|
|
chTmp[0] = *lpSrc++;
|
|
chTmp[1] = *lpSrc++;
|
|
|
|
MultiByteToWideChar(JOHAB_CP, MB_PRECOMPOSED, chTmp, TWO_BYTE, &wUni, ONE_WORD);
|
|
|
|
WideCharToMultiByte(WANSUNG_CP, 0, &wUni, ONE_WORD, chTmp, TWO_BYTE, NULL, NULL);
|
|
|
|
*lpDest++ = chTmp[0];
|
|
*lpDest++ = chTmp[1];
|
|
|
|
wCount += 2;
|
|
}
|
|
#endif
|
|
}
|
|
*lpDest = '\0';
|
|
return (wCount);
|
|
}
|
|
|
|
WORD
|
|
KsToJohab(
|
|
LPSTR lpSrc,
|
|
LPSTR lpDest
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Arguments:
|
|
|
|
Return Value:
|
|
|
|
--*/
|
|
|
|
{
|
|
#if defined(OLD_CONV)
|
|
WANSUNG wsSCode, wsDCode;
|
|
WORD wCount = 0, wLoc;
|
|
#else
|
|
WORD wCount = 0;
|
|
#endif
|
|
|
|
while (*lpSrc)
|
|
{
|
|
if ((BYTE)(*lpSrc) < (BYTE)0x80)
|
|
{
|
|
*lpDest++ = *lpSrc++;
|
|
wCount++;
|
|
}
|
|
else
|
|
#if defined(OLD_CONV)
|
|
{
|
|
wsSCode.e.high = *lpSrc++;
|
|
wsSCode.e.low = *lpSrc++;
|
|
if (wsSCode.w >= (WORD)0xA4A1 && wsSCode.w <= (WORD)0xA4D3)
|
|
{
|
|
wsDCode.w = wKSCompCode[wsSCode.w - 0xA4A1];
|
|
*lpDest++ = wsDCode.e.high;
|
|
*lpDest++ = wsDCode.e.low;
|
|
}
|
|
else if (wsSCode.w >= (WORD)0xB0A1 && wsSCode.w <= (WORD)0xC8FE
|
|
&& wsSCode.e.low != (BYTE)0xFF)
|
|
{
|
|
wLoc = (wsSCode.e.high - 176) * 94;
|
|
wLoc += wsSCode.e.low - 161;
|
|
wsDCode.w = wKSCharCode[wLoc];
|
|
*lpDest++ = wsDCode.e.high;
|
|
*lpDest++ = wsDCode.e.low;
|
|
}
|
|
else
|
|
{
|
|
*lpDest++ = wsSCode.e.high;
|
|
*lpDest++ = wsSCode.e.low;
|
|
}
|
|
wCount += 2;
|
|
}
|
|
#else
|
|
{
|
|
WCHAR wUni;
|
|
CHAR chTmp[2];
|
|
|
|
chTmp[0] = *lpSrc++;
|
|
chTmp[1] = *lpSrc++;
|
|
|
|
MultiByteToWideChar(WANSUNG_CP, MB_PRECOMPOSED, chTmp, TWO_BYTE, &wUni, ONE_WORD);
|
|
|
|
WideCharToMultiByte(JOHAB_CP, 0, &wUni, ONE_WORD, chTmp, TWO_BYTE, NULL, NULL);
|
|
|
|
*lpDest++ = chTmp[0];
|
|
*lpDest++ = chTmp[1];
|
|
|
|
wCount += 2;
|
|
}
|
|
#endif
|
|
}
|
|
*lpDest = '\0';
|
|
return (wCount);
|
|
}
|
|
|
|
LRESULT
|
|
TransCodeConvert(
|
|
HIMC hIMC,
|
|
LPIMESTRUCT lpIme
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Arguments:
|
|
|
|
Return Value:
|
|
|
|
--*/
|
|
|
|
{
|
|
UNREFERENCED_PARAMETER(hIMC);
|
|
|
|
switch (lpIme->wParam)
|
|
{
|
|
case IME_JUNJAtoBANJA:
|
|
lpIme->wCount = JunjaToBanja(lpSource(lpIme), lpDest(lpIme));
|
|
break;
|
|
|
|
case IME_BANJAtoJUNJA:
|
|
lpIme->wCount = BanjaToJunja(lpSource(lpIme), lpDest(lpIme));
|
|
break;
|
|
|
|
case IME_JOHABtoKS:
|
|
lpIme->wCount = JohabToKs(lpSource(lpIme), lpDest(lpIme));
|
|
break;
|
|
|
|
case IME_KStoJOHAB:
|
|
lpIme->wCount = KsToJohab(lpSource(lpIme), lpDest(lpIme));
|
|
break;
|
|
|
|
default:
|
|
lpIme->wCount = 0;
|
|
}
|
|
return (lpIme->wCount);
|
|
}
|
|
|
|
LRESULT TransConvertList( HIMC hImc, LPIMESTRUCT lpIme)
|
|
{
|
|
LPSTR lpSrc;
|
|
LPSTR lpDst;
|
|
HGLOBAL hCandList;
|
|
LPCANDIDATELIST lpCandList;
|
|
LPSTR lpCandStr;
|
|
UINT i, uBufLen;
|
|
LRESULT lRet = 0;
|
|
|
|
lpSrc = lpSource(lpIme);
|
|
lpDst = lpDest(lpIme);
|
|
uBufLen = ImmGetConversionListA(GetKeyboardLayout(0), hImc, (LPCSTR)lpSrc,
|
|
NULL, 0, GCL_CONVERSION);
|
|
if (uBufLen)
|
|
{
|
|
hCandList = GlobalAlloc(GHND, uBufLen);
|
|
lpCandList = (LPCANDIDATELIST)GlobalLock(hCandList);
|
|
if (lpCandList == NULL) {
|
|
return 0;
|
|
}
|
|
lRet = ImmGetConversionListA(GetKeyboardLayout(0), hImc, (LPCSTR)lpSrc,
|
|
lpCandList, uBufLen, GCL_CONVERSION);
|
|
for (i = 0; i < lpCandList->dwCount; i++)
|
|
{
|
|
lpCandStr = (LPSTR)lpCandList + lpCandList->dwOffset[i];
|
|
*lpDst++ = *lpCandStr++;
|
|
*lpDst++ = *lpCandStr++;
|
|
}
|
|
*lpDst = '\0';
|
|
lpIme->wCount = (WORD)lpCandList->dwCount * 2;
|
|
GlobalUnlock(hCandList);
|
|
GlobalFree(hCandList);
|
|
}
|
|
return (lRet);
|
|
}
|
|
|
|
LRESULT TransGetMNTable( HIMC hImc, LPIMESTRUCT lpIme)
|
|
{
|
|
LPSTR lpMnemonic;
|
|
int iCount, iCIM;
|
|
|
|
UNREFERENCED_PARAMETER(hImc);
|
|
|
|
lpMnemonic = (LPSTR)(lpIme->lParam1);
|
|
// Better place would be Registry instead of WIN.INI,
|
|
// but leave it for now.
|
|
iCIM = GetProfileInt(L"WANSUNG", L"InputMethod", IDD_2BEOL) - IDD_2BEOL;
|
|
for (iCount = 0; iCount < 96; iCount++, lpMnemonic += 2)
|
|
{
|
|
*lpMnemonic = LOBYTE(HMNTable[iCIM][iCount]);
|
|
*(lpMnemonic+1) = HIBYTE(HMNTable[iCIM][iCount]);
|
|
}
|
|
return TRUE;
|
|
}
|