UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cmd.h
Go to the documentation of this file.
1 
12 /*
13 Copyright (C) 1997-2001 Id Software, Inc.
14 
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License
17 as published by the Free Software Foundation; either version 2
18 of the License, or (at your option) any later version.
19 
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 
24 See the GNU General Public License for more details.
25 
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 
30 */
31 
32 #pragma once
33 
34 #include "filesys.h"
35 #include "../shared/cxx.h"
36 #include "../shared/sharedptr.h"
37 #include <stdarg.h>
38 
39 #include "../shared/cxx.h"
40 void Cbuf_Init(void);
41 void Cbuf_Shutdown(void);
42 void Cbuf_AddText(const char* format, ...) __attribute__((format(__printf__, 1, 2)));
43 
46 /* inserted at the beginning of the buffer, before any remaining unexecuted */
47 /* commands. */
48 void Cbuf_InsertText(const char* text);
49 
52 void Cbuf_AddEarlyCommands(bool clear);
53 
59 bool Cbuf_AddLateCommands(void);
60 
67 void Cbuf_Execute(void);
68 
73 void Cbuf_CopyToDefer(void);
74 void Cbuf_InsertFromDefer(void);
75 
76 #ifdef DEBUG
77 void Cmd_PrintDebugCommands(void);
78 #endif
79 
80 
81 /*=========================================================================== */
82 
83 
84 typedef void (*xcommand_t) (void);
85 
86 typedef struct cmdList_s {
87  const char* name;
88  xcommand_t function;
89  const char* description;
90 } cmdList_t;
91 
96 class CmdListener {
97 public:
98  virtual ~CmdListener() {}
99  virtual void onAdd (const char* cmdName) = 0;
100  virtual void onRemove (const char* cmdName) = 0;
101 };
102 
104 
105 void Cmd_Init(void);
106 void Cmd_Shutdown(void);
107 
115 void Cmd_AddCommand(const char* cmd_name, xcommand_t function, const char* desc = nullptr);
116 
117 void Cmd_RemoveCommand(const char* cmd_name);
118 void Cmd_TableCheck(void);
119 void Cmd_TableAddList(const cmdList_t* cmdList);
120 void Cmd_TableRemoveList(const cmdList_t* cmdList);
121 
122 void Cmd_AddParamCompleteFunction(const char* cmd_name, int (*function)(const char* partial, const char** match));
123 
124 void Cmd_AddUserdata(const char* cmd_name, void* userdata);
125 void* Cmd_GetUserdata (const char* cmd_name);
126 
135 bool Cmd_GenericCompleteFunction(char const* candidate, char const* partial, char const** match);
136 
140 bool Cmd_Exists(const char* cmd_name);
141 
146 void Cmd_RegisterCmdListener(CmdListenerPtr listener);
147 
152 void Cmd_UnRegisterCmdListener(CmdListenerPtr listener);
153 
158 int Cmd_CompleteCommandParameters(const char* command, const char* partial, const char** match);
159 int Cmd_CompleteCommand(const char* partial, const char** match);
160 
166 int Cmd_Argc(void);
167 const char* Cmd_Argv(int arg);
168 const char* Cmd_Args(void);
169 void* Cmd_Userdata(void);
170 
171 void Cmd_TokenizeString(const char* text, bool macroExpand, bool replaceWhitespaces = true);
172 
177 void Cmd_ExecuteString(const char* text, ...) __attribute__((format(__printf__, 1, 2)));
178 void Cmd_vExecuteString(const char* fmt, va_list ap);
179 
185 void Cmd_ForwardToServer(void);
186 
190 const char* Cmd_GetCommandDesc(const char* command);
191 
195 void Cmd_BufClear(void);
196 
201 void Cmd_WriteAliases(qFILE* f);
202 
206 void Cmd_Dummy_f(void);
207 
208 #include "ScopedCommand.h"
void Cmd_RemoveCommand(const char *cmd_name)
Removes a command from script interface.
Definition: cmd.cpp:786
void Cbuf_Shutdown(void)
Definition: cmd.cpp:117
void Cbuf_Init(void)
allocates an initial text buffer that will grow as needed
Definition: cmd.cpp:109
void void Cbuf_InsertText(const char *text)
when a command wants to issue other commands immediately, the text is
Definition: cmd.cpp:157
void Cbuf_AddEarlyCommands(bool clear)
adds all the +set commands from the command line
Definition: cmd.cpp:275
void Cmd_AddCommand(const char *cmd_name, xcommand_t function, const char *desc=nullptr)
called by the init functions of other parts of the program to register commands and functions to call...
Definition: cmd.cpp:744
void Cbuf_CopyToDefer(void)
These two functions are used to defer any pending commands while a map is being loaded.
Definition: cmd.cpp:191
void Cmd_ForwardToServer(void)
adds the current command line as a clc_stringcmd to the client message. things like godmode...
Definition: cl_main.cpp:98
void Cmd_UnRegisterCmdListener(CmdListenerPtr listener)
Unregisters a command listener.
Definition: cmd.cpp:878
virtual void onRemove(const char *cmdName)=0
int Cmd_CompleteCommand(const char *partial, const char **match)
Unix like tab completion for console commands.
Definition: cmd.cpp:924
bool Cmd_Exists(const char *cmd_name)
used by the cvar code to check for cvar / command name overlap
Definition: cmd.cpp:887
void Cmd_Dummy_f(void)
Dummy binding if you don't want unknown commands forwarded to the server.
Definition: cmd.cpp:1083
void Cmd_AddParamCompleteFunction(const char *cmd_name, int(*function)(const char *partial, const char **match))
Definition: cmd.cpp:679
#define __attribute__(x)
Definition: cxx.h:37
bool Cbuf_AddLateCommands(void)
adds all the remaining + commands from the command line
Definition: cmd.cpp:298
const char * Cmd_Args(void)
Returns a single string containing argv(1) to argv(argc()-1)
Definition: cmd.cpp:526
void Cbuf_InsertFromDefer(void)
Copies back any deferred commands.
Definition: cmd.cpp:201
void Cmd_Init(void)
Definition: cmd.cpp:1127
const char * name
Definition: cmd.h:87
int Cmd_CompleteCommandParameters(const char *command, const char *partial, const char **match)
attempts to match a partial command for automatic command line completion returns nullptr if nothing ...
Definition: cmd.cpp:903
void Cmd_TableCheck(void)
Check both the functiontable and the associated hashtable for invalid entries.
Definition: cmd.cpp:826
void Cmd_TableAddList(const cmdList_t *cmdList)
Definition: cmd.cpp:853
void Cmd_BufClear(void)
Clears the command execution buffer.
Definition: cmd.cpp:543
void Cmd_TokenizeString(const char *text, bool macroExpand, bool replaceWhitespaces=true)
Parses the given string into command line tokens.
Definition: cmd.cpp:565
Definition: cmd.h:86
const char * Cmd_Argv(int arg)
Returns a given argument.
Definition: cmd.cpp:516
void(* xcommand_t)(void)
Definition: cmd.h:84
void Cmd_ExecuteString(const char *text,...) __attribute__((format(__printf__
Parses a single line of text into arguments and tries to execute it as if it was typed at the console...
void void Cmd_vExecuteString(const char *fmt, va_list ap)
Definition: cmd.cpp:952
void Cbuf_AddText(const char *format,...) __attribute__((format(__printf__
const GLuint *typedef void(APIENTRY *GenRenderbuffersEXT_t)(GLsizei
Definition: r_gl.h:189
int Cmd_Argc(void)
The functions that execute commands get their parameters with these functions. Cmd_Argv() will return...
Definition: cmd.cpp:505
QGL_EXTERN GLfloat f
Definition: r_gl.h:114
Listener for command changes.
Definition: cmd.h:96
SharedPtr< CmdListener > CmdListenerPtr
Definition: cmd.h:103
bool Cmd_GenericCompleteFunction(char const *candidate, char const *partial, char const **match)
Definition: cmd.cpp:648
void Cmd_Shutdown(void)
Definition: cmd.cpp:1145
Filesystem header file.
void Cmd_AddUserdata(const char *cmd_name, void *userdata)
Adds userdata to the console command.
Definition: cmd.cpp:724
void * Cmd_Userdata(void)
Return the userdata of the called command.
Definition: cmd.cpp:534
void Cmd_RegisterCmdListener(CmdListenerPtr listener)
Registers a command listener.
Definition: cmd.cpp:869
virtual void onAdd(const char *cmdName)=0
struct cmdList_s cmdList_t
void * Cmd_GetUserdata(const char *cmd_name)
Fetches the userdata for a console command.
Definition: cmd.cpp:700
void Cmd_WriteAliases(qFILE *f)
Writes the persistent aliases to the given filehandle.
Definition: cmd.cpp:454
const char * Cmd_GetCommandDesc(const char *command)
Searches for the description of a given command.
Definition: cmd.cpp:629
virtual ~CmdListener()
Definition: cmd.h:98
void Cbuf_Execute(void)
Pulls off terminated lines of text from the command buffer and sends them through Cmd_ExecuteString...
Definition: cmd.cpp:214
void format(__printf__, 1, 2)))
const char * description
Definition: cmd.h:89
void Cmd_TableRemoveList(const cmdList_t *cmdList)
Definition: cmd.cpp:859