mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
libs/vkd3d-common: Add debugstr_a() function.
This commit is contained in:
parent
31c6bfe24f
commit
7be0b64a0f
@ -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) \
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user