33 #if !defined( HAVE_FGETC_NOLOCK ) 34 #define getc_unlocked getc 38 static int vprint( std::string* result,
const char* format, va_list ap )
49 size_t len = vsnprintf( msg,
sizeof(msg), format, ap );
51 if( len <
sizeof(msg) )
53 result->append( msg, msg + len );
60 std::vector<char> buf;
63 len = vsnprintf( &buf[0], len+1, format, tmp );
65 result->append( &buf[0], &buf[0] + len );
74 int StrPrintf( std::string* result,
const char* format, ... )
78 va_start( args, format );
79 int ret =
vprint( result, format, args );
91 va_start( args, format );
92 int ignore =
vprint( &ret, format, args );
103 m_length( 0 ), m_lineNum( 0 ), m_line( NULL ),
104 m_capacity( 0 ), m_maxLineLength( aMaxLineLength )
106 if( aMaxLineLength != 0 )
159 unsigned aStartingLineNumber,
unsigned aMaxLineLength ):
162 m_fp = wxFopen( aFileName, wxT(
"rt" ) );
167 _(
"Unable to open filename \"%s\" for reading" ), aFileName.GetData() );
178 unsigned aStartingLineNumber,
179 unsigned aMaxLineLength ) :
230 m_lines( aString ), m_ndx( 0 )
255 if( nlOffset == std::string::npos )
336 if( strlen( wrapee ) == 0 )
341 for( ; *wrapee; ++wrapee, isFirst = false )
343 static const char quoteThese[] =
"\t ()" 350 if( strchr( quoteThese, *wrapee ) )
353 if( !isFirst &&
'-' == *wrapee )
363 return GetQuoteChar( wrapee, quoteChar );
375 int ret = vsnprintf( &m_buffer[0], m_buffer.size(), fmt, ap );
377 if( ret >= (
int) m_buffer.size() )
379 m_buffer.resize( ret + 1000 );
380 ret = vsnprintf( &m_buffer[0], m_buffer.size(), fmt, tmp );
386 write( &m_buffer[0], ret );
396 va_start( args, fmt );
397 int ret =
vprint( fmt, args);
410 va_start( args, fmt );
415 for(
int i=0;
i<nestLevel; ++
i )
418 result = sprint(
"%*c",
NESTWIDTH,
' ' );
424 result =
vprint( fmt, args );
435 static const char quoteThese[] =
"\t ()\n\r";
437 if( !aWrapee.size() ||
440 aWrapee.find_first_of( quoteThese ) != std::string::npos )
444 ret.reserve( aWrapee.size()*2 + 2 );
448 for( std::string::const_iterator it = aWrapee.begin(); it!=aWrapee.end(); ++it )
489 return Quotes( (
const char*) aWrapee.utf8_str() );
497 m_mystring.append( aOutBuf, aCount );
502 std::string copy = m_mystring;
506 for( std::string::iterator
i=copy.begin();
i!=copy.end(); ++
i )
508 if( !isspace( *
i ) && *
i!=
')' && *
i!=
'(' && *
i!=
'"' )
518 const wxChar* aMode,
char aQuoteChar ):
520 m_filename( aFileName )
522 m_fp = wxFopen( aFileName, aMode );
527 _(
"cannot open or save file \"%s\"" ),
543 if( 1 != fwrite( aOutBuf, aCount, 1,
m_fp ) )
546 _(
"error writing to file \"%s\"" ),
561 for(
int total = 0; total<aCount; total += lastWrite )
563 lastWrite = m_os.Write( aOutBuf, aCount ).LastWrite();
567 THROW_IO_ERROR( _(
"OUTPUTSTREAM_OUTPUTFORMATTER write error" ) );
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
#define LINE_READER_LINE_INITIAL_SIZE
char * m_line
the read line of UTF8 text
~FILE_LINE_READER()
Destructor may or may not close the open file, depending on doOwn in constructor. ...
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
int StrPrintf(std::string *result, const char *format,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
unsigned m_capacity
no. bytes allocated for line.
void expandCapacity(unsigned aNewsize)
Function expandCapacity will expand the capacity of line up to maxLineLength but not greater...
#define LINE_READER_LINE_DEFAULT_MAX
#define OUTPUTFMTBUFZ
default buffer size for any OUTPUT_FORMATTER
LINE_READER(unsigned aMaxLineLength=LINE_READER_LINE_DEFAULT_MAX)
Constructor LINE_READER builds a line reader and fixes the length of the maximum supported line lengt...
wxString m_source
origin of text lines, e.g. filename or "clipboard"
FILE * m_fp
I may own this file, but might not.
FILE_LINE_READER(const wxString &aFileName, unsigned aStartingLineNumber=0, unsigned aMaxLineLength=LINE_READER_LINE_DEFAULT_MAX)
Constructor FILE_LINE_READER takes aFileName and the size of the desired line buffer and opens the fi...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
static int vprint(std::string *result, const char *format, va_list ap)
bool m_iOwn
if I own the file, I'll promise to close it, else not.
unsigned m_length
no. bytes in line before trailing nul.
Class STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
#define THROW_IO_ERROR(msg)
STRING_LINE_READER(const std::string &aString, const wxString &aSource)
Constructor STRING_LINE_READER( const std::string&, const wxString& )
unsigned m_maxLineLength
maximum allowed capacity using resizing.