mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-18 10:02:12 +00:00
SPlit the common argument processing into an own file
This commit is contained in:
parent
6c81165985
commit
6379c981f8
3 changed files with 182 additions and 142 deletions
8
Makefile
8
Makefile
|
@ -203,6 +203,7 @@ COMMON_OBJS = \
|
||||||
build/common/cmd_execution.o \
|
build/common/cmd_execution.o \
|
||||||
build/common/cmd_parser.o \
|
build/common/cmd_parser.o \
|
||||||
build/common/cmd_script.o \
|
build/common/cmd_script.o \
|
||||||
|
build/common/com_arg.o \
|
||||||
build/common/com_clientserver.o \
|
build/common/com_clientserver.o \
|
||||||
build/common/common.o \
|
build/common/common.o \
|
||||||
build/common/crc.o \
|
build/common/crc.o \
|
||||||
|
@ -285,6 +286,7 @@ DEDICATED_SERVER_COMMON_OBJS = \
|
||||||
build/dedicated_server_common/cmd_execution.o \
|
build/dedicated_server_common/cmd_execution.o \
|
||||||
build/dedicated_server_common/cmd_parser.o \
|
build/dedicated_server_common/cmd_parser.o \
|
||||||
build/dedicated_server_common/cmd_script.o \
|
build/dedicated_server_common/cmd_script.o \
|
||||||
|
build/dedicated_server_common/com_arg.o \
|
||||||
build/dedicated_server_common/com_clientserver.o \
|
build/dedicated_server_common/com_clientserver.o \
|
||||||
build/dedicated_server_common/common.o \
|
build/dedicated_server_common/common.o \
|
||||||
build/dedicated_server_common/crc.o \
|
build/dedicated_server_common/crc.o \
|
||||||
|
@ -525,6 +527,9 @@ build/common/cmd_parser.o : src/common/cmd_parser.c
|
||||||
build/common/cmd_script.o : src/common/cmd_script.c
|
build/common/cmd_script.o : src/common/cmd_script.c
|
||||||
$(CC) $(CFLAGS_CLIENT) -o $@ -c $<
|
$(CC) $(CFLAGS_CLIENT) -o $@ -c $<
|
||||||
|
|
||||||
|
build/common/com_arg.o : src/common/com_arg.c
|
||||||
|
$(CC) $(CFLAGS_CLIENT) -o $@ -c $<
|
||||||
|
|
||||||
build/common/com_clientserver.o : src/common/com_clientserver.c
|
build/common/com_clientserver.o : src/common/com_clientserver.c
|
||||||
$(CC) $(CFLAGS_CLIENT) -o $@ -c $<
|
$(CC) $(CFLAGS_CLIENT) -o $@ -c $<
|
||||||
|
|
||||||
|
@ -686,6 +691,9 @@ build/dedicated_server_common/cmd_parser.o : src/common/cmd_parser.c
|
||||||
build/dedicated_server_common/cmd_script.o : src/common/cmd_script.c
|
build/dedicated_server_common/cmd_script.o : src/common/cmd_script.c
|
||||||
$(CC) $(CFLAGS_DEDICATED_SERVER) -o $@ -c $<
|
$(CC) $(CFLAGS_DEDICATED_SERVER) -o $@ -c $<
|
||||||
|
|
||||||
|
build/dedicated_server_common/com_arg.o : src/common/com_arg.c
|
||||||
|
$(CC) $(CFLAGS_DEDICATED_SERVER) -o $@ -c $<
|
||||||
|
|
||||||
build/dedicated_server_common/com_clientserver.o : src/common/com_clientserver.c
|
build/dedicated_server_common/com_clientserver.o : src/common/com_clientserver.c
|
||||||
$(CC) $(CFLAGS_DEDICATED_SERVER) -o $@ -c $<
|
$(CC) $(CFLAGS_DEDICATED_SERVER) -o $@ -c $<
|
||||||
|
|
||||||
|
|
172
src/common/com_arg.c
Normal file
172
src/common/com_arg.c
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 1997-2001 Id Software, Inc.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||||
|
* 02111-1307, USA.
|
||||||
|
*
|
||||||
|
* =======================================================================
|
||||||
|
*
|
||||||
|
* Common argument processing
|
||||||
|
*
|
||||||
|
* =======================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qcommon.h"
|
||||||
|
|
||||||
|
#define MAX_NUM_ARGVS 50
|
||||||
|
|
||||||
|
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 i;
|
||||||
|
|
||||||
|
for (i=1 ; i<com_argc ; i++)
|
||||||
|
{
|
||||||
|
if (!strcmp (parm,com_argv[i]))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int COM_Argc (void)
|
||||||
|
{
|
||||||
|
return com_argc;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *COM_Argv (int arg)
|
||||||
|
{
|
||||||
|
if (arg < 0 || arg >= com_argc || !com_argv[arg])
|
||||||
|
return "";
|
||||||
|
|
||||||
|
return com_argv[arg];
|
||||||
|
}
|
||||||
|
|
||||||
|
void COM_ClearArgv (int arg)
|
||||||
|
{
|
||||||
|
if (arg < 0 || arg >= com_argc || !com_argv[arg])
|
||||||
|
return;
|
||||||
|
|
||||||
|
com_argv[arg] = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
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 )
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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 i;
|
||||||
|
|
||||||
|
for (i=0 ; i<count ; i++)
|
||||||
|
if (start[i] == search)
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *CopyString (char *in)
|
||||||
|
{
|
||||||
|
char *out;
|
||||||
|
|
||||||
|
out = Z_Malloc ((int)strlen(in)+1);
|
||||||
|
strcpy (out, in);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Info_Print (char *s)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
key[20] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
*o = 0;
|
||||||
|
|
||||||
|
Com_Printf ("%s", key);
|
||||||
|
|
||||||
|
if (!*s)
|
||||||
|
{
|
||||||
|
Com_Printf ("MISSING VALUE\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
o = value;
|
||||||
|
s++;
|
||||||
|
|
||||||
|
while (*s && *s != '\\')
|
||||||
|
*o++ = *s++;
|
||||||
|
|
||||||
|
*o = 0;
|
||||||
|
|
||||||
|
if (*s)
|
||||||
|
s++;
|
||||||
|
|
||||||
|
Com_Printf ("%s\n", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,10 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "qcommon.h"
|
#include "qcommon.h"
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
#define MAX_NUM_ARGVS 50
|
|
||||||
|
|
||||||
int com_argc;
|
|
||||||
char *com_argv[MAX_NUM_ARGVS+1];
|
|
||||||
int realtime;
|
int realtime;
|
||||||
|
|
||||||
FILE *log_stats_file;
|
FILE *log_stats_file;
|
||||||
|
@ -87,144 +84,7 @@ Handles byte ordering and avoids alignment errors
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 i;
|
|
||||||
|
|
||||||
for (i=1 ; i<com_argc ; i++)
|
|
||||||
{
|
|
||||||
if (!strcmp (parm,com_argv[i]))
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int COM_Argc (void)
|
|
||||||
{
|
|
||||||
return com_argc;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *COM_Argv (int arg)
|
|
||||||
{
|
|
||||||
if (arg < 0 || arg >= com_argc || !com_argv[arg])
|
|
||||||
return "";
|
|
||||||
|
|
||||||
return com_argv[arg];
|
|
||||||
}
|
|
||||||
|
|
||||||
void COM_ClearArgv (int arg)
|
|
||||||
{
|
|
||||||
if (arg < 0 || arg >= com_argc || !com_argv[arg])
|
|
||||||
return;
|
|
||||||
|
|
||||||
com_argv[arg] = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
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 )
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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 i;
|
|
||||||
|
|
||||||
for (i=0 ; i<count ; i++)
|
|
||||||
if (start[i] == search)
|
|
||||||
return i;
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *CopyString (char *in)
|
|
||||||
{
|
|
||||||
char *out;
|
|
||||||
|
|
||||||
out = Z_Malloc ((int)strlen(in)+1);
|
|
||||||
strcpy (out, in);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Info_Print (char *s)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
key[20] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
*o = 0;
|
|
||||||
|
|
||||||
Com_Printf ("%s", key);
|
|
||||||
|
|
||||||
if (!*s)
|
|
||||||
{
|
|
||||||
Com_Printf ("MISSING VALUE\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
o = value;
|
|
||||||
s++;
|
|
||||||
|
|
||||||
while (*s && *s != '\\')
|
|
||||||
*o++ = *s++;
|
|
||||||
|
|
||||||
*o = 0;
|
|
||||||
|
|
||||||
if (*s)
|
|
||||||
s++;
|
|
||||||
|
|
||||||
Com_Printf ("%s\n", value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue