Remove/Replace unprintable characters for printing to stdout/log

some chars draw lines etc in Q2's font (conchars.pcx), but aren't
printable in ASCII.
Now they're replaced with equivalent real chars or just spaces.
This commit is contained in:
Daniel Gibson 2017-03-19 19:17:20 +01:00
parent 6b3195e942
commit 2e31ae0ec5

View file

@ -80,12 +80,13 @@ Com_VPrintf(int print_level, const char *fmt, va_list argptr)
}
else
{
int i;
char msg[MAXPRINTMSG];
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
int msgLen = vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
if(msgLen >= MAXPRINTMSG) msgLen = MAXPRINTMSG-1;
if (rd_target)
{
if ((strlen(msg) + strlen(rd_buffer)) > (rd_buffersize - 1))
if ((msgLen + strlen(rd_buffer)) > (rd_buffersize - 1))
{
rd_flush(rd_target, rd_buffer);
*rd_buffer = 0;
@ -99,6 +100,36 @@ Com_VPrintf(int print_level, const char *fmt, va_list argptr)
Con_Print(msg);
#endif
// remove unprintable characters
for(i=0; i<msgLen; ++i)
{
char c = msg[i];
if(c < ' ' && (c < '\t' || c > '\r'))
{
switch(c)
{
// no idea if the following two are ever sent here, but in conchars.pcx they look like this
// so do the replacements.. won't hurt I guess..
case 0x10:
msg[i] = '[';
break;
case 0x11:
msg[i] = ']';
break;
// horizontal line chars
case 0x1D:
case 0x1F:
msg[i] = '-';
break;
case 0x1E:
msg[i] = '=';
break;
default: // just replace all other unprintable chars with space, should be good enough
msg[i] = ' ';
}
}
}
/* also echo to debugging console */
Sys_ConsoleOutput(msg);