diff --git a/Makefile b/Makefile index ffe4f913..9cb406b3 100644 --- a/Makefile +++ b/Makefile @@ -462,6 +462,8 @@ CLIENT_OBJS_ := \ src/client/sound/snd_mix.o \ src/client/sound/snd_vorbis.o \ src/client/sound/snd_wav.o \ + src/common/argproc.o \ + src/common/clientserver.o \ src/common/crc.o \ src/common/cmdparser.o \ src/common/cvar.o \ @@ -473,8 +475,6 @@ CLIENT_OBJS_ := \ src/common/pmove.o \ src/common/szone.o \ src/common/zone.o \ - src/common/common/com_arg.o \ - src/common/common/com_clientserver.o \ src/common/message/msg_io.o \ src/common/message/msg_read.o \ src/common/model/cm_areaportals.o \ @@ -523,6 +523,8 @@ endif # Used by the server SERVER_OBJS_ := \ + src/common/argproc.o \ + src/common/clientserver.o \ src/common/crc.o \ src/common/cmdparser.o \ src/common/cvar.o \ @@ -534,8 +536,6 @@ SERVER_OBJS_ := \ src/common/pmove.o \ src/common/szone.o \ src/common/zone.o \ - src/common/common/com_arg.o \ - src/common/common/com_clientserver.o \ src/common/message/msg_io.o \ src/common/message/msg_read.o \ src/common/model/cm_areaportals.o \ diff --git a/src/common/common/com_arg.c b/src/common/argproc.c similarity index 62% rename from src/common/common/com_arg.c rename to src/common/argproc.c index 7857dab5..e23ead3e 100644 --- a/src/common/common/com_arg.c +++ b/src/common/argproc.c @@ -24,134 +24,167 @@ * ======================================================================= */ -#include "../header/common.h" +#include "header/common.h" -#define MAX_NUM_ARGVS 50 +#define MAX_NUM_ARGVS 50 -int com_argc; -char *com_argv[MAX_NUM_ARGVS+1]; +int com_argc; +char *com_argv[MAX_NUM_ARGVS + 1]; /* * Returns the position (1 to argc-1) in the program's argument list * where the given parameter apears, or 0 if not present */ -int COM_CheckParm (char *parm) +int +COM_CheckParm(char *parm) { - int i; + int i; - for (i=1 ; i= com_argc || !com_argv[arg]) + if ((arg < 0) || (arg >= com_argc) || !com_argv[arg]) + { return ""; + } return com_argv[arg]; } -void COM_ClearArgv (int arg) +void +COM_ClearArgv(int arg) { - if (arg < 0 || arg >= com_argc || !com_argv[arg]) + if ((arg < 0) || (arg >= com_argc) || !com_argv[arg]) + { return; + } com_argv[arg] = ""; } -void COM_InitArgv (int argc, char **argv) +void +COM_InitArgv(int argc, char **argv) { - int i; + int i; if (argc > MAX_NUM_ARGVS) - Com_Error (ERR_FATAL, "argc > MAX_NUM_ARGVS"); + { + Com_Error(ERR_FATAL, "argc > MAX_NUM_ARGVS"); + } com_argc = argc; - for (i=0 ; i= MAX_TOKEN_CHARS ) + if (!argv[i] || (strlen(argv[i]) >= MAX_TOKEN_CHARS)) + { com_argv[i] = ""; + } else + { com_argv[i] = argv[i]; + } } } /* * Adds the given string at the end of the current argument list */ -void COM_AddParm (char *parm) +void +COM_AddParm(char *parm) { if (com_argc == MAX_NUM_ARGVS) - Com_Error (ERR_FATAL, "COM_AddParm: MAX_NUM)ARGS"); + { + Com_Error(ERR_FATAL, "COM_AddParm: MAX_NUM)ARGS"); + } com_argv[com_argc++] = parm; } -int memsearch (byte *start, int count, int search) +int +memsearch(byte *start, int count, int search) { - int i; + int i; - for (i=0 ; i #include -#define MAXPRINTMSG 4096 +#define MAXPRINTMSG 4096 -FILE *logfile; -cvar_t *logfile_active; /* 1 = buffer log, 2 = flush after each print */ +FILE *logfile; +cvar_t *logfile_active; /* 1 = buffer log, 2 = flush after each print */ jmp_buf abortframe; /* an ERR_DROP occured, exit the entire frame */ -int server_state; +int server_state; -static int rd_target; -static char *rd_buffer; -static int rd_buffersize; -static void (*rd_flush)(int target, char *buffer); +static int rd_target; +static char *rd_buffer; +static int rd_buffersize; +static void (*rd_flush)(int target, char *buffer); -void Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush)) +void +Com_BeginRedirect(int target, char *buffer, int buffersize, void (*flush)) { if (!target || !buffer || !buffersize || !flush) + { return; + } rd_target = target; rd_buffer = buffer; @@ -53,7 +56,8 @@ void Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush)) *rd_buffer = 0; } -void Com_EndRedirect (void) +void +Com_EndRedirect(void) { rd_flush(rd_target, rd_buffer); @@ -67,91 +71,106 @@ void Com_EndRedirect (void) * Both client and server can use this, and it will output * to the apropriate place. */ -void Com_Printf (char *fmt, ...) +void +Com_Printf(char *fmt, ...) { - va_list argptr; - char msg[MAXPRINTMSG]; + va_list argptr; + char msg[MAXPRINTMSG]; - va_start (argptr,fmt); - vsnprintf (msg,MAXPRINTMSG,fmt,argptr); - va_end (argptr); + va_start(argptr, fmt); + vsnprintf(msg, MAXPRINTMSG, fmt, argptr); + va_end(argptr); if (rd_target) { - if ((strlen (msg) + strlen(rd_buffer)) > (rd_buffersize - 1)) + if ((strlen(msg) + strlen(rd_buffer)) > (rd_buffersize - 1)) { rd_flush(rd_target, rd_buffer); *rd_buffer = 0; } - strcat (rd_buffer, msg); + strcat(rd_buffer, msg); return; } #ifndef DEDICATED_ONLY - Con_Print (msg); + Con_Print(msg); #endif /* also echo to debugging console */ - Sys_ConsoleOutput (msg); + Sys_ConsoleOutput(msg); /* logfile */ if (logfile_active && logfile_active->value) { - char name[MAX_QPATH]; + char name[MAX_QPATH]; if (!logfile) { - Com_sprintf (name, sizeof(name), "%s/qconsole.log", FS_Gamedir ()); + Com_sprintf(name, sizeof(name), "%s/qconsole.log", FS_Gamedir()); if (logfile_active->value > 2) - logfile = fopen (name, "a"); + { + logfile = fopen(name, "a"); + } else - logfile = fopen (name, "w"); + { + logfile = fopen(name, "w"); + } } if (logfile) - fprintf (logfile, "%s", msg); + { + fprintf(logfile, "%s", msg); + } if (logfile_active->value > 1) - fflush (logfile); /* force it to save every time */ + { + fflush(logfile); /* force it to save every time */ + } } } /* * A Com_Printf that only shows up if the "developer" cvar is set */ -void Com_DPrintf (char *fmt, ...) +void +Com_DPrintf(char *fmt, ...) { - va_list argptr; - char msg[MAXPRINTMSG]; + va_list argptr; + char msg[MAXPRINTMSG]; if (!developer || !developer->value) - return; /* don't confuse non-developers with techie stuff... */ + { + return; /* don't confuse non-developers with techie stuff... */ + } - va_start (argptr,fmt); - vsnprintf (msg,MAXPRINTMSG,fmt,argptr); - va_end (argptr); + va_start(argptr, fmt); + vsnprintf(msg, MAXPRINTMSG, fmt, argptr); + va_end(argptr); - Com_Printf ("%s", msg); + Com_Printf("%s", msg); } /* * A Com_Printf that only shows up when either the "modder" or "developer" * cvars is set */ -void Com_MDPrintf (char *fmt, ...) +void +Com_MDPrintf(char *fmt, ...) { va_list argptr; char msg[MAXPRINTMSG]; - if((!modder || !modder->value) && (!developer || !developer->value)) + if ((!modder || !modder->value) && (!developer || !developer->value)) + { return; + } - va_start (argptr,fmt); - vsnprintf (msg,MAXPRINTMSG,fmt,argptr); - va_end (argptr); + va_start(argptr, fmt); + vsnprintf(msg, MAXPRINTMSG, fmt, argptr); + va_end(argptr); Com_Printf("%s", msg); } @@ -160,56 +179,60 @@ void Com_MDPrintf (char *fmt, ...) * Both client and server can use this, and it will * do the apropriate things. */ -void Com_Error (int code, char *fmt, ...) +void +Com_Error(int code, char *fmt, ...) { - va_list argptr; - static char msg[MAXPRINTMSG]; - static qboolean recursive; + va_list argptr; + static char msg[MAXPRINTMSG]; + static qboolean recursive; if (recursive) - Sys_Error ("recursive error after: %s", msg); + { + Sys_Error("recursive error after: %s", msg); + } recursive = true; - va_start (argptr,fmt); - vsnprintf (msg,MAXPRINTMSG,fmt,argptr); - va_end (argptr); + va_start(argptr, fmt); + vsnprintf(msg, MAXPRINTMSG, fmt, argptr); + va_end(argptr); if (code == ERR_DISCONNECT) { #ifndef DEDICATED_ONLY - CL_Drop (); + CL_Drop(); #endif recursive = false; - longjmp (abortframe, -1); + longjmp(abortframe, -1); } else if (code == ERR_DROP) { - Com_Printf ("********************\nERROR: %s\n********************\n", msg); - SV_Shutdown (va("Server crashed: %s\n", msg), false); + Com_Printf("********************\nERROR: %s\n********************\n", + msg); + SV_Shutdown(va("Server crashed: %s\n", msg), false); #ifndef DEDICATED_ONLY - CL_Drop (); + CL_Drop(); #endif recursive = false; - longjmp (abortframe, -1); + longjmp(abortframe, -1); } else { - SV_Shutdown (va("Server fatal crashed: %s\n", msg), false); + SV_Shutdown(va("Server fatal crashed: %s\n", msg), false); #ifndef DEDICATED_ONLY - CL_Shutdown (); + CL_Shutdown(); #endif } if (logfile) { - fclose (logfile); + fclose(logfile); logfile = NULL; } - Sys_Error ("%s", msg); + Sys_Error("%s", msg); recursive = false; } @@ -217,19 +240,23 @@ void Com_Error (int code, char *fmt, ...) * Both client and server can use this, and it will * do the apropriate things. */ -void Com_Quit (void) +void +Com_Quit(void) { Com_Printf("\n----------- shutting down ----------\n"); - SV_Shutdown ("Server quit\n", false); - Sys_Quit (); + SV_Shutdown("Server quit\n", false); + Sys_Quit(); } -int Com_ServerState (void) +int +Com_ServerState(void) { return server_state; } -void Com_SetServerState (int state) +void +Com_SetServerState(int state) { server_state = state; } +