Initial
This commit is contained in:
47
mdiwin/STREAM.CPP
Normal file
47
mdiwin/STREAM.CPP
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <mdiwin/istream.hpp>
|
||||
|
||||
IStream::IStream(const char *pathFileName)
|
||||
: mFileDescriptor(-1), mCurrentWord(0), mCurrentChar(0), mhGlobalBuffer(0),
|
||||
mlpBuffer(0), mBufferIndex(0), mlpBufferPointer(0)
|
||||
{
|
||||
if(-1==(mFileDescriptor=::open(pathFileName,O_RDONLY|O_BINARY,0,SH_DENYWR)))return;
|
||||
mhGlobalBuffer=::GlobalAlloc(GMEM_FIXED,MaxInputBuffer);
|
||||
if(!mhGlobalBuffer)return;
|
||||
mlpBuffer=(UCHAR FAR *)::GlobalLock(mhGlobalBuffer);
|
||||
}
|
||||
|
||||
IStream::~IStream()
|
||||
{
|
||||
if(-1!=mFileDescriptor)::close(mFileDescriptor);
|
||||
if(mhGlobalBuffer)
|
||||
{
|
||||
::GlobalUnlock(mhGlobalBuffer);
|
||||
::GlobalFree(mhGlobalBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
WORD IStream::getChar(void)
|
||||
{
|
||||
if(-1==mFileDescriptor)return FALSE;
|
||||
if(!mBufferIndex)
|
||||
{
|
||||
mBufferIndex=::read(mFileDescriptor,(VPTR)mlpBuffer,MaxInputBuffer);
|
||||
if(!mBufferIndex)return FALSE;
|
||||
mlpBufferPointer=mlpBuffer;
|
||||
}
|
||||
mCurrentChar=*(mlpBufferPointer);
|
||||
mlpBufferPointer++;
|
||||
mBufferIndex--;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
WORD IStream::getWord(void)
|
||||
{
|
||||
if(-1==mFileDescriptor)return FALSE;
|
||||
mCurrentWord=0;
|
||||
if(!getChar())return FALSE;
|
||||
mCurrentWord=mCurrentChar;
|
||||
if(!getChar())return FALSE;
|
||||
mCurrentWord|=((short)mCurrentChar)<<8;
|
||||
return TRUE;
|
||||
}
|
||||
Reference in New Issue
Block a user