<floatÇüÀ» int·Î ºü¸£°Ô cast ÇÏ´Â ¹æ¹ý>
ÀÌ°Ç º¸Åë °ÔÀÓÁ¦ÀÛÇÒ¶§ ¸¹ÀÌ ¾²ÀÌ´Â ±â¹ýÀε¥, °£´ÜÇϸ鼵µ ºü¸¥¼Óµµ¸¦
³»ÁÖ´Â ¹æ¹ýÀÔ´Ï´Ù.
º¸Åë floatÇüÀ» intÇüÀ¸·Î castÇÒ¶§ (int)·Î castÇϴµ¥¿ä...
ÀÌ·¸°Ô ÇÏ´Â °Í º¸´Ù´Â ´ÙÀ½°ú °°ÀÌ ÇØÁÖ¸é ÈξÀ ºü¸£°Ô µË´Ï´Ù.
numÀ̶õ floatÇü º¯¼ö°¡ ÀÖÀ»¶§
*(int *)#
¶ó°í ÇØÁÖ¸é ÈξÀ ºü¸¥ ÇÁ·Î±×·¥À» ÀÛ¼ºÇÒ ¼ö ÀÖ½À´Ï´Ù.
< ¹®ÀÚ¿¿¡¼ ÄÚµåÁ¾·ù ¾Ë¾Æ³»±â >
ÀÌ°Ç ¹®ÀÚ¿¿¡¼ ÁöÁ¤µÈ À§Ä¡ÀÇ ±ÛÀÚ°¡ ¿µ¹®ÀÎÁö, ÇÑ±Û »óÀ§/ÇÏÀ§ ¹ÙÀÌÆ®ÀÎÁö¸¦ ÆǺ°ÇÏ´Â ·çƾÀÔ´Ï´Ù. Âü°í·Î TCodeTypeÀº ´ÙÀ½°ú °°Àº ÀǹÌÀÔ´Ï´Ù.
ctEng : ¿µ¹®
ctFirst: ÇÑ±Û »óÀ§¹ÙÀÌÆ®
ctLast : ÇÑ±Û ÇÏÀ§¹ÙÀÌÆ®
enum TCodeType { ctError = -1, ctEng, ctFirst, ctLast };
TCodeType GetCodeType( char *str, int pos )
{
TCodeType type = ctEng;
BYTE *ptr = (BYTE *)str;
while( *ptr ) {
type
= (type == ctFirst) ? ctLast : (*ptr >= 0x80 ? ctFirst : ctEng);
if(
pos == 0 ) return type;
pos--;
ptr++;
}
return ctError;
}
< Á¶ÇÕ/¿Ï¼ºÇü ÇѱÛÄÚµå ÆÇ´Ü ¼Ò½º >
Discription : ÇѱÛÄÚµå ÀÎ½Ä ·çƾ
ÇѱÛÄÚµå´Â
Á¶ÇÕÇüÄÚµå¿Í ¿Ï¼ºÇü ÄÚµåÀÇ ºóµµ¼ö¸¦ °Ë»çÇؼ
ÆÇ´ÜÇϰԵǴµ¥,
ÀÌ·¸°Ô ºóµµ¼ö¸¸°¡Áö°í ÆÇ´ÜÇÏ°Ô µÇ¸é Á¤È®
ÇÑ
ÆÇ´ÜÀÌ Èûµé´Ù.
µû¶ó¼
ÀüÈÄ Äڵ带 ÂüÁ¶ÇÏ°í, ¶§·Î´Â ±ÛÀÚ¼ø¼¿¡ µû¸¥ ÆÇ´Ü
À»
°¡¹ÌÇÏ¿© Á»´õ Á¤È®ÇÑ ÆÇ´ÜÀ» ÇÒ ¼ö ÀÖµµ·Ï Çß´Ù.
****************************************************************************/
//------------------------------------------------------------------------
// #include <vcl\vcl.h>
#include <windows.h>
// #pragma hdrstop
#include <stdlib.h>
//------------------------------------------------------------------------
#define KS5061_VERIFY_COUNT 512 // ¿Ï¼ºÇüÄÚµå È®ÀΠȽ¼ö
bool _JisCheck = false;
//------------------------------------------------------------------------
int Check_HanRange( int hancode, int HexStart, int HexEnd, int max )
{
for( int i = 0; i < max; i++ )
{
if( hancode > HexStart+0x0100*i &&
hancode < HexEnd+0x0100*i )
return true;
}
return false;
}
//------------------------------------------------------------------------
int codecmp(const void *p,const void *q);
#define MAX_CODE 48
int isNotKsCode( int hancode )
{
static int kssmcode[MAX_CODE] = {
0x8877, // "°"
0x8969, // "°á"
0x89a1, // "°í"
0x8b71, // "±Ý"
0x8fa1, // "³¢"
0x9281, // "´©"
0x9c61, // "¶ó"
0x9e81, // "·ç"
0xa061, // "¸¶"
0xa0f5, // "¸Ú"
0xa2a1, // "¹¹"
0xa3a8, // "¹Ï"
0xa4e1, // "¹ö"
0xa4e5, // "¹ø"
0xa4f1, // "¹ü"
0xa5c1, // "ºÁ"
0xa7a1, // "ºñ"
0xa8b1, // "»´"
0xaca1, // "»þ"
0xace1, // "¼"
0xace2, // "¼"
0xace3, // "¼"
0xace4, // "¼"
0xace5, // "¼±
0xace6, // "¼"
0xace7, // "¼"
0xace8, // "¼"
0xace9, // "¼"
0xb3a2, // "¾¿"
0xb4a1, // "¾ß"
0xb4a2, // "¾à"
0xb4e1, // "¾î"
0xb4f1, // "¾ö"
0xb4f4, // "¾ø"
0xb541, // "¿¡"
0xb5e1, // "¿Ö"
0xb765, // "˼"
0xb8e5, // "Àü"
0xb941, // "Á¦"
0xb9a1, // "Á¶"
0xb9a5, // "Á¸"
0xb9c1, // "ÁÂ"
0xc561, // "ÄÑ"
0xc7a1, // "Å°"
0xcfa1, // "ÇÇ"
0xdbad, // "¦"
0xdccf, // "¨Ï"
0xe7e6, // "Ùæ"
};
// Á¶ÇÕÇü ÀϾîÀÇ °æ¿ì ¿Ï¼ºÇü°ú µ¿ÀÏÇÑ ºÎºÐÀÌ Àִµ¥,
// ¿Ï¼ºÇü¿¡¼´Â °ÅÀÇ »ç¿ëµÇÁö ¾Ê´Â ¹®ÀÚÀ̹ǷÎ,
// ¾Æ·¡ Äڵ尡 ÀÖÀ»°æ¿ì ¹«Á¶°Ç Á¶ÇÕÇüÀ¸·Î ÀνÄ
// ¸¸ÀÏ Á¶ÇÕÇü ÀϾî Äڵ尡 ¾Æ´Ï¶ó¸é...
if( hancode == 0xb7e7 ) return false;
if( (int *)bsearch(&hancode, kssmcode, MAX_CODE, sizeof(int),
codecmp) !=
NULL ||
( hancode >= 0xd000 && hancode <= 0xd3ff
) ||
( hancode >= 0xdda1 &&
hancode <= 0xde98 ) ||
( hancode >= 0xdba1 &&
hancode <= 0xdbc8 ) ||
// Á¶ÇÕÇü ÇѱÛÀÌ Á¦´ë·Î
ÀνÄÀÌ µÇÁö ¾Ê´ø ¹®Á¦ ÇØ°á
// ¾Æ·¡ Äڵ尡 ÀÖÀ»°æ¿ì ¹«Á¶°Ç
Á¶ÇÕÇüÀ¸·Î ÀνÄ
// ÀϺΠ¿Ï¼ºÇü Äڵ尡 Á¶ÇÕÇüÀ¸·Î
ÀνÄÇÏ´Â ¿À·ù°¡ ÀÖ¾î¼
// °Ë»ç ¹üÀ§¸¦ 0xb400 - 0xb8ff
¿¡¼ 0xb400 - 0xb7ff·Î ¹Ù²Þ
// Á¶ÇÕÇü°ú ¿Ï¼ºÇü µÑ´Ù »ç¿ëµÇ´Â
ÄÚµåÁß, ¿Ï¼ºÇü¿¡¼ ÀÚÁÖ
// »ç¿ëµÇÁö ¾Ê´Â ÄÚµåµéÀº Á¶ÇÕÇü
ÄÚµå·Î °£ÁÖÇÑ´Ù.
( hancode >= 0xc500 &&
hancode <= 0xc5ff ) ||
( hancode >= 0xb700 &&
hancode <= 0xb7cd ) ||
( hancode >= 0xb7cf &&
hancode <= 0xb7ff ) ||
// Á¶ÇÕÇü ¸ðÀ½ÀÏ°æ¿ì ¹«Á¶°Ç
Á¶ÇÕÇüÀ¸·Î ÀνÄ
( hancode >= 0xda00 &&
hancode <= 0xdaff ) ||
// Á¶ÇÕÇü ¼±¹®ÀÚÀÏ°æ¿ìµµ
¹«Á¶°Ç Á¶ÇÕÇüÀ¸·Î ÀνÄ
// ¸¸ÀÏ Á¶ÇÕÇü ¼±¹®ÀÚ Äڵ尡
¾Æ´Ï¶ó¸é...
( hancode >= 0xd9b0 &&
hancode <= 0xd9cf ) ||
( hancode >= 0xd4b0 &&
hancode <= 0xd4cf ) )
return true;
return false;
}
//------------------------------------------------------------------------
int isKS( String buf, int len )
{
int hancode;
byte first, second;
int ks_count = 0;
int kssm_count = 0;
int max, count = 0;
int JpCount = 0;
if( len >= 0 ) max = len;
else max = buf.Length();
int oldcode = false;
for( int i = 0; i < max; i++ )
{
first = buf[count];
count++;
if(first < 0x80) continue; // ÇѱÛÄڵ尡
¾Æ´Ï¶ó¸é
second = buf[count];
if( count > 10240 ) break;
if( count >= max ) break;
count++;
hancode = (first << 8) + second; // ÇѱÛÄڵ带 Á¶ÇÕÇϱâ
// Á¶ÇÕÇü°ú ¿Ï¼ºÇü µÑ´Ù ÀÚÁÖ ¾²ÀÌ´Â ÄÚµåÀÏ°æ¿ì¿¡´Â
// Ä«¿îÆ®¸¦ ÇÏÁö¾Ê´Â´Ù.
if( hancode >= 0xb500 && hancode <
0xb5ff &&
hancode != 0xb5a5 &&
hancode != 0xb5e1 &&
hancode != 0xb541 )
continue;
// ¿Ï¼ºÇü¿¡¼ »¡,·¡,´á,µ¥,µ¡°ú °°Àº ±ÛÀÚ´Â
Á¶ÇÕÇü¿¡¼µµ ÀÚÁÖ ¾²ÀÌ´Â
// ±ÛÀÚÀ̹ǷΠī¿îÆ®¸¦ ÇÏÁö ¾Ê´Â´Ù.
if( hancode == 0xbba1 ||
hancode == 0xb7a1 ||
hancode == 0xb4e5 ||
hancode == 0xb7b6 ||
hancode == 0xb4f6 ||
hancode == 0xb8e1 || //
"Àú"
hancode == 0xb1c1 || //
"½÷"
hancode == 0xbaa1 || //
"Áà"
hancode == 0xbba5 || //
"Áø"
hancode == 0xb6a1 || //
"¿ö"/"¶¡"
hancode == 0xb6e1 || //
"ˤ"
hancode == 0xa1a1 ) continue;
// ¶ç¾ö¶ç¾ö ¶ç¿öÁø
KS5061ÀÇ Æ¯¼ö¹®ÀÚ ÄÚµåÀΰ¡?
if( ( (hancode > 0xa1a2 && hancode
< 0xa1ff) ||
(hancode > 0xa2a0 &&
hancode < 0xa2e6) ||
(hancode > 0xa3a0 &&
hancode < 0xa3ff) ||
(hancode > 0xa4a0 &&
hancode < 0xa4ff) ||
(hancode > 0xa5a0 &&
hancode < 0xa5f9) ||
(hancode > 0xa6a0 &&
hancode < 0xa6e5) ||
(hancode > 0xa7a0 &&
hancode < 0xa7f0) ||
(hancode > 0xa8a0 &&
hancode < 0xa8ff) ||
(hancode > 0xa9a0 &&
hancode < 0xa9ff) ||
(hancode > 0xaaa0 &&
hancode < 0xaaf4) ||
(hancode > 0xaba0 &&
hancode < 0xabf7) ||
(hancode > 0xaca0 &&
hancode < 0xacc2) ||
(hancode > 0xacd0 &&
hancode < 0xacf2) ||
hancode == 0xaec2 ||
(hancode > 0xadd0 && hancode < 0xadff) ||
// KS5061ÀÇ ÇѱÛÄÚµåÀΰ¡?
Check_HanRange( hancode,
0xb0a0, 0xb0ff, 16 ) ||
Check_HanRange( hancode,
0xc0a0, 0xc0ff, 9 ) ||
( hancode == 0xb8ae
) ||
( hancode == 0xb7e7 )
|| // ¿Ï¼ºÇü '·ç'
// KS5061ÀÇ ÇÑÀÚÄÚµåÀΰ¡?
Check_HanRange( hancode,
0xcaa0, 0xcaff, 6 ) ||
Check_HanRange( hancode,
0xd0a0, 0xd0ff, 16 ) ||
Check_HanRange( hancode,
0xe0a0, 0xe0ff, 16 ) ||
Check_HanRange( hancode,
0xf0a0, 0xf0ff, 14 ) ) &&
// Á¶ÇÕÇü°ú ¿Ï¼ºÇü
µÑ´Ù »ç¿ëµÇ´Â ÄÚµåÁß, Á¶ÇÕÇü¿¡¼ ÀÚÁÖ
// »ç¿ëµÇ´Â ÄÚµå´Â
°Á¦·Î Á¶ÇÕÇü ÄÚµå·Î °£ÁÖÇÑ´Ù.
!isNotKsCode( hancode
) )
{
if(++ks_count >= KS5061_VERIFY_COUNT)
break;
}
else
{
if(++kssm_count >= KS5061_VERIFY_COUNT)
break;
}
}
// ´ëºÎºÐ Á¶ÇÕÇüº¸´Ù´Â ¿Ï¼ºÇü ±ÛÀÌ ¸¹À¸¹Ç·Î Ä«¿îÆ®
°ªÀÌ
// °°À» °æ¿ì ¿Ï¼ºÇüÀ¸·Î ó¸®Çϵµ·Ï ÇÑ´Ù.
if( ks_count >= kssm_count )
return KS_CODE;
else
return KSSM_CODE;
}
< Á¶ÇÕ<->È®Àå¿Ï¼ºÇü º¯È¯ ¼Ò½º >
È®Àå¿Ï¼ºÇüÀÇ °æ¿ì Å©±â°¡ Å« °ü°è·Î #define¹®À» ÅëÇؼ ÇÁ·Î±×·¡¿¡ ³»ÀåÇÒ¼öµµ ÀÖ°í, ¶Ç´Â ¿ÜºÎ ÆÄÀÏ·Î ÀúÀåÇÏ¿© ÀоîµéÀϼöÀÖµµ·Ï Çß½À´Ï´Ù.
//------------------------------------------------------------------------
// #include <vcl\vcl.h>
// #pragma hdrstop
//------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dir.h>
#include <io.h>
#include <dos.h>
#include <dir.h>
#include <dos.h>
#include <io.h>
typedef unsigned short int word;
#define DLL_ExtKS
typedef struct { // ÇÑ±Û ÄÚµå ÇüÅÂ
word lasc :5;
word midc :5;
word firc :5;
word dummy:1;
} hcode;
#define SINGLENUM 51 // ÇÑ±Û ³¹ÀÚÀÇ ¼ö
#define SIZE_EXTKS (sizeof(word)*8822)
#define SIZE_KS (sizeof(word)*2350)
int isReadTable = false;
// È®Àå ¿Ï¼ºÇü Å×À̺íÀ» Àоî¿À´Â ÇÔ¼ö
int Read_ExtKSTable( void );
// ÇöÀç ÀÌÁöÆе尡 ÀÖ´Â °æ·Î¿Í ÆÄÀϸíÀ» ÇÕ¼º
// ÀÌ°Ç µû·Î ¸¸µé¾î¾ß ÇÔ.
void SetFilePath( char *dest, char *filename );
// ÇÑ±Û ÄÚµå º¯È¯
int codecmp(const void *p,const void *q);
word comb2comb(char src, char dest, word code); // Á¶ÇÕ --> Á¶ÇÕ
word KSSM2KS(word code); // Á¶ÇÕ ->
¿Ï¼º
word KS2KSSM(word code); // ¿Ï¼º ->
Á¶ÇÕ
word KSSM2ExtKS(word code); // Á¶ÇÕ -> È®Àå¿Ï¼º
word ExtKS2KSSM(word code); // È®Àå¿Ï¼º -> Á¶ÇÕ
word *ExtKSTable;
word *KSTable;
// ÇÑ±Û ³¹ÀÚ 51ÀÚÀÇ Á¶ÇÕÇü ÄÚµå
word SingleTable[SINGLENUM] = {
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
};
// Á¶ÇÕÇü ÄÚµå Å×À̺í
// »ïº¸ Á¶ÇÕÇü
char KSSM1Table[32] = {
-1, 0, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1
};
char KSSM2Table[32] = {
-1, -1, 0, 1, 2, 3, 4, 5,
-1, -1, 6, 7, 8, 9, 10, 11,
-1, -1, 12, 13, 14, 15, 16, 17, -1, -1, 18, 19, 20, 21, -1,
-1
};
char KSSM2Table0[22] = {
2, 3, 4, 5, 6, 7, 10,
11, 12, 13, 14, 15, 18, 19, 20, 21,
22, 23, 26, 27, 28, 29
};
char KSSM3Table[32] = {
-1, 0, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, -1, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, -1,
-1
};
char KSSM3Table0[28] = {
1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
};
word SpecTable[128] = {
0xa1d9, 0xa1da, 0xa2be, 0xa1df, 0xa2c0, 0xa2bc,
0xa1dc, 0xa1e0,
0xa1db, 0xa1e1, 0xa1ce, 0xa1cf, 0xa2dc, 0xa2dd,
0xa2b4, 0xa2ba,
0xa2b8, 0xa2d5, 0xa3a1, 0xa2d2, 0xa1d7, 0xa1aa,
0xa2d9, 0xa1e8,
0xa1e9, 0xa1e6, 0xa1e7, 0xa1d0, 0xa1ea, 0xa1e3,
0xa1e5, 0xeced,
0xeac5, 0xfbfd, 0xe2a9, 0xd9ca, 0xd0dd, 0xf7cf,
0xd2b4, 0xa2cf,
0xa1b8, 0xa1b9, 0xa8f6, 0xa8f9, 0xa3df, 0xa1ad,
0xa1c5, 0xa2c6,
0xa2c7, 0xa2c8, 0xa6a2, 0xa6a9, 0xa6be, 0xa6b9,
0xa6c1, 0xa6c2,
0xa6b4, 0xa6ad, 0xa6af, 0xa6b0, 0xa6c3, 0xa6c4,
0xa6a4, 0xa6a6,
0xa6aa, 0xa6a8, 0xa6a7, 0xa6a1, 0xa6ab, 0xa6bc,
0xa6b7, 0xa6b1,
0xa6ae, 0xa6b5, 0xa6b3, 0xa6b2, 0xa6ac, 0xa6b6,
0xa6ba, 0xa6bf,
0xa6b8, 0xa6bd, 0xa6c5, 0xa6c6, 0xa6c8, 0xa6c7,
0xa6c0, 0xa6bb,
0xa6a5, 0xa6a3, 0xa2c3, 0xa2c9, 0xa2ca, 0xa2cb,
0xa2cc, 0x
a5e1,
0xa9ac, 0xa5c3, 0xa5f0, 0xa5d2, 0xa5f2, 0xa5ec,
0xa5f3, 0xa5d5,
0xa5e8, 0xa7d9, 0xa5e4, 0xa1c4, 0xa9aa, 0xa1f4,
0xa1fb, 0xa1d5,
0xa1be, 0xa1c3, 0xa1c2, 0xa1f2, 0xa1f3, 0xa1c0,
0xa2cd, 0xa1a3,
0xa1a4, 0xa1e7, 0xa1ee, 0xa9fa, 0xa9f7, 0, 0,
0xaec2,
};
//------------------------------------------------------------------------
word comb2comb(char src, char dest, word code)
{
int firc, midc, lasc;
if(src == dest) return code;
firc = ((hcode *)&code)->firc;
midc = ((hcode *)&code)->midc;
lasc = ((hcode *)&code)->lasc;
if( src == KSSM_CODE )
{
firc = KSSM1Table[firc];
midc = KSSM2Table[midc];
lasc = KSSM3Table[lasc];
}
if( firc < 0 || midc < 0 || lasc < 0 ) return
0;
if( dest == KSSM_CODE )
{
firc++;
midc = KSSM2Table0[midc];
lasc = KSSM3Table0[lasc];
}
return(0x8000 + (firc << 10) + (midc << 5) + lasc);
}
//------------------------------------------------------------------------
int codecmp(const void *p,const void *q)
{
word *p1 = (word *)p;
word *q1 = (word *)q;
return (*p1 - *q1);
}
//------------------------------------------------------------------------
word KSSM2ExtKS(word Code)
{
word newCode;
word index;
word *p;
BYTE high, low;
newCode = KSSM2KS(Code);
if( newCode == 0 )
{
if( (p = (word *)bsearch(&Code, ExtKSTable,
SIZE_EXTKS
/ sizeof(word),
sizeof(word),
codecmp2)) != NULL)
index = p - ExtKSTable;
else return 0;
if(index < 5696)
{
high = (index / 178) + 0x81;
index %= 178;
if(index < 26 ) low = 0x41 + index;
else if(index < 52) low = 0x61
+ index - 26;
else low = 0x81 + index - 52;
}
else if(index < 8804)
{
index -= 5696;
high = (index / 84) + 0xA1;
index %= 84;
if(index < 26) low = 0x41
+ index;
else if(index < 52) low = 0x61
+ index - 26;
else low = 0x81 + index
- 52;
}
else {
high = 0xC6;
low = (index - 8804) % 18 + 0x41;
}
newCode = (((word) high) << 8) + low;
}
return newCode;
}
//------------------------------------------------------------------------
word ExtKS2KSSM(word Code)
{
word newCode;
BYTE high, low;
word index;
newCode = KS2KSSM(Code);
if( newCode == 0 )
{
high = (BYTE) (Code >> 8);
low = (BYTE) Code;
if( high >= 0x81 && high <= 0xA0
)
{
index = (high - 0x81) * 178;
if( low >= 0x41 && low
<= 0x5A ) index += (low - 0x41);
else if( low >= 0x61 &&
low <= 0x7A ) index += (low - 0x61 + 26);
else index += (low - 0x81 + 52);
}
else if( high >= 0xA1 && high <=
0xC5 )
{
index = (high - 0xA1) * 84 + 5696;
if( low >= 0x41 && low
<= 0x5A ) index += (low - 0x41);
else if( low >= 0x61 &&
low <= 0x7A ) index += (low - 0x61 + 26);
else index += (low - 0x81 +
52);
}
else if( high == 0xC6 && low >= 0x41
&& low <= 0x52 )
index = (low - 0x41 +
8804);
if( index >= 8822 ) return 0;
newCode = ExtKSTable[index];
}
return newCode;
}
//------------------------------------------------------------------------
word KSSM2KS(word code)
{
BYTE high, low;
BYTE temp;
int index;
word *p;
high = (BYTE)(code >> 8);
low = (BYTE)code;
if( high == 0xd4 )
{
index = low-0x81;
if( index < 128 )
return SpecTable[index];
}
// ÇÑ±Û º¯È¯
if( (p = (word *)bsearch(&code, KSTable, 2350,
sizeof(word), codecmp2))
!= NULL )
{
index = p - KSTable;
return((((index / 94)+0xb0)<<8)+(index %
94) + 0xa1);
}
// Ư¼ö ¹®ÀÚ º¯È¯1
else
{
if( high >= 0xd9 && high <= 0xde
)
{
if( low < 0x30 || (low > 0x7e
&& low < 0x91) )
return(0);
if( low >= 0xa1 )
temp = (high - 0xd9) *
2 + 0xa1 + 1;
else
{
temp = (high - 0xd9) *
2 + 0xa1;
if( low <= 0x7e ) low
+= 0x70;
else low
+= (0x70 - 18);
}
return((temp << 8) + low);
}
// Ư¼ö ¹®ÀÚ º¯È¯2
else
{
if( high == 0xd4 )
{
if( low < 0x80 ) return
0;
if( low <= 0xdd )
{
temp = 0xad;
low += 0x21;
}
else
{
temp = 0xae;
low -= 0x3d;
}
return((temp <<
8) + low);
}
// ÇÑÀÚ º¯È¯
else if( high >= 0xe0 &&
high <= 0xf9)
{
if( low < 0x30 || (low
> 0x7e && low < 0x91)) return 0;
if( low >= 0xa1) temp
= (high - 0xe0) * 2 + 0xca + 1;
else
{
temp = (high
- 0xe0) * 2 + 0xca;
if( low <=
0x7e ) low += 0x70;
else low += (0x70 - 18);
}
return((temp <<
8) + low);
}
}
}
for(index = 0;index < SINGLENUM;index++)
if( SingleTable[index] == code) return(0xa4a1
+ index);
return(0);
}
//------------------------------------------------------------------------
word KS2KSSM(word code)
{
BYTE high, low;
BYTE temp;
int index;
int mod, rem;
high = (BYTE)(code >> 8);
low = (BYTE)code;
// Ư¼ö ¹®ÀÚ º¯È¯1
if( high >= 0xa1 && high <= 0xac )
{
if( low < 0xa1 || low > 0xfe) return 0;
mod = (high - 0xa1) >> 1;
rem = (high - 0xa1) & 0x01;
if( rem) temp = low;
else {
temp = low - 0x70;
if( temp > 0x7e) temp += 18;
}
return(((mod + 0xd9) << 8) + temp);
}
// Ư¼ö ¹®ÀÚ º¯È¯2
else if( high == 0xad) {
if( low < 0xa1 || low > 0xfe) return 0;
temp = low - 0x21;
return((0xd4 << 8) + temp);
}
// Ư¼ö ¹®ÀÚ º¯È¯3
else if( high == 0xae) {
if( low < 0xa1 || low > 0xc1)
{
if( low == 0xc2 ) return 0xd4ff;
return 0;
}
temp = low + 0x3d;
return((0xd4 << 8) + temp);
}
// ÇÑ±Û º¯È¯
else if( high >= 0xb0 && high <= 0xc8) {
if( low < 0xa1 || low > 0xfe) return(0);
index = (high - 0xb0) * 94 + low - 0xa1;
return(KSTable[index]);
}
// ÇÑÀÚ º¯È¯
else if( high >= 0xca && high <= 0xfd) {
if( low < 0xa1 || low > 0xfe) return(0);
mod = (high - 0xca) >> 1;
rem = (high - 0xca) & 0x01;
if( rem) temp = low;
else {
temp = low - 0x70;
if( temp > 0x7e) temp += 18;
}
return(((mod + 0xe0) << 8) + temp);
}
index = ((code >> 8) - 0xb0) * 94 + (code & 0x00ff)
- 0xa1;
if( index < 0 || index >= 2350 ) return 0;
return(KSTable[index]);
}
//------------------------------------------------------------------------
bool _isReadExtKSTable = false;
int Read_ExtKSTable( void )
{
if( ExtKSTable ) return true;
char tempfile[300];
int retval = false;
FILE *fp;
SetFilePath( tempfile, "ExtKS.TBL" );
fp = fopen( tempfile, "rb" );
if( fp )
{
if( (unsigned long)filelength(fileno(fp)) == SIZE_EXTKS+SIZE_KS
)
{
ExtKSTable = new word [8822];
KSTable = new word [2350];
fread( ExtKSTable, SIZE_EXTKS, 1,
fp );
fread( KSTable, SIZE_KS, 1, fp );
retval = true;
}
fclose( fp );
return retval;
}
return false;
}
//------------------------------------------------------------------------
word ConvertHanCode(char SrcCode, char DestCode, word code)
{
if(SrcCode == KS_CODE )
return ExtKS2KSSM(code);
else
return KSSM2ExtKS(code);
}
//-------------
-----------------------------------------------------------
void ConvertHanCodeStr(char SrcCode, char DestCode, char *str, int size
)
{
BYTE high, low;
int i;
BYTE *ptr = (BYTE *)str;
word code;
if(SrcCode == DestCode) return;
if( Read_ExtKSTable() )
{
for( i = 0; i < size; )
{
if( !*(ptr) ) break;
high = *(ptr);
if( high >= 0x80 )
{
if( i+1 < size )
{
low = *(ptr+1);
code = (high
<< 8) + low;
code = ConvertHanCode(SrcCode,
DestCode, code);
if( code )
{
*(ptr)
= (BYTE)(code >> 8);
*(ptr+1)
= (BYTE)(code & 0xFF);
}
else
{
*(ptr)
= ' ';
*(ptr+1)
= ' ';
}
i += 2;
ptr += 2;
}
else
{
i++;
ptr++;
}
}
else
{
i++;
ptr++;
}
}
}
}
//------------------------------------------------------------------------
void Convert_Hanja2Han( char *str )
{
int Code;
BYTE *ptr = (BYTE *)str;
BYTE high, low;
if( !Read_ExtKSTable() ) return;
while( *ptr )
{
high = *ptr;
if( high >= 0x80 )
{
if( *(ptr+1) )
{
low = *(ptr+1);
Code = ExtKS2KSSM( (high<<8)
+ low );
high = Code>>8;
low = (BYTE)Code;
Hanja2Han( high, low );
Code = KSSM2ExtKS( (high<<8)
+ low );
high = Code>>8;
low = (BYTE)Code;
*ptr = high;
*(ptr+1) = low;
ptr += 2;
}
else break;
}
else ptr++;
}
}
//------------------------------------------------------------------------