Move stuff from common/common/ to common/

This commit is contained in:
Yamagi Burmeister 2012-06-07 13:54:08 +02:00
parent 56aff1dc89
commit e0faf784a6
3 changed files with 168 additions and 103 deletions

View file

@ -462,6 +462,8 @@ CLIENT_OBJS_ := \
src/client/sound/snd_mix.o \ src/client/sound/snd_mix.o \
src/client/sound/snd_vorbis.o \ src/client/sound/snd_vorbis.o \
src/client/sound/snd_wav.o \ src/client/sound/snd_wav.o \
src/common/argproc.o \
src/common/clientserver.o \
src/common/crc.o \ src/common/crc.o \
src/common/cmdparser.o \ src/common/cmdparser.o \
src/common/cvar.o \ src/common/cvar.o \
@ -473,8 +475,6 @@ CLIENT_OBJS_ := \
src/common/pmove.o \ src/common/pmove.o \
src/common/szone.o \ src/common/szone.o \
src/common/zone.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_io.o \
src/common/message/msg_read.o \ src/common/message/msg_read.o \
src/common/model/cm_areaportals.o \ src/common/model/cm_areaportals.o \
@ -523,6 +523,8 @@ endif
# Used by the server # Used by the server
SERVER_OBJS_ := \ SERVER_OBJS_ := \
src/common/argproc.o \
src/common/clientserver.o \
src/common/crc.o \ src/common/crc.o \
src/common/cmdparser.o \ src/common/cmdparser.o \
src/common/cvar.o \ src/common/cvar.o \
@ -534,8 +536,6 @@ SERVER_OBJS_ := \
src/common/pmove.o \ src/common/pmove.o \
src/common/szone.o \ src/common/szone.o \
src/common/zone.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_io.o \
src/common/message/msg_read.o \ src/common/message/msg_read.o \
src/common/model/cm_areaportals.o \ src/common/model/cm_areaportals.o \

View file

@ -24,7 +24,7 @@
* ======================================================================= * =======================================================================
*/ */
#include "../header/common.h" #include "header/common.h"
#define MAX_NUM_ARGVS 50 #define MAX_NUM_ARGVS 50
@ -35,82 +35,108 @@ char *com_argv[MAX_NUM_ARGVS+1];
* Returns the position (1 to argc-1) in the program's argument list * Returns the position (1 to argc-1) in the program's argument list
* where the given parameter apears, or 0 if not present * 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; i++) for (i = 1; i < com_argc; i++)
{ {
if (!strcmp(parm, com_argv[i])) if (!strcmp(parm, com_argv[i]))
{
return i; return i;
} }
}
return 0; return 0;
} }
int COM_Argc (void) int
COM_Argc(void)
{ {
return com_argc; return com_argc;
} }
char *COM_Argv (int arg) char *
COM_Argv(int arg)
{
if ((arg < 0) || (arg >= com_argc) || !com_argv[arg])
{ {
if (arg < 0 || arg >= com_argc || !com_argv[arg])
return ""; return "";
}
return com_argv[arg]; 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; return;
}
com_argv[arg] = ""; 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) if (argc > MAX_NUM_ARGVS)
{
Com_Error(ERR_FATAL, "argc > MAX_NUM_ARGVS"); Com_Error(ERR_FATAL, "argc > MAX_NUM_ARGVS");
}
com_argc = argc; com_argc = argc;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
if (!argv[i] || strlen(argv[i]) >= MAX_TOKEN_CHARS ) if (!argv[i] || (strlen(argv[i]) >= MAX_TOKEN_CHARS))
{
com_argv[i] = ""; com_argv[i] = "";
}
else else
{
com_argv[i] = argv[i]; com_argv[i] = argv[i];
} }
} }
}
/* /*
* Adds the given string at the end of the current argument list * 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) 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; 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 < count; i++) for (i = 0; i < count; i++)
{
if (start[i] == search) if (start[i] == search)
{
return i; return i;
}
}
return -1; return -1;
} }
char *CopyString (char *in) char *
CopyString(char *in)
{ {
char *out; char *out;
@ -119,7 +145,8 @@ char *CopyString (char *in)
return out; return out;
} }
void Info_Print (char *s) void
Info_Print(char *s)
{ {
char key[512]; char key[512];
char value[512]; char value[512];
@ -127,14 +154,18 @@ void Info_Print (char *s)
int l; int l;
if (*s == '\\') if (*s == '\\')
{
s++; s++;
}
while (*s) while (*s)
{ {
o = key; o = key;
while (*s && *s != '\\') while (*s && *s != '\\')
{
*o++ = *s++; *o++ = *s++;
}
l = o - key; l = o - key;
@ -145,7 +176,9 @@ void Info_Print (char *s)
} }
else else
{
*o = 0; *o = 0;
}
Com_Printf("%s", key); Com_Printf("%s", key);
@ -159,13 +192,18 @@ void Info_Print (char *s)
s++; s++;
while (*s && *s != '\\') while (*s && *s != '\\')
{
*o++ = *s++; *o++ = *s++;
}
*o = 0; *o = 0;
if (*s) if (*s)
{
s++; s++;
}
Com_Printf("%s\n", value); Com_Printf("%s\n", value);
} }
} }

View file

@ -24,7 +24,7 @@
* ======================================================================= * =======================================================================
*/ */
#include "../header/common.h" #include "header/common.h"
#include <stdlib.h> #include <stdlib.h>
#include <setjmp.h> #include <setjmp.h>
@ -40,10 +40,13 @@ static char *rd_buffer;
static int rd_buffersize; static int rd_buffersize;
static void (*rd_flush)(int target, char *buffer); 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) if (!target || !buffer || !buffersize || !flush)
{
return; return;
}
rd_target = target; rd_target = target;
rd_buffer = buffer; rd_buffer = buffer;
@ -53,7 +56,8 @@ void Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush))
*rd_buffer = 0; *rd_buffer = 0;
} }
void Com_EndRedirect (void) void
Com_EndRedirect(void)
{ {
rd_flush(rd_target, rd_buffer); rd_flush(rd_target, rd_buffer);
@ -67,7 +71,8 @@ void Com_EndRedirect (void)
* Both client and server can use this, and it will output * Both client and server can use this, and it will output
* to the apropriate place. * to the apropriate place.
*/ */
void Com_Printf (char *fmt, ...) void
Com_Printf(char *fmt, ...)
{ {
va_list argptr; va_list argptr;
char msg[MAXPRINTMSG]; char msg[MAXPRINTMSG];
@ -105,30 +110,41 @@ void Com_Printf (char *fmt, ...)
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) if (logfile_active->value > 2)
{
logfile = fopen(name, "a"); logfile = fopen(name, "a");
}
else else
{
logfile = fopen(name, "w"); logfile = fopen(name, "w");
} }
}
if (logfile) if (logfile)
{
fprintf(logfile, "%s", msg); fprintf(logfile, "%s", msg);
}
if (logfile_active->value > 1) 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 * 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; va_list argptr;
char msg[MAXPRINTMSG]; char msg[MAXPRINTMSG];
if (!developer || !developer->value) 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); va_start(argptr, fmt);
vsnprintf(msg, MAXPRINTMSG, fmt, argptr); vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
@ -141,13 +157,16 @@ void Com_DPrintf (char *fmt, ...)
* A Com_Printf that only shows up when either the "modder" or "developer" * A Com_Printf that only shows up when either the "modder" or "developer"
* cvars is set * cvars is set
*/ */
void Com_MDPrintf (char *fmt, ...) void
Com_MDPrintf(char *fmt, ...)
{ {
va_list argptr; va_list argptr;
char msg[MAXPRINTMSG]; char msg[MAXPRINTMSG];
if ((!modder || !modder->value) && (!developer || !developer->value)) if ((!modder || !modder->value) && (!developer || !developer->value))
{
return; return;
}
va_start(argptr, fmt); va_start(argptr, fmt);
vsnprintf(msg, MAXPRINTMSG, fmt, argptr); vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
@ -160,14 +179,17 @@ void Com_MDPrintf (char *fmt, ...)
* Both client and server can use this, and it will * Both client and server can use this, and it will
* do the apropriate things. * do the apropriate things.
*/ */
void Com_Error (int code, char *fmt, ...) void
Com_Error(int code, char *fmt, ...)
{ {
va_list argptr; va_list argptr;
static char msg[MAXPRINTMSG]; static char msg[MAXPRINTMSG];
static qboolean recursive; static qboolean recursive;
if (recursive) if (recursive)
{
Sys_Error("recursive error after: %s", msg); Sys_Error("recursive error after: %s", msg);
}
recursive = true; recursive = true;
@ -186,7 +208,8 @@ void Com_Error (int code, char *fmt, ...)
else if (code == ERR_DROP) else if (code == ERR_DROP)
{ {
Com_Printf ("********************\nERROR: %s\n********************\n", msg); Com_Printf("********************\nERROR: %s\n********************\n",
msg);
SV_Shutdown(va("Server crashed: %s\n", msg), false); SV_Shutdown(va("Server crashed: %s\n", msg), false);
#ifndef DEDICATED_ONLY #ifndef DEDICATED_ONLY
CL_Drop(); CL_Drop();
@ -217,19 +240,23 @@ void Com_Error (int code, char *fmt, ...)
* Both client and server can use this, and it will * Both client and server can use this, and it will
* do the apropriate things. * do the apropriate things.
*/ */
void Com_Quit (void) void
Com_Quit(void)
{ {
Com_Printf("\n----------- shutting down ----------\n"); Com_Printf("\n----------- shutting down ----------\n");
SV_Shutdown("Server quit\n", false); SV_Shutdown("Server quit\n", false);
Sys_Quit(); Sys_Quit();
} }
int Com_ServerState (void) int
Com_ServerState(void)
{ {
return server_state; return server_state;
} }
void Com_SetServerState (int state) void
Com_SetServerState(int state)
{ {
server_state = state; server_state = state;
} }