|
//====================================================================
// Although great care has gone into developing this software,
// it is provided without any guarantee of reliability, accuracy
// of information, or correctness of operation. I am not responsible
// for any damages that may occur as a result of using this software.
// Use this software entirely at your own risk.
// Copyright 2003, Chris Richardson
//
// Description: A CRT FILE* based source stream for lexer input.
//
//====================================================================
#include "stdafx.h"
#include "FILEStream.h"
//////////////////////////////////////////////////////////////////////
// CFILEStream Implementation.
//////////////////////////////////////////////////////////////////////
CFILEStream::CFILEStream()
{
c_pstFile = NULL;
memset( c_szFileName, 0, sizeof( c_szFileName ) );
}
//
// ------------------------------------------------------------------
//
CFILEStream::~CFILEStream()
{
if( c_pstFile )
{
Close();
}
}
//
// ------------------------------------------------------------------
//
ParseStatus CFILEStream::Open( const TCHAR * p_pszPath )
{
if( c_pstFile )
return PARSE_STATUS_FILE_ALREADY_OPEN;
c_pstFile = _tfopen( p_pszPath, _T("rt") );
if( !c_pstFile )
return PARSE_STATUS_FILE_OPEN_FAILED;
_tcscpy( c_szFileName, p_pszPath );
return PARSE_STATUS_OK;
}
//
// ------------------------------------------------------------------
//
ParseStatus CFILEStream::Close()
{
if( !c_pstFile )
return PARSE_STATUS_FILE_NOT_OPEN;
fclose( c_pstFile );
c_pstFile = NULL;
memset( c_szFileName, 0, sizeof( c_szFileName ) );
return PARSE_STATUS_OK;
}
//
// ------------------------------------------------------------------
//
TCHAR CFILEStream::GetC()
{
// Only do debug mode checking here.
assert( c_pstFile );
return _gettc( c_pstFile );
}
//
// ------------------------------------------------------------------
//
TCHAR CFILEStream::UngetC( TCHAR p_cC )
{
// Only do debug mode checking here.
assert( c_pstFile );
return _ungettc( p_cC, c_pstFile );
}
//
// ------------------------------------------------------------------
//
unsigned long CFILEStream::GetPos()
{
fpos_t a_fpPos = 0;
fgetpos( c_pstFile, &a_fpPos );
return (unsigned long)a_fpPos;
}
//
// ------------------------------------------------------------------
//
void CFILEStream::SetPos( unsigned long p_ulPos )
{
fpos_t a_fpPos = (fpos_t)p_ulPos;
fsetpos( c_pstFile, &a_fpPos );
}
//
// ------------------------------------------------------------------
//
TCHAR * CFILEStream::GetS( TCHAR * p_pszStr, int p_iLength )
{
assert( c_pstFile );
return _fgetts( p_pszStr, p_iLength, c_pstFile );
}
//
// ------------------------------------------------------------------
//
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.