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_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 \

View file

@ -24,7 +24,7 @@
* =======================================================================
*/
#include "../header/common.h"
#include "header/common.h"
#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
* where the given parameter apears, or 0 if not present
*/
int COM_CheckParm (char *parm)
int
COM_CheckParm(char *parm)
{
int i;
for (i = 1; i < com_argc; i++)
{
if (!strcmp(parm, com_argv[i]))
{
return i;
}
}
return 0;
}
int COM_Argc (void)
int
COM_Argc(void)
{
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 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;
if (argc > MAX_NUM_ARGVS)
{
Com_Error(ERR_FATAL, "argc > MAX_NUM_ARGVS");
}
com_argc = argc;
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] = "";
}
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_argv[com_argc++] = parm;
}
int memsearch (byte *start, int count, int search)
int
memsearch(byte *start, int count, int search)
{
int i;
for (i = 0; i < count; i++)
{
if (start[i] == search)
{
return i;
}
}
return -1;
}
char *CopyString (char *in)
char *
CopyString(char *in)
{
char *out;
@ -119,7 +145,8 @@ char *CopyString (char *in)
return out;
}
void Info_Print (char *s)
void
Info_Print(char *s)
{
char key[512];
char value[512];
@ -127,14 +154,18 @@ void Info_Print (char *s)
int l;
if (*s == '\\')
{
s++;
}
while (*s)
{
o = key;
while (*s && *s != '\\')
{
*o++ = *s++;
}
l = o - key;
@ -145,7 +176,9 @@ void Info_Print (char *s)
}
else
{
*o = 0;
}
Com_Printf("%s", key);
@ -159,13 +192,18 @@ void Info_Print (char *s)
s++;
while (*s && *s != '\\')
{
*o++ = *s++;
}
*o = 0;
if (*s)
{
s++;
}
Com_Printf("%s\n", value);
}
}

View file

@ -24,7 +24,7 @@
* =======================================================================
*/
#include "../header/common.h"
#include "header/common.h"
#include <stdlib.h>
#include <setjmp.h>
@ -40,10 +40,13 @@ 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,7 +71,8 @@ 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];
@ -105,30 +110,41 @@ void Com_Printf (char *fmt, ...)
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 */
}
}
}
/*
* 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];
if (!developer || !developer->value)
{
return; /* don't confuse non-developers with techie stuff... */
}
va_start(argptr, fmt);
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"
* 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))
{
return;
}
va_start(argptr, fmt);
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
@ -160,14 +179,17 @@ 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;
if (recursive)
{
Sys_Error("recursive error after: %s", msg);
}
recursive = true;
@ -186,7 +208,8 @@ void Com_Error (int code, char *fmt, ...)
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);
#ifndef DEDICATED_ONLY
CL_Drop();
@ -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();
}
int Com_ServerState (void)
int
Com_ServerState(void)
{
return server_state;
}
void Com_SetServerState (int state)
void
Com_SetServerState(int state)
{
server_state = state;
}