Commit 7f84f6ae authored by Dick Hollenbeck's avatar Dick Hollenbeck

Another constructor for FILE_LINE_READER which enables more consistent file...

Another constructor for FILE_LINE_READER which enables more consistent file open strategies, and only call setvbuf() when the file is at position 0
parent 2d1a7e09
...@@ -89,6 +89,27 @@ void LINE_READER::expandCapacity( unsigned newsize ) ...@@ -89,6 +89,27 @@ void LINE_READER::expandCapacity( unsigned newsize )
} }
FILE_LINE_READER::FILE_LINE_READER( const wxString& aFileName,
unsigned aStartingLineNumber,
unsigned aMaxLineLength ) throw( IO_ERROR ) :
LINE_READER( aMaxLineLength ),
iOwn( true )
{
fp = wxFopen( aFileName, wxT( "rt" ) );
if( !fp )
{
wxString msg = wxString::Format(
_( "Unable to open filename '%s' for reading" ), aFileName.GetData() );
THROW_IO_ERROR( msg );
}
setvbuf( fp, NULL, _IOFBF, BUFSIZ * 8 );
source = aFileName;
lineNum = aStartingLineNumber;
}
FILE_LINE_READER::FILE_LINE_READER( FILE* aFile, const wxString& aFileName, FILE_LINE_READER::FILE_LINE_READER( FILE* aFile, const wxString& aFileName,
bool doOwn, bool doOwn,
unsigned aStartingLineNumber, unsigned aStartingLineNumber,
...@@ -97,7 +118,7 @@ FILE_LINE_READER::FILE_LINE_READER( FILE* aFile, const wxString& aFileName, ...@@ -97,7 +118,7 @@ FILE_LINE_READER::FILE_LINE_READER( FILE* aFile, const wxString& aFileName,
iOwn( doOwn ), iOwn( doOwn ),
fp( aFile ) fp( aFile )
{ {
if( doOwn ) if( doOwn && ftell( aFile ) == 0L )
{ {
setvbuf( fp, NULL, _IOFBF, BUFSIZ * 8 ); setvbuf( fp, NULL, _IOFBF, BUFSIZ * 8 );
} }
......
...@@ -308,6 +308,27 @@ protected: ...@@ -308,6 +308,27 @@ protected:
public: public:
/**
* Constructor FILE_LINE_READER
* takes @a aFileName and the size of the desired line buffer and opens
* the file and assumes the obligation to close it.
*
* @param aFileName is the name of the file to open and to use for error reporting purposes.
*
* @param aStartingLineNumber is the initial line number to report on error, and is
* accessible here for the case where multiple DSNLEXERs are reading from the
* same file in sequence, all from the same open file (with @a doOwn = false).
* Internally it is incremented by one after each ReadLine(), so the first
* reported line number will always be one greater than what is provided here.
*
* @param aMaxLineLength is the number of bytes to use in the line buffer.
*
* @throw IO_ERROR if @a aFileName cannot be opened.
*/
FILE_LINE_READER( const wxString& aFileName,
unsigned aStartingLineNumber = 0,
unsigned aMaxLineLength = LINE_READER_LINE_DEFAULT_MAX ) throw( IO_ERROR );
/** /**
* Constructor FILE_LINE_READER * Constructor FILE_LINE_READER
* takes an open FILE and the size of the desired line buffer and takes * takes an open FILE and the size of the desired line buffer and takes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment