Fixed line breaks in verbose test logging output

This commit is contained in:
Sam Lantinga 2017-08-29 23:12:26 -07:00
parent 94e0f3e95b
commit c3d428d402
1 changed files with 70 additions and 55 deletions

View File

@ -32,6 +32,18 @@
#define AUDIO_USAGE \ #define AUDIO_USAGE \
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]" "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
static void SDL_snprintfcat(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ... )
{
size_t length = SDL_strlen(text);
va_list ap;
va_start(ap, fmt);
text += length;
maxlen -= length;
SDL_vsnprintf(text, maxlen, fmt, ap);
va_end(ap);
}
SDLTest_CommonState * SDLTest_CommonState *
SDLTest_CommonCreateState(char **argv, Uint32 flags) SDLTest_CommonCreateState(char **argv, Uint32 flags)
{ {
@ -463,123 +475,123 @@ SDLTest_CommonUsage(SDLTest_CommonState * state)
} }
static void static void
SDLTest_PrintRendererFlag(Uint32 flag) SDLTest_PrintRendererFlag(char *text, size_t maxlen, Uint32 flag)
{ {
switch (flag) { switch (flag) {
case SDL_RENDERER_PRESENTVSYNC: case SDL_RENDERER_PRESENTVSYNC:
SDL_Log("PresentVSync"); SDL_snprintfcat(text, maxlen, "PresentVSync");
break; break;
case SDL_RENDERER_ACCELERATED: case SDL_RENDERER_ACCELERATED:
SDL_Log("Accelerated"); SDL_snprintfcat(text, maxlen, "Accelerated");
break; break;
default: default:
SDL_Log("0x%8.8x", flag); SDL_snprintfcat(text, maxlen, "0x%8.8x", flag);
break; break;
} }
} }
static void static void
SDLTest_PrintPixelFormat(Uint32 format) SDLTest_PrintPixelFormat(char *text, size_t maxlen, Uint32 format)
{ {
switch (format) { switch (format) {
case SDL_PIXELFORMAT_UNKNOWN: case SDL_PIXELFORMAT_UNKNOWN:
SDL_Log("Unknown"); SDL_snprintfcat(text, maxlen, "Unknown");
break; break;
case SDL_PIXELFORMAT_INDEX1LSB: case SDL_PIXELFORMAT_INDEX1LSB:
SDL_Log("Index1LSB"); SDL_snprintfcat(text, maxlen, "Index1LSB");
break; break;
case SDL_PIXELFORMAT_INDEX1MSB: case SDL_PIXELFORMAT_INDEX1MSB:
SDL_Log("Index1MSB"); SDL_snprintfcat(text, maxlen, "Index1MSB");
break; break;
case SDL_PIXELFORMAT_INDEX4LSB: case SDL_PIXELFORMAT_INDEX4LSB:
SDL_Log("Index4LSB"); SDL_snprintfcat(text, maxlen, "Index4LSB");
break; break;
case SDL_PIXELFORMAT_INDEX4MSB: case SDL_PIXELFORMAT_INDEX4MSB:
SDL_Log("Index4MSB"); SDL_snprintfcat(text, maxlen, "Index4MSB");
break; break;
case SDL_PIXELFORMAT_INDEX8: case SDL_PIXELFORMAT_INDEX8:
SDL_Log("Index8"); SDL_snprintfcat(text, maxlen, "Index8");
break; break;
case SDL_PIXELFORMAT_RGB332: case SDL_PIXELFORMAT_RGB332:
SDL_Log("RGB332"); SDL_snprintfcat(text, maxlen, "RGB332");
break; break;
case SDL_PIXELFORMAT_RGB444: case SDL_PIXELFORMAT_RGB444:
SDL_Log("RGB444"); SDL_snprintfcat(text, maxlen, "RGB444");
break; break;
case SDL_PIXELFORMAT_RGB555: case SDL_PIXELFORMAT_RGB555:
SDL_Log("RGB555"); SDL_snprintfcat(text, maxlen, "RGB555");
break; break;
case SDL_PIXELFORMAT_BGR555: case SDL_PIXELFORMAT_BGR555:
SDL_Log("BGR555"); SDL_snprintfcat(text, maxlen, "BGR555");
break; break;
case SDL_PIXELFORMAT_ARGB4444: case SDL_PIXELFORMAT_ARGB4444:
SDL_Log("ARGB4444"); SDL_snprintfcat(text, maxlen, "ARGB4444");
break; break;
case SDL_PIXELFORMAT_ABGR4444: case SDL_PIXELFORMAT_ABGR4444:
SDL_Log("ABGR4444"); SDL_snprintfcat(text, maxlen, "ABGR4444");
break; break;
case SDL_PIXELFORMAT_ARGB1555: case SDL_PIXELFORMAT_ARGB1555:
SDL_Log("ARGB1555"); SDL_snprintfcat(text, maxlen, "ARGB1555");
break; break;
case SDL_PIXELFORMAT_ABGR1555: case SDL_PIXELFORMAT_ABGR1555:
SDL_Log("ABGR1555"); SDL_snprintfcat(text, maxlen, "ABGR1555");
break; break;
case SDL_PIXELFORMAT_RGB565: case SDL_PIXELFORMAT_RGB565:
SDL_Log("RGB565"); SDL_snprintfcat(text, maxlen, "RGB565");
break; break;
case SDL_PIXELFORMAT_BGR565: case SDL_PIXELFORMAT_BGR565:
SDL_Log("BGR565"); SDL_snprintfcat(text, maxlen, "BGR565");
break; break;
case SDL_PIXELFORMAT_RGB24: case SDL_PIXELFORMAT_RGB24:
SDL_Log("RGB24"); SDL_snprintfcat(text, maxlen, "RGB24");
break; break;
case SDL_PIXELFORMAT_BGR24: case SDL_PIXELFORMAT_BGR24:
SDL_Log("BGR24"); SDL_snprintfcat(text, maxlen, "BGR24");
break; break;
case SDL_PIXELFORMAT_RGB888: case SDL_PIXELFORMAT_RGB888:
SDL_Log("RGB888"); SDL_snprintfcat(text, maxlen, "RGB888");
break; break;
case SDL_PIXELFORMAT_BGR888: case SDL_PIXELFORMAT_BGR888:
SDL_Log("BGR888"); SDL_snprintfcat(text, maxlen, "BGR888");
break; break;
case SDL_PIXELFORMAT_ARGB8888: case SDL_PIXELFORMAT_ARGB8888:
SDL_Log("ARGB8888"); SDL_snprintfcat(text, maxlen, "ARGB8888");
break; break;
case SDL_PIXELFORMAT_RGBA8888: case SDL_PIXELFORMAT_RGBA8888:
SDL_Log("RGBA8888"); SDL_snprintfcat(text, maxlen, "RGBA8888");
break; break;
case SDL_PIXELFORMAT_ABGR8888: case SDL_PIXELFORMAT_ABGR8888:
SDL_Log("ABGR8888"); SDL_snprintfcat(text, maxlen, "ABGR8888");
break; break;
case SDL_PIXELFORMAT_BGRA8888: case SDL_PIXELFORMAT_BGRA8888:
SDL_Log("BGRA8888"); SDL_snprintfcat(text, maxlen, "BGRA8888");
break; break;
case SDL_PIXELFORMAT_ARGB2101010: case SDL_PIXELFORMAT_ARGB2101010:
SDL_Log("ARGB2101010"); SDL_snprintfcat(text, maxlen, "ARGB2101010");
break; break;
case SDL_PIXELFORMAT_YV12: case SDL_PIXELFORMAT_YV12:
SDL_Log("YV12"); SDL_snprintfcat(text, maxlen, "YV12");
break; break;
case SDL_PIXELFORMAT_IYUV: case SDL_PIXELFORMAT_IYUV:
SDL_Log("IYUV"); SDL_snprintfcat(text, maxlen, "IYUV");
break; break;
case SDL_PIXELFORMAT_YUY2: case SDL_PIXELFORMAT_YUY2:
SDL_Log("YUY2"); SDL_snprintfcat(text, maxlen, "YUY2");
break; break;
case SDL_PIXELFORMAT_UYVY: case SDL_PIXELFORMAT_UYVY:
SDL_Log("UYVY"); SDL_snprintfcat(text, maxlen, "UYVY");
break; break;
case SDL_PIXELFORMAT_YVYU: case SDL_PIXELFORMAT_YVYU:
SDL_Log("YVYU"); SDL_snprintfcat(text, maxlen, "YVYU");
break; break;
case SDL_PIXELFORMAT_NV12: case SDL_PIXELFORMAT_NV12:
SDL_Log("NV12"); SDL_snprintfcat(text, maxlen, "NV12");
break; break;
case SDL_PIXELFORMAT_NV21: case SDL_PIXELFORMAT_NV21:
SDL_Log("NV21"); SDL_snprintfcat(text, maxlen, "NV21");
break; break;
default: default:
SDL_Log("0x%8.8x", format); SDL_snprintfcat(text, maxlen, "0x%8.8x", format);
break; break;
} }
} }
@ -588,32 +600,34 @@ static void
SDLTest_PrintRenderer(SDL_RendererInfo * info) SDLTest_PrintRenderer(SDL_RendererInfo * info)
{ {
int i, count; int i, count;
char text[1024];
SDL_Log(" Renderer %s:\n", info->name); SDL_Log(" Renderer %s:\n", info->name);
SDL_Log(" Flags: 0x%8.8X", info->flags); SDL_snprintf(text, sizeof(text), " Flags: 0x%8.8X", info->flags);
SDL_Log(" ("); SDL_snprintfcat(text, sizeof(text), " (");
count = 0; count = 0;
for (i = 0; i < sizeof(info->flags) * 8; ++i) { for (i = 0; i < sizeof(info->flags) * 8; ++i) {
Uint32 flag = (1 << i); Uint32 flag = (1 << i);
if (info->flags & flag) { if (info->flags & flag) {
if (count > 0) { if (count > 0) {
SDL_Log(" | "); SDL_snprintfcat(text, sizeof(text), " | ");
} }
SDLTest_PrintRendererFlag(flag); SDLTest_PrintRendererFlag(text, sizeof(text), flag);
++count; ++count;
} }
} }
SDL_Log(")\n"); SDL_snprintfcat(text, sizeof(text), ")");
SDL_Log("%s\n", text);
SDL_Log(" Texture formats (%d): ", info->num_texture_formats); SDL_snprintf(text, sizeof(text), " Texture formats (%d): ", info->num_texture_formats);
for (i = 0; i < (int) info->num_texture_formats; ++i) { for (i = 0; i < (int) info->num_texture_formats; ++i) {
if (i > 0) { if (i > 0) {
SDL_Log(", "); SDL_snprintfcat(text, sizeof(text), ", ");
} }
SDLTest_PrintPixelFormat(info->texture_formats[i]); SDLTest_PrintPixelFormat(text, sizeof(text), info->texture_formats[i]);
} }
SDL_Log("\n"); SDL_Log("%s\n", text);
if (info->max_texture_width || info->max_texture_height) { if (info->max_texture_width || info->max_texture_height) {
SDL_Log(" Max Texture Size: %dx%d\n", SDL_Log(" Max Texture Size: %dx%d\n",
@ -646,6 +660,7 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
{ {
int i, j, m, n, w, h; int i, j, m, n, w, h;
SDL_DisplayMode fullscreen_mode; SDL_DisplayMode fullscreen_mode;
char text[1024];
if (state->flags & SDL_INIT_VIDEO) { if (state->flags & SDL_INIT_VIDEO) {
if (state->verbose & VERBOSE_VIDEO) { if (state->verbose & VERBOSE_VIDEO) {
@ -653,14 +668,14 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
if (n == 0) { if (n == 0) {
SDL_Log("No built-in video drivers\n"); SDL_Log("No built-in video drivers\n");
} else { } else {
SDL_Log("Built-in video drivers:"); SDL_snprintf(text, sizeof(text), "Built-in video drivers:");
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
if (i > 0) { if (i > 0) {
SDL_Log(","); SDL_snprintfcat(text, sizeof(text), ",");
} }
SDL_Log(" %s", SDL_GetVideoDriver(i)); SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetVideoDriver(i));
} }
SDL_Log("\n"); SDL_Log("%s\n", text);
} }
} }
if (SDL_VideoInit(state->videodriver) < 0) { if (SDL_VideoInit(state->videodriver) < 0) {
@ -931,14 +946,14 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
if (n == 0) { if (n == 0) {
SDL_Log("No built-in audio drivers\n"); SDL_Log("No built-in audio drivers\n");
} else { } else {
SDL_Log("Built-in audio drivers:"); SDL_snprintf(text, sizeof(text), "Built-in audio drivers:");
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
if (i > 0) { if (i > 0) {
SDL_Log(","); SDL_snprintfcat(text, sizeof(text), ",");
} }
SDL_Log(" %s", SDL_GetAudioDriver(i)); SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetAudioDriver(i));
} }
SDL_Log("\n"); SDL_Log("%s\n", text);
} }
} }
if (SDL_AudioInit(state->audiodriver) < 0) { if (SDL_AudioInit(state->audiodriver) < 0) {