I
immediately
Unregistered / Unconfirmed
GUEST, unregistred user!
void ClipSample(CString strSrcFile,CString strSampleFile)
{
//ºÏ³Éºó£¬»¹Òª¶ÔÎļþ½øÐд¦Àí£¬ÒÔɾ³ý±»Ëæ»ú²åÈëµÄ"±±¾©½Ýͨ..."Ñù±¾¡£
CFile file;
if(!file.Open(strSrcFile,CFile::modeReadWrite))
{
return;
}
CFile fileSample;
fileSample.Open(strSampleFile,CFile::modeRead);
size_t size=file.GetLength();
char *cSrc=new char[size+16];
memse2t(cSrc,0,sizeof(cSrc));
size=fileSample.GetLength();
char* cSample=new char[size+16];
memset(cSample,0,sizeof(cSample));
file.Read(cSrc,file.GetLength());
fileSample.Read(cSample,fileSample.GetLength());
char* p1;
char* p2;
p1=cSrc;
p2=cSample;
int total_count=file.GetLength();
int sample_count=fileSample.GetLength();
BOOL bFind=FALSE;
while(true)//Èç¹ûʣϵÄÊý¾ÝÒѲ»×ãÒÔ¹¹³ÉÒ»¸öÑù±¾£¬¾ÍÎÞÐèÔٱȽÏÁË¡£
{
p2=cSample;//¸´Î»¡£
if(*p1==*p2)
{
p1++;
p2++;
while(*p1==*p2)
{
p1++;
p2++;
if(p1-cSrc>=total_count)
break;
if(p2-cSample>=sample_count)
break;
}
}
if(p2-cSample>=sample_count)//˵Ã÷ÕÒµ½Á˸ÃÄ¿±ê´®¡£
{
//½«´ÓÔ­´®ÖÐÌÞ³ý¸ÃÄ¿±ê´®¡£
//Ñù±¾µÄβ²¿°éËæ×Å´óÁ¿µÄ¾²Òô(³¬¹ý6K)£¬²¢Î´±È½Ï£¬Ò²ÒªÉ¾³ýÕâЩ¾²Òô¡£
memmove(p1-sample_count,p1+6*1024,total_count-(p1-cSrc)-6*1024);
p1=p1-sample_count;
total_count-=sample_count;
total_count-=6*1024;
bFind=TRUE;//ÕÒµ½¡£
}
else
{
//δÕÒµ½¡£
p1++;
if(p1-cSrc>=total_count)
break;
}
}
if(bFind)
{
file.Close();
file.Open(strSrcFile,CFile::modeCreate|CFile::modeReadWrite);
file.Write(cSrc,total_count);
}
file.Close();
fileSample.Close();
delete cSample;
delete cSrc;
}
//乱码为注释.
{
//ºÏ³Éºó£¬»¹Òª¶ÔÎļþ½øÐд¦Àí£¬ÒÔɾ³ý±»Ëæ»ú²åÈëµÄ"±±¾©½Ýͨ..."Ñù±¾¡£
CFile file;
if(!file.Open(strSrcFile,CFile::modeReadWrite))
{
return;
}
CFile fileSample;
fileSample.Open(strSampleFile,CFile::modeRead);
size_t size=file.GetLength();
char *cSrc=new char[size+16];
memse2t(cSrc,0,sizeof(cSrc));
size=fileSample.GetLength();
char* cSample=new char[size+16];
memset(cSample,0,sizeof(cSample));
file.Read(cSrc,file.GetLength());
fileSample.Read(cSample,fileSample.GetLength());
char* p1;
char* p2;
p1=cSrc;
p2=cSample;
int total_count=file.GetLength();
int sample_count=fileSample.GetLength();
BOOL bFind=FALSE;
while(true)//Èç¹ûʣϵÄÊý¾ÝÒѲ»×ãÒÔ¹¹³ÉÒ»¸öÑù±¾£¬¾ÍÎÞÐèÔٱȽÏÁË¡£
{
p2=cSample;//¸´Î»¡£
if(*p1==*p2)
{
p1++;
p2++;
while(*p1==*p2)
{
p1++;
p2++;
if(p1-cSrc>=total_count)
break;
if(p2-cSample>=sample_count)
break;
}
}
if(p2-cSample>=sample_count)//˵Ã÷ÕÒµ½Á˸ÃÄ¿±ê´®¡£
{
//½«´ÓÔ­´®ÖÐÌÞ³ý¸ÃÄ¿±ê´®¡£
//Ñù±¾µÄβ²¿°éËæ×Å´óÁ¿µÄ¾²Òô(³¬¹ý6K)£¬²¢Î´±È½Ï£¬Ò²ÒªÉ¾³ýÕâЩ¾²Òô¡£
memmove(p1-sample_count,p1+6*1024,total_count-(p1-cSrc)-6*1024);
p1=p1-sample_count;
total_count-=sample_count;
total_count-=6*1024;
bFind=TRUE;//ÕÒµ½¡£
}
else
{
//δÕÒµ½¡£
p1++;
if(p1-cSrc>=total_count)
break;
}
}
if(bFind)
{
file.Close();
file.Open(strSrcFile,CFile::modeCreate|CFile::modeReadWrite);
file.Write(cSrc,total_count);
}
file.Close();
fileSample.Close();
delete cSample;
delete cSrc;
}
//乱码为注释.