Skip to content

Commit

Permalink
proper skip of text coloring codes in terminal/debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-lysiuk committed Nov 15, 2023
1 parent 480e749 commit e9da5e0
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions Quake/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,9 @@ Handles cursor positioning, line wrapping, etc

static const char* Con_ToAscii(const char *message)
{
// '\xFF' means skip this character
static const char translate[] =
".\1\2.......\n. .."
"\0\xFF\xFF.......\n. .."
"[]0123456789.-=-"
" !\"#$%&'()*+,-./"
"0123456789:;<=>?"
Expand All @@ -510,18 +511,24 @@ static const char* Con_ToAscii(const char *message)
"pqrstuvwxyz{|}~.";

static char ascii[MAXPRINTMSG];
char* asciiptr = ascii;

for (size_t i = 0; i < MAXPRINTMSG; ++i)
for (const char* ch = message; ; ++ch)
{
unsigned char ch = message[i];
if (asciiptr - ascii == MAXPRINTMSG - 1)
break; // ascii array must remain null-terminated

if (ch == '\0')
{
ascii[i] = '\0';
break;
}
unsigned char oldch = *ch;
char newch = translate[oldch];

ascii[i] = translate[ch];
if (newch == '\xFF')
continue;

*asciiptr = newch;
++asciiptr;

if (oldch == '\0')
break;
}

return ascii;
Expand Down

0 comments on commit e9da5e0

Please sign in to comment.