www.pudn.com > Triumph.rar > Medium.cpp
// Medium.cpp: implementation of the CMedium class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Medium.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMedium::CMedium()
{
USED=FALSE;
}
CMedium::~CMedium()
{
}
void CMedium::Attach(LPCTSTR ciku)
{
file.Open(ciku,CFile::modeRead);
USED=TRUE;
}
void CMedium::Detach()
{
file.Close();
USED=FALSE;
}
CString CharToString(char x)
{
CString ret(" ");
ret.SetAt(0,x);
return ret;
}
CString FirstWord(CString str)//根据空格键找到第一个单词
{
return str.Left(str.Find(' ',0));
}
NOTESTRUCT CMedium::Search(CString Task) //Task是要查的单词
{
////////////////////
//将Task中的空格排除掉(暂时还没加如代码!)
//////////////////////
ASSERT(USED==TRUE);//确认有可用的词库
NOTESTRUCT NoteStruct;//NoteStruct是将要返回的结果
NoteStruct.WordLength=0;//初始默认为找不到单词(单词长度为0)
NoteStruct.Word=Task;//写入信息.....
//下面开始在词库里面匹配单词
file.Seek(0,CFile::begin);
//##//////////////////////////////////////
CString strTemp;//用于暂时储存word和phonetic
file.ReadString(strTemp);
if(Task==FirstWord(strTemp)) //词库的第一个单词就是要找的!呵呵
{
NoteStruct.WordLength=Task.GetLength();
file.ReadString(NoteStruct.Explanation);//写入解释.....
////////////////写入音标/////////////
int left=strTemp.Find('[',0);
int right=strTemp.Find(']',left);
NoteStruct.Phonetic=strTemp.Mid(left,right-left+1);
////////////////写入音标/////////////
goto TheEnd;
}
while(TRUE)
{
if(!file.ReadString(strTemp)) //超出文件尾部
{goto TheEnd;}
if(!file.ReadString(strTemp))
{goto TheEnd;}
if(!file.ReadString(strTemp))
{goto TheEnd;}
if(Task==FirstWord(strTemp)) //找到匹配单词
{
NoteStruct.WordLength=Task.GetLength();
file.ReadString(NoteStruct.Explanation);//写入解释.....
////////////////写入音标/////////////
int left=strTemp.Find('[',0);
int right=strTemp.Find(']',left);
NoteStruct.Phonetic=strTemp.Mid(left,right-left+1);
////////////////写入音标/////////////
goto TheEnd ;
}
}
//##//////////////////////////////////////
TheEnd:
return NoteStruct;
}
NOTESTRUCT CMedium::Search(CString Task, CString ciku)//ciku是词库的目录
{
CFileFind filefind;
BOOL b=filefind.FindFile(ciku);
Attach(ciku+"\\"+CharToString(Task.GetAt(0))+".txt");
NOTESTRUCT ns=Search(Task);
Detach();
return ns;
}