From 5bd3fccecd3677e8acfaed52672d6e9b14a6fb82 Mon Sep 17 00:00:00 2001 From: sezero Date: Mon, 26 Apr 2010 16:30:40 +0000 Subject: [PATCH] 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 --- quakespasm/Quake/common.c | 2 +- quakespasm/Quake/common.h | 2 +- quakespasm/Quake/console.c | 24 +++++++++++++----------- quakespasm/Quake/console.h | 16 ++++++++-------- quakespasm/Quake/gl_model.c | 2 +- quakespasm/Quake/host.c | 10 +++++----- quakespasm/Quake/host_cmd.c | 22 +++++++++++----------- quakespasm/Quake/mathlib.c | 5 ++--- quakespasm/Quake/net_dgrm.c | 12 ++++++------ quakespasm/Quake/pl_linux.c | 2 +- quakespasm/Quake/pl_osx.m | 2 +- quakespasm/Quake/pl_win.c | 2 +- quakespasm/Quake/platform.h | 2 +- quakespasm/Quake/pr_edict.c | 2 +- quakespasm/Quake/pr_exec.c | 2 +- quakespasm/Quake/progs.h | 2 +- quakespasm/Quake/quakedef.h | 22 ++++++++++++++++++---- quakespasm/Quake/server.h | 4 ++-- quakespasm/Quake/sys.h | 8 ++++---- quakespasm/Quake/sys_sdl.c | 6 +++--- 20 files changed, 82 insertions(+), 67 deletions(-) diff --git a/quakespasm/Quake/common.c b/quakespasm/Quake/common.c index 69dfb2a9..a4999385 100644 --- a/quakespasm/Quake/common.c +++ b/quakespasm/Quake/common.c @@ -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; diff --git a/quakespasm/Quake/common.h b/quakespasm/Quake/common.h index 54b079e5..0d3d9079 100644 --- a/quakespasm/Quake/common.h +++ b/quakespasm/Quake/common.h @@ -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 diff --git a/quakespasm/Quake/console.c b/quakespasm/Quake/console.c index 677f20d2..d091be79 100644 --- a/quakespasm/Quake/console.c +++ b/quakespasm/Quake/console.c @@ -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; diff --git a/quakespasm/Quake/console.h b/quakespasm/Quake/console.h index f88b4c12..47b8d881 100644 --- a/quakespasm/Quake/console.h +++ b/quakespasm/Quake/console.h @@ -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 */ diff --git a/quakespasm/Quake/gl_model.c b/quakespasm/Quake/gl_model.c index b73c97f3..1df9f01a 100644 --- a/quakespasm/Quake/gl_model.c +++ b/quakespasm/Quake/gl_model.c @@ -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 } diff --git a/quakespasm/Quake/host.c b/quakespasm/Quake/host.c index 7d3f64eb..881dcd1d 100644 --- a/quakespasm/Quake/host.c +++ b/quakespasm/Quake/host.c @@ -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]; diff --git a/quakespasm/Quake/host_cmd.c b/quakespasm/Quake/host_cmd.c index 5e577f2f..3a36ec88 100644 --- a/quakespasm/Quake/host_cmd.c +++ b/quakespasm/Quake/host_cmd.c @@ -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 ; jactive) @@ -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); } } diff --git a/quakespasm/Quake/mathlib.c b/quakespasm/Quake/mathlib.c index 6371a487..eab19c40 100644 --- a/quakespasm/Quake/mathlib.c +++ b/quakespasm/Quake/mathlib.c @@ -24,8 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #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", diff --git a/quakespasm/Quake/net_dgrm.c b/quakespasm/Quake/net_dgrm.c index bd760abd..b8f095dc 100644 --- a/quakespasm/Quake/net_dgrm.c +++ b/quakespasm/Quake/net_dgrm.c @@ -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; } } diff --git a/quakespasm/Quake/pl_linux.c b/quakespasm/Quake/pl_linux.c index 60895f8d..e93d3fa4 100644 --- a/quakespasm/Quake/pl_linux.c +++ b/quakespasm/Quake/pl_linux.c @@ -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? diff --git a/quakespasm/Quake/pl_osx.m b/quakespasm/Quake/pl_osx.m index 81bf589c..d0bc12fe 100644 --- a/quakespasm/Quake/pl_osx.m +++ b/quakespasm/Quake/pl_osx.m @@ -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); diff --git a/quakespasm/Quake/pl_win.c b/quakespasm/Quake/pl_win.c index bbd25d95..b801af9f 100644 --- a/quakespasm/Quake/pl_win.c +++ b/quakespasm/Quake/pl_win.c @@ -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); } diff --git a/quakespasm/Quake/platform.h b/quakespasm/Quake/platform.h index 9c6789ea..cd84a574 100644 --- a/quakespasm/Quake/platform.h +++ b/quakespasm/Quake/platform.h @@ -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 */ diff --git a/quakespasm/Quake/pr_edict.c b/quakespasm/Quake/pr_edict.c index 4170c42a..8a9a4d9b 100644 --- a/quakespasm/Quake/pr_edict.c +++ b/quakespasm/Quake/pr_edict.c @@ -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 *)); } diff --git a/quakespasm/Quake/pr_exec.c b/quakespasm/Quake/pr_exec.c index 7a85b8ba..f1e2cdfb 100644 --- a/quakespasm/Quake/pr_exec.c +++ b/quakespasm/Quake/pr_exec.c @@ -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]; diff --git a/quakespasm/Quake/progs.h b/quakespasm/Quake/progs.h index ac7bf095..9b21a966 100644 --- a/quakespasm/Quake/progs.h +++ b/quakespasm/Quake/progs.h @@ -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); diff --git a/quakespasm/Quake/quakedef.h b/quakespasm/Quake/quakedef.h index 42e591c7..f2138d58 100644 --- a/quakespasm/Quake/quakedef.h +++ b/quakespasm/Quake/quakedef.h @@ -52,9 +52,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include //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); diff --git a/quakespasm/Quake/server.h b/quakespasm/Quake/server.h index 9a977857..32b6c8ae 100644 --- a/quakespasm/Quake/server.h +++ b/quakespasm/Quake/server.h @@ -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); diff --git a/quakespasm/Quake/sys.h b/quakespasm/Quake/sys.h index f9c64f78..2fa983cc 100644 --- a/quakespasm/Quake/sys.h +++ b/quakespasm/Quake/sys.h @@ -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); diff --git a/quakespasm/Quake/sys_sdl.c b/quakespasm/Quake/sys_sdl.c index 376bcfe8..ac9026f3 100644 --- a/quakespasm/Quake/sys_sdl.c +++ b/quakespasm/Quake/sys_sdl.c @@ -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;