www.pudn.com > dialogic_IVR.rar > Mindex.cpp
// Mindex.cpp: implementation of the CMindex class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Mindex.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMindex::CMindex()
{
memset( DestPath, 0x0, 256 );
pCombIdx = new IDXINFO[256];
memset( (char *)pCombIdx, 0x0, sizeof(IDXINFO)*256 );
pCombBuf = new char[4000];
memset( pCombBuf, 0x08, 4000 );
Count = 1;
CombBufLen = 4000;
pCombIdx[0].Id = ' ';
pCombIdx[0].Offset = 0;
pCombIdx[0].Length = 4000;
strcpy( pCombIdx[0].Note, "静音" );
}
CMindex::~CMindex()
{
if ( pCombIdx != NULL ) delete pCombIdx;
if ( pCombBuf != NULL ) delete pCombBuf ;
}
void CMindex::ResetComb(void)
{
if ( pCombIdx != NULL ) delete pCombIdx;
if ( pCombBuf != NULL ) delete pCombBuf ;
memset( DestPath, 0x0, 256 );
pCombIdx = new IDXINFO[256];
memset( (char *)pCombIdx, 0x0, sizeof(IDXINFO)*256 );
pCombBuf = new char[4000];
memset( pCombBuf, 0x80, 4000 );
Count = 1;
CombBufLen = 4000;
pCombIdx[0].Id = ' ';
pCombIdx[0].Offset = 0;
pCombIdx[0].Length = 4000;
strcpy( pCombIdx[0].Note, "静音" );
}
void CMindex::SetPath( char *m_Path)
{
int Length;
if( m_Path != NULL )
{
strcpy( DestPath, m_Path );
Length = strlen( DestPath );
if( DestPath[ Length-1 ] != '\\' ) strcat( DestPath, "\\" );
}
}
int CMindex::ReadIdx( void )
{
CFile pFile;
int Length;
char m_File[256], Debugbuf[256];
strcpy( m_File, DestPath );
strcat( m_File, "Combvoc.idx") ;
if ( !pFile.Open( m_File, CFile::modeRead|CFile::typeBinary ) )
{
sprintf( Debugbuf, "Open File %s Error!", m_File );
AfxMessageBox(Debugbuf);
return 0;
}
Length = pFile.GetLength();
Count = Length / sizeof(IDXINFO);
pFile.Read( (char *) pCombIdx, Length );
pFile.Close();
return(Count);
}
int CMindex::WriteIdx( void )
{
CFile pFile;
char m_File[256], Debugbuf[256];
strcpy( m_File, DestPath );
strcat( m_File, "Combvoc.idx") ;
if ( !pFile.Open( m_File, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary ) )
{
sprintf( Debugbuf, "Create File %s Error!", m_File );
AfxMessageBox(Debugbuf);
return 0;
}
pFile.Write( (char *) pCombIdx, Count*sizeof(IDXINFO));
pFile.Close();
return(Count);
}
int CMindex::ReadBuf( void )
{
CFile pFile;
char m_File[256], Debugbuf[256];
strcpy( m_File, DestPath );
strcat( m_File, "Combvoc.vox") ;
if ( !pFile.Open( m_File, CFile::modeRead|CFile::typeBinary ) )
{
sprintf( Debugbuf, "Open File %s Error!", m_File );
AfxMessageBox(Debugbuf);
return 0;
}
CombBufLen = pFile.GetLength();
RallocComb( CombBufLen );
pFile.ReadHuge( pCombBuf, CombBufLen );
pFile.Close();
return(CombBufLen);
}
int CMindex::WriteBuf( void )
{
CFile pFile;
char m_File[256], Debugbuf[256];
strcpy( m_File, DestPath );
strcat( m_File, "Combvoc.vox") ;
if ( !pFile.Open( m_File, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary ) )
{
sprintf( Debugbuf, "Create File %s Error!", m_File );
AfxMessageBox(Debugbuf);
return 0;
}
pFile.WriteHuge( pCombBuf, CombBufLen );
pFile.Close();
return(CombBufLen);
}
int CMindex::FindId( char m_Id, int &m_Offset, int &m_Length )
{
int i = 0;
if( Count == 0 )
{
m_Offset = 0;
m_Length = 0;
return 0;
}
for( i=0; i