2001-02-21 19:35:06 +00:00
|
|
|
/*
|
|
|
|
cmd.c
|
|
|
|
|
|
|
|
script command processing module
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 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:
|
|
|
|
|
|
|
|
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-21 19:35:06 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <ctype.h>
|
2002-05-15 22:14:17 +00:00
|
|
|
#include <errno.h>
|
2002-07-31 05:19:03 +00:00
|
|
|
#include <stdlib.h>
|
2002-06-10 22:03:51 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
#include "QF/cbuf.h"
|
2002-07-31 22:03:53 +00:00
|
|
|
#include "QF/idparse.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-08-22 22:03:16 +00:00
|
|
|
#include "QF/cvar.h"
|
2002-07-31 05:19:03 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/hash.h"
|
|
|
|
#include "QF/qargs.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/zone.h"
|
2002-06-10 22:03:51 +00:00
|
|
|
|
2001-02-21 19:35:06 +00:00
|
|
|
typedef struct cmdalias_s {
|
|
|
|
struct cmdalias_s *next;
|
2002-03-21 19:47:31 +00:00
|
|
|
const char *name;
|
|
|
|
const char *value;
|
2001-02-21 19:35:06 +00:00
|
|
|
} cmdalias_t;
|
|
|
|
|
2007-03-18 03:48:09 +00:00
|
|
|
typedef struct cmd_provider_s
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
cbuf_interpreter_t* interp;
|
|
|
|
} cmd_provider_t;
|
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
static cmdalias_t *cmd_alias;
|
2002-03-18 23:39:03 +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
|
|
|
VISIBLE int cmd_warncmd;
|
|
|
|
static cvar_t cmd_warncmd_cvar = {
|
|
|
|
.name = "cmd_warncmd",
|
|
|
|
.description =
|
|
|
|
"Toggles the display of error messages for unknown commands",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &cmd_warncmd },
|
|
|
|
};
|
2001-02-21 19:35:06 +00:00
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
static hashtab_t *cmd_alias_hash;
|
|
|
|
static hashtab_t *cmd_hash;
|
2007-03-18 03:48:09 +00:00
|
|
|
static hashtab_t *cmd_provider_hash;
|
2001-07-06 17:45:32 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE cbuf_args_t *cmd_args;
|
2002-07-31 05:19:03 +00:00
|
|
|
static cbuf_t *cmd_cbuf;
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE cmd_source_t cmd_source;
|
2001-02-21 19:35:06 +00:00
|
|
|
|
2001-07-30 01:01:39 +00:00
|
|
|
|
2002-05-11 03:00:14 +00:00
|
|
|
/* Command parsing functions */
|
2001-02-21 19:35:06 +00:00
|
|
|
|
2012-08-13 06:03:40 +00:00
|
|
|
static cmd_function_t *cmd_functions; // possible commands to execute
|
2001-02-21 19:35:06 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2001-02-21 19:35:06 +00:00
|
|
|
Cmd_Argc (void)
|
|
|
|
{
|
2002-07-31 05:19:03 +00:00
|
|
|
return cmd_args->argc;
|
2001-02-21 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE const char *
|
2001-02-21 19:35:06 +00:00
|
|
|
Cmd_Argv (int arg)
|
|
|
|
{
|
2002-07-31 05:19:03 +00:00
|
|
|
if (arg >= cmd_args->argc)
|
2002-03-03 03:36:27 +00:00
|
|
|
return "";
|
2002-07-31 05:19:03 +00:00
|
|
|
return cmd_args->argv[arg]->str;
|
2002-03-27 06:24:19 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE const char *
|
2001-07-10 18:25:54 +00:00
|
|
|
Cmd_Args (int start)
|
2001-02-21 19:35:06 +00:00
|
|
|
{
|
2002-07-31 05:19:03 +00:00
|
|
|
if (start >= cmd_args->argc)
|
2002-04-24 22:33:04 +00:00
|
|
|
return "";
|
2002-07-31 05:19:03 +00:00
|
|
|
return cmd_args->args[start];
|
2001-02-21 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_Command (cbuf_args_t *args)
|
2002-05-11 03:00:14 +00:00
|
|
|
{
|
|
|
|
cmd_function_t *cmd;
|
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
cmd_args = args;
|
|
|
|
//cmd_source = src;
|
2002-05-11 03:00:14 +00:00
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
if (!args->argc)
|
2003-02-14 08:06:01 +00:00
|
|
|
return 0; // no tokens
|
2002-05-11 03:00:14 +00:00
|
|
|
|
|
|
|
// check functions
|
2002-07-31 05:19:03 +00:00
|
|
|
cmd = (cmd_function_t *) Hash_Find (cmd_hash, args->argv[0]->str);
|
2002-05-11 03:00:14 +00:00
|
|
|
if (cmd) {
|
2002-07-31 05:19:03 +00:00
|
|
|
if (cmd->function) {
|
2002-05-11 03:00:14 +00:00
|
|
|
cmd->function ();
|
2021-03-19 18:56:16 +00:00
|
|
|
} else if (cmd->datafunc) {
|
|
|
|
cmd->datafunc (cmd->data);
|
2002-07-31 05:19:03 +00:00
|
|
|
}
|
2003-02-14 08:06:01 +00:00
|
|
|
return 0;
|
2002-05-11 03:00:14 +00:00
|
|
|
}
|
2002-07-31 05:19:03 +00:00
|
|
|
// check cvars
|
2002-05-11 03:00:14 +00:00
|
|
|
if (Cvar_Command ())
|
2003-02-14 08:06:01 +00:00
|
|
|
return 0;
|
2003-11-20 07:02:14 +00:00
|
|
|
if (cbuf_active->unknown_command && cbuf_active->unknown_command ())
|
|
|
|
return 0;
|
2002-11-14 02:10:55 +00:00
|
|
|
if (cbuf_active->strict)
|
2003-02-14 08:06:01 +00:00
|
|
|
return -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
|
|
|
else if (cmd_warncmd || developer & SYS_dev)
|
2002-05-11 03:00:14 +00:00
|
|
|
Sys_Printf ("Unknown command \"%s\"\n", Cmd_Argv (0));
|
2003-02-14 08:06:01 +00:00
|
|
|
return 0;
|
2002-05-11 03:00:14 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 18:56:16 +00:00
|
|
|
static int
|
|
|
|
add_command (const char *cmd_name, xcommand_t func, xdatacmd_t datafunc,
|
|
|
|
void *data, const char *description)
|
2002-05-11 03:00:14 +00:00
|
|
|
{
|
|
|
|
cmd_function_t *cmd;
|
|
|
|
cmd_function_t **c;
|
|
|
|
|
2001-02-21 19:35:06 +00:00
|
|
|
// fail if the command already exists
|
2002-03-21 19:47:31 +00:00
|
|
|
cmd = (cmd_function_t *) Hash_Find (cmd_hash, cmd_name);
|
2001-02-21 19:35:06 +00:00
|
|
|
if (cmd) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "Cmd_AddCommand: %s already defined\n",
|
2010-11-23 05:09:30 +00:00
|
|
|
cmd_name);
|
2002-04-12 17:19:49 +00:00
|
|
|
return 0;
|
2001-02-21 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2002-03-29 07:43:02 +00:00
|
|
|
cmd = calloc (1, sizeof (cmd_function_t));
|
2002-05-14 06:37:28 +00:00
|
|
|
SYS_CHECKMEM (cmd);
|
2001-02-21 19:35:06 +00:00
|
|
|
cmd->name = cmd_name;
|
2021-03-19 18:56:16 +00:00
|
|
|
cmd->function = func;
|
|
|
|
cmd->datafunc = datafunc;
|
|
|
|
cmd->data = data;
|
2001-02-21 19:35:06 +00:00
|
|
|
cmd->description = description;
|
|
|
|
Hash_Add (cmd_hash, cmd);
|
|
|
|
for (c = &cmd_functions; *c; c = &(*c)->next)
|
2002-03-21 19:47:31 +00:00
|
|
|
if (strcmp ((*c)->name, cmd->name) >= 0)
|
2001-02-21 19:35:06 +00:00
|
|
|
break;
|
|
|
|
cmd->next = *c;
|
|
|
|
*c = cmd;
|
2002-04-12 17:19:49 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-03-19 18:56:16 +00:00
|
|
|
/* Registers a command and handler function */
|
|
|
|
VISIBLE int
|
|
|
|
Cmd_AddCommand (const char *cmd_name, xcommand_t function,
|
|
|
|
const char *description)
|
|
|
|
{
|
|
|
|
return add_command (cmd_name, function, 0, 0, description);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Registers a command and handler function with data */
|
|
|
|
VISIBLE int
|
|
|
|
Cmd_AddDataCommand (const char *cmd_name, xdatacmd_t function,
|
|
|
|
void *data, const char *description)
|
|
|
|
{
|
|
|
|
return add_command (cmd_name, 0, function, data, description);
|
|
|
|
}
|
|
|
|
|
2002-05-11 03:00:14 +00:00
|
|
|
/* Unregisters a command */
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2002-04-12 17:19:49 +00:00
|
|
|
Cmd_RemoveCommand (const char *name)
|
|
|
|
{
|
|
|
|
cmd_function_t *cmd;
|
|
|
|
cmd_function_t **c;
|
|
|
|
|
|
|
|
cmd = (cmd_function_t *) Hash_Del (cmd_hash, name);
|
|
|
|
if (!cmd)
|
|
|
|
return 0;
|
|
|
|
for (c = &cmd_functions; *c; c = &(*c)->next)
|
2003-04-25 03:06:34 +00:00
|
|
|
if (*c == cmd)
|
2002-04-12 17:19:49 +00:00
|
|
|
break;
|
2003-04-25 03:06:34 +00:00
|
|
|
*c = cmd->next;
|
2002-04-12 17:19:49 +00:00
|
|
|
free (cmd);
|
|
|
|
return 1;
|
2001-02-21 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2002-05-11 03:00:14 +00:00
|
|
|
/* Checks for the existance of a command */
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE qboolean
|
2001-07-15 07:04:17 +00:00
|
|
|
Cmd_Exists (const char *cmd_name)
|
2001-02-21 19:35:06 +00:00
|
|
|
{
|
|
|
|
cmd_function_t *cmd;
|
|
|
|
|
2002-03-21 19:47:31 +00:00
|
|
|
cmd = (cmd_function_t *) Hash_Find (cmd_hash, cmd_name);
|
2001-02-21 19:35:06 +00:00
|
|
|
if (cmd) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-05-11 03:00:14 +00:00
|
|
|
|
|
|
|
/* Command completion functions */
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE const char *
|
2001-07-15 07:04:17 +00:00
|
|
|
Cmd_CompleteCommand (const char *partial)
|
2001-02-21 19:35:06 +00:00
|
|
|
{
|
2002-03-21 19:47:31 +00:00
|
|
|
cmd_function_t *cmd;
|
|
|
|
int len;
|
2001-02-21 19:35:06 +00:00
|
|
|
|
|
|
|
len = strlen (partial);
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
return NULL;
|
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
// check for exact match
|
2001-02-21 19:35:06 +00:00
|
|
|
for (cmd = cmd_functions; cmd; cmd = cmd->next)
|
2007-06-09 06:55:15 +00:00
|
|
|
if (!strcmp (partial, cmd->name))
|
2001-02-21 19:35:06 +00:00
|
|
|
return cmd->name;
|
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
// check for partial match
|
2001-02-21 19:35:06 +00:00
|
|
|
for (cmd = cmd_functions; cmd; cmd = cmd->next)
|
2007-06-09 06:55:15 +00:00
|
|
|
if (!strncmp (partial, cmd->name, len))
|
2001-02-21 19:35:06 +00:00
|
|
|
return cmd->name;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-06-28 04:05:14 +00:00
|
|
|
/*
|
|
|
|
Cmd_CompleteCountPossible
|
|
|
|
|
|
|
|
New function for tab-completion system
|
|
|
|
Added by EvilTypeGuy
|
|
|
|
Thanks to Fett erich@heintz.com
|
|
|
|
Thanks to taniwha
|
|
|
|
*/
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2001-07-15 07:04:17 +00:00
|
|
|
Cmd_CompleteCountPossible (const char *partial)
|
2001-06-28 04:05:14 +00:00
|
|
|
{
|
2002-03-21 19:47:31 +00:00
|
|
|
cmd_function_t *cmd;
|
|
|
|
int len;
|
|
|
|
int h;
|
|
|
|
|
2001-06-28 04:05:14 +00:00
|
|
|
h = 0;
|
2002-03-21 19:47:31 +00:00
|
|
|
len = strlen (partial);
|
|
|
|
|
2001-06-28 04:05:14 +00:00
|
|
|
if (!len)
|
|
|
|
return 0;
|
2002-03-21 19:47:31 +00:00
|
|
|
|
2001-06-28 04:05:14 +00:00
|
|
|
// Loop through the command list and count all partial matches
|
|
|
|
for (cmd = cmd_functions; cmd; cmd = cmd->next)
|
2007-06-09 06:55:15 +00:00
|
|
|
if (!strncmp (partial, cmd->name, len))
|
2001-06-28 04:05:14 +00:00
|
|
|
h++;
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Cmd_CompleteBuildList
|
|
|
|
|
|
|
|
New function for tab-completion system
|
|
|
|
Added by EvilTypeGuy
|
|
|
|
Thanks to Fett erich@heintz.com
|
|
|
|
Thanks to taniwha
|
|
|
|
*/
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE const char **
|
2001-07-15 07:04:17 +00:00
|
|
|
Cmd_CompleteBuildList (const char *partial)
|
2001-06-28 04:05:14 +00:00
|
|
|
{
|
2002-03-21 19:47:31 +00:00
|
|
|
cmd_function_t *cmd;
|
|
|
|
int len = 0;
|
|
|
|
int bpos = 0;
|
|
|
|
int sizeofbuf;
|
|
|
|
const char **buf;
|
|
|
|
|
|
|
|
sizeofbuf = (Cmd_CompleteCountPossible (partial) + 1) * sizeof (char *);
|
|
|
|
len = strlen (partial);
|
|
|
|
buf = malloc (sizeofbuf + sizeof (char *));
|
2001-06-28 04:05:14 +00:00
|
|
|
|
2002-05-14 06:37:28 +00:00
|
|
|
SYS_CHECKMEM (buf);
|
2001-06-28 04:05:14 +00:00
|
|
|
// Loop through the alias list and print all matches
|
|
|
|
for (cmd = cmd_functions; cmd; cmd = cmd->next)
|
2007-06-09 06:55:15 +00:00
|
|
|
if (!strncmp (partial, cmd->name, len))
|
2001-06-28 04:05:14 +00:00
|
|
|
buf[bpos++] = cmd->name;
|
|
|
|
|
|
|
|
buf[bpos] = NULL;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2002-05-11 03:00:14 +00:00
|
|
|
/* Hash table functions for aliases and commands */
|
|
|
|
static void
|
|
|
|
cmd_alias_free (void *_a, void *unused)
|
2002-04-16 23:56:21 +00:00
|
|
|
{
|
2002-05-11 03:00:14 +00:00
|
|
|
cmdalias_t *a = (cmdalias_t *) _a;
|
|
|
|
|
|
|
|
free ((char *) a->name);
|
|
|
|
free ((char *) a->value);
|
|
|
|
free (a);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2012-07-18 13:34:37 +00:00
|
|
|
cmd_alias_get_key (const void *_a, void *unused)
|
2002-05-11 03:00:14 +00:00
|
|
|
{
|
|
|
|
cmdalias_t *a = (cmdalias_t *) _a;
|
|
|
|
|
|
|
|
return a->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2012-07-18 13:34:37 +00:00
|
|
|
cmd_get_key (const void *c, void *unused)
|
2002-05-11 03:00:14 +00:00
|
|
|
{
|
|
|
|
cmd_function_t *cmd = (cmd_function_t *) c;
|
|
|
|
|
|
|
|
return cmd->name;
|
2002-04-16 23:56:21 +00:00
|
|
|
}
|
|
|
|
|
2007-03-18 03:48:09 +00:00
|
|
|
static void
|
|
|
|
cmd_provider_free (void *_a, void *unused)
|
|
|
|
{
|
|
|
|
cmd_provider_t *p = (cmd_provider_t *) _a;
|
|
|
|
|
|
|
|
free ((char *) p->name);
|
|
|
|
free (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2012-07-18 13:34:37 +00:00
|
|
|
cmd_provider_get_key (const void *_a, void *unused)
|
2007-03-18 03:48:09 +00:00
|
|
|
{
|
|
|
|
cmd_provider_t *p = (cmd_provider_t *) _a;
|
|
|
|
|
|
|
|
return p->name;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-07-30 02:06:37 +00:00
|
|
|
Cmd_Runalias_f (void)
|
2002-06-01 22:13:14 +00:00
|
|
|
{
|
|
|
|
cmdalias_t *a;
|
2002-07-30 02:06:37 +00:00
|
|
|
|
2002-06-01 22:13:14 +00:00
|
|
|
a = (cmdalias_t *) Hash_Find (cmd_alias_hash, Cmd_Argv (0));
|
2002-07-30 02:06:37 +00:00
|
|
|
|
2002-06-01 22:13:14 +00:00
|
|
|
if (a) {
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_InsertText (cbuf_active, a->value);
|
2002-06-01 22:13:14 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2002-07-30 02:06:37 +00:00
|
|
|
Sys_Printf
|
|
|
|
("BUG: No alias found for registered command. Please report this to the QuakeForge development team.");
|
2002-06-01 22:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-05-11 03:00:14 +00:00
|
|
|
Cmd_Alias_f (void)
|
2001-02-21 19:35:06 +00:00
|
|
|
{
|
2002-05-11 03:00:14 +00:00
|
|
|
cmdalias_t *alias;
|
2005-03-28 04:35:22 +00:00
|
|
|
dstring_t *cmd;
|
2002-05-11 03:00:14 +00:00
|
|
|
int i, c;
|
|
|
|
const char *s;
|
2001-02-21 19:35:06 +00:00
|
|
|
|
2002-05-11 03:00:14 +00:00
|
|
|
if (Cmd_Argc () == 1) {
|
|
|
|
Sys_Printf ("Current alias commands:\n");
|
|
|
|
for (alias = cmd_alias; alias; alias = alias->next)
|
|
|
|
Sys_Printf ("alias %s \"%s\"\n", alias->name, alias->value);
|
|
|
|
return;
|
|
|
|
}
|
2001-02-21 19:35:06 +00:00
|
|
|
|
2002-05-11 03:00:14 +00:00
|
|
|
s = Cmd_Argv (1);
|
|
|
|
// if the alias already exists, reuse it
|
|
|
|
alias = (cmdalias_t *) Hash_Find (cmd_alias_hash, s);
|
2002-05-11 06:09:50 +00:00
|
|
|
if (Cmd_Argc () == 2) {
|
|
|
|
if (alias)
|
2002-07-31 05:19:03 +00:00
|
|
|
Sys_Printf ("alias %s \"%s\"\n", alias->name, alias->value);
|
2002-05-11 06:09:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-06-01 22:13:14 +00:00
|
|
|
if (alias)
|
2002-05-11 03:00:14 +00:00
|
|
|
free ((char *) alias->value);
|
2002-12-14 20:34:20 +00:00
|
|
|
else if (!Cmd_Exists (s)) {
|
2002-05-11 03:00:14 +00:00
|
|
|
cmdalias_t **a;
|
2001-02-21 19:35:06 +00:00
|
|
|
|
2002-05-11 03:00:14 +00:00
|
|
|
alias = calloc (1, sizeof (cmdalias_t));
|
2002-05-14 06:37:28 +00:00
|
|
|
SYS_CHECKMEM (alias);
|
2002-05-11 03:00:14 +00:00
|
|
|
alias->name = strdup (s);
|
|
|
|
Hash_Add (cmd_alias_hash, alias);
|
|
|
|
for (a = &cmd_alias; *a; a = &(*a)->next)
|
|
|
|
if (strcmp ((*a)->name, alias->name) >= 0)
|
|
|
|
break;
|
|
|
|
alias->next = *a;
|
|
|
|
*a = alias;
|
2002-12-14 20:34:20 +00:00
|
|
|
Cmd_AddCommand (alias->name, Cmd_Runalias_f, "Alias command.");
|
|
|
|
} else {
|
|
|
|
Sys_Printf ("alias: a command with the name \"%s\" already exists.\n", s);
|
|
|
|
return;
|
2002-05-11 03:00:14 +00:00
|
|
|
}
|
|
|
|
// copy the rest of the command line
|
2005-03-28 04:35:22 +00:00
|
|
|
cmd = dstring_newstr ();
|
2002-05-11 03:00:14 +00:00
|
|
|
c = Cmd_Argc ();
|
|
|
|
for (i = 2; i < c; i++) {
|
2005-03-28 04:35:22 +00:00
|
|
|
dstring_appendstr (cmd, Cmd_Argv (i));
|
2002-05-11 03:00:14 +00:00
|
|
|
if (i != c - 1)
|
2005-03-28 04:35:22 +00:00
|
|
|
dstring_appendstr (cmd, " ");
|
2002-05-11 03:00:14 +00:00
|
|
|
}
|
|
|
|
|
2005-03-28 04:35:22 +00:00
|
|
|
alias->value = dstring_freeze (cmd);
|
2001-02-21 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-05-11 03:00:14 +00:00
|
|
|
Cmd_UnAlias_f (void)
|
|
|
|
{
|
|
|
|
cmdalias_t *alias;
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
if (Cmd_Argc () != 2) {
|
|
|
|
Sys_Printf ("unalias <alias>: erase an existing alias\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = Cmd_Argv (1);
|
|
|
|
alias = Hash_Del (cmd_alias_hash, s);
|
|
|
|
|
|
|
|
if (alias) {
|
|
|
|
cmdalias_t **a;
|
|
|
|
|
2002-06-10 22:03:51 +00:00
|
|
|
Cmd_RemoveCommand (alias->name);
|
2002-07-30 02:06:37 +00:00
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
for (a = &cmd_alias; *a != alias; a = &(*a)->next)
|
|
|
|
;
|
|
|
|
*a = alias->next;
|
|
|
|
|
|
|
|
free ((char *) alias->name);
|
|
|
|
free ((char *) alias->value);
|
|
|
|
free (alias);
|
|
|
|
} else {
|
|
|
|
Sys_Printf ("Unknown alias \"%s\"\n", s);
|
2002-05-11 06:09:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-21 19:35:06 +00:00
|
|
|
Cmd_CmdList_f (void)
|
|
|
|
{
|
|
|
|
cmd_function_t *cmd;
|
|
|
|
int i;
|
|
|
|
int show_description = 0;
|
2002-07-30 02:06:37 +00:00
|
|
|
|
2002-03-21 19:47:31 +00:00
|
|
|
if (Cmd_Argc () > 1)
|
2001-02-21 19:35:06 +00:00
|
|
|
show_description = 1;
|
|
|
|
for (cmd = cmd_functions, i = 0; cmd; cmd = cmd->next, i++) {
|
|
|
|
if (show_description) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%-20s :\n%s\n", cmd->name, cmd->description);
|
2001-02-21 19:35:06 +00:00
|
|
|
} else {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%s\n", cmd->name);
|
2001-02-21 19:35:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("------------\n%d commands\n", i);
|
2001-02-21 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-07-30 01:01:39 +00:00
|
|
|
Cmd_Help_f (void)
|
|
|
|
{
|
2002-03-21 19:47:31 +00:00
|
|
|
const char *name;
|
|
|
|
cvar_t *var;
|
2001-07-30 01:01:39 +00:00
|
|
|
cmd_function_t *cmd;
|
|
|
|
|
|
|
|
if (Cmd_Argc () != 2) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("usage: help <cvar/command>\n");
|
2001-07-30 01:01:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = Cmd_Argv (1);
|
|
|
|
|
2007-06-09 06:55:15 +00:00
|
|
|
for (cmd = cmd_functions; cmd && strcmp (name, cmd->name);
|
2002-07-30 02:06:37 +00:00
|
|
|
cmd = cmd->next);
|
2001-07-30 01:01:39 +00:00
|
|
|
if (cmd) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%s\n", cmd->description);
|
2001-07-30 01:01:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = Cvar_FindVar (name);
|
|
|
|
if (!var)
|
|
|
|
var = Cvar_FindAlias (name);
|
|
|
|
if (var) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%s\n", var->description);
|
2001-07-30 01:01:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("variable/command not found\n");
|
2001-07-30 01:01:39 +00:00
|
|
|
}
|
2021-04-12 13:09:09 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_Exec_f (void)
|
2002-03-18 23:39:03 +00:00
|
|
|
{
|
2002-07-31 05:19:03 +00:00
|
|
|
char *f;
|
2021-07-29 02:12:37 +00:00
|
|
|
size_t mark;
|
2002-05-11 03:00:14 +00:00
|
|
|
|
|
|
|
if (Cmd_Argc () != 2) {
|
2002-07-31 05:19:03 +00:00
|
|
|
Sys_Printf ("exec <filename> : execute a script file\n");
|
2002-04-22 04:23:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-28 06:01:45 +00:00
|
|
|
mark = Hunk_LowMark (0);
|
2014-01-23 02:57:57 +00:00
|
|
|
f = (char *) QFS_LoadHunkFile (QFS_FOpenFile (Cmd_Argv (1)));
|
2002-07-31 05:19:03 +00:00
|
|
|
if (!f) {
|
|
|
|
Sys_Printf ("couldn't exec %s\n", Cmd_Argv (1));
|
2002-04-22 04:23:36 +00:00
|
|
|
return;
|
|
|
|
}
|
[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
|
|
|
if (!Cvar_Command () && (cmd_warncmd || (developer & SYS_dev)))
|
2002-07-31 05:19:03 +00:00
|
|
|
Sys_Printf ("execing %s\n", Cmd_Argv (1));
|
2002-11-09 07:13:52 +00:00
|
|
|
Cbuf_InsertText (cbuf_active, f);
|
2021-07-28 06:01:45 +00:00
|
|
|
Hunk_FreeToLowMark (0, mark);
|
2002-04-22 04:23:36 +00:00
|
|
|
}
|
|
|
|
|
2002-05-31 05:38:06 +00:00
|
|
|
/*
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_Echo_f
|
2002-05-31 05:38:06 +00:00
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
Just prints the rest of the line to the console
|
2002-05-31 05:38:06 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_Echo_f (void)
|
2002-06-13 05:58:48 +00:00
|
|
|
{
|
2002-07-31 05:19:03 +00:00
|
|
|
if (Cmd_Argc () == 2)
|
|
|
|
Sys_Printf ("%s\n", Cmd_Argv (1));
|
|
|
|
else
|
|
|
|
Sys_Printf ("%s\n", Cmd_Args (1));
|
2002-06-13 05:58:48 +00:00
|
|
|
}
|
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
/* Pauses execution of the current stack until
|
|
|
|
next call of Cmd_Execute (usually next frame) */
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_Wait_f (void)
|
2002-05-31 05:38:06 +00:00
|
|
|
{
|
2002-07-31 22:03:53 +00:00
|
|
|
cbuf_active->state = CBUF_STATE_WAIT;
|
2002-05-15 22:14:17 +00:00
|
|
|
}
|
|
|
|
|
2002-10-13 19:46:47 +00:00
|
|
|
/* Pauses execution for a specified number
|
|
|
|
of seconds */
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-10-13 19:46:47 +00:00
|
|
|
Cmd_Sleep_f (void)
|
|
|
|
{
|
|
|
|
double waittime;
|
|
|
|
cbuf_t *p;
|
|
|
|
cbuf_active->state = CBUF_STATE_WAIT;
|
|
|
|
waittime = atof (Cmd_Argv (1));
|
|
|
|
for (p = cbuf_active; p->up; p = p->up); // Get to top of stack
|
|
|
|
p->resumetime = Sys_DoubleTime() + waittime;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_StuffCmds (cbuf_t *cbuf)
|
2002-06-10 22:03:51 +00:00
|
|
|
{
|
2002-07-31 05:19:03 +00:00
|
|
|
int i, j;
|
2011-09-08 03:30:58 +00:00
|
|
|
dstring_t *build;
|
2002-07-30 02:06:37 +00:00
|
|
|
|
2011-09-08 03:30:58 +00:00
|
|
|
if (!*com_cmdline)
|
2002-06-10 22:03:51 +00:00
|
|
|
return;
|
|
|
|
|
2011-09-08 03:30:58 +00:00
|
|
|
build = dstring_newstr ();
|
2002-07-30 02:06:37 +00:00
|
|
|
|
2011-09-08 03:30:58 +00:00
|
|
|
// pull out the commands
|
|
|
|
for (i = 0; com_cmdline[i]; i++) {
|
|
|
|
if (com_cmdline[i] == '+') {
|
2002-07-31 05:19:03 +00:00
|
|
|
i++;
|
2002-07-30 02:06:37 +00:00
|
|
|
|
2011-09-08 03:30:58 +00:00
|
|
|
for (j = i;
|
|
|
|
(com_cmdline[j]
|
2012-08-18 02:02:52 +00:00
|
|
|
&& !((j == 0 || isspace((byte) com_cmdline[j - 1]))
|
2011-09-08 03:30:58 +00:00
|
|
|
&& ((com_cmdline[j] == '+')
|
|
|
|
|| (com_cmdline[j] == '-'))));
|
|
|
|
j++)
|
|
|
|
;
|
2002-07-31 05:19:03 +00:00
|
|
|
|
2011-09-08 03:30:58 +00:00
|
|
|
dstring_appendsubstr (build, com_cmdline + i, j - i);
|
|
|
|
dstring_appendstr (build, "\n");
|
2002-07-31 05:19:03 +00:00
|
|
|
i = j - 1;
|
|
|
|
}
|
2002-05-15 22:14:17 +00:00
|
|
|
}
|
|
|
|
|
2011-09-08 03:30:58 +00:00
|
|
|
if (build->str[0])
|
|
|
|
Cbuf_InsertText (cbuf, build->str);
|
2002-05-11 00:36:12 +00:00
|
|
|
|
2011-09-08 03:30:58 +00:00
|
|
|
dstring_delete (build);
|
2002-05-11 00:36:12 +00:00
|
|
|
}
|
2002-05-11 03:00:14 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_StuffCmds_f (void)
|
2002-05-11 00:36:12 +00:00
|
|
|
{
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_StuffCmds (cbuf_active);
|
2002-05-11 00:36:12 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2001-02-21 19:35:06 +00:00
|
|
|
Cmd_Init_Hash (void)
|
|
|
|
{
|
2020-03-25 06:43:16 +00:00
|
|
|
cmd_hash = Hash_NewTable (1021, cmd_get_key, 0, 0, 0);
|
|
|
|
cmd_alias_hash = Hash_NewTable (1021, cmd_alias_get_key,
|
|
|
|
cmd_alias_free, 0, 0);
|
|
|
|
cmd_provider_hash = Hash_NewTable(1021, cmd_provider_get_key,
|
|
|
|
cmd_provider_free, 0, 0);
|
2001-02-21 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2001-02-21 19:35:06 +00:00
|
|
|
Cmd_Init (void)
|
|
|
|
{
|
2001-08-22 22:03:16 +00:00
|
|
|
Cmd_AddCommand ("stuffcmds", Cmd_StuffCmds_f, "Execute the commands given "
|
|
|
|
"at startup again");
|
|
|
|
Cmd_AddCommand ("alias", Cmd_Alias_f, "Used to create a reference to a "
|
|
|
|
"command or list of commands.\n"
|
|
|
|
"When used without parameters, displays all current "
|
|
|
|
"aliases.\n"
|
|
|
|
"Note: Enclose multiple commands within quotes and "
|
|
|
|
"seperate each command with a semi-colon.");
|
2001-02-21 19:35:06 +00:00
|
|
|
Cmd_AddCommand ("unalias", Cmd_UnAlias_f, "Remove the selected alias");
|
|
|
|
Cmd_AddCommand ("cmdlist", Cmd_CmdList_f, "List all commands");
|
2001-08-22 22:03:16 +00:00
|
|
|
Cmd_AddCommand ("help", Cmd_Help_f, "Display help for a command or "
|
|
|
|
"variable");
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_AddCommand ("exec", Cmd_Exec_f, "Execute a script file");
|
|
|
|
Cmd_AddCommand ("echo", Cmd_Echo_f, "Print text to console");
|
|
|
|
Cmd_AddCommand ("wait", Cmd_Wait_f, "Wait a game tic");
|
2002-10-13 19:46:47 +00:00
|
|
|
Cmd_AddCommand ("sleep", Cmd_Sleep_f, "Wait for a certain number of seconds.");
|
[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 (&cmd_warncmd_cvar, 0, 0);
|
2002-08-03 06:04:00 +00:00
|
|
|
cmd_cbuf = Cbuf_New (&id_interp);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2007-03-18 03:48:09 +00:00
|
|
|
Cmd_AddProvider("id", &id_interp);
|
2001-02-21 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_ExecuteString (const char *text, cmd_source_t src)
|
2001-12-03 21:06:57 +00:00
|
|
|
{
|
2003-11-25 02:47:05 +00:00
|
|
|
cbuf_t *old = cbuf_active;
|
|
|
|
cbuf_active = cmd_cbuf;
|
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
cmd_source = src;
|
|
|
|
COM_TokenizeString (text, cmd_cbuf->args);
|
|
|
|
Cmd_Command (cmd_cbuf->args);
|
2003-11-25 02:47:05 +00:00
|
|
|
|
|
|
|
cbuf_active = old;
|
2002-07-31 05:19:03 +00:00
|
|
|
return 0;
|
2001-12-03 21:06:57 +00:00
|
|
|
}
|
2001-02-21 19:35:06 +00:00
|
|
|
|
2021-04-12 13:09:09 +00:00
|
|
|
VISIBLE int
|
2002-11-08 16:39:28 +00:00
|
|
|
Cmd_Exec_File (cbuf_t *cbuf, const char *path, int qfs)
|
2001-02-21 19:35:06 +00:00
|
|
|
{
|
2002-07-31 05:19:03 +00:00
|
|
|
char *f;
|
|
|
|
int len;
|
2002-08-27 07:16:28 +00:00
|
|
|
QFile *file;
|
2001-02-21 19:35:06 +00:00
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
if (!path || !*path)
|
2021-04-12 13:09:09 +00:00
|
|
|
return 0;
|
2002-11-08 16:39:28 +00:00
|
|
|
if (qfs) {
|
2014-01-23 02:57:57 +00:00
|
|
|
file = QFS_FOpenFile (path);
|
2002-11-08 16:39:28 +00:00
|
|
|
} else {
|
2010-08-24 07:01:01 +00:00
|
|
|
char *newpath = Sys_ExpandSquiggle (path);
|
2003-05-25 05:40:25 +00:00
|
|
|
file = Qopen (newpath, "r");
|
|
|
|
free (newpath);
|
2002-11-08 16:39:28 +00:00
|
|
|
}
|
|
|
|
if (file) {
|
2002-09-27 04:27:19 +00:00
|
|
|
len = Qfilesize (file);
|
2002-07-31 05:19:03 +00:00
|
|
|
f = (char *) malloc (len + 1);
|
|
|
|
if (f) {
|
|
|
|
f[len] = 0;
|
|
|
|
Qread (file, f, len);
|
2002-07-31 06:06:44 +00:00
|
|
|
Cbuf_InsertText (cbuf, f);
|
2002-07-31 05:19:03 +00:00
|
|
|
free (f);
|
2001-02-21 19:35:06 +00:00
|
|
|
}
|
2002-11-08 16:39:28 +00:00
|
|
|
Qclose (file);
|
2021-04-12 13:09:09 +00:00
|
|
|
return 1;
|
2001-02-21 19:35:06 +00:00
|
|
|
}
|
2021-04-12 13:09:09 +00:00
|
|
|
return 0;
|
2002-07-31 05:19:03 +00:00
|
|
|
}
|
2001-02-21 19:35:06 +00:00
|
|
|
|
2007-03-18 03:48:09 +00:00
|
|
|
VISIBLE void
|
|
|
|
Cmd_AddProvider(const char *name, cbuf_interpreter_t *interp)
|
|
|
|
{
|
|
|
|
cmd_provider_t *p = (cmd_provider_t *) Hash_Find (cmd_provider_hash, name);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2007-03-18 03:48:09 +00:00
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
cmd_provider_t *p = malloc(sizeof(cmd_provider_t));
|
|
|
|
p->name = strdup(name);
|
|
|
|
p->interp = interp;
|
|
|
|
Hash_Add(cmd_provider_hash, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VISIBLE cbuf_interpreter_t *
|
|
|
|
Cmd_GetProvider(const char *name)
|
|
|
|
{
|
|
|
|
cmd_provider_t *p = (cmd_provider_t *) Hash_Find (cmd_provider_hash, name);
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2007-03-18 03:48:09 +00:00
|
|
|
if (!p)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return p->interp;
|
|
|
|
}
|