37 #include "../shared/parse.h"
40 #define ALIAS_HASH_SIZE 32
42 #define MAX_ALIAS_NAME 32
60 #define ALIAS_LOOP_COUNT 16
101 #define CMD_BUFFER_SIZE 8192
119 SZ_Init(&cmd_text,
nullptr, 0);
130 va_start(argptr, format);
141 const int len = strlen(text);
164 const int templen = cmd_text.
cursize;
168 memcpy(temp, cmd_text.
data, templen);
224 char* text = (
char*) cmd_text.
data;
227 for (i = 0; i < cmd_text.
cursize; i++) {
231 if (!(quotes & 1) && text[
i] ==
';')
237 if (i >
sizeof(line) - 1)
238 i =
sizeof(line) - 1;
240 memcpy(line, text, i);
251 memmove(text, text + i, cmd_text.
cursize);
278 for (
int i = 1;
i < argc;
i++) {
303 for (
int i = 1;
i < argc;
i++) {
310 for (
int i = 1;
i < argc;
i++) {
319 for (
int i = 0;
i < s - 1;
i++) {
325 for (j =
i; text[j] !=
'+' && text[j] !=
'-' && text[j] !=
'\0'; j++) {}
327 const char c = text[j];
335 const bool ret = build[0] !=
'\0';
399 for (a = cmd_alias; a; a = a->
next)
405 const size_t len = strlen(s);
416 for (a = cmd_alias_hash[hash]; a; a = a->
hash_next) {
428 cmd_alias_hash[
hash] = a;
437 for (
int i = 2;
i < c;
i++) {
459 for (
int i = 0;
i < strlen(a->value);
i++) {
460 if (a->value[
i] ==
'"')
475 #define CMD_HASH_SIZE 32
578 while (*text && *text <=
' ' && *text !=
'\n') {
602 if (com_token[0] ==
'*') {
617 if (
Q_streq(cmdName, cmd->getName()))
634 Q_strncpyz(searchName, cmdName,
sizeof(searchName));
635 char* sep = strstr(searchName,
" ");
657 Q_strncpyz(matchString, candidate,
sizeof(matchString));
658 *match = matchString;
661 char* dst = matchString;
662 char const* src = candidate;
663 while (*dst == *src) {
681 if (!cmdName || !cmdName[0])
702 if (!cmdName || !cmdName[0]) {
703 Com_Printf(
"Cmd_GetUserdata: Invalide parameter\n");
712 Com_Printf(
"Cmd_GetUserdata: '%s' not found\n", cmdName);
726 if (!cmdName || !cmdName[0])
751 Com_Printf(
"Cmd_AddCommand: %s already defined as a var\n", cmdName);
771 HASH_Add(cmd_functions_hash, cmd, hash);
777 (*i)->onAdd(cmdName);
794 Com_Printf(
"Cmd_RemoveCommand: %s not added\n", cmdName);
808 Com_Printf(
"Cmd_RemoveCommand: %s not added\n", cmdName);
815 (*i)->onRemove(cmdName);
832 if (
Q_streq(
"hugo", cmd->getName())) {
833 Com_Printf(
"Cmd_TableCheck: found bad entry\n");
841 if (
Q_streq(
"hugo", cmd->getName())) {
842 Com_Printf(
"Cmd_TableCheck: found bad hash entry\n");
849 Com_Printf(
"cmdCount: %i hashCount: %i\n", cmdCount, hashCount);
909 if (!cmd->completeParam)
911 return cmd->completeParam(partial, match);
926 if (partial[0] ==
'\0')
935 if (cmd->description)
972 if (!cmd->function) {
1030 int i = 0, j = 0,
len = 0;
1031 const char* token =
nullptr;
1037 len = strlen(token);
1041 if (c == 2 && strncmp(cmd->getName(), token,
len)) {
1046 if (cmd->description)
1050 for (
const cmd_alias_t* alias = cmd_alias; alias; alias = alias->
next, j++) {
1051 if (c == 2 && strncmp(alias->name, token,
len)) {
1093 static void Cmd_Test_f (
void)
1096 if (!
Q_streq(cmd->getName(),
"quit"))
1101 void Cmd_PrintDebugCommands (
void)
1103 const char* otherCommands[] = {
"mem_stats",
"cl_configstrings",
"cl_userinfo",
"devmap"};
1109 Com_Printf(
" * %s\n %s\n", cmd->getName(), cmd->description);
1115 Com_Printf(
" * %s\n %s\n", otherCommands[num - 1], desc);
1119 " make everything visible to everyone\n"
1120 " * sv debug_actorinvlist\n"
1121 " Show the whole inv of all actors on the server console\n"
1141 Cmd_AddCommand(
"debug_cmdtest", Cmd_Test_f,
"Calls every command in the current list");
1148 cmd_functions =
nullptr;
1151 cmd_alias =
nullptr;
void Cmd_UnRegisterCmdListener(CmdListenerPtr listener)
Unregisters a command listener.
void Cbuf_InsertText(const char *text)
Adds command text immediately after the current command.
bool Q_strnull(const char *string)
void Cmd_vExecuteString(const char *fmt, va_list ap)
const char * Cmd_Argv(int arg)
Returns a given argument.
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
static void Cmd_Wait_f(void)
Causes execution of the remainder of the command buffer to be delayed until next frame. This allows commands like: bind g "impulse 5; +attack; wait; -attack; impulse 2".
#define Mem_AllocTypeN(type, n)
const char * FS_NextFileFromFileList(const char *files)
Returns the next file that is found in the virtual filesystem identified by the given file pattern...
static void Cmd_Alias_f(void)
Creates a new command that executes a command string (possibly ; separated)
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
const char * Com_Argv(int arg)
Returns an argument of script commandline.
int Cmd_CompleteCommand(const char *partial, const char **match)
Unix like tab completion for console commands.
void Cmd_RemoveCommand(const char *cmdName)
Removes a command from script interface.
static void Cmd_Help_f(void)
Display some help about cmd and cvar usage.
struct cmd_alias_s * hash_next
static byte cmd_text_buf[CMD_BUFFER_SIZE]
memPool_t * com_aliasSysPool
void Cbuf_AddText(const char *format,...)
Adds command text at the end of the buffer.
void Cmd_TokenizeString(const char *text, bool macroExpand, bool replaceWhitespaces)
Parses the given string into command line tokens.
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
Command text buffering and command execution header.
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
void Com_Printf(const char *const fmt,...)
bool Cmd_GenericCompleteFunction(char const *candidate, char const *partial, char const **match)
static void * cmd_userdata
static void Cmd_Exec_f(void)
memPool_t * com_cmdSysPool
void Cmd_TableRemoveList(const cmdList_t *cmdList)
#define Q_strvalid(string)
void SZ_Clear(sizebuf_t *buf)
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
static cmd_function_t * cmd_functions
bool Cvar_Command(void)
Handles variable inspection and changing from the console.
void SZ_Write(sizebuf_t *buf, const void *data, int length)
void * Cmd_Userdata(void)
Return the userdata of the called command.
#define MAX_STRING_TOKENS
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
static CmdListeners cmdListeners
void * Cmd_GetUserdata(const char *cmdName)
Fetches the userdata for a console command.
static void Cmd_Open_f(void)
Reopens the command buffer for writing.
static cmd_function_t * cmd_functions_hash[CMD_HASH_SIZE]
bool Cmd_Exists(const char *cmdName)
Checks whether a function exists already.
void Cmd_BufClear(void)
Clears the argv vector and set argc to zero.
struct cmd_function_s * next
const char * Com_MacroExpandString(const char *text)
Expands strings with cvar values that are dereferenced by a '*cvar'.
int(* completeParam)(const char *partial, const char **match)
static wrapCache_t * hash[MAX_WRAP_HASH]
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
Message IO functions - handles byte ordering and avoids alignment errors.
std::vector< CmdListenerPtr > CmdListeners
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
int FS_Printf(qFILE *f, const char *msg,...)
Can print chunks for 1024 chars into a file.
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
#define Q_strcasecmp(a, b)
#define HASH_Add(hash, elem, index)
#define Mem_FreePool(pool)
bool Cbuf_AddLateCommands(void)
Adds command line parameters as script statements.
static sizebuf_t cmd_text
void SZ_Init(sizebuf_t *buf, byte *data, int length)
void Cmd_ForwardToServer(void)
adds the current command line as a clc_stringcmd to the client message. things like action...
struct cmd_alias_s * next
static char com_token[4096]
const char * getName() const
void Cmd_AddUserdata(const char *cmdName, void *userdata)
Adds userdata to the console command.
void Cbuf_CopyToDefer(void)
Defers any outstanding commands.
struct cmd_alias_s cmd_alias_t
const char * Com_Parse(const char *data_p[], char *target, size_t size, bool replaceWhitespaces)
Parse a token out of a string.
static void Cmd_Close_f(void)
Will no longer add any command to command buffer ...until cmd_close is false again.
void Cbuf_Init(void)
allocates an initial text buffer that will grow as needed
static void Cmd_Echo_f(void)
Just prints the rest of the line to the console.
static char * cmd_argv[MAX_STRING_TOKENS]
QGL_EXTERN GLuint GLchar GLuint * len
int Com_Argc(void)
Returns the script commandline argument count.
struct cmd_function_s * hash_next
void Com_ClearArgv(int arg)
Reset com_argv entry to empty string.
static cmd_alias_t * cmd_alias_hash[ALIAS_HASH_SIZE]
static char cmd_args[MAX_STRING_CHARS]
void Cmd_TableCheck(void)
Check both the functiontable and the associated hashtable for invalid entries.
unsigned int Com_HashKey(const char *name, int hashsize)
returns hash key for a string
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
void Cmd_RegisterCmdListener(CmdListenerPtr listener)
Registers a command listener.
definitions common between client and server, but not game lib
void Cmd_AddParamCompleteFunction(const char *cmdName, int(*function)(const char *partial, const char **match))
static int Cmd_CompleteExecCommand(const char *partial, const char **match)
Autocomplete function for exec command.
const char * Cmd_GetCommandDesc(const char *cmdName)
Returns the command description for a given command.
struct cmd_function_s cmd_function_t
const char * Cvar_GetString(const char *varName)
Returns the value of cvar as string.
#define Mem_PoolStrDup(in, pool, tagNum)
static cmd_alias_t * cmd_alias
int Cmd_CompleteCommandParameters(const char *command, const char *partial, const char **match)
Unix like tab completion for console commands parameters.
void Cbuf_InsertFromDefer(void)
Copies back any deferred commands.
void Cmd_Dummy_f(void)
Dummy binding if you don't want unknown commands forwarded to the server.
#define Mem_PoolAllocType(type, pool)
void Cbuf_Execute(void)
Pulls off terminated lines of text from the command buffer and sends them through Cmd_ExecuteString...
static void Cmd_List_f(void)
List all available script interface functions.
char name[MAX_ALIAS_NAME]
void Cbuf_AddEarlyCommands(bool clear)
Adds command line parameters as script statements Commands lead with a +, and continue until another ...
char * Com_Chop(char *s)
Removed trailing whitespaces.
static char defer_text_buf[CMD_BUFFER_SIZE]
void Cmd_WriteAliases(qFILE *f)
Write lines containing "aliasa alias value" for all aliases with the archive flag set to true...
const char * Cmd_Args(void)
Returns a single string containing argv(1) to argv(argc()-1)
void format(__printf__, 1, 2)))
void Cmd_TableAddList(const cmdList_t *cmdList)
void FS_FreeFile(void *buffer)
static cmd_function_t * Cmd_TableFind(const char *cmdName)