SDL-1.2: checkkeys test: Improve printing of Unicode-Chars

From f3c9cf1a2604b931246439f96b9410316400c377 Mon Sep 17 00:00:00 2001
From: Daniel Gibson <[EMAIL REDACTED]>
Date: Mon, 8 Nov 2021 00:33:30 +0100
Subject: [PATCH] checkkeys test: Improve printing of Unicode-Chars
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

.. at least on platforms that use UTF-8, like modern Linux (Windows
should work as well as before).
Also unified the output to print sth like "'Ä' (0x00C4)", i.e. both the
actual char and the unicode constant, on all platforms.
---
 test/checkkeys.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/test/checkkeys.c b/test/checkkeys.c
index b37da930..2df1d90e 100644
--- a/test/checkkeys.c
+++ b/test/checkkeys.c
@@ -68,13 +68,19 @@ static void PrintKey(SDL_keysym *sym, int pressed)
 			printf(" (^%c)", sym->unicode+'@');
 		} else {
 #ifdef UNICODE
-			printf(" (%c)", sym->unicode);
-#else
+			printf(" '%c' (0x%.4X)", sym->unicode, (int)sym->unicode);
+#elif defined(_WIN32)
 			/* This is a Latin-1 program, so only show 8-bits */
 			if ( !(sym->unicode & 0xFF00) )
-				printf(" (%c)", sym->unicode);
+				printf(" '%c' (0x%.4X)", sym->unicode, (int)sym->unicode);
 			else
-				printf(" (0x%X)", sym->unicode);
+				printf(" (0x%.4X)", (int)sym->unicode);
+#else /* other platforms than Windows hopefully use UTF-8 for 8bit chars */
+			Uint32 utf32str[2] = { sym->unicode, 0 };
+			const char* utf32type = (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "UTF-32LE" : "UTF-32BE";
+			char* utf8str = SDL_iconv_string("UTF-8", utf32type, (const char*)utf32str, 2*4);
+			printf(" '%s' (0x%.4X)", utf8str, (int)sym->unicode);
+			SDL_free(utf8str);
 #endif
 		}
 	}