2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
qargs.c
|
|
|
|
|
|
|
|
command line argument processing routines
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/crc.h"
|
2011-09-11 05:47:56 +00:00
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/idparse.h"
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "QF/qargs.h"
|
2021-04-12 13:09:09 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/qtypes.h"
|
|
|
|
#include "QF/sys.h"
|
2021-04-12 13:09:09 +00:00
|
|
|
#include "QF/va.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
char *fs_globalcfg;
|
|
|
|
static cvar_t fs_globalcfg_cvar = {
|
|
|
|
.name = "fs_globalcfg",
|
|
|
|
.description =
|
|
|
|
"global configuration file",
|
|
|
|
.default_value = FS_GLOBALCFG,
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = 0, .value = &fs_globalcfg },
|
|
|
|
};
|
|
|
|
char *fs_usercfg;
|
|
|
|
static cvar_t fs_usercfg_cvar = {
|
|
|
|
.name = "fs_usercfg",
|
|
|
|
.description =
|
|
|
|
"user configuration file",
|
|
|
|
.default_value = FS_USERCFG,
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = 0, .value = &fs_usercfg },
|
|
|
|
};
|
2011-09-11 05:47:56 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static const char **largv;
|
|
|
|
static const char *argvdummy = " ";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static const char *safeargvs[] =
|
2001-02-19 21:15:25 +00:00
|
|
|
{ "-stdvid", "-nolan", "-nosound", "-nocdaudio", "-nojoy", "-nomouse",
|
|
|
|
"-dibonly" };
|
|
|
|
|
2003-04-17 00:01:48 +00:00
|
|
|
#define NUM_SAFE_ARGVS ((int) (sizeof(safeargvs)/sizeof(safeargvs[0])))
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int com_argc;
|
|
|
|
VISIBLE const char **com_argv;
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *com_cmdline;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE qboolean nouse = false; // 1999-10-29 +USE fix by Maddes
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
|
2001-02-19 21:15:25 +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
|
|
|
|
*/
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2003-01-06 18:28:13 +00:00
|
|
|
COM_CheckParm (const char *parm)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i < com_argc; i++) {
|
|
|
|
if (!com_argv[i])
|
|
|
|
continue; // NEXTSTEP sometimes clears appkit
|
|
|
|
// vars.
|
|
|
|
if (!strcmp (parm, com_argv[i]))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2003-01-06 18:28:13 +00:00
|
|
|
COM_InitArgv (int argc, const char **argv)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
qboolean safe;
|
|
|
|
int i, len;
|
2003-01-06 18:28:13 +00:00
|
|
|
char *cmdline;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
safe = false;
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
largv = (const char **) calloc (1, (argc + NUM_SAFE_ARGVS + 1) *
|
2018-09-07 11:00:57 +00:00
|
|
|
sizeof (const char *));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (com_argc = 0, len = 0; com_argc < argc; com_argc++) {
|
|
|
|
largv[com_argc] = argv[com_argc];
|
|
|
|
if ((argv[com_argc]) && !strcmp ("-safe", argv[com_argc]))
|
|
|
|
safe = true;
|
2018-09-07 13:30:44 +00:00
|
|
|
if (argv[com_argc])
|
2001-02-19 21:15:25 +00:00
|
|
|
len += strlen (argv[com_argc]) + 1;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
cmdline = (char *) calloc (1, len + 1); // need strlen(cmdline)+2
|
|
|
|
cmdline[0] = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (len) {
|
|
|
|
for (i = 1; i < argc; i++) {
|
2003-01-06 18:28:13 +00:00
|
|
|
strncat (cmdline, argv[i], len - strlen (cmdline));
|
|
|
|
assert (len - strlen (cmdline) > 0);
|
|
|
|
strncat (cmdline, " ", len - strlen (cmdline));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2003-01-06 18:28:13 +00:00
|
|
|
cmdline[len - 1] = '\0';
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2003-01-06 18:28:13 +00:00
|
|
|
com_cmdline = cmdline;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (safe) {
|
2001-08-22 22:03:16 +00:00
|
|
|
// 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
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = 0; i < NUM_SAFE_ARGVS; i++) {
|
|
|
|
largv[com_argc] = safeargvs[i];
|
|
|
|
com_argc++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
largv[com_argc] = argvdummy;
|
|
|
|
com_argv = largv;
|
|
|
|
|
|
|
|
if (COM_CheckParm ("-nouse")) {
|
|
|
|
nouse = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
COM_AddParm
|
|
|
|
|
|
|
|
Adds the given string at the end of the current argument list
|
|
|
|
*/
|
|
|
|
void
|
2003-01-06 18:28:13 +00:00
|
|
|
COM_AddParm (const char *parm)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
largv[com_argc++] = parm;
|
|
|
|
}
|
2011-09-11 05:47:56 +00:00
|
|
|
|
|
|
|
void
|
2021-04-12 13:09:09 +00:00
|
|
|
COM_ParseConfig (cbuf_t *cbuf)
|
2011-09-11 05:47:56 +00:00
|
|
|
{
|
|
|
|
// execute +set as early as possible
|
|
|
|
Cmd_StuffCmds (cbuf);
|
|
|
|
Cbuf_Execute_Sets (cbuf);
|
|
|
|
|
2021-04-12 13:09:09 +00:00
|
|
|
// execute set commands in the global configuration file if it exists
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&fs_globalcfg_cvar, 0, 0);
|
|
|
|
Cmd_Exec_File (cbuf, fs_globalcfg, 0);
|
2011-09-11 05:47:56 +00:00
|
|
|
Cbuf_Execute_Sets (cbuf);
|
|
|
|
|
|
|
|
// execute +set again to override the config file
|
|
|
|
Cmd_StuffCmds (cbuf);
|
|
|
|
Cbuf_Execute_Sets (cbuf);
|
|
|
|
|
2021-04-12 13:09:09 +00:00
|
|
|
// execute set commands in the user configuration file if it exists
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&fs_usercfg_cvar, 0, 0);
|
|
|
|
Cmd_Exec_File (cbuf, fs_usercfg, 0);
|
2011-09-11 05:47:56 +00:00
|
|
|
Cbuf_Execute_Sets (cbuf);
|
|
|
|
|
|
|
|
// execute +set again to override the config file
|
|
|
|
Cmd_StuffCmds (cbuf);
|
|
|
|
Cbuf_Execute_Sets (cbuf);
|
2021-04-12 13:09:09 +00:00
|
|
|
}
|
2011-09-11 05:47:56 +00:00
|
|
|
|
2021-11-14 01:12:14 +00:00
|
|
|
int
|
|
|
|
COM_Check_quakerc (const char *cmd, cbuf_t *cbuf)
|
2021-04-12 13:09:09 +00:00
|
|
|
{
|
|
|
|
const char *l, *p;
|
|
|
|
int ret = 0;
|
|
|
|
QFile *f;
|
|
|
|
|
|
|
|
f = QFS_FOpenFile ("quake.rc");
|
|
|
|
while (f && (l = Qgetline (f))) {
|
|
|
|
if ((p = strstr (l, cmd))) {
|
|
|
|
if (p == l) {
|
|
|
|
if (cbuf) {
|
|
|
|
Cbuf_AddText (cbuf, l);
|
|
|
|
}
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Qclose (f);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
COM_ExecConfig (cbuf_t *cbuf, int skip_quakerc)
|
|
|
|
{
|
|
|
|
// quakeforge.cfg overrides quake.rc as it contains quakeforge-specific
|
|
|
|
// commands. If it doesn't exist, then this is the first time quakeforge
|
|
|
|
// has been used in this installation, thus any existing legacy config
|
|
|
|
// should be used to set up defaults on the assumption that the user has
|
|
|
|
// things set up to work with another (hopefully compatible) client
|
|
|
|
if (Cmd_Exec_File (cbuf, "quakeforge.cfg", 1)) {
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cmd_Exec_File (cbuf, fs_usercfg, 0);
|
2021-04-12 13:09:09 +00:00
|
|
|
Cmd_StuffCmds (cbuf);
|
2021-11-14 01:12:14 +00:00
|
|
|
COM_Check_quakerc ("startdemos", cbuf);
|
2021-04-12 13:09:09 +00:00
|
|
|
} else {
|
|
|
|
if (!skip_quakerc) {
|
|
|
|
Cbuf_InsertText (cbuf, "exec quake.rc\n");
|
|
|
|
}
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cmd_Exec_File (cbuf, fs_usercfg, 0);
|
2021-04-12 13:09:09 +00:00
|
|
|
// Reparse the command line for + commands.
|
|
|
|
// (sets still done, but it doesn't matter)
|
|
|
|
// (Note, no non-base commands exist yet)
|
2021-11-14 01:12:14 +00:00
|
|
|
if (skip_quakerc || !COM_Check_quakerc ("stuffcmds", 0)) {
|
2021-04-12 13:09:09 +00:00
|
|
|
Cmd_StuffCmds (cbuf);
|
|
|
|
}
|
|
|
|
}
|
2011-09-11 05:47:56 +00:00
|
|
|
}
|