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,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 ; i++)
for (i = 1; i < com_argc; i++)
{
if (!strcmp (parm,com_argv[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;
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<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] = "";
}
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<count ; 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;
char *out;
out = Z_Malloc ((int)strlen(in)+1);
strcpy (out, in);
out = Z_Malloc((int)strlen(in) + 1);
strcpy(out, in);
return out;
}
void Info_Print (char *s)
void
Info_Print(char *s)
{
char key[512];
char value[512];
char *o;
int l;
char key[512];
char value[512];
char *o;
int l;
if (*s == '\\')
{
s++;
}
while (*s)
{
o = key;
while (*s && *s != '\\')
{
*o++ = *s++;
}
l = o - key;
if (l < 20)
{
memset (o, ' ', 20-l);
memset(o, ' ', 20 - l);
key[20] = 0;
}
else
{
*o = 0;
}
Com_Printf ("%s", key);
Com_Printf("%s", key);
if (!*s)
{
Com_Printf ("MISSING VALUE\n");
Com_Printf("MISSING VALUE\n");
return;
}
@ -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);
Com_Printf("%s\n", value);
}
}

View file

@ -24,26 +24,29 @@
* =======================================================================
*/
#include "../header/common.h"
#include "header/common.h"
#include <stdlib.h>
#include <setjmp.h>
#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;
}