www.pudn.com > ÖÇÄÜÄÚÂëʶ±ð£¬Ö§³ÖÆÁĻȡ´Ê·ÒëµÄ³ÌÐò.zip > MULTCODE.CPP
#include "stdafx.h" #include#include "cspublic.h" #include "multcode.h" CJudgeCode OJudgeCode( JUDGE_LIB_NAME ) ; //×Ô¶¯Åжϣ¬ÐèÒªÔõô´¦ÀíÄÚÂë //·µ»Ø0Ϊ¹ú±êÂ룬1ΪBIG5Â룬2£¬3£¬4ΪÆäËüȱʡÄÚÂë int JudgeCode( LPSTR lpsStr , int nNum ) //ÅжÏΪºÎÖÖÄÚÂë { int nResult ; if( GetRecGbBig5() ) //ÐèÒª×Ô¶¯Ê¶±ðGBÓëBIG5ÄÚÂë //ÅжÏÊǺÎÖÖÄÚÂë nResult =OJudgeCode.JudgeGBorBig5( lpsStr , nNum ) ; else //²»ÐèÒª×Ô¶¯Ê¶±ðÄÚÂë { nResult =GetOutputCode() ; //µÃµ½È±Ê¡Êä³öÄÚÂë if( nResult==1 ) //BIG5 ChangeBig5ToGb( lpsStr , nNum ) ; //ת»»ÄÚÂë } if( GetRecHz() ) //ÐèÒª×Ô¶¯Ê¶±ðHZÂë OJudgeCode.JudgeHZ( lpsStr , nNum ) ; return nResult ; } //--------------------------------------------------------------------------------------------// //×Ô¶¯ÅжÏÊǺÎÖÖÄÚÂë CJudgeCode::CJudgeCode( char * psFileName ): CFile( psFileName , CFile::modeRead ) { DWORD dwFileLen =GetLength() ; //µÃµ½Îļþ³¤¶È if( dwFileLen % 4 ) //²»Äܱ»4Õû³ý { ::MessageBox( 0 , "The length of the file is wrong!" , 0 , MB_OK ) ; return ; } m_nItemNum =(int)(dwFileLen / 4) ; //±íÖÐÏîÊý //·ÖÅäÄÚ´æ m_lpsList =(char huge*)GlobalAllocPtr( GMEM_FIXED , dwFileLen ) ; if( !m_lpsList ) { ::MessageBox( 0 , "GlobalAllocPtr error" , 0 , MB_OK ) ; return ; } //¶Á³ö´Ê×é±í ReadHuge( m_lpsList , dwFileLen ) ; Close() ; } CJudgeCode::~CJudgeCode( void ) { if( m_lpsList ) GlobalFreePtr( m_lpsList ) ; } //×Ô¶¯ÅжÏ×Ö·û´®ÊÇGBÂ뻹ÊÇBIG5Âë int CJudgeCode::JudgeGBorBig5( LPSTR lpsStr , int nNum ) { //ÅÐ¶ÏÆäÊÇ·ñΪGBÂë if( IsGB( lpsStr , nNum ) ) return( 0 ) ; //ΪGBÂë //µÃµ½µ±Ç°È±Ê¡ÄÚÂë int nResult =GetOutputCode() ; if( nResult==1 ) //ÊÇBIG5 { ChangeBig5ToGb( lpsStr , nNum ) ; //½«Æäת»»ÎªGBÂë return( 1 ) ; //ÊÇBIG5 } //ÊäÈë×Ö·û´®²»ÊÇGBÂ룬¼ÙÉèÆäΪBIG5£¬½«Æäת»»ÎªGBÂë LPSTR lpsString =(LPSTR)GlobalAllocPtr( GMEM_FIXED , nNum ) ; if( !lpsString ) { ::MessageBox( 0 , "GlobalAllocPtr error,in JudgeCode" , 0 , MB_OK ) ; return -1 ; } _fstrncpy( lpsString , lpsStr , nNum ) ; //¸´ÖÆ ChangeBig5ToGb( lpsString , nNum ) ; //ÅжÏת»»½á¹ûÊÇ·ñÊÇGBÂë if( IsGB( lpsString , nNum ) ) //ÊäÈë´®ÊÇBIG5 { _fstrncpy( lpsStr , lpsString , nNum ) ; //¸´ÖÆ GlobalFreePtr( lpsString ) ; return( 1 ) ; } GlobalFreePtr( lpsString ) ; //ÊäÈë´®¼´²»ÊÇGBÂë¡¢Ò²²»ÊÇBIG5Â룬ÒÔȱʡÄÚÂëGBÂëΪ׼ return( nResult ) ; } //ÅжÏ×Ö·û´®ÊÇ·ñÊÇGBÂë int CJudgeCode::IsGB( LPSTR lpsStr , int nNum ) { int nLinePoint ; //×Ö·ûÖ¸Õë char sWordBuff[4] ; int n ; nLinePoint =0 ; //ÉèÖÃ×Ö·ûÖ¸Õë //µÃµ½µÚÒ»¸ö×Ö l100: while( 1 ) { n =GetZi( lpsStr , nNum , (LPINT)&nLinePoint , (LPSTR)sWordBuff ) ; if( !n ) //µ½×Ö·û´®Î² return 0 ; if( n == 2 ) //Á¬Ðø¶þ¸öºº×Ö break ; } do { //µÃµ½µÚ¶þ¸ö×Ö n =GetZi( lpsStr , nNum , (LPINT)&nLinePoint , (LPSTR)(sWordBuff+2) ) ; if( !n ) //µ½×Ö·û´®Î² return 0 ; //ÅжϸÃÁ½¸ö×ÖÊÇ·ñÄܹ»×é³ÉÒ»¸ö´Ê if( IsWord( (LPSTR)sWordBuff ) ) //ÊÇÒ»¸ö´Ê return 1 ; //ÊÇGBÂë if( n == 2 ) //ÏÂÃæ»¹ÓÐÒ»×Ö { //±£´æµÚ¶þ¸ö×Ö,¼´¶ªÆúµÚÒ»¸ö×Ö£¬ÒÔµÚ¶þ¸ö×ÖΪµÚÒ»¸ö×Ö sWordBuff[0] =sWordBuff[2] ; sWordBuff[1] =sWordBuff[3] ; } else //ÏÂÃæÒѾûÓÐ×Ö£¬ÒªÕÒµÚÒ»¸öºº×Ö goto l100 ; } while( 1 ) ; } //´Ó×Ö·û´®Öеõ½Ò»¸öºº×Ö int CJudgeCode::GetZi( LPSTR lpsLine , int nNum , LPINT lpnLinePoint , LPSTR lpsZi ) { for( int i=*lpnLinePoint ; i < nNum-1 ; i++ ) { if( lpsLine[i]&0x80 ) //Óöµ½Ò»¸öºº×Ö { //¼Ç¼¸Ãºº×Ö lpsZi[0] =lpsLine[i++] ; lpsZi[1] =lpsLine[i++] ; *lpnLinePoint =i ; //¼Ç¼ָÕë //ÅжÏÏÂÒ»¸öÊÇ·ñÒ²ÊǺº×Ö if( i < nNum - 1 ) //»¹ÓпÉÄÜ×é³Éºº×Ö { if( lpsLine[i]&0x80 ) //Ò²ÊǺº×Ö return 2 ; //Á¬ÐøÁ½¸ö¶¼ÊǺº×Ö } return 1 ; //ÏÂÒ»¸ö²»ÊǺº×Ö } } return 0 ; //ÕÒ²»µ½ºº×Ö } //Åжϸü¸¸ö×ÖÊÇ·ñÄܹ»×é³ÉÒ»¸ö´Ê int CJudgeCode::IsWord( LPSTR lpsWordBuff ) { LONG nFirst=0 ; //±íÍ· LONG nLast=m_nItemNum-1 ; //±íβ LONG nMiddle ; //±íÖÐ int n ; while( nFirst <= nLast ) { nMiddle =( nFirst+nLast )/2 ; //¶þ·Ö n =_fstrncmp( m_lpsList+nMiddle*4 , lpsWordBuff , 4 ) ; if( !n ) //ÏàµÈ return 1 ; if( n < 0 ) nFirst =nMiddle+1 ; else nLast =nMiddle-1 ; } return 0 ; } //ÅжÏÊÇ·ñ´æÔÚHZÂë void CJudgeCode::JudgeHZ( LPSTR lpsStr , int nNum ) { int nSub =0 ; for( int i=0 ; i