mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-21 11:21:52 +00:00
Com_VPrintf(level, fmt, argptr) (Com_D?Printf() wraps that)
somehow all the printf()-like things in Q2 wrap each other and each one prints into a buffer and then calls the next one with ("%s", buf). That's not very clever and kinda annoying. As in the end everyone calls Com_Printf() I created Com_VPrintf() that can be called instead with the va_list. I also added printf-format annotation to Com_Printf() and Com_DPrintf() and fixed places where Com_Printf() was called with the wrong type.
This commit is contained in:
parent
c743aaa8fe
commit
54ae3be0c6
5 changed files with 77 additions and 69 deletions
|
@ -348,7 +348,7 @@ Huff1Decompress(cblock_t in)
|
|||
|
||||
if ((input - in.data != in.count) && (input - in.data != in.count + 1))
|
||||
{
|
||||
Com_Printf("Decompression overread by %i", (input - in.data) - in.count);
|
||||
Com_Printf("Decompression overread by %i", (int)(input - in.data) - in.count);
|
||||
}
|
||||
|
||||
out.count = out_p - out.data;
|
||||
|
|
|
@ -67,6 +67,74 @@ Com_EndRedirect(void)
|
|||
rd_flush = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Both client and server can use this, and it will output
|
||||
* to the apropriate place.
|
||||
*/
|
||||
void
|
||||
Com_VPrintf(int print_level, char *fmt, va_list argptr)
|
||||
{
|
||||
if((print_level == PRINT_DEVELOPER) && (!developer || !developer->value))
|
||||
{
|
||||
return; /* don't confuse non-developers with techie stuff... */
|
||||
}
|
||||
else
|
||||
{
|
||||
char msg[MAXPRINTMSG];
|
||||
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
|
||||
|
||||
if (rd_target)
|
||||
{
|
||||
if ((strlen(msg) + strlen(rd_buffer)) > (rd_buffersize - 1))
|
||||
{
|
||||
rd_flush(rd_target, rd_buffer);
|
||||
*rd_buffer = 0;
|
||||
}
|
||||
|
||||
strcat(rd_buffer, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
Con_Print(msg);
|
||||
#endif
|
||||
|
||||
/* also echo to debugging console */
|
||||
Sys_ConsoleOutput(msg);
|
||||
|
||||
/* logfile */
|
||||
if (logfile_active && logfile_active->value)
|
||||
{
|
||||
char name[MAX_QPATH];
|
||||
|
||||
if (!logfile)
|
||||
{
|
||||
Com_sprintf(name, sizeof(name), "%s/qconsole.log", FS_Gamedir());
|
||||
|
||||
if (logfile_active->value > 2)
|
||||
{
|
||||
logfile = fopen(name, "a");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
logfile = fopen(name, "w");
|
||||
}
|
||||
}
|
||||
|
||||
if (logfile)
|
||||
{
|
||||
fprintf(logfile, "%s", msg);
|
||||
}
|
||||
|
||||
if (logfile_active->value > 1)
|
||||
{
|
||||
fflush(logfile); /* force it to save every time */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Both client and server can use this, and it will output
|
||||
* to the apropriate place.
|
||||
|
@ -75,61 +143,9 @@ void
|
|||
Com_Printf(char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char msg[MAXPRINTMSG];
|
||||
|
||||
va_start(argptr, fmt);
|
||||
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
|
||||
Com_VPrintf(PRINT_ALL, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
if (rd_target)
|
||||
{
|
||||
if ((strlen(msg) + strlen(rd_buffer)) > (rd_buffersize - 1))
|
||||
{
|
||||
rd_flush(rd_target, rd_buffer);
|
||||
*rd_buffer = 0;
|
||||
}
|
||||
|
||||
strcat(rd_buffer, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
Con_Print(msg);
|
||||
#endif
|
||||
|
||||
/* also echo to debugging console */
|
||||
Sys_ConsoleOutput(msg);
|
||||
|
||||
/* logfile */
|
||||
if (logfile_active && logfile_active->value)
|
||||
{
|
||||
char name[MAX_QPATH];
|
||||
|
||||
if (!logfile)
|
||||
{
|
||||
Com_sprintf(name, sizeof(name), "%s/qconsole.log", FS_Gamedir());
|
||||
|
||||
if (logfile_active->value > 2)
|
||||
{
|
||||
logfile = fopen(name, "a");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
logfile = fopen(name, "w");
|
||||
}
|
||||
}
|
||||
|
||||
if (logfile)
|
||||
{
|
||||
fprintf(logfile, "%s", msg);
|
||||
}
|
||||
|
||||
if (logfile_active->value > 1)
|
||||
{
|
||||
fflush(logfile); /* force it to save every time */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -139,18 +155,9 @@ void
|
|||
Com_DPrintf(char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char msg[MAXPRINTMSG];
|
||||
|
||||
if (!developer || !developer->value)
|
||||
{
|
||||
return; /* don't confuse non-developers with techie stuff... */
|
||||
}
|
||||
|
||||
va_start(argptr, fmt);
|
||||
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
|
||||
Com_VPrintf(PRINT_DEVELOPER, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
Com_Printf("%s", msg);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -849,7 +849,7 @@ Cmd_CompleteCommand(char *partial)
|
|||
/* Sort it */
|
||||
qsort(pmatch, i, sizeof(pmatch[0]), qsort_strcomp);
|
||||
|
||||
Com_Printf("\n\n", partial);
|
||||
Com_Printf("\n\n");
|
||||
|
||||
for (o = 0; o < i; o++)
|
||||
{
|
||||
|
|
|
@ -745,7 +745,7 @@ FS_LoadPAK(const char *packPath)
|
|||
pack->numFiles = numFiles;
|
||||
pack->files = files;
|
||||
|
||||
Com_Printf("Added packfile '%s' (%i files).\n", pack, numFiles);
|
||||
Com_Printf("Added packfile '%s' (%i files).\n", pack->name, numFiles);
|
||||
|
||||
return pack;
|
||||
}
|
||||
|
@ -816,7 +816,7 @@ FS_LoadPK3(const char *packPath)
|
|||
pack->numFiles = numFiles;
|
||||
pack->files = files;
|
||||
|
||||
Com_Printf("Added packfile '%s' (%i files).\n", pack, numFiles);
|
||||
Com_Printf("Added packfile '%s' (%i files).\n", pack->name, numFiles);
|
||||
|
||||
return pack;
|
||||
}
|
||||
|
|
|
@ -709,8 +709,9 @@ void FS_CreatePath(char *path);
|
|||
|
||||
void Com_BeginRedirect(int target, char *buffer, int buffersize, void (*flush));
|
||||
void Com_EndRedirect(void);
|
||||
void Com_Printf(char *fmt, ...);
|
||||
void Com_DPrintf(char *fmt, ...);
|
||||
void Com_Printf(char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
void Com_DPrintf(char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
void Com_VPrintf(int print_level, char *fmt, va_list argptr); /* print_level is PRINT_ALL or PRINT_DEVELOPER */
|
||||
void Com_MDPrintf(char *fmt, ...);
|
||||
void Com_Error(int code, char *fmt, ...);
|
||||
void Com_Quit(void);
|
||||
|
|
Loading…
Reference in a new issue