2000-01-27 17:06:02 +00:00
|
|
|
/*
|
2000-03-24 13:34:14 +00:00
|
|
|
qargs.c
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
command line argument processing routines
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999,2000 Nelson Rush.
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
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.
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
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.
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
|
|
|
|
2000-03-24 13:34:14 +00:00
|
|
|
#include <config.h>
|
2000-02-10 13:49:39 +00:00
|
|
|
#include <string.h>
|
2000-01-27 17:06:02 +00:00
|
|
|
#include <ctype.h>
|
2000-02-10 16:24:10 +00:00
|
|
|
#include <stdlib.h>
|
2000-01-27 17:06:02 +00:00
|
|
|
#include <qtypes.h>
|
2000-02-04 13:40:04 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <crc.h>
|
|
|
|
#include <sys.h>
|
|
|
|
#include <cmd.h>
|
|
|
|
#include <console.h>
|
|
|
|
#include <client.h>
|
2000-02-27 07:13:32 +00:00
|
|
|
#include <assert.h>
|
2000-03-24 13:34:14 +00:00
|
|
|
#include <lib_replace.h>
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-08-20 13:33:48 +00:00
|
|
|
usercmd_t nullcmd; // guarenteed to be zero
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-02-10 13:49:39 +00:00
|
|
|
static char **largv;
|
2000-01-27 17:06:02 +00:00
|
|
|
static char *argvdummy = " ";
|
|
|
|
|
2000-02-10 13:49:39 +00:00
|
|
|
static char *safeargvs[] =
|
|
|
|
{"-stdvid", "-nolan", "-nosound", "-nocdaudio", "-nojoy", "-nomouse", "-dibonly"};
|
|
|
|
|
|
|
|
#define NUM_SAFE_ARGVS (sizeof(safeargvs)/sizeof(safeargvs[0]))
|
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
int com_argc;
|
|
|
|
char **com_argv;
|
2000-02-10 13:49:39 +00:00
|
|
|
char *com_cmdline;
|
2000-02-27 07:13:32 +00:00
|
|
|
cvar_t *cmdline;
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-08-20 14:15:20 +00:00
|
|
|
qboolean nouse = false; // 1999-10-29 +USE fix by Maddes
|
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
/*
|
|
|
|
================
|
|
|
|
COM_CheckParm
|
|
|
|
|
|
|
|
Returns the position (1 to argc-1) in the program's argument list
|
|
|
|
where the given parameter apears, or 0 if not present
|
|
|
|
================
|
|
|
|
*/
|
2000-08-20 13:33:48 +00:00
|
|
|
int
|
|
|
|
COM_CheckParm ( char *parm )
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
int i;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
for (i=1 ; i<com_argc ; i++)
|
|
|
|
{
|
|
|
|
if (!com_argv[i])
|
|
|
|
continue; // NEXTSTEP sometimes clears appkit vars.
|
|
|
|
if (!Q_strcmp (parm,com_argv[i]))
|
|
|
|
return i;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
COM_InitArgv
|
|
|
|
================
|
|
|
|
*/
|
2000-08-20 13:33:48 +00:00
|
|
|
void
|
|
|
|
COM_InitArgv ( int argc, char **argv )
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
qboolean safe;
|
2000-02-10 13:49:39 +00:00
|
|
|
int i, len;
|
2000-01-27 17:06:02 +00:00
|
|
|
|
|
|
|
safe = false;
|
|
|
|
|
2000-02-10 13:49:39 +00:00
|
|
|
largv = (char**)malloc ((argc + NUM_SAFE_ARGVS + 1) * sizeof (char**));
|
|
|
|
|
|
|
|
for (com_argc=0, len=0 ; com_argc < argc ; com_argc++)
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
largv[com_argc] = argv[com_argc];
|
2000-02-20 21:19:50 +00:00
|
|
|
if ((argv[com_argc]) && !Q_strcmp ("-safe", argv[com_argc]))
|
2000-01-27 17:06:02 +00:00
|
|
|
safe = true;
|
2000-04-18 09:30:45 +00:00
|
|
|
if (com_argc)
|
|
|
|
len += strlen (argv[com_argc]) + 1;
|
2000-02-10 13:49:39 +00:00
|
|
|
}
|
|
|
|
|
2000-08-20 13:33:48 +00:00
|
|
|
com_cmdline = (char*)malloc (len+1); // need strlen(com_cmdline)+2
|
2000-02-10 13:49:39 +00:00
|
|
|
com_cmdline[0] = 0;
|
2000-04-18 09:30:45 +00:00
|
|
|
if (len) {
|
|
|
|
for (i=1; i < argc; i++)
|
|
|
|
{
|
|
|
|
strncat (com_cmdline, argv[i], len);
|
|
|
|
assert(len - strlen(com_cmdline) > 0);
|
|
|
|
strcat (com_cmdline, " ");
|
|
|
|
}
|
|
|
|
com_cmdline[len - 1] = '\0';
|
2000-01-27 17:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (safe)
|
|
|
|
{
|
|
|
|
// force all the safe-mode switches. Note that we reserved extra space in
|
|
|
|
// case we need to add these, so we don't need an overflow check
|
|
|
|
for (i=0 ; i<NUM_SAFE_ARGVS ; i++)
|
|
|
|
{
|
|
|
|
largv[com_argc] = safeargvs[i];
|
|
|
|
com_argc++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
largv[com_argc] = argvdummy;
|
|
|
|
com_argv = largv;
|
2000-02-10 13:49:39 +00:00
|
|
|
|
|
|
|
if (COM_CheckParm ("-rogue"))
|
|
|
|
{
|
|
|
|
rogue = true;
|
|
|
|
standard_quake = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (COM_CheckParm ("-hipnotic"))
|
|
|
|
{
|
|
|
|
hipnotic = true;
|
|
|
|
standard_quake = false;
|
|
|
|
}
|
2000-08-20 14:15:20 +00:00
|
|
|
|
|
|
|
// 1999-10-29 +USE fix by Maddes start
|
|
|
|
if (COM_CheckParm ("-nouse"))
|
|
|
|
{
|
|
|
|
nouse = true;
|
|
|
|
}
|
|
|
|
// 1999-10-29 +USE fix by Maddes end
|
2000-01-27 17:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
COM_AddParm
|
|
|
|
|
|
|
|
Adds the given string at the end of the current argument list
|
|
|
|
================
|
|
|
|
*/
|
2000-08-20 13:33:48 +00:00
|
|
|
void
|
|
|
|
COM_AddParm ( char *parm )
|
2000-01-27 17:06:02 +00:00
|
|
|
{
|
|
|
|
largv[com_argc++] = parm;
|
|
|
|
}
|