Exemple #1
0
	void Write(const char *fmt, ...)
	{
#ifdef OM_TRACE_ENABLE
		va_list ap;
		va_start(ap, fmt);
		const int SIZ = 10*1024;
		char buf[SIZ];
#ifdef WIN32
		vsnprintf_s(buf, SIZ, SIZ, fmt, ap);
#else
		vsprintf(buf, fmt, ap);
#endif
		DebugWrite(buf);
#endif

	}
void IOConsole::Error(const char *formatString, ...)
{
	va_list ap;
	va_start(ap, formatString);

	char buffer[MAX_STRING_LENGTH];
	vsnprintf_s(buffer, MAX_STRING_LENGTH, MAX_STRING_LENGTH-1, formatString, ap);

	SetConsoleTextAttribute(m_hOutput, FOREGROUND_RED | FOREGROUND_INTENSITY);
	(*this) << buffer;
	SetConsoleTextAttribute(m_hOutput, FOREGROUND_RED | FOREGROUND_BLUE 
		| FOREGROUND_GREEN | FOREGROUND_INTENSITY);

	va_end(ap);
	//		assert(0);
}
int MyMeshText::CreateStringColorAndShadow(bool concat, float fontheight, float x, float y, unsigned char justificationflags, ColorByte color, ColorByte shadowcolor, float shadowoffx, float shadowoffy, Vector2 size, const char* text, ...)
{
    const char* stringtodraw = text;
    if( g_pLanguageTable != 0 && text[0] == '.' )
        stringtodraw = g_pLanguageTable->LookUp( text );

    char* tempbuffer = g_pRTQGlobals->m_TempBuffer;
    va_list arg;
    va_start( arg, text );
    vsnprintf_s( tempbuffer, sizeof(g_pRTQGlobals->m_TempBuffer), _TRUNCATE, stringtodraw, arg );
    va_end(arg);
    
    CreateString( concat, fontheight, x+shadowoffx, y+shadowoffy, 0, 0, justificationflags, shadowcolor, size, tempbuffer );
    concat = true;
    return CreateString( concat, fontheight, x, y, 0, 0, justificationflags, color, size, tempbuffer );
}
void CCALL	WriteReport_Alert (const char* format, ...)
{
	char		buffer [512];
	va_list		argList;

	va_start (argList, format);
#if defined (macintosh)
	vsnprintf (buffer, sizeof (buffer), format, argList);
#else
	vsnprintf_s (buffer, sizeof (buffer), _TRUNCATE, format, argList);
#endif

	ACAPI_WriteReport (buffer, true);

	return;
}		// WriteReport_Alert
Exemple #5
0
CMethodLogger::CMethodLogger(const char* aFile, const char* aFunction, const std::string& aMessage, int aLine, ...)
 : iFile(aFile), iFunction(aFunction), iLine(aLine)
{
   // Assemble the user-generated message
   std::string msg = std::string(">> ENTRY: ") + aMessage;
   char buffer[510];
   va_list args;
   va_start(args, aLine);
#ifdef AK_SYSTEM_WINDOWS
   vsnprintf_s(buffer, 500, _TRUNCATE, msg.c_str(), args);
#else
   vsnprintf(buffer, 500, msg.c_str(), args);
#endif
   va_end(args);
   LogAppend(ELogLevel::EDEBUG, iFile, iFunction, buffer, iLine);
}
int LOG_ALT(const char *fmt,...)
{
	char buf[102400];
	int len = sizeof(buf)-1;
	int xlen = 0;
    iop_log_service_t *log = g_iop_log_service;
    struct tm t;
	int level = IOP_LOG_ALERT;
    time_t n ;
	int r;
	if(log && (level > log->log_level))
    {
        return -1;
    }
	buf[len] = 0;
	n= time(NULL);
	#ifdef WIN32
		localtime_s(&t,&n);
		r = _snprintf_s(buf,len, len,"[ALT %02d:%02d:%02d] ", 
                t.tm_hour,t.tm_min, t.tm_sec);
	#else
		t = *localtime(&n);
	    r = snprintf(buf,len, "[ALT %02d:%02d:%02d] ", 
                t.tm_hour,t.tm_min, t.tm_sec);
	#endif
	{
	va_list ap;
    va_start(ap, fmt);

#ifdef WIN32
	xlen = vsnprintf_s((char *)buf+r,len-r,len-r, fmt, ap);
#else
	xlen = vsnprintf((char *)buf+r,len-r, fmt, ap);
#endif
	va_end(ap);
	}
    if(xlen + r > len)
    {
        r = len;
    }
    else
    {
        r += xlen;
    }
    return iop_log_write(log,buf, r);

}
Exemple #7
0
      static int
      format(char* str, size_t size, const char* format, ...)
      {
        std::va_list ap;
        va_start(ap, format);

#if defined(DUNE_SYS_HAS_VSNPRINTF)
        int rv = vsnprintf(str, size, format, ap);
#elif defined(DUNE_SYS_HAS_VSNPRINTF_S)
        int rv = vsnprintf_s(str, size, size - 1, format, ap);
#else
        int rv = std::vsprintf(str, format, ap);
#endif

        va_end(ap);
        return rv;
      }
/// @par
///
/// Example:
/// @code
/// // Where ctx is an instance of rcContext and filepath is a char array.
/// ctx->log(RC_LOG_ERROR, "buildTiledNavigation: Could not load '%s'", filepath);
/// @endcode
void rcContext::log(const rcLogCategory category, const char* format, ...)
{
    if (!m_logEnabled)
        return;
    static const int MSG_SIZE = 512;
    char msg[MSG_SIZE];
    va_list ap;
    va_start(ap, format);
    int len = vsnprintf_s(msg, MSG_SIZE, format, ap);
    if (len >= MSG_SIZE)
    {
        len = MSG_SIZE-1;
        msg[MSG_SIZE-1] = '\0';
    }
    va_end(ap);
    doLog(category, msg, len);
}
int MyMeshText::CreateStringColorShadowStyleZAndRot(bool concat, float fontheight, float x, float y, float z, float rotz, unsigned char justificationflags, ColorByte color, TextShadowStyles shadowstyle, ColorByte shadowcolor, float shadowoffx, float shadowoffy, Vector2 size, const char* text, ...)
{
    const char* stringtodraw = text;
    if( g_pLanguageTable != 0 && text[0] == '.' )
        stringtodraw = g_pLanguageTable->LookUp( text );

    char* tempbuffer = g_pRTQGlobals->m_TempBuffer;
    va_list arg;
    va_start( arg, text );
    vsnprintf_s( tempbuffer, sizeof(g_pRTQGlobals->m_TempBuffer), _TRUNCATE, stringtodraw, arg );
    va_end(arg);
    
    if( shadowstyle == TextShadowStyle_None )
    {
    }
    else if( shadowstyle == TextShadowStyle_Single )
    {
        CreateString( concat, fontheight, x+shadowoffx, y+shadowoffy, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
    }
    else if( shadowstyle == TextShadowStyle_Quad )
    {
        CreateString( concat, fontheight, x+shadowoffx, y+shadowoffy, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
        concat = true;
        CreateString( concat, fontheight, x-shadowoffy, y+shadowoffx, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
        CreateString( concat, fontheight, x-shadowoffx, y-shadowoffy, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
        CreateString( concat, fontheight, x+shadowoffy, y-shadowoffx, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
    }
    else if( shadowstyle == TextShadowStyle_OctPlusPlus )
    {
        CreateString( concat, fontheight, x+shadowoffx, y+shadowoffy, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
        concat = true;
        CreateString( concat, fontheight, x-shadowoffy, y+shadowoffx, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
        CreateString( concat, fontheight, x-shadowoffx, y-shadowoffy, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
        CreateString( concat, fontheight, x+shadowoffy, y-shadowoffx, z, rotz, justificationflags, shadowcolor, size, tempbuffer );

        CreateString( concat, fontheight, x           , y+shadowoffy, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
        CreateString( concat, fontheight, x-shadowoffx, y           , z, rotz, justificationflags, shadowcolor, size, tempbuffer );
        CreateString( concat, fontheight, x           , y-shadowoffy, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
        CreateString( concat, fontheight, x+shadowoffx, y           , z, rotz, justificationflags, shadowcolor, size, tempbuffer );

        CreateString( concat, fontheight, x+shadowoffx*2, y+shadowoffy*2, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
        CreateString( concat, fontheight, x+shadowoffx*3, y+shadowoffy*3, z, rotz, justificationflags, shadowcolor, size, tempbuffer );
    }

    return CreateString( concat, fontheight, x, y, z, rotz, justificationflags, color, size, tempbuffer );
}
Exemple #10
0
void log(const char * pszFormat, ...)
{
    char szBuf[MAX_LEN];

    va_list ap;
    va_start(ap, pszFormat);
    vsnprintf_s(szBuf, MAX_LEN, MAX_LEN, pszFormat, ap);
    va_end(ap);

    WCHAR wszBuf[MAX_LEN] = {0};
    MultiByteToWideChar(CP_UTF8, 0, szBuf, -1, wszBuf, sizeof(wszBuf));
    OutputDebugStringW(wszBuf);
    OutputDebugStringA("\n");

    WideCharToMultiByte(CP_ACP, 0, wszBuf, sizeof(wszBuf), szBuf, sizeof(szBuf), NULL, FALSE);
    printf("%s\n", szBuf);
}
// [v]snprintf on Windows only matches C99 when no errors or overflow.
int pn_i_vsnprintf(char *buf, size_t count, const char *fmt, va_list ap) {
  if (fmt == NULL)
    return -1;
  if ((buf == NULL) && (count > 0))
    return -1;
  if (count > 0) {
    int n = vsnprintf_s(buf, count, _TRUNCATE, fmt, ap);
    if (n >= 0)  // no overflow
      return n;  // same as C99
    buf[count-1] = '\0';
  }
  // separate call to get needed buffer size on overflow
  int n = _vscprintf(fmt, ap);
  if (n >= (int) count)
    return n;
  return -1;
}
Exemple #12
0
	void Trace(const char * msg, ...)
	{
		if( s_Enable )
		{
			EnterCriticalSection(&logCS);

			static char buffer[BUFFER_SIZE] = {0,};
			va_list args;
			va_start(args, msg);
			vsnprintf_s(buffer, BUFFER_SIZE, BUFFER_SIZE-1, msg, args);
			va_end(args);
			
			cout << buffer << endl;

			LeaveCriticalSection(&logCS);
		}
	}
Exemple #13
0
	////////////////////// func. /////////////////////
	void JString::Format(const char* format, ...)
	{
		va_list vlist;

		char* pTempBuf = new char[JSTRING_BUFFER_MAX + 1];
		pTempBuf[0] = NULL;

		va_start(vlist, format);
		vsnprintf_s(pTempBuf, JSTRING_BUFFER_MAX + 1, JSTRING_BUFFER_MAX, format, vlist);
		va_end(vlist);

		Release();
		Init(strlen(pTempBuf));

		strncpy_s(pBuffer, nLength + 1, pTempBuf, nLength);
		delete[] pTempBuf;
	}
Exemple #14
0
void log(const char* text, ...)
{
	const int BUFFER_SIZE = 1024;
	char buffer[BUFFER_SIZE];

	va_list ap;
	va_start(ap, text);
	vsnprintf_s(buffer, BUFFER_SIZE, BUFFER_SIZE, text, ap);
	va_end(ap);

	FILE *outfile;
	if (fopen_s(&outfile, "bwapi-data\\logs\\BWSAL.log", "a+")==0)
	{
		fprintf_s(outfile, buffer);
		fclose(outfile);
	}
}
void NCLDebug::DrawTextWsNDT(const Vector3& pos, const float font_size, const TextAlignment alignment, const Vector4 colour, const string text, ...)
{
	va_list args;
	va_start(args, text);

	char buf[1024];
	int needed = vsnprintf_s(buf, 1023, _TRUNCATE, text.c_str(), args);
	va_end(args);

	int length = (needed < 0) ? 1024 : needed;

	std::string formatted_text = std::string(buf, (size_t)length);

	Vector4 cs_pos = m_ProjViewMtx * Vector4(pos.x, pos.y, pos.z, 1.0f);
	cs_pos.z = 1.0f * cs_pos.w;
	DrawTextCs(cs_pos, font_size, formatted_text, alignment, colour);
}
Exemple #16
0
void CLogFile::Printf(const char * szFormat, ...)
{
	// Lock the mutex
	m_mutex.TryLock(1);

	// Collect the arguments
	va_list vaArgs;
	char szBuffer[2048];
	va_start(vaArgs, szFormat);
	vsnprintf_s(szBuffer, sizeof(szBuffer), szFormat, vaArgs);
	va_end(vaArgs);

	// Print the message
	Print(szBuffer);

	// Unlock the mutex
	m_mutex.Unlock();
}
int debugPrintf( const char *format, ... )
	{
	va_list argPtr;
	char buffer[ 1024 ];
	int length;

	va_start( argPtr, format );

#if VC_GE_2005( _MSC_VER )
	length = vsnprintf_s( buffer, 1024, _TRUNCATE, format, argPtr );
#else
	length = vsprintf( buffer, format, argPtr );
#endif /* VC++ 2005 or newer */
	va_end( argPtr );
	OutputDebugString( buffer );

	return( length );
	}
Exemple #18
0
int
flac_snprintf(char *str, size_t size, const char *fmt, ...)
{
	va_list va;
	int rc ;

	va_start (va, fmt);

#ifdef _MSC_VER
	rc = vsnprintf_s (str, size, _TRUNCATE, fmt, va);
	rc = (rc > 0) ? rc : (size == 0 ? 1024 : size * 2);
#else
	rc = vsnprintf (str, size, fmt, va);
#endif
	va_end (va);

	return rc;
}
		AssertBehavior ReportFailure(const char* condition, const char* file, int line, const char* msg, ...)
		{
			const char* message = nullptr;
			if (msg != nullptr)
			{
				char messageBuffer[1024];
				{
					va_list args;
					va_start(args, msg);
					vsnprintf_s(messageBuffer, 1024, msg, args);
					va_end(args);
				}

				message = messageBuffer;
			}

			return DefaultAssertHandler(condition, message, file, line);
		}
Exemple #20
0
void die(char * message,...)
{
    char    buf[1024];
    va_list args;

    va_start(args, message);
#if defined(SAFESTR)
    vsnprintf_s(buf, sizeof(buf), sizeof(buf) - 1, message, args);
#else
    _vsnprintf(buf, sizeof(buf), message, args);
#endif
    fprintf(stderr, "%s\n", buf);
    if (g_log)
    {
        g_log->Log(0, "die", buf);
    }
    my_exit(1);
}
Exemple #21
0
      static std::string
      str(const char* format, ...)
      {
        char bfr[1024] = {0};
        std::va_list ap;
        va_start(ap, format);

#if defined(DUNE_SYS_HAS_VSNPRINTF)
        vsnprintf(bfr, sizeof(bfr), format, ap);
#elif defined(DUNE_SYS_HAS_VSNPRINTF_S)
        vsnprintf_s(bfr, sizeof(bfr), sizeof(bfr) - 1, format, ap);
#else
        std::vsprintf(bfr, format, ap);
#endif
        va_end(ap);

        return bfr;
      }
static
int local_vsnprintf(char *str, size_t size, const char *fmt, va_list va)
{
	int rc;

#if defined _MSC_VER
	if (size == 0)
		return 1024;
	rc = vsnprintf_s (str, size, _TRUNCATE, fmt, va);
	if (rc < 0)
		rc = size - 1;
#elif defined __MINGW32__
	rc = __mingw_vsnprintf (str, size, fmt, va);
#else
	rc = vsnprintf (str, size, fmt, va);
#endif

	return rc;
}
Exemple #23
0
void vClient::SendSystem( char* szStr, ... )
{
	static const Address addrCall = 0x00494910;

	char szBuff[512] = {0,};
	va_list arg;
	va_start(arg, szStr);
	vsnprintf_s(szBuff, 512, szStr, arg);
	va_end(arg);

	__asm
	{
		lea		ecx, szBuff;
		push	ecx;

		mov		ecx, addrCoreClient;
		call	addrCall;
	}
}
Exemple #24
0
internal
void writeFileLine(file_t* file, const char* format, ...)
{
	char line[512];
	va_list args;
	va_start(args, format);
	vsnprintf_s(line, sizeof(line), _TRUNCATE, format, args);
	va_end(args);

	char* write = line;
	while (*write)
		write++;

	*(write++) = '\r';
	*(write++) = '\n';
	*(write++) = 0;

	file_write(file, line);
}
Exemple #25
0
internal
void writeFileKeyValue(file_t* file, const char* key, const char* valueFormat, ...)
{
	char value[256];
	char line[512];
	va_list args;
	va_start(args, valueFormat);
	vsnprintf_s(value, sizeof(value), _TRUNCATE, valueFormat, args);
	va_end(args);

	char* write = str_append(line, key);
	*(write++) = '=';
	write = str_append(write, value);
	*(write++) = '\r';
	*(write++) = '\n';
	*(write++) = 0;

	file_write(file, line);
}
Exemple #26
0
void EbrDebugLogShim(const char* format, ...) {
#ifdef _DEBUG
    va_list va;

    va_start(va, format);
    char buf[c_bufferCount];
    int len = vsnprintf_s(buf, _countof(buf), _TRUNCATE, format, va);
    va_end(va);

    // Trim off newline for EBR debug.
    if ((len > 0) && (len < (c_bufferCount - 1)) && (buf[len - 1] == '\n')) {
        buf[len - 1] = '\0';
    }
    wchar_t wbuf[c_bufferCount];
    size_t wlen;
    mbstowcs_s(&wlen, wbuf, _countof(wbuf), buf, _TRUNCATE);
    TraceVerbose(L"EbrDebugLog", wbuf);
#endif
}
Exemple #27
0
void LogError ( const char* traceStr, ... )
{
	va_list argsVA;
	const int logSize = 4096;
	char buffer[logSize];
	memset ( (void*)buffer, 0, logSize );

	va_start ( argsVA, traceStr );
#ifdef WIN32
	vsnprintf_s( buffer, logSize, logSize, traceStr, argsVA );
#else
	vsnprintf( buffer, logSize, traceStr, argsVA );
#endif
	va_end( argsVA );
	LogMsg("ERROR: %s", buffer);

	GetBaseApp()->SetConsoleVisible(true); //make sure we see the error
	//assert(!"Got an error, your majesty...");
}
sText::sText(std::string Fontfile, unsigned int size, const char *fmt, ...)
{
	char text[1024];
	va_list ap;

	if(fmt == NULL) return;

	va_start(ap, fmt);
	vsnprintf_s(text,1024,1024, fmt, ap);
	va_end(ap);

	FontObject.loadFromFile(std::string("Media/").append(Fontfile));
	
	textObject.setFont(FontObject);
	
	textObject.setCharacterSize(size);

	textObject.setString(text);
}
	void write(const char* format, ...)
	{
		if (fh.isValidFile() == false)
			return;

		size_t size = 512;
		char* temp = NULL;

		va_list arglist;
		va_start( arglist, format );

		int res = 0;
		do
		{
			size *= 2;
			
			if (temp)
				delete [] temp;

			temp = new char[size];
			
#ifdef WIN32
			res = vsnprintf_s(temp, size, _TRUNCATE, format, arglist);
#else
			res = vsnprintf(temp, size, format, arglist);
#endif
		}
#ifdef WIN32
		while (res == -1);
#else
		while ((size_t)res > size);
#endif
		
		va_end( arglist );

		try
		{
			fh.write(temp, res);
		}
		catch (...)
		{
		}
	}
//-----------------------------------------------------------------------------------------------
void DebuggerPrintf( const char* messageFormat, ... )
{
	const int MESSAGE_MAX_LENGTH = 2048;
	char messageLiteral[ MESSAGE_MAX_LENGTH ];
	va_list variableArgumentList;
	va_start( variableArgumentList, messageFormat );
	vsnprintf_s( messageLiteral, MESSAGE_MAX_LENGTH, _TRUNCATE, messageFormat, variableArgumentList );
	va_end( variableArgumentList );
	messageLiteral[ MESSAGE_MAX_LENGTH - 1 ] = '\0'; // In case vsnprintf overran (doesn't auto-terminate)

#if defined( PLATFORM_WINDOWS )
	if( IsDebuggerAvailable() )
	{
		OutputDebugStringA( messageLiteral );
	}
#endif

	std::cout << messageLiteral;
}