Another constructor for FILE_LINE_READER which enables more consistent file open strategies, and only call setvbuf() when the file is at position 0
This commit is contained in:
parent
2d1a7e099b
commit
7f84f6aeb1
|
@ -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,
|
||||
bool doOwn,
|
||||
unsigned aStartingLineNumber,
|
||||
|
@ -97,7 +118,7 @@ FILE_LINE_READER::FILE_LINE_READER( FILE* aFile, const wxString& aFileName,
|
|||
iOwn( doOwn ),
|
||||
fp( aFile )
|
||||
{
|
||||
if( doOwn )
|
||||
if( doOwn && ftell( aFile ) == 0L )
|
||||
{
|
||||
setvbuf( fp, NULL, _IOFBF, BUFSIZ * 8 );
|
||||
}
|
||||
|
|
|
@ -308,6 +308,27 @@ protected:
|
|||
|
||||
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
|
||||
* takes an open FILE and the size of the desired line buffer and takes
|
||||
|
|
Loading…
Reference in New Issue