Determine whether or not to newline

Errors/warnings should be newlined, even if engine code doesn't provide it.
This commit is contained in:
Kawe Mazidjatari 2023-05-22 23:17:50 +02:00
parent bafaa1b7de
commit f122e856fb
2 changed files with 21 additions and 7 deletions

View File

@ -168,11 +168,17 @@ void CModAppSystemGroup::InitPluginSystem(CModAppSystemGroup* pModAppSystemGroup
//-----------------------------------------------------------------------------
int HSys_Error_Internal(char* fmt, va_list args)
{
char buffer[2048]{};
char buffer[2048];
Error(eDLL_T::COMMON, NO_ERROR, "_______________________________________________________________\n");
Error(eDLL_T::COMMON, NO_ERROR, "] ENGINE ERROR ################################################\n");
vsprintf(buffer, fmt, args);
Error(eDLL_T::COMMON, NO_ERROR, "%s", buffer);
int nLen = vsprintf(buffer, fmt, args);
bool shouldNewline = true;
if (nLen > 0)
shouldNewline = buffer[nLen - 1] != '\n';
Error(eDLL_T::COMMON, NO_ERROR, shouldNewline ? "%s\n" : "%s", buffer);
///////////////////////////////////////////////////////////////////////////
return Sys_Error_Internal(fmt, args);

View File

@ -29,17 +29,21 @@
void _Error(char* fmt, ...)
{
char buf[4096];
bool shouldNewline = true;
{/////////////////////////////
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
int len = vsnprintf(buf, sizeof(buf), fmt, args);
buf[sizeof(buf) - 1] = '\0';
va_end(args);
if (len > 0)
shouldNewline = buf[len-1] != '\n';
}/////////////////////////////
Error(eDLL_T::ENGINE, NO_ERROR, "%s", buf);
Error(eDLL_T::ENGINE, NO_ERROR, shouldNewline ? "%s\n" : "%s", buf);
v_Error("%s", buf);
}
@ -52,19 +56,23 @@ void _Error(char* fmt, ...)
void _Warning(int level, char* fmt, ...)
{
char buf[10000];
bool shouldNewline = true;
{/////////////////////////////
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
int len = vsnprintf(buf, sizeof(buf), fmt, args);
buf[sizeof(buf) - 1] = '\0';
va_end(args);
if (len > 0)
shouldNewline = buf[len - 1] != '\n';
}/////////////////////////////
if (level < 5)
{
Warning(eDLL_T::COMMON, "Warning(%d):%s", level, buf);
Warning(eDLL_T::COMMON, shouldNewline ? "Warning(%d):%s\n" : "Warning(%d):%s", level, buf);
}
v_Warning(level, "%s", buf);