static int FormatMessage(const char* format, va_list args) { // appends formatted message to sMessage[] int len = ((int)strlen(sMessage)); if (len < 0 ) return -1; if (MAX_MSG_LENGTH-1-len < 2) return -1; sMessage[MAX_MSG_LENGTH-1] = 0; on_vsnprintf(sMessage+len, MAX_MSG_LENGTH-1-len, format, args); return 0; }
void ON_TextLog::Print( const char* format, ... ) { // format message and append it to the log const int MAX_MSG_LENGTH = 2047; char s[MAX_MSG_LENGTH+1]; va_list args; s[0] = 0; if (format) { va_start(args, format); on_vsnprintf( s, MAX_MSG_LENGTH-1, format, args); va_end(args); s[MAX_MSG_LENGTH] = 0; } if ( *s ) { char* s0 = s; char* s1 = s; for ( s1 = s0; *s1; s1++) { if ( *s1 == '\n' ) { *s1 = 0; if ( m_beginning_of_line && m_indent && m_indent[0] ) AppendText( m_indent ); if (*s0) AppendText(s0); AppendText("\n"); m_beginning_of_line = 1; s0 = s1+1; } } if (*s0) { if ( m_beginning_of_line && m_indent && m_indent[0] ) AppendText( m_indent ); AppendText(s0); m_beginning_of_line = 0; } } }
void ON_MSC_CDECL ON_String::Format( const unsigned char* sFormat, ...) { #define MAX_MSG_LENGTH 2048 char sMessage[MAX_MSG_LENGTH]; va_list args; /* put formatted message in sMessage */ memset(sMessage,0,sizeof(sMessage)); if (sFormat) { va_start(args, sFormat); on_vsnprintf(sMessage, MAX_MSG_LENGTH-1, (const char*)sFormat, args); sMessage[MAX_MSG_LENGTH-1] = 0; va_end(args); } const int len = Length(sMessage); if ( len < 1 ) { Destroy(); Create(); } else { ReserveArray( len ); CopyToArray( len, sMessage ); } }