📄 getcode.cpp
字号:
//各种内码输入法
#include "stdafx.h"
#include "cspublic.h"
#include "csinput.h"
#include "getcode.h"
static unsigned char c1 , c2 ; //记录翻页位置
int nPages , nPageStep ; //记录翻页次数和最后一次翻页的步长
//把16进制字符转换成10进制整型
int CharToInt( char c )
{
if( c>='0' && c<='9' ) //是数字
return( c-'0' ) ;
if( c>='a' && c<='f' ) //是16进制数
return( c-'a'+10 ) ;
if( c>='A' && c<='F' )
return( c-'A'+10 ) ;
return -1 ;
}
//-------------------------------------------------------------------------------------------------------//
//判断GB内码是否合法
BOOL JudgeGBCode( LPCSTR lpcsInput , int nLenOfInput )
{
int n ;
switch( nLenOfInput )
{
case 1: //左边第一位
n =CharToInt( lpcsInput[0] ) ;
if( n>=0xa && n<=0xf )
return 1 ;
return 0 ;
case 2: //左边第二位
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( (n>=0xa1 && n<=0xa9) || (n>=0xb0 && n<=0xf7) )
return 1 ;
return 0 ;
case 3: //左边第三位
//先判断第一字节
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( !((n>=0xa1 && n<=0xa9) || (n>=0xb0 && n<=0xf7)) )
return 0 ;
n =CharToInt( lpcsInput[2] ) ;
if( n>=0xa && n<=0xf )
return 1 ;
return 0 ;
case 4: //左边第四位
//先判断第一字节
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( !((n>=0xa1 && n<=0xa9) || (n>=0xb0 && n<=0xf7)) )
return 0 ;
n =CharToInt( lpcsInput[2] )*16+CharToInt( lpcsInput[3] ) ;
if( n>=0xa1 && n<=0xfe )
return 1 ;
return 0 ;
}
return 0 ;
}
//根据c1,c2,得到GB码的下一个代码,c1,c2必须正确
BOOL GetNextGBCode( void )
{
if( c2==0xfe ) //c2已经到头
{
if( c1==0xf7 ) //c1也已经到头
return 0 ;
c2 =0xa1 ;
if( c1==0xa9 )
c1 =0xb0 ;
else
c1++ ;
}
else
c2++ ;
return 1 ;
}
//根据c1,c2,得到GB码的上一个代码,c1,c2必须正确
BOOL GetPriorGBCode( void )
{
if( c2==0xa1 ) //c2已经到头
{
if( c1==0xa1 ) //c1也已经到头
return 0 ;
c2 =0xfe ;
if( c1==0xb0 )
c1 =0xa9 ;
else
c1-- ;
}
else
c2-- ;
return 1 ;
}
//初始GB的c1,c2
void InitGBC1C2( LPCSTR lpcsInput , int nLenOfInput )
{
int n ;
switch( nLenOfInput )
{
case 1:
n =CharToInt( lpcsInput[0] ) ;
if( n==0xa )
c1 =0xa1 ;
else
c1 =n*16 ;
c2 =0xa1 ;
break ;
case 2:
c1 =CharToInt( lpcsInput[0] )*16 + CharToInt( lpcsInput[1] ) ;
c2 =0xa1 ;
break ;
case 3:
c1 =CharToInt( lpcsInput[0] )*16 + CharToInt( lpcsInput[1] ) ;
n =CharToInt( lpcsInput[2] ) ;
if( n==0xa )
c2 =0xa1 ;
else
c2 =n*16 ;
break ;
}
}
//-----------------------------------------------------------------------------------------------//
//判断BIG5内码是否合法
BOOL JudgeBig5Code( LPCSTR lpcsInput , int nLenOfInput )
{
int n ;
switch( nLenOfInput )
{
case 1: //左边第一位
n =CharToInt( lpcsInput[0] ) ;
if( n>=0xa && n<=0xf )
return 1 ;
return 0 ;
case 2: //左边第二位
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( n>=0xa1 && n<=0xf9)
return 1 ;
return 0 ;
case 3: //左边第三位
//先判断第一字节
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( n<0xa1 || n>0xf9)
return 0 ;
n =CharToInt( lpcsInput[2] ) ;
if( n>=0x4 && n<=0xf )
return 1 ;
return 0 ;
case 4: //左边第四位
//先判断第一字节
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( n<0xa1 || n>0xf9)
return 0 ;
n =CharToInt( lpcsInput[2] )*16+CharToInt( lpcsInput[3] ) ;
if( n>=0x40 && n<=0xfe )
return 1 ;
return 0 ;
}
return 0 ;
}
//根据c1,c2,得到BIG5码的下一个代码,c1,c2必须正确
BOOL GetNextBig5Code( void )
{
if( c2==0xfe ) //c2已经到头
{
if( c1==0xf9 ) //c1也已经到头
return 0 ;
c2 =0x40 ;
c1++ ;
}
else
c2++ ;
return 1 ;
}
//根据c1,c2,得到BIG5码的上一个代码,c1,c2必须正确
BOOL GetPriorBig5Code( void )
{
if( c2==0x40 ) //c2已经到头
{
if( c1==0xa1 ) //c1也已经到头
return 0 ;
c2 =0xfe ;
c1-- ;
}
else
c2-- ;
return 1 ;
}
//初始BIG5的c1,c2
void InitBig5C1C2( LPCSTR lpcsInput , int nLenOfInput )
{
int n ;
switch( nLenOfInput )
{
case 1:
n =CharToInt( lpcsInput[0] ) ;
if( n==0xa )
c1 =0xa1 ;
else
c1 =n*16 ;
c2 =0x40 ;
break ;
case 2:
c1 =CharToInt( lpcsInput[0] )*16 + CharToInt( lpcsInput[1] ) ;
c2 =0x40 ;
break ;
case 3:
c1 =CharToInt( lpcsInput[0] )*16 + CharToInt( lpcsInput[1] ) ;
n =CharToInt( lpcsInput[2] ) ;
c2 =n*16 ;
break ;
}
}
//-----------------------------------------------------------------------------------------//
//判断SHIFT-JIS内码是否合法
BOOL JudgeShiftJisCode( LPCSTR lpcsInput , int nLenOfInput )
{
int n , n1 ;
switch( nLenOfInput )
{
case 1: //左边第一位
n =CharToInt( lpcsInput[0] ) ;
if( n>=0x8 && n<=0xe )
return 1 ;
return 0 ;
case 2: //左边第二位
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( n>=0x81 && n<=0xea)
return 1 ;
return 0 ;
case 3: //左边第三位
//先判断第一字节
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( n<0x81 || n>0xea)
return 0 ;
n =CharToInt( lpcsInput[2] ) ;
if( n>=0x4 && n<=0xf )
return 1 ;
return 0 ;
case 4: //左边第四位
//先判断第一字节
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( n<0x81 || n>0xea)
return 0 ;
n1 =CharToInt( lpcsInput[2] )*16+CharToInt( lpcsInput[3] ) ;
if( n==0xea )
{
if( n1!=0x7f && n1>=0x40 && n1<=0xa2 )
return 1 ;
return 0 ;
}
if( n1!=0x7f && n1>=0x40 && n1<=0xfc )
return 1 ;
return 0 ;
}
return 0 ;
}
//根据c1,c2,得到SHIFT-JIS码的下一个代码,c1,c2必须正确
BOOL GetNextShiftJisCode( void )
{
if( c2==0xfc ) //c2已经到头
{
if( c1==0xea ) //c1也已经到头
return 0 ;
c2 =0x40 ;
c1++ ;
}
else
{
if( c1==0xea && c2==0xa2 ) //已经到头
return 0 ;
c2++ ;
if( c2==0x7f )
c2++ ; //跳过0x7f
}
return 1 ;
}
//根据c1,c2,得到Shift-Jis码的上一个代码,c1,c2必须正确
BOOL GetPriorShiftJisCode( void )
{
if( c2==0x40 ) //c2已经到头
{
if( c1==0x81 ) //c1也已经到头
return 0 ;
c2 =0xfc ;
c1-- ;
}
else
c2-- ;
return 1 ;
}
//初始Shift-Jis的c1,c2
void InitShiftJisC1C2( LPCSTR lpcsInput , int nLenOfInput )
{
int n ;
switch( nLenOfInput )
{
case 1:
n =CharToInt( lpcsInput[0] ) ;
if( n==0x8 )
c1 =0x81 ;
else
c1 =n*16 ;
c2 =0x40 ;
break ;
case 2:
c1 =CharToInt( lpcsInput[0] )*16 + CharToInt( lpcsInput[1] ) ;
c2 =0x40 ;
break ;
case 3:
c1 =CharToInt( lpcsInput[0] )*16 + CharToInt( lpcsInput[1] ) ;
n =CharToInt( lpcsInput[2] ) ;
c2 =n*16 ;
break ;
}
}
//------------------------------------------------------------------------------------------------//
//判断EUC-JIS内码是否合法
BOOL JudgeEucJisCode( LPCSTR lpcsInput , int nLenOfInput )
{
int n , n1 ;
switch( nLenOfInput )
{
case 1: //左边第一位
n =CharToInt( lpcsInput[0] ) ;
if( n>=0xa && n<=0xf )
return 1 ;
return 0 ;
case 2: //左边第二位
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( n>=0xa1 && n<=0xf4 )
return 1 ;
return 0 ;
case 3: //左边第三位
//先判断第一字节
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( n<0xa1 || n>0xf4 )
return 0 ;
n =CharToInt( lpcsInput[2] ) ;
if( n>=0xa && n<=0xf )
return 1 ;
return 0 ;
case 4: //左边第四位
//先判断第一字节
n =CharToInt( lpcsInput[0] )*16+CharToInt( lpcsInput[1] ) ;
if( n<0xa1 && n>0xf4 )
return 0 ;
n1 =CharToInt( lpcsInput[2] )*16+CharToInt( lpcsInput[3] ) ;
if( n==0xf4 )
{
if( n1>=0xa1 && n1<=0xa4 )
return 1 ;
return 0 ;
}
if( n>=0xa1 && n<=0xfe )
return 1 ;
return 0 ;
}
return 0 ;
}
//根据c1,c2,得到EUC-JIS码的下一个代码,c1,c2必须正确
BOOL GetNextEucJisCode( void )
{
if( c2==0xfe ) //c2已经到头
{
if( c1==0xf4 ) //c1也已经到头
return 0 ;
c2 =0xa1 ;
c1++ ;
}
else
{
if( c1==0xf4 && c2==0xa4 ) //已经到头
return 0 ;
c2++ ;
}
return 1 ;
}
//根据c1,c2,得到EUC-JIS码的上一个代码,c1,c2必须正确
BOOL GetPriorEucJisCode( void )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -