This commit is contained in:
2024-08-07 09:16:27 -04:00
parent fdfadd5c7e
commit 5f971cf684
5200 changed files with 731717 additions and 0 deletions

71
gif/ISTREAM.CPP Normal file
View File

@@ -0,0 +1,71 @@
#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;
}