From f92af6098b93f8dae639e7644286ca3fdf81a09a Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Sun, 18 Aug 2024 12:38:11 +0200 Subject: [PATCH] Trace localization entries with unprintable characters to debug output if developer cvar is set to 2 or higher --- Quake/common.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Quake/common.c b/Quake/common.c index fd03cd69c..6ba1a6331 100644 --- a/Quake/common.c +++ b/Quake/common.c @@ -3490,7 +3490,7 @@ LOC_LoadFile qboolean LOC_LoadFile (const char *file) { char path[1024]; - int i,lineno; + int i,lineno,warnings; char *cursor; SDL_RWops *rw = NULL; @@ -3591,6 +3591,7 @@ fail: mz_zip_reader_end(&archive); if ((unsigned char)(cursor[0]) == 0xEF && (unsigned char)(cursor[1]) == 0xBB && (unsigned char)(cursor[2]) == 0xBF) cursor += 3; + warnings = 0; lineno = 0; while (*cursor) { @@ -3701,6 +3702,19 @@ fail: mz_zip_reader_end(&archive); UTF8_ToQuake (value, strlen (value) + 1, value); + // Log entries with unprintable characters if developer is set to 2 or higher + if (developer.value >= 2.f && strchr (value, QCHAR_BOX)) + { + int trim = (int) strlen (value); + // trim trailing newlines + while (trim > 0 && value[trim - 1] == '\n') + --trim; + // print header before first entry + if (!warnings++) + Sys_Printf ("Entries with unprintable characters:\n"); + Sys_Printf (" %d. %s = \"%.*s\"\n", warnings, line, trim, value); + } + entry = &localization.entries[localization.numentries++]; entry->key = line; entry->value = value; @@ -3710,6 +3724,9 @@ fail: mz_zip_reader_end(&archive); *cursor++ = 0; // terminate line and advance to next } + if (developer.value >= 2.f && warnings > 0) + Sys_Printf ("%d strings with unprintable characters\n", warnings); + // hash all entries localization.numindices = localization.numentries * 2; // 50% load factor