Skip to content

Commit

Permalink
Trace localization entries with unprintable characters
Browse files Browse the repository at this point in the history
to debug output if developer cvar is set to 2 or higher
  • Loading branch information
andrei-drexler committed Aug 18, 2024
1 parent e8b7963 commit f92af60
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Quake/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit f92af60

Please sign in to comment.