libs/vkd3d-common: Add debugstr_a() function.

This commit is contained in:
Józef Kucia 2017-06-16 22:38:21 +02:00
parent 31c6bfe24f
commit 7be0b64a0f
2 changed files with 61 additions and 0 deletions

View File

@ -34,6 +34,7 @@ void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function,
const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4) DECLSPEC_HIDDEN;
const char *vkd3d_dbg_sprintf(const char *fmt, ...) VKD3D_PRINTF_FUNC(1, 2) DECLSPEC_HIDDEN;
const char *debugstr_a(const char *str) DECLSPEC_HIDDEN;
const char *debugstr_w(const WCHAR *wstr) DECLSPEC_HIDDEN;
#define VKD3D_DBG_LOG(level) \

View File

@ -103,6 +103,66 @@ const char *vkd3d_dbg_sprintf(const char *fmt, ...)
return buffer;
}
const char *debugstr_a(const char *str)
{
char *buffer, *ptr;
char c;
if (!str)
return "(null)";
ptr = buffer = get_buffer();
*ptr++ = '"';
while ((c = *str++) && ptr <= buffer + VKD3D_DEBUG_BUFFER_SIZE - 8)
{
int escape_char;
switch (c)
{
case '"':
case '\\':
case '\n':
case '\r':
case '\t':
escape_char = c;
break;
default:
escape_char = 0;
break;
}
if (escape_char)
{
*ptr++ = '\\';
*ptr++ = escape_char;
continue;
}
if (isprint(c))
{
*ptr++ = c;
}
else
{
*ptr++ = '\\';
sprintf(ptr, "%02x", c);
ptr += 2;
}
}
*ptr++ = '"';
if (c)
{
*ptr++ = '.';
*ptr++ = '.';
*ptr++ = '.';
}
*ptr = '\0';
return buffer;
}
const char *debugstr_w(const WCHAR *wstr)
{
char *buffer, *ptr;