72 lines
1.5 KiB
C++
72 lines
1.5 KiB
C++
#include <gif/istream.hpp>
|
|
|
|
IStream::IStream(void)
|
|
: mFileDescriptor(-1), mCurrentWord(0), mCurrentChar(0), mhGlobalBuffer(0),
|
|
mlpBuffer(0), mBufferIndex(0), mlpBufferPointer(0)
|
|
{
|
|
}
|
|
|
|
IStream::IStream(const char *pathFileName)
|
|
: mFileDescriptor(-1), mCurrentWord(0), mCurrentChar(0), mhGlobalBuffer(0),
|
|
mlpBuffer(0), mBufferIndex(0), mlpBufferPointer(0)
|
|
{
|
|
open(pathFileName);
|
|
}
|
|
|
|
IStream::~IStream()
|
|
{
|
|
close();
|
|
}
|
|
|
|
BOOL IStream::open(const char *pathFileName)
|
|
{
|
|
close();
|
|
if(-1==(mFileDescriptor=::open(pathFileName,O_RDONLY|O_BINARY,0,SH_DENYWR)))return FALSE;
|
|
mhGlobalBuffer=::GlobalAlloc(GMEM_FIXED,MaxInputBuffer);
|
|
if(!mhGlobalBuffer){close();return FALSE;}
|
|
mlpBuffer=(UCHAR FAR *)::GlobalLock(mhGlobalBuffer);
|
|
mlpBufferPointer=0;
|
|
mBufferIndex=0;
|
|
mCurrentChar=0;
|
|
mCurrentWord=0;
|
|
return TRUE;
|
|
}
|
|
|
|
void IStream::close(void)
|
|
{
|
|
if(-1!=mFileDescriptor)::close(mFileDescriptor);
|
|
mFileDescriptor=-1;
|
|
if(mhGlobalBuffer)
|
|
{
|
|
::GlobalUnlock(mhGlobalBuffer);
|
|
::GlobalFree(mhGlobalBuffer);
|
|
mhGlobalBuffer=0;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|