Constified Con_DebugLog, Con_Print, Con_Printf, Con_Warning, Con_DPrintf,

Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, Con_LogCenterPrint,
Con_NotifyBox, PL_ErrorDialog, PR_RunError, Host_EndGame, Host_Error,
SV_ClientPrintf, SV_BroadcastPrintf, Host_ClientCommands, Sys_DebugLog,
Sys_Error, Sys_Printf, BOPS_Error and va. Added noreturn attribute to
Sys_Error, Sys_Quit, BOPS_Error, PR_RunError, Host_EndGame and Host_Error.
Added format printf attribute to Con_DebugLog, Con_Printf, Con_Warning,
Con_DPrintf, Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, PL_ErrorDialog,
PR_RunError, Host_EndGame, Host_Error, SV_ClientPrintf, SV_BroadcastPrintf,
Host_ClientCommands, Sys_DebugLog, Sys_Error, Sys_Printf and va. Adjusted
Host_Status_f and NET_Ban_f for the new attributes. Fixed broken format
strings in Con_Dump_f, Mod_LoadTexinfo, PR_AllocStringSlots and FloorDivMod.
Defined __attribute__ macros in quakedef.h so that we don't break non-gcc
compilers.


git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@154 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2010-04-26 16:30:40 +00:00
parent 268b5a3e90
commit 5bd3fccecd
20 changed files with 82 additions and 67 deletions

View file

@ -1281,7 +1281,7 @@ static char *get_va_buffer(void)
return va_buffers[buffer_idx];
}
char *va(char *format, ...)
char *va (const char *format, ...)
{
va_list argptr;
char *va_buf;

View file

@ -164,7 +164,7 @@ void COM_FileBase (char *in, char *out);
void COM_DefaultExtension (char *path, char *extension);
void COM_CreatePath (char *path);
char *va(char *format, ...);
char *va (const char *format, ...) __attribute__((__format__(__printf__,1,2)));
// does a varargs printf into a temp buffer

View file

@ -187,7 +187,7 @@ void Con_Dump_f (void)
f = fopen (name, "w");
if (!f)
{
Con_Printf ("ERROR: couldn't open file.\n", name);
Con_Printf ("ERROR: couldn't open file %s.\n", name);
return;
}
@ -407,7 +407,7 @@ All console printing must go through this in order to be logged to disk
If no console is visible, the notify window will pop up.
================
*/
void Con_Print (char *txt)
void Con_Print (const char *txt)
{
int y;
int c, l;
@ -489,7 +489,8 @@ void Con_Print (char *txt)
Con_DebugLog
================
*/
void Con_DebugLog(char *file, char *fmt, ...)
void Con_DebugLog(const char *file, const char *fmt, ...) __attribute__((__format__(__printf__,2,3)));
void Con_DebugLog(const char *file, const char *fmt, ...)
{
va_list argptr;
static char data[1024];
@ -513,7 +514,7 @@ Handles cursor positioning, line wrapping, etc
*/
#define MAXPRINTMSG 4096
// FIXME: make a buffer size safe vsprintf?
void Con_Printf (char *fmt, ...)
void Con_Printf (const char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
@ -558,7 +559,7 @@ void Con_Printf (char *fmt, ...)
Con_Warning -- johnfitz -- prints a warning to the console
================
*/
void Con_Warning (char *fmt, ...)
void Con_Warning (const char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
@ -578,7 +579,7 @@ Con_DPrintf
A Con_Printf that only shows up if the "developer" cvar is set
================
*/
void Con_DPrintf (char *fmt, ...)
void Con_DPrintf (const char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
@ -600,7 +601,7 @@ Con_DPrintf2 -- johnfitz -- only prints if "developer" >= 2
currently not used
================
*/
void Con_DPrintf2 (char *fmt, ...)
void Con_DPrintf2 (const char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
@ -623,7 +624,7 @@ Con_SafePrintf
Okay to call even when the screen can't be updated
==================
*/
void Con_SafePrintf (char *fmt, ...)
void Con_SafePrintf (const char *fmt, ...)
{
va_list argptr;
char msg[1024];
@ -644,7 +645,8 @@ void Con_SafePrintf (char *fmt, ...)
Con_CenterPrintf -- johnfitz -- pad each line with spaces to make it appear centered
================
*/
void Con_CenterPrintf (int linewidth, char *fmt, ...)
void Con_CenterPrintf (int linewidth, const char *fmt, ...) __attribute__((__format__(__printf__,2,3)));
void Con_CenterPrintf (int linewidth, const char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG]; //the original message
@ -685,7 +687,7 @@ void Con_CenterPrintf (int linewidth, char *fmt, ...)
Con_LogCenterPrint -- johnfitz -- echo centerprint message to the console
==================
*/
void Con_LogCenterPrint (char *str)
void Con_LogCenterPrint (const char *str)
{
if (!strcmp(str, con_lastcenterstring))
return; //ignore duplicates
@ -1221,7 +1223,7 @@ void Con_DrawConsole (int lines, qboolean drawinput)
Con_NotifyBox
==================
*/
void Con_NotifyBox (char *text)
void Con_NotifyBox (const char *text)
{
double t1, t2;

View file

@ -39,25 +39,25 @@ void Con_DrawCharacter (int cx, int line, int num);
void Con_CheckResize (void);
void Con_Init (void);
void Con_DrawConsole (int lines, qboolean drawinput);
void Con_Print (char *txt);
void Con_Printf (char *fmt, ...);
void Con_Warning (char *fmt, ...); //johnfitz
void Con_DPrintf (char *fmt, ...);
void Con_DPrintf2 (char *fmt, ...); //johnfitz
void Con_SafePrintf (char *fmt, ...);
void Con_Print (const char *txt);
void Con_Printf (const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
void Con_Warning (const char *fmt, ...) __attribute__((__format__(__printf__,1,2))); //johnfitz
void Con_DPrintf (const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
void Con_DPrintf2 (const char *fmt, ...) __attribute__((__format__(__printf__,1,2))); //johnfitz
void Con_SafePrintf (const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
void Con_Clear_f (void);
void Con_DrawNotify (void);
void Con_ClearNotify (void);
void Con_ToggleConsole_f (void);
void Con_NotifyBox (char *text); // during startup for sound / cd warnings
void Con_NotifyBox (const char *text); // during startup for sound / cd warnings
void Con_Show (void);
void Con_Hide (void);
char *Con_Quakebar (int len);
void Con_TabComplete (void);
void Con_LogCenterPrint (char *str);
void Con_LogCenterPrint (const char *str);
#endif /* __CONSOLE_H */

View file

@ -830,7 +830,7 @@ void Mod_LoadTexinfo (lump_t *l)
//johnfitz: report missing textures
if (missing && loadmodel->numtextures > 1)
Con_Printf ("Mod_LoadTexinfo: one or more textures is missing from BSP file\n", missing);
Con_Printf ("Mod_LoadTexinfo: %d texture(s) missing from BSP file\n", missing);
//johnfitz
}

View file

@ -108,7 +108,7 @@ void Max_Edicts_f (void)
Host_EndGame
================
*/
void Host_EndGame (char *message, ...)
void Host_EndGame (const char *message, ...)
{
va_list argptr;
char string[1024];
@ -139,7 +139,7 @@ Host_Error
This shuts down both the client and server
================
*/
void Host_Error (char *error, ...)
void Host_Error (const char *error, ...)
{
va_list argptr;
char string[1024];
@ -324,7 +324,7 @@ Sends text across to be displayed
FIXME: make this just a stuffed echo?
=================
*/
void SV_ClientPrintf (char *fmt, ...)
void SV_ClientPrintf (const char *fmt, ...)
{
va_list argptr;
char string[1024];
@ -344,7 +344,7 @@ SV_BroadcastPrintf
Sends text to all active clients
=================
*/
void SV_BroadcastPrintf (char *fmt, ...)
void SV_BroadcastPrintf (const char *fmt, ...)
{
va_list argptr;
char string[1024];
@ -369,7 +369,7 @@ Host_ClientCommands
Send text over to the client to be executed
=================
*/
void Host_ClientCommands (char *fmt, ...)
void Host_ClientCommands (const char *fmt, ...)
{
va_list argptr;
char string[1024];

View file

@ -492,7 +492,7 @@ void Host_Status_f (void)
int minutes;
int hours = 0;
int j;
void (*print) (char *fmt, ...);
void (*print_fn) (const char *fmt, ...) __fp_attribute__((__format__(__printf__,1,2)));
if (cmd_source == src_command)
{
@ -501,19 +501,19 @@ void Host_Status_f (void)
Cmd_ForwardToServer ();
return;
}
print = Con_Printf;
print_fn = Con_Printf;
}
else
print = SV_ClientPrintf;
print_fn = SV_ClientPrintf;
print ("host: %s\n", Cvar_VariableString ("hostname"));
print ("version: %4.2f\n", VERSION);
print_fn ("host: %s\n", Cvar_VariableString ("hostname"));
print_fn ("version: %4.2f\n", VERSION);
if (tcpipAvailable)
print ("tcp/ip: %s\n", my_tcpip_address);
print_fn ("tcp/ip: %s\n", my_tcpip_address);
if (ipxAvailable)
print ("ipx: %s\n", my_ipx_address);
print ("map: %s\n", sv.name);
print ("players: %i active (%i max)\n\n", net_activeconnections, svs.maxclients);
print_fn ("ipx: %s\n", my_ipx_address);
print_fn ("map: %s\n", sv.name);
print_fn ("players: %i active (%i max)\n\n", net_activeconnections, svs.maxclients);
for (j=0, client = svs.clients ; j<svs.maxclients ; j++, client++)
{
if (!client->active)
@ -529,8 +529,8 @@ void Host_Status_f (void)
}
else
hours = 0;
print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v.frags, hours, minutes, seconds);
print (" %s\n", client->netconnection->address);
print_fn ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v.frags, hours, minutes, seconds);
print_fn (" %s\n", client->netconnection->address);
}
}

View file

@ -24,8 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <math.h>
#include "quakedef.h"
void Sys_Error (char *error, ...);
vec3_t vec3_origin = {0,0,0};
int nanmask = 255<<23;
@ -134,6 +132,7 @@ BOPS_Error
Split out like this for ASM to call.
==================
*/
void BOPS_Error (void) __attribute__((__noreturn__));
void BOPS_Error (void)
{
Sys_Error ("BoxOnPlaneSide: Bad signbits");
@ -477,7 +476,7 @@ void FloorDivMod (double numer, double denom, int *quotient,
#ifndef PARANOID
if (denom <= 0.0)
Sys_Error ("FloorDivMod: bad denominator %d\n", denom);
Sys_Error ("FloorDivMod: bad denominator %f\n", denom);
// if ((floor(numer) != numer) || (floor(denom) != denom))
// Sys_Error ("FloorDivMod: non-integer numer or denom %f %f\n",

View file

@ -105,7 +105,7 @@ void NET_Ban_f (void)
{
char addrStr [32];
char maskStr [32];
void (*print) (char *fmt, ...);
void (*print_fn) (const char *fmt, ...) __fp_attribute__((__format__(__printf__,1,2)));
if (cmd_source == src_command)
{
@ -114,13 +114,13 @@ void NET_Ban_f (void)
Cmd_ForwardToServer ();
return;
}
print = Con_Printf;
print_fn = Con_Printf;
}
else
{
if (pr_global_struct->deathmatch && !host_client->privileged)
return;
print = SV_ClientPrintf;
print_fn = SV_ClientPrintf;
}
switch (Cmd_Argc ())
@ -130,10 +130,10 @@ void NET_Ban_f (void)
{
Q_strcpy(addrStr, inet_ntoa(*(struct in_addr *)&banAddr));
Q_strcpy(maskStr, inet_ntoa(*(struct in_addr *)&banMask));
print("Banning %s [%s]\n", addrStr, maskStr);
print_fn("Banning %s [%s]\n", addrStr, maskStr);
}
else
print("Banning not active\n");
print_fn("Banning not active\n");
break;
case 2:
@ -150,7 +150,7 @@ void NET_Ban_f (void)
break;
default:
print("BAN ip_address [mask]\n");
print_fn("BAN ip_address [mask]\n");
break;
}
}

View file

@ -47,7 +47,7 @@ void PL_VID_Shutdown (void)
{
}
void PL_ErrorDialog(char *text)
void PL_ErrorDialog(const char *text)
{
// TODO: we can dlopen gtk for an error
// dialog window. would it be worth it?

View file

@ -32,7 +32,7 @@ void PL_VID_Shutdown (void)
{
}
void PL_ErrorDialog(char *text)
void PL_ErrorDialog(const char *text)
{
NSString *msg = [NSString stringWithCString:text encoding:NSASCIIStringEncoding];
NSRunAlertPanel(nil, msg, nil, nil, nil);

View file

@ -56,7 +56,7 @@ void PL_VID_Shutdown (void)
DestroyIcon(icon);
}
void PL_ErrorDialog(char *text)
void PL_ErrorDialog(const char *text)
{
MessageBox(NULL, text, "Quake Error", MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
}

View file

@ -30,7 +30,7 @@ void PL_SetWindowIcon(void);
void PL_VID_Shutdown (void);
// show an error dialog
void PL_ErrorDialog(char *text);
void PL_ErrorDialog(const char *text);
#endif /* _QUAKE_PLATFORM_H */

View file

@ -1167,7 +1167,7 @@ int NUM_FOR_EDICT(edict_t *e)
static void PR_AllocStringSlots (void)
{
pr_maxknownstrings += PR_STRING_ALLOCSLOTS;
Con_DPrintf("PR_AllocStringSlots: realloc'ing for slots\n", pr_maxknownstrings);
Con_DPrintf("PR_AllocStringSlots: realloc'ing for %d slots\n", pr_maxknownstrings);
pr_knownstrings = (char **) Z_Realloc (pr_knownstrings, pr_maxknownstrings * sizeof(char *));
}

View file

@ -262,7 +262,7 @@ PR_RunError
Aborts the currently executing function
============
*/
void PR_RunError (char *error, ...)
void PR_RunError (const char *error, ...)
{
va_list argptr;
char string[1024];

View file

@ -126,7 +126,7 @@ extern int pr_xstatement;
extern unsigned short pr_crc;
void PR_RunError (char *error, ...);
void PR_RunError (const char *error, ...) __attribute__((__format__(__printf__,1,2)));
void ED_PrintEdicts (void);
void ED_PrintNum (int ent);

View file

@ -52,9 +52,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <setjmp.h>
#include <assert.h> //johnfitz
#if !defined(__GNUC__)
#define __attribute__(x)
#endif /* __GNUC__ */
/* argument format attributes for function
* pointers are supported for gcc >= 3.1
*/
#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0))
#define __fp_attribute__ __attribute__
#else
#define __fp_attribute__(x)
#endif
#if defined(_WIN32) && !defined(WINDED)
#if defined(_M_IX86)
#if defined(_M_IX86) && !defined(__i386__)
#define __i386__ 1
#endif
@ -312,11 +326,11 @@ void Host_ServerFrame (void);
void Host_InitCommands (void);
void Host_Init (quakeparms_t *parms);
void Host_Shutdown(void);
void Host_Error (char *error, ...);
void Host_EndGame (char *message, ...);
void Host_Error (const char *error, ...) __attribute__((__format__(__printf__,1,2), __noreturn__));
void Host_EndGame (const char *message, ...) __attribute__((__format__(__printf__,1,2), __noreturn__));
void Host_Frame (float time);
void Host_Quit_f (void);
void Host_ClientCommands (char *fmt, ...);
void Host_ClientCommands (const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
void Host_ShutdownServer (qboolean crash);
void Host_WriteConfiguration (void);

View file

@ -214,8 +214,8 @@ void SV_AddUpdates (void);
void SV_ClientThink (void);
void SV_AddClientToServer (struct qsocket_s *ret);
void SV_ClientPrintf (char *fmt, ...);
void SV_BroadcastPrintf (char *fmt, ...);
void SV_ClientPrintf (const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
void SV_BroadcastPrintf (const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
void SV_Physics (void);

View file

@ -49,15 +49,15 @@ void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length);
//
// system IO
//
void Sys_DebugLog(char *file, char *fmt, ...);
void Sys_DebugLog(const char *file, const char *fmt, ...) __attribute__((__format__(__printf__,2,3)));
void Sys_Error (char *error, ...);
void Sys_Error (const char *error, ...) __attribute__((__format__(__printf__,1,2), __noreturn__));
// an error will cause the entire program to exit
void Sys_Printf (char *fmt, ...);
void Sys_Printf (const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
// send text to the console
void Sys_Quit (void);
void Sys_Quit (void) __attribute__((__noreturn__));
double Sys_FloatTime (void);

View file

@ -153,11 +153,11 @@ void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
{
}
void Sys_DebugLog(char *file, char *fmt, ...)
void Sys_DebugLog(const char *file, const char *fmt, ...)
{
}
void Sys_Error (char *error, ...)
void Sys_Error (const char *error, ...)
{
va_list argptr;
char text[1024], text2[1024];
@ -221,7 +221,7 @@ void Sys_Error (char *error, ...)
exit (1);
}
void Sys_Printf (char *fmt, ...)
void Sys_Printf (const char *fmt, ...)
{
va_list argptr;