this brings back knghtbrd's Sys_Printf redirection, but in such a way that

Sys_Printf still has the format attribute. To redirect Sys_Printf, declare the
redrecting function as void (const char *, va_list) and call Sys_SetPrintf
with this function as its parameter.
This commit is contained in:
Bill Currie 2001-07-05 04:59:43 +00:00
parent b4ac2446a1
commit e5e289e994
2 changed files with 33 additions and 6 deletions

View file

@ -29,6 +29,8 @@
#ifndef __sys_h
#define __sys_h
#include <stdarg.h>
#include "QF/gcc_attr.h"
extern struct cvar_s *sys_nostdout;
@ -36,6 +38,10 @@ extern struct cvar_s *sys_nostdout;
int Sys_FileTime (const char *path);
void Sys_mkdir (const char *path);
typedef void (*sys_printf_t) (const char *fmt, va_list args);
void Sys_SetPrintf (sys_printf_t func);
void Sys_Printf (const char *fmt, ...) __attribute__((format(printf,1,2)));
void Sys_Error (const char *error, ...) __attribute__((format(printf,1,2)));
void Sys_Quit (void);

View file

@ -60,7 +60,10 @@
#include "QF/cvar.h"
#include "QF/sys.h"
static void Sys_StdPrintf (const char *fmt, va_list args);
cvar_t *sys_nostdout;
static sys_printf_t sys_printf_function = Sys_StdPrintf;
/* The translation table between the graphical font and plain ASCII --KB */
static char qfont_table[256] = {
@ -142,12 +145,23 @@ Sys_FileTime (const char *path)
}
/*
Sys_Printf
Sys_SetPrintf
for want of a better name, but it sets the function pointer for the
actual implementation of Sys_Printf.
*/
void
Sys_Printf (const char *fmt, ...)
Sys_SetPrintf (sys_printf_t func)
{
sys_printf_function = func;
}
/*
Sys_Printf
*/
static void
Sys_StdPrintf (const char *fmt, va_list args)
{
va_list argptr;
char msg[MAXPRINTMSG];
unsigned char *p;
@ -155,9 +169,7 @@ Sys_Printf (const char *fmt, ...)
if (sys_nostdout && sys_nostdout->int_val)
return;
va_start (argptr, fmt);
vsnprintf (msg, sizeof (msg), fmt, argptr);
va_end (argptr);
vsnprintf (msg, sizeof (msg), fmt, args);
/* translate to ASCII instead of printing [xx] --KB */
for (p = (unsigned char *) msg; *p; p++)
@ -166,6 +178,15 @@ Sys_Printf (const char *fmt, ...)
fflush (stdout);
}
void
Sys_Printf (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
sys_printf_function (fmt, args);
va_end (argptr);
}
/*
Sys_DoubleTime
*/