UFO: Alien Invasion
Loading...
Searching...
No Matches
cmd.cpp File Reference

Script command processing module Command text buffering. Any number of commands can be added in a frame, from several different sources. Most commands come from either keyBindings or console line input, but remote servers can also send across commands and entire text files can be accessed. More...

#include "cmd.h"
#include "common.h"
#include "msg.h"
#include "../shared/parse.h"
Include dependency graph for cmd.cpp:

Go to the source code of this file.

Data Structures

struct  cmd_alias_t
struct  cmd_function_t

Macros

#define ALIAS_HASH_SIZE   32
#define MAX_ALIAS_NAME   32
#define ALIAS_LOOP_COUNT   16
#define CMD_BUFFER_SIZE   8192
#define CMD_HASH_SIZE   32

Typedefs

typedef std::vector< CmdListenerPtrCmdListeners

Functions

void Cmd_ForwardToServer (void)
 adds the current command line as a clc_stringcmd to the client message. things like action, turn, etc, are commands directed to the server, so when they are typed in at the console, they will need to be forwarded.
static void Cmd_Open_f (void)
 Reopens the command buffer for writing.
static void Cmd_Close_f (void)
 Will no longer add any command to command buffer ...until cmd_close is false again.
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".
void Cbuf_Init (void)
 allocates an initial text buffer that will grow as needed
void Cbuf_Shutdown (void)
void Cbuf_AddText (const char *format,...)
 Adds command text at the end of the buffer.
void Cbuf_InsertText (const char *text)
 Adds command text immediately after the current command.
void Cbuf_CopyToDefer (void)
 Defers any outstanding commands.
void Cbuf_InsertFromDefer (void)
 Copies back any deferred commands.
void Cbuf_Execute (void)
 Pulls off
terminated lines of text from the command buffer and sends them through Cmd_ExecuteString. Stops when the buffer is empty. Normally called once per frame, but may be explicitly invoked. Do not call inside a command function!
void Cbuf_AddEarlyCommands (bool clear)
 Adds command line parameters as script statements Commands lead with a +, and continue until another + Set commands are added early, so they are guaranteed to be set before the client and server initialize for the first time. Other commands are added late, after all initialization is complete.
bool Cbuf_AddLateCommands (void)
 Adds command line parameters as script statements.
static void Cmd_Exec_f (void)
static void Cmd_Echo_f (void)
 Just prints the rest of the line to the console.
static void Cmd_Alias_f (void)
 Creates a new command that executes a command string (possibly ; separated).
void Cmd_WriteAliases (qFILE *f)
 Write lines containing "aliasa alias value" for all aliases with the archive flag set to true.
int Cmd_Argc (void)
 Return the number of arguments of the current command. "command parameter" will result in a argc of 2, not 1.
const char * Cmd_Argv (int arg)
 Returns a given argument.
const char * Cmd_Args (void)
 Returns a single string containing argv(1) to argv(argc()-1).
voidCmd_Userdata (void)
 Return the userdata of the called command.
void Cmd_BufClear (void)
 Clears the argv vector and set argc to zero.
void Cmd_TokenizeString (const char *text, bool macroExpand, bool replaceWhitespaces)
 Parses the given string into command line tokens.
static cmd_function_tCmd_TableFind (const char *cmdName)
const char * Cmd_GetCommandDesc (const char *cmdName)
 Returns the command description for a given command.
bool Cmd_GenericCompleteFunction (char const *candidate, char const *partial, char const **match)
void Cmd_AddParamCompleteFunction (const char *cmdName, int(*function)(const char *partial, const char **match))
voidCmd_GetUserdata (const char *cmdName)
 Fetches the userdata for a console command.
void Cmd_AddUserdata (const char *cmdName, void *userdata)
 Adds userdata to the console command.
void Cmd_AddCommand (const char *cmdName, xcommand_t function, const char *desc)
 Add a new command to the script interface.
void Cmd_RemoveCommand (const char *cmdName)
 Removes a command from script interface.
void Cmd_TableCheck (void)
 Check both the functiontable and the associated hashtable for invalid entries.
void Cmd_TableAddList (const cmdList_t *cmdList)
void Cmd_TableRemoveList (const cmdList_t *cmdList)
void Cmd_RegisterCmdListener (CmdListenerPtr listener)
 Registers a command listener.
void Cmd_UnRegisterCmdListener (CmdListenerPtr listener)
 Unregisters a command listener.
bool Cmd_Exists (const char *cmdName)
 Checks whether a function exists already.
int Cmd_CompleteCommandParameters (const char *command, const char *partial, const char **match)
 Unix like tab completion for console commands parameters.
int Cmd_CompleteCommand (const char *partial, const char **match)
 Unix like tab completion for console commands.
void Cmd_vExecuteString (const char *fmt, va_list ap)
void Cmd_ExecuteString (const char *text,...)
 A complete command line has been parsed, so try to execute it.
static void Cmd_Help_f (void)
 Display some help about cmd and cvar usage.
static void Cmd_List_f (void)
 List all available script interface functions.
static int Cmd_CompleteExecCommand (const char *partial, const char **match)
 Autocomplete function for exec command.
void Cmd_Dummy_f (void)
 Dummy binding if you don't want unknown commands forwarded to the server.
void Cmd_Init (void)
void Cmd_Shutdown (void)

Variables

static CmdListeners cmdListeners
static cmd_alias_tcmd_alias
static cmd_alias_tcmd_alias_hash [ALIAS_HASH_SIZE]
static bool cmdWait
static bool cmdClosed
static int alias_count
static sizebuf_t cmd_text
static byte cmd_text_buf [CMD_BUFFER_SIZE]
static char defer_text_buf [CMD_BUFFER_SIZE]
static int cmd_argc
static char * cmd_argv [MAX_STRING_TOKENS]
static char cmd_args [MAX_STRING_CHARS]
static voidcmd_userdata
static cmd_function_tcmd_functions
static cmd_function_tcmd_functions_hash [CMD_HASH_SIZE]

Detailed Description

Script command processing module Command text buffering. Any number of commands can be added in a frame, from several different sources. Most commands come from either keyBindings or console line input, but remote servers can also send across commands and entire text files can be accessed.

The + command line options are also added to the command buffer.

Command execution takes a null terminated string, breaks it into tokens, then searches for a command or variable that matches the first token.

Definition in file cmd.cpp.

Macro Definition Documentation

◆ ALIAS_HASH_SIZE

#define ALIAS_HASH_SIZE   32

Definition at line 40 of file cmd.cpp.

Referenced by Cmd_Alias_f(), and Cmd_vExecuteString().

◆ ALIAS_LOOP_COUNT

#define ALIAS_LOOP_COUNT   16

Definition at line 60 of file cmd.cpp.

Referenced by Cmd_vExecuteString().

◆ CMD_BUFFER_SIZE

#define CMD_BUFFER_SIZE   8192

Definition at line 101 of file cmd.cpp.

Referenced by Cbuf_AddText().

◆ CMD_HASH_SIZE

#define CMD_HASH_SIZE   32

◆ MAX_ALIAS_NAME

#define MAX_ALIAS_NAME   32

Definition at line 42 of file cmd.cpp.

Referenced by Cmd_Alias_f().

Typedef Documentation

◆ CmdListeners

typedef std::vector<CmdListenerPtr> CmdListeners

Definition at line 52 of file cmd.cpp.

Function Documentation

◆ Cbuf_AddEarlyCommands()

void Cbuf_AddEarlyCommands ( bool clear)

Adds command line parameters as script statements Commands lead with a +, and continue until another + Set commands are added early, so they are guaranteed to be set before the client and server initialize for the first time. Other commands are added late, after all initialization is complete.

adds all the +set commands from the command line

See also
Cbuf_AddLateCommands

Definition at line 275 of file cmd.cpp.

References Cbuf_AddText(), Com_Argc(), Com_Argv(), Com_ClearArgv(), i, and Q_streq.

Referenced by Cbuf_AddText(), and Qcommon_Init().

◆ Cbuf_AddLateCommands()

bool Cbuf_AddLateCommands ( void )

Adds command line parameters as script statements.

adds all the remaining + commands from the command line

Note
Commands lead with a + and continue until another + or -
Returns
true if any late commands were added
See also
Cbuf_AddEarlyCommands

Definition at line 298 of file cmd.cpp.

References Cbuf_AddText(), Com_Argc(), Com_Argv(), i, Mem_AllocTypeN, Mem_Free, and Q_strcat().

Referenced by Cbuf_AddText(), and Qcommon_Init().

◆ Cbuf_AddText()

◆ Cbuf_CopyToDefer()

void Cbuf_CopyToDefer ( void )

Defers any outstanding commands.

These two functions are used to defer any pending commands while a map is being loaded.

Used when loading a map, for example. Copies then clears the command buffer to a temporary area.

Definition at line 191 of file cmd.cpp.

References cmd_text, cmd_text_buf, and defer_text_buf.

Referenced by Cbuf_AddText(), and SV_Map().

◆ Cbuf_Execute()

void Cbuf_Execute ( void )

Pulls off
terminated lines of text from the command buffer and sends them through Cmd_ExecuteString. Stops when the buffer is empty. Normally called once per frame, but may be explicitly invoked. Do not call inside a command function!

See also
Cmd_ExecuteString Pulls off \n terminated lines of text from the command buffer and sends them through Cmd_ExecuteString, stopping when the buffer is empty. Normally called once per frame, but may be explicitly invoked.
Note
Do not call inside a command function!

Definition at line 214 of file cmd.cpp.

References alias_count, Cmd_ExecuteString(), cmd_text, cmdWait, and i.

Referenced by Cbuf_AddText(), Cbuf_Execute_timer(), CL_ParseServerMessage(), CL_SendCommand(), GAME_GetImportData(), Qcommon_Init(), UFO_ExecuteTestWindow(), and cgame_import_t::void().

◆ Cbuf_Init()

void Cbuf_Init ( void )

allocates an initial text buffer that will grow as needed

Definition at line 109 of file cmd.cpp.

References cmd_text, cmd_text_buf, and SZ_Init().

Referenced by Qcommon_Init(), and TEST_Init().

◆ Cbuf_InsertFromDefer()

void Cbuf_InsertFromDefer ( void )

Copies back any deferred commands.

Definition at line 201 of file cmd.cpp.

References Cbuf_InsertText(), and defer_text_buf.

Referenced by Cbuf_AddText(), SV_Begin_f(), and SV_StartMatch_f().

◆ Cbuf_InsertText()

void Cbuf_InsertText ( const char * text)

Adds command text immediately after the current command.

when a command wants to issue other commands immediately, the text is

Note
Adds a \n to the text
Todo
actually change the command buffer to do less copying

Definition at line 157 of file cmd.cpp.

References Cbuf_AddText(), cmd_text, Mem_AllocTypeN, Mem_Free, Q_strnull(), SZ_Clear(), and SZ_Write().

Referenced by Cbuf_AddText(), Cbuf_InsertFromDefer(), Cmd_Exec_f(), and Cmd_vExecuteString().

◆ Cbuf_Shutdown()

void Cbuf_Shutdown ( void )
Note
Reset the Cbuf memory.

Definition at line 117 of file cmd.cpp.

References cmd_text, and SZ_Init().

Referenced by TEST_Shutdown().

◆ Cmd_AddCommand()

void Cmd_AddCommand ( const char * cmdName,
xcommand_t function,
const char * desc )

Add a new command to the script interface.

called by the init functions of other parts of the program to register commands and functions to call for them. The cmd_name is referenced later, so it should not be in temp memory if function is nullptr, the command will be forwarded to the server as a clc_stringcmd instead of executed locally

Parameters
[in]cmdNameThe name the command is available via script interface
[in]functionThe function pointer
[in]descA short description of what the cmd does. It is shown for e.g. the tab completion or the command list.
See also
Cmd_RemoveCommand

Definition at line 744 of file cmd.cpp.

References cmd_functions, cmd_functions_hash, CMD_HASH_SIZE, Cmd_TableFind(), cmdListeners, com_cmdSysPool, Com_DPrintf(), Com_HashKey(), Com_Printf(), cmd_function_t::completeParam, Cvar_GetString(), DEBUG_COMMANDS, cmd_function_t::description, cmd_function_t::function, hash, HASH_Add, i, Mem_PoolAllocType, cmd_function_t::name, cmd_function_t::next, and Q_strvalid.

Referenced by ACTOR_InitStartup(), CL_BattlescapeRadarInit(), CL_CameraInit(), CL_InitLocal(), CL_ServerEventsInit(), CLMN_Init(), Cmd_Init(), Cmd_TableAddList(), Con_Init(), Cvar_Init(), GAME_GetImportData(), GAME_InitStartup(), HUD_InitCallbacks(), HUD_InitStartup(), IN_Init(), INV_InitCallbacks(), INV_InitStartup(), Irc_Init(), Key_Init(), NET_Init(), uiConFuncNode::onLoaded(), PTL_InitStartup(), Qcommon_Init(), S_Init(), SCR_Init(), CampaignTest::SetUpTestCase(), SV_InitOperatorCommands(), SV_MapcycleInit(), TEAM_InitStartup(), TEST_F(), TOTD_InitStartup(), TUT_InitStartup(), UI_Init(), UI_InitActions(), UI_InitData(), UI_InitWindows(), UI_RegisterAbstractNode(), UI_RegisterEditorNode(), UI_RegisterGeoscapeNode(), UI_RegisterMaterialEditorNode(), UI_RegisterModelNode(), VID_Init(), WEB_CGameCommands(), and WEB_InitStartup().

◆ Cmd_AddParamCompleteFunction()

void Cmd_AddParamCompleteFunction ( const char * cmdName,
int(* function )(const char *partial, const char **match) )
Parameters
[in]cmdNameThe name the command we want to add the complete function
[in]functionThe complete function pointer
See also
Cmd_AddCommand
Cmd_CompleteCommandParameters

Definition at line 679 of file cmd.cpp.

References Cmd_TableFind(), and cmd_function_t::completeParam.

Referenced by Cmd_Init(), GAME_GetImportData(), Key_Init(), M_Init(), S_Init(), SV_InitOperatorCommands(), UI_InitWindows(), and UI_RegisterEditorNode().

◆ Cmd_AddUserdata()

void Cmd_AddUserdata ( const char * cmdName,
void * userdata )

Adds userdata to the console command.

Parameters
[in]cmdNameThe name the command we want to add edit
[in]userdatafor this function
See also
Cmd_AddCommand
Cmd_CompleteCommandParameters
Cmd_GetUserdata

Definition at line 724 of file cmd.cpp.

References Cmd_TableFind(), and cmd_function_t::userdata.

Referenced by uiConFuncNode::onLoaded().

◆ Cmd_Alias_f()

◆ Cmd_Argc()

int Cmd_Argc ( void )

Return the number of arguments of the current command. "command parameter" will result in a argc of 2, not 1.

The functions that execute commands get their parameters with these functions. Cmd_Argv() will return an empty string, not a nullptr if arg > argc, so string operations are always safe.

Returns
the number of arguments including the command itself.
See also
Cmd_Argv

Definition at line 505 of file cmd.cpp.

References cmd_argc.

Referenced by CL_ActorSelect_f(), CL_ActorTargetAlign_f(), CL_CamSetAngles_f(), CL_CamSetZoom_f(), CL_ConnectionlessPacket(), CL_Env_f(), CL_ForwardToServer_f(), CL_GetTipOfTheDay_f(), CL_OpenURL_f(), CL_PressKey_f(), CL_SetRatioFilter_f(), Cmd_Alias_f(), Cmd_Echo_f(), Cmd_Exec_f(), Cmd_ForwardToServer(), Cmd_List_f(), Cmd_vExecuteString(), Com_DeveloperSet_f(), Com_WriteConfig_f(), Cvar_Add_f(), Cvar_Command(), Cvar_Copy_f(), Cvar_Define_f(), Cvar_Del_f(), Cvar_List_f(), Cvar_Mod_f(), Cvar_Set_f(), Cvar_SetOld_f(), Cvar_Switch_f(), GAME_ActorSelect_f(), GAME_AutoTeam_f(), GAME_GetImportData(), GAME_LoadTeam_f(), GAME_SaveTeam_f(), GAME_SetMode_f(), GAME_TeamDelete_f(), GAME_ToggleActorForTeam_f(), HUD_DisplayActions_f(), HUD_DisplayFiremodes_f(), HUD_ExecuteAction_f(), HUD_FireWeapon_f(), HUD_PopupFiremodeReservation_f(), HUD_RemainingTUs_f(), HUD_SelectReactionFiremode_f(), HUD_ShotReserve_f(), cgame_import_t::int(), game_import_t::int(), INV_UpdateActorLoad_f(), INV_UpdateObject_f(), Irc_Client_Join_f(), Irc_Client_Kick_f(), Irc_Client_Mode_f(), Irc_Client_Msg_f(), Irc_Client_Part_f(), Irc_Client_PrivMsg_f(), Irc_Client_Topic_f(), Irc_Client_Who_f(), Irc_Client_Whois_f(), Irc_Client_Whowas_f(), Irc_Connect_f(), Irc_UserClick_f(), Irc_UserRightClick_f(), Key_Bind_f(), Key_Unbind_f(), Key_WriteBindings_f(), M_Change_f(), M_Play_f(), R_ScreenShot(), R_ScreenShot_f(), S_Play_f(), SCR_TimeRefresh_f(), SV_InitGameProgs(), SV_Kick_f(), SV_Map_f(), SV_MapcycleAdd_f(), SV_ServerCommand_f(), SV_UserInfo_f(), SVC_RemoteCommand(), TUT_ListClick_f(), UI_AddCvarListener_f(), UI_AddListener_f(), UI_CloseWindow_f(), UI_DebugTree_f(), UI_EditorNodeExtract_f(), UI_ExecuteLuaConFunc(), UI_GeoscapeNodeScroll_f(), UI_GeoscapeNodeZoom_f(), UI_GetParamNumber(), UI_InitStack_f(), UI_ListMaps_f(), UI_MaterialEditorChangeValue_f(), UI_MaterialEditorNewStage_f(), UI_MaterialEditorRemoveStage_f(), UI_MaterialEditorSelectStage_f(), UI_Popup_f(), UI_PopWindow_f(), UI_PushChildWindow_f(), UI_PushDropDownWindow_f(), UI_PushWindow_f(), UI_RemoveCvarListener_f(), UI_RemoveListener_f(), UI_ResetData_f(), UI_SelectMap_f(), WEB_Auth_f(), WEB_DeleteCGame_f(), WEB_DownloadCGame_f(), WEB_ListCGame_f(), and WEB_UploadCGame_f().

◆ Cmd_Args()

const char * Cmd_Args ( void )

◆ Cmd_Argv()

const char * Cmd_Argv ( int arg)

Returns a given argument.

Parameters
[in]argThe argument at position arg in cmd_argv. 0 will return the command name.
Returns
The argument from cmd_argv
See also
Cmd_Argc

Definition at line 516 of file cmd.cpp.

References cmd_argc, and cmd_argv.

Referenced by CL_ActorSelect_f(), CL_ActorTargetAlign_f(), CL_CamSetAngles_f(), CL_CamSetZoom_f(), CL_ConnectionlessPacket(), CL_Env_f(), CL_ForwardToServer_f(), CL_OpenURL_f(), CL_PressKey_f(), CL_SetRatioFilter_f(), Cmd_Alias_f(), Cmd_Echo_f(), Cmd_Exec_f(), Cmd_ForwardToServer(), Cmd_List_f(), Cmd_vExecuteString(), Com_DeveloperSet_f(), Com_WriteConfig_f(), Cvar_Add_f(), Cvar_Command(), Cvar_Copy_f(), Cvar_Define_f(), Cvar_Del_f(), Cvar_List_f(), Cvar_Mod_f(), Cvar_Set_f(), Cvar_SetOld_f(), Cvar_Switch_f(), GAME_ActorSelect_f(), GAME_AutoTeam_f(), GAME_GetImportData(), GAME_LoadTeam_f(), GAME_SaveTeam_f(), GAME_SetMode_f(), GAME_TeamDelete_f(), GAME_ToggleActorForTeam_f(), HUD_DisplayActions_f(), HUD_DisplayFiremodes_f(), HUD_ExecuteAction_f(), HUD_FireWeapon_f(), HUD_RemainingTUs_f(), HUD_SelectReactionFiremode_f(), HUD_ShotReserve_f(), IN_KeyDown(), IN_KeyUp(), INV_UpdateActorLoad_f(), INV_UpdateObject_f(), Irc_Client_Join_f(), Irc_Client_Kick_f(), Irc_Client_Mode_f(), Irc_Client_Part_f(), Irc_Client_PrivMsg_f(), Irc_Client_Topic_f(), Irc_Client_Who_f(), Irc_Client_Whois_f(), Irc_Client_Whowas_f(), Irc_Connect_f(), Irc_UserClick_f(), Irc_UserRightClick_f(), Key_Bind_f(), Key_Unbind_f(), Key_Unbindall_f(), Key_WriteBindings_f(), M_Change_f(), M_Play_f(), R_ScreenShot(), R_ScreenShot_f(), S_Play_f(), SV_ConnectionlessPacket(), SV_ExecuteUserCommand(), SV_GetPlayerClientStructure(), SV_InitGameProgs(), SV_Kick_f(), SV_Map_f(), SV_MapcycleAdd_f(), SV_ServerCommand_f(), SV_UserInfo_f(), SVC_DirectConnect(), SVC_Info(), SVC_RemoteCommand(), TEST_F(), TUT_ListClick_f(), UI_AddCvarListener_f(), UI_AddListener_f(), UI_CloseWindow_f(), UI_DebugTree_f(), UI_EditorNodeExtract_f(), UI_ExecuteLuaConFunc(), UI_GeoscapeNodeScroll_f(), UI_GeoscapeNodeZoom_f(), UI_GetParam(), UI_InitStack_f(), UI_ListMaps_f(), UI_MaterialEditorChangeValue_f(), UI_MaterialEditorNewStage_f(), UI_MaterialEditorRemoveStage_f(), UI_MaterialEditorSelectStage_f(), UI_Popup_f(), UI_PopWindow_f(), UI_PushChildWindow_f(), UI_PushDropDownWindow_f(), UI_PushWindow_f(), UI_RemoveCvarListener_f(), UI_RemoveListener(), UI_RemoveListener_f(), UI_ResetData_f(), UI_SelectMap_f(), UI_TextScrollEnd(), WEB_Auth_f(), WEB_DeleteCGame_f(), WEB_DownloadCGame_f(), WEB_ListCGame_f(), and WEB_UploadCGame_f().

◆ Cmd_BufClear()

void Cmd_BufClear ( void )

Clears the argv vector and set argc to zero.

Clears the command execution buffer.

See also
Cmd_TokenizeString

Definition at line 543 of file cmd.cpp.

References cmd_argc, cmd_args, cmd_argv, cmd_userdata, i, and Mem_Free.

Referenced by Cmd_ExecuteString(), and Cmd_TokenizeString().

◆ Cmd_Close_f()

void Cmd_Close_f ( void )
static

Will no longer add any command to command buffer ...until cmd_close is false again.

See also
Cmd_Open_f

Definition at line 79 of file cmd.cpp.

References cmdClosed, Com_DPrintf(), and DEBUG_COMMANDS.

Referenced by Cmd_Init().

◆ Cmd_CompleteCommand()

int Cmd_CompleteCommand ( const char * partial,
const char ** match )

Unix like tab completion for console commands.

Parameters
[in]partialThe beginning of the command we try to complete
[out]matchThe found entry of the list we are searching, in case of more than one entry their common suffix is returned.
See also
Cvar_CompleteVariable
Key_CompleteCommand

Definition at line 924 of file cmd.cpp.

References cmd_alias, cmd_functions, Cmd_GenericCompleteFunction(), Com_Printf(), and S_COLOR_GREEN.

Referenced by Com_ConsoleCompleteCommand().

◆ Cmd_CompleteCommandParameters()

int Cmd_CompleteCommandParameters ( const char * command,
const char * partial,
const char ** match )

Unix like tab completion for console commands parameters.

attempts to match a partial command for automatic command line completion returns nullptr if nothing fits

Parameters
[in]commandThe command we try to complete the parameter for
[in]partialThe beginning of the parameter we try to complete
[out]matchThe command we are writing back (if something was found)
See also
Cvar_CompleteVariable
Key_CompleteCommand

Definition at line 903 of file cmd.cpp.

References cmd_functions_hash, CMD_HASH_SIZE, Com_HashKey(), hash, and Q_strcasecmp.

Referenced by Com_ConsoleCompleteCommand().

◆ Cmd_CompleteExecCommand()

int Cmd_CompleteExecCommand ( const char * partial,
const char ** match )
static

Autocomplete function for exec command.

See also
Cmd_AddParamCompleteFunction

Definition at line 1066 of file cmd.cpp.

References Cmd_GenericCompleteFunction(), Com_Printf(), and FS_NextFileFromFileList().

Referenced by Cmd_Init().

◆ Cmd_Dummy_f()

void Cmd_Dummy_f ( void )

Dummy binding if you don't want unknown commands forwarded to the server.

Definition at line 1083 of file cmd.cpp.

Referenced by Cmd_ExecuteString(), S_Init(), and CampaignTest::SetUpTestCase().

◆ Cmd_Echo_f()

void Cmd_Echo_f ( void )
static

Just prints the rest of the line to the console.

Definition at line 383 of file cmd.cpp.

References Cmd_Argc(), Cmd_Argv(), Com_Printf(), and i.

Referenced by Cmd_Init().

◆ Cmd_Exec_f()

void Cmd_Exec_f ( void )
static

Definition at line 352 of file cmd.cpp.

References Cbuf_InsertText(), Cmd_Argc(), Cmd_Argv(), Com_Printf(), f, FS_FreeFile(), FS_LoadFile(), len, Mem_AllocTypeN, and Mem_Free.

Referenced by Cmd_Init().

◆ Cmd_ExecuteString()

◆ Cmd_Exists()

bool Cmd_Exists ( const char * cmdName)

Checks whether a function exists already.

used by the cvar code to check for cvar / command name overlap

Parameters
[in]cmdNameThe script interface function name to search for

Definition at line 887 of file cmd.cpp.

References Cmd_TableFind().

Referenced by uiConFuncNode::deleteNode(), M_Init(), uiConFuncNode::onLoaded(), and UI_Shutdown().

◆ Cmd_ForwardToServer()

void Cmd_ForwardToServer ( void )

adds the current command line as a clc_stringcmd to the client message. things like action, turn, etc, are commands directed to the server, so when they are typed in at the console, they will need to be forwarded.

Definition at line 98 of file cl_main.cpp.

Referenced by Cmd_vExecuteString().

◆ Cmd_GenericCompleteFunction()

bool Cmd_GenericCompleteFunction ( char const * candidate,
char const * partial,
char const ** match )

Tests whether candidate has partial as prefix and determines the common prefix of all candidates passed to it.

See also
Cmd_AddParamCompleteFunction
Parameters
[out]matchThe found entry of the list we are searching, in case of more than one entry their common suffix is returned.
[in]candidateA completion candidate.
[in]partialThe prefix a candidate must have to be considered a match.
Returns
true if the candidate matches partial.

Definition at line 648 of file cmd.cpp.

References MAX_QPATH, Q_strncpyz(), and Q_strstart().

Referenced by cgame_import_t::bool(), Cmd_CompleteCommand(), Cmd_CompleteExecCommand(), Cvar_CompleteVariable(), GAME_GetImportData(), Key_CompleteKeyName(), M_CompleteMusic(), S_CompleteSounds(), SV_CompleteMapCommand(), SV_CompleteServerCommand(), and UI_CompleteWithWindow().

◆ Cmd_GetCommandDesc()

const char * Cmd_GetCommandDesc ( const char * cmdName)

Returns the command description for a given command.

Searches for the description of a given command.

Parameters
[in]cmdNameCommand id in global command array
Note
never returns a nullptr pointer
Todo
  • search alias, too

Definition at line 629 of file cmd.cpp.

References Cmd_TableFind(), cmd_function_t::description, MAX_VAR, and Q_strncpyz().

Referenced by CLMN_AddBindings(), and Cmd_ExecuteString().

◆ Cmd_GetUserdata()

void * Cmd_GetUserdata ( const char * cmdName)

Fetches the userdata for a console command.

Parameters
[in]cmdNameThe name the command we want to add edit
Returns
nullptr if no userdata was set or the command wasn't found, the userdata pointer if it was found and set
See also
Cmd_AddCommand
Cmd_CompleteCommandParameters
Cmd_AddUserdata

Definition at line 700 of file cmd.cpp.

References Cmd_TableFind(), Com_Printf(), and cmd_function_t::userdata.

Referenced by uiConFuncNode::deleteNode(), uiConFuncNode::onWindowClosed(), uiConFuncNode::onWindowOpened(), and UI_ConFuncIsVirtual().

◆ Cmd_Help_f()

void Cmd_Help_f ( void )
static

Display some help about cmd and cvar usage.

Definition at line 1019 of file cmd.cpp.

References Com_Printf(), and S_COLOR_GREEN.

Referenced by Cmd_Init().

◆ Cmd_Init()

◆ Cmd_List_f()

void Cmd_List_f ( void )
static

List all available script interface functions.

Definition at line 1028 of file cmd.cpp.

References cmd_alias, Cmd_Argc(), Cmd_Argv(), cmd_functions, Com_Printf(), i, len, and S_COLOR_GREEN.

Referenced by Cmd_Init().

◆ Cmd_Open_f()

void Cmd_Open_f ( void )
static

Reopens the command buffer for writing.

See also
Cmd_Close_f

Definition at line 68 of file cmd.cpp.

References cmdClosed, Com_DPrintf(), and DEBUG_COMMANDS.

Referenced by Cmd_Init().

◆ Cmd_RegisterCmdListener()

void Cmd_RegisterCmdListener ( CmdListenerPtr listener)

Registers a command listener.

Parameters
listenerThe listener callback to register

Definition at line 869 of file cmd.cpp.

References cmdListeners.

Referenced by GAME_InitStartup().

◆ Cmd_RemoveCommand()

void Cmd_RemoveCommand ( const char * cmdName)

◆ Cmd_Shutdown()

◆ Cmd_TableAddList()

void Cmd_TableAddList ( const cmdList_t * cmdList)

◆ Cmd_TableCheck()

void Cmd_TableCheck ( void )

Check both the functiontable and the associated hashtable for invalid entries.

Definition at line 826 of file cmd.cpp.

References cmd_functions, cmd_functions_hash, CMD_HASH_SIZE, Com_Printf(), i, and Q_streq.

◆ Cmd_TableFind()

cmd_function_t * Cmd_TableFind ( const char * cmdName)
static

◆ Cmd_TableRemoveList()

void Cmd_TableRemoveList ( const cmdList_t * cmdList)

◆ Cmd_TokenizeString()

void Cmd_TokenizeString ( const char * text,
bool macroExpand,
bool replaceWhitespaces )

Parses the given string into command line tokens.

Note
cmd_argv and cmd_argv are filled and set here
*cvars will be expanded unless they are in a quoted token
See also
Com_MacroExpandString
Parameters
[in]textThe text to parse and tokenize. Must be null terminated. Does not need to be "\n" terminated.
[in]macroExpandexpand cvar string with their values
[in]replaceWhitespacesReplace "\\t" and "\\n" to "\t" and "\n"

Definition at line 565 of file cmd.cpp.

References cmd_argc, cmd_args, cmd_argv, Cmd_BufClear(), Com_Chop(), com_cmdSysPool, Com_MacroExpandString(), Com_Parse(), com_token, Cvar_GetString(), MAX_STRING_TOKENS, Mem_PoolStrDup, and Q_strncpyz().

Referenced by CL_ConnectionlessPacket(), Cmd_vExecuteString(), SV_ConnectionlessPacket(), SV_ExecuteUserCommand(), and TEST_F().

◆ Cmd_UnRegisterCmdListener()

void Cmd_UnRegisterCmdListener ( CmdListenerPtr listener)

Unregisters a command listener.

Parameters
listenerThe listener callback to unregister

Definition at line 878 of file cmd.cpp.

References cmdListeners.

Referenced by GAME_Shutdown().

◆ Cmd_Userdata()

void * Cmd_Userdata ( void )

Return the userdata of the called command.

Definition at line 534 of file cmd.cpp.

References cmd_userdata.

Referenced by UI_ConfuncCommand_f().

◆ Cmd_vExecuteString()

◆ Cmd_Wait_f()

void Cmd_Wait_f ( void )
static

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".

Definition at line 90 of file cmd.cpp.

References cmdWait.

Referenced by Cmd_Init().

◆ Cmd_WriteAliases()

void Cmd_WriteAliases ( qFILE * f)

Write lines containing "aliasa alias value" for all aliases with the archive flag set to true.

Writes the persistent aliases to the given filehandle.

Parameters
fFilehandle to write the aliases to

Definition at line 454 of file cmd.cpp.

References cmd_alias, f, FS_Printf(), and i.

Referenced by Cmd_ExecuteString(), and Com_WriteConfigToFile().

Variable Documentation

◆ alias_count

int alias_count
static

Definition at line 61 of file cmd.cpp.

Referenced by Cbuf_Execute(), Cmd_Shutdown(), and Cmd_vExecuteString().

◆ cmd_alias

cmd_alias_t* cmd_alias
static

Definition at line 55 of file cmd.cpp.

Referenced by Cmd_Alias_f(), Cmd_CompleteCommand(), Cmd_List_f(), Cmd_Shutdown(), and Cmd_WriteAliases().

◆ cmd_alias_hash

cmd_alias_t* cmd_alias_hash[ALIAS_HASH_SIZE]
static

Definition at line 56 of file cmd.cpp.

Referenced by Cmd_Alias_f(), Cmd_Shutdown(), and Cmd_vExecuteString().

◆ cmd_argc

int cmd_argc
static

Definition at line 491 of file cmd.cpp.

Referenced by Cmd_Argc(), Cmd_Argv(), Cmd_BufClear(), Cmd_Shutdown(), and Cmd_TokenizeString().

◆ cmd_args

char cmd_args[MAX_STRING_CHARS]
static

Definition at line 493 of file cmd.cpp.

Referenced by Cmd_Args(), Cmd_BufClear(), and Cmd_TokenizeString().

◆ cmd_argv

char* cmd_argv[MAX_STRING_TOKENS]
static

Definition at line 492 of file cmd.cpp.

Referenced by Cmd_Argv(), Cmd_BufClear(), Cmd_Shutdown(), and Cmd_TokenizeString().

◆ cmd_functions

cmd_function_t* cmd_functions
static

◆ cmd_functions_hash

◆ cmd_text

sizebuf_t cmd_text
static

◆ cmd_text_buf

byte cmd_text_buf[CMD_BUFFER_SIZE]
static

Definition at line 103 of file cmd.cpp.

Referenced by Cbuf_AddText(), Cbuf_CopyToDefer(), and Cbuf_Init().

◆ cmd_userdata

void* cmd_userdata
static

Definition at line 494 of file cmd.cpp.

Referenced by Cmd_BufClear(), Cmd_Userdata(), and Cmd_vExecuteString().

◆ cmdClosed

bool cmdClosed
static

Definition at line 58 of file cmd.cpp.

Referenced by Cbuf_AddText(), Cmd_Close_f(), Cmd_Open_f(), and Cmd_Shutdown().

◆ cmdListeners

CmdListeners cmdListeners
static

◆ cmdWait

bool cmdWait
static

Definition at line 57 of file cmd.cpp.

Referenced by Cbuf_Execute(), Cmd_Shutdown(), and Cmd_Wait_f().

◆ defer_text_buf

char defer_text_buf[CMD_BUFFER_SIZE]
static

Definition at line 104 of file cmd.cpp.

Referenced by Cbuf_CopyToDefer(), and Cbuf_InsertFromDefer().