From 6379c981f8697f4a831334151cdc5ae54497c29c Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Tue, 31 Aug 2010 09:03:32 +0000 Subject: [PATCH] SPlit the common argument processing into an own file --- Makefile | 12 ++- src/common/com_arg.c | 172 +++++++++++++++++++++++++++++++++++++++++++ src/common/common.c | 140 ----------------------------------- 3 files changed, 182 insertions(+), 142 deletions(-) create mode 100644 src/common/com_arg.c diff --git a/Makefile b/Makefile index 80db2738..37677c2a 100644 --- a/Makefile +++ b/Makefile @@ -203,6 +203,7 @@ COMMON_OBJS = \ build/common/cmd_execution.o \ build/common/cmd_parser.o \ build/common/cmd_script.o \ + build/common/com_arg.o \ build/common/com_clientserver.o \ build/common/common.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_parser.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/common.o \ build/dedicated_server_common/crc.o \ @@ -524,7 +526,10 @@ build/common/cmd_parser.o : src/common/cmd_parser.c build/common/cmd_script.o : src/common/cmd_script.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 $(CC) $(CFLAGS_CLIENT) -o $@ -c $< @@ -685,7 +690,10 @@ build/dedicated_server_common/cmd_parser.o : src/common/cmd_parser.c build/dedicated_server_common/cmd_script.o : src/common/cmd_script.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 $(CC) $(CFLAGS_DEDICATED_SERVER) -o $@ -c $< diff --git a/src/common/com_arg.c b/src/common/com_arg.c new file mode 100644 index 00000000..0656da24 --- /dev/null +++ b/src/common/com_arg.c @@ -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 || !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= 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 -#define MAX_NUM_ARGVS 50 -int com_argc; -char *com_argv[MAX_NUM_ARGVS+1]; int realtime; 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 || !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= 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