#include "../game/q_shared.h"
#include "qcommon.h"
Include dependency graph for cmd.c:

Go to the source code of this file.
Data Structures | |
| struct | cmd_function_s |
| struct | cmd_t |
Defines | |
| #define | MAX_CMD_BUFFER 16384 |
| #define | MAX_CMD_LINE 1024 |
Typedefs | |
| typedef cmd_function_s | cmd_function_t |
Functions | |
| void | Cbuf_AddText (const char *text) |
| void | Cbuf_Execute (void) |
| void | Cbuf_ExecuteText (int exec_when, const char *text) |
| void | Cbuf_Init (void) |
| void | Cbuf_InsertText (const char *text) |
| void | Cmd_AddCommand (const char *cmd_name, xcommand_t function) |
| int | Cmd_Argc (void) |
| char * | Cmd_Args (void) |
| void | Cmd_ArgsBuffer (char *buffer, int bufferLength) |
| char * | Cmd_ArgsFrom (int arg) |
| char * | Cmd_Argv (int arg) |
| void | Cmd_ArgvBuffer (int arg, char *buffer, int bufferLength) |
| char * | Cmd_Cmd () |
| void | Cmd_CommandCompletion (void(*callback)(const char *s)) |
| void | Cmd_Echo_f (void) |
| void | Cmd_Exec_f (void) |
| void | Cmd_ExecuteString (const char *text) |
| void | Cmd_Init (void) |
| void | Cmd_List_f (void) |
| void | Cmd_RemoveCommand (const char *cmd_name) |
| void | Cmd_TokenizeString (const char *text_in) |
| void | Cmd_Vstr_f (void) |
| void | Cmd_Wait_f (void) |
Variables | |
| int | cmd_argc |
| char * | cmd_argv [MAX_STRING_TOKENS] |
| char | cmd_cmd [BIG_INFO_STRING] |
| cmd_function_t * | cmd_functions |
| cmd_t | cmd_text |
| byte | cmd_text_buf [MAX_CMD_BUFFER] |
| char | cmd_tokenized [BIG_INFO_STRING+MAX_STRING_TOKENS] |
| int | cmd_wait |
|
|
|
|
|
Definition at line 28 of file cmd.c. Referenced by Cbuf_Execute(). |
|
|
Referenced by Cmd_AddCommand(), Cmd_CommandCompletion(), Cmd_ExecuteString(), Cmd_List_f(), and Cmd_RemoveCommand(). |
|
|
Definition at line 88 of file cmd.c. References cmd_text, Com_Memcpy(), Com_Printf(), cmd_t::cursize, cmd_t::data, l, cmd_t::maxsize, and strlen(). Referenced by Cbuf_ExecuteText(), CL_AddKeyUpCommands(), CL_CgameSystemCalls(), CL_FirstSnapshot(), CL_GetServerCommand(), CL_KeyEvent(), CL_NextDemo(), CL_Reconnect_f(), CL_StartDemoLoop(), Com_AddStartupCommands(), Com_EventLoop(), Com_Init(), Console_Key(), FS_Restart(), MainWndProc(), and SV_Frame(). 00088 {
00089 int l;
00090
00091 l = strlen (text);
00092
00093 if (cmd_text.cursize + l >= cmd_text.maxsize)
00094 {
00095 Com_Printf ("Cbuf_AddText: overflow\n");
00096 return;
00097 }
00098 Com_Memcpy(&cmd_text.data[cmd_text.cursize], text, l);
00099 cmd_text.cursize += l;
00100 }
|
Here is the call graph for this function:

|
|
Definition at line 168 of file cmd.c. References Cmd_ExecuteString(), cmd_text, cmd_wait, Com_Memcpy(), cmd_t::cursize, cmd_t::data, i, line, MAX_CMD_LINE, and memmove(). Referenced by Cbuf_ExecuteText(), CL_Init(), CL_NextDemo(), Com_Frame(), and Com_Init(). 00169 {
00170 int i;
00171 char *text;
00172 char line[MAX_CMD_LINE];
00173 int quotes;
00174
00175 while (cmd_text.cursize)
00176 {
00177 if ( cmd_wait ) {
00178 // skip out while text still remains in buffer, leaving it
00179 // for next frame
00180 cmd_wait--;
00181 break;
00182 }
00183
00184 // find a \n or ; line break
00185 text = (char *)cmd_text.data;
00186
00187 quotes = 0;
00188 for (i=0 ; i< cmd_text.cursize ; i++)
00189 {
00190 if (text[i] == '"')
00191 quotes++;
00192 if ( !(quotes&1) && text[i] == ';')
00193 break; // don't break if inside a quoted string
00194 if (text[i] == '\n' || text[i] == '\r' )
00195 break;
00196 }
00197
00198 if( i >= (MAX_CMD_LINE - 1)) {
00199 i = MAX_CMD_LINE - 1;
00200 }
00201
00202 Com_Memcpy (line, text, i);
00203 line[i] = 0;
00204
00205 // delete the text from the command buffer and move remaining commands down
00206 // this is necessary because commands (exec) can insert data at the
00207 // beginning of the text buffer
00208
00209 if (i == cmd_text.cursize)
00210 cmd_text.cursize = 0;
00211 else
00212 {
00213 i++;
00214 cmd_text.cursize -= i;
00215 memmove (text, text+i, cmd_text.cursize);
00216 }
00217
00218 // execute the command line
00219
00220 Cmd_ExecuteString (line);
00221 }
00222 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 141 of file cmd.c. References Cbuf_AddText(), Cbuf_Execute(), Cbuf_InsertText(), Cmd_ExecuteString(), Com_Error(), ERR_FATAL, EXEC_APPEND, EXEC_INSERT, EXEC_NOW, and strlen(). Referenced by CL_Frame(), CL_KeyEvent(), CL_UISystemCalls(), MainWndProc(), RoQShutdown(), and SV_GameSystemCalls(). 00142 {
00143 switch (exec_when)
00144 {
00145 case EXEC_NOW:
00146 if (text && strlen(text) > 0) {
00147 Cmd_ExecuteString (text);
00148 } else {
00149 Cbuf_Execute();
00150 }
00151 break;
00152 case EXEC_INSERT:
00153 Cbuf_InsertText (text);
00154 break;
00155 case EXEC_APPEND:
00156 Cbuf_AddText (text);
00157 break;
00158 default:
00159 Com_Error (ERR_FATAL, "Cbuf_ExecuteText: bad exec_when");
00160 }
00161 }
|
Here is the call graph for this function:

|
|
Definition at line 74 of file cmd.c. References cmd_text, cmd_t::cursize, cmd_t::data, and cmd_t::maxsize. Referenced by Com_Init(). 00075 {
00076 cmd_text.data = cmd_text_buf;
00077 cmd_text.maxsize = MAX_CMD_BUFFER;
00078 cmd_text.cursize = 0;
00079 }
|
|
|
Definition at line 111 of file cmd.c. References cmd_text, Com_Memcpy(), Com_Printf(), cmd_t::cursize, cmd_t::data, i, cmd_t::maxsize, and strlen(). Referenced by Cbuf_ExecuteText(), Cmd_Exec_f(), and Cmd_Vstr_f(). 00111 {
00112 int len;
00113 int i;
00114
00115 len = strlen( text ) + 1;
00116 if ( len + cmd_text.cursize > cmd_text.maxsize ) {
00117 Com_Printf( "Cbuf_InsertText overflowed\n" );
00118 return;
00119 }
00120
00121 // move the existing command text
00122 for ( i = cmd_text.cursize - 1 ; i >= 0 ; i-- ) {
00123 cmd_text.data[ i + len ] = cmd_text.data[ i ];
00124 }
00125
00126 // copy the new text in
00127 Com_Memcpy( cmd_text.data, text, len - 1 );
00128
00129 // add a \n
00130 cmd_text.data[ len - 1 ] = '\n';
00131
00132 cmd_text.cursize += len;
00133 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 550 of file cmd.c. References cmd_function_t, cmd_functions, Com_Printf(), CopyString(), cmd_function_s::function, cmd_function_s::name, cmd_function_s::next, S_Malloc(), and strcmp(). Referenced by CL_AddCgameCommand(), CL_Init(), CL_InitInput(), CL_InitKeyCommands(), Cmd_Init(), Com_Init(), Com_InitHunkMemory(), Con_Init(), Cvar_Init(), FS_Startup(), GLimp_Init(), IN_Init(), S_Init(), SV_AddOperatorCommands(), Sys_Init(), and VM_Init(). 00550 {
00551 cmd_function_t *cmd;
00552
00553 // fail if the command already exists
00554 for ( cmd = cmd_functions ; cmd ; cmd=cmd->next ) {
00555 if ( !strcmp( cmd_name, cmd->name ) ) {
00556 // allow completion-only commands to be silently doubled
00557 if ( function != NULL ) {
00558 Com_Printf ("Cmd_AddCommand: %s already defined\n", cmd_name);
00559 }
00560 return;
00561 }
00562 }
00563
00564 // use a small malloc to avoid zone fragmentation
00565 cmd = S_Malloc (sizeof(cmd_function_t));
00566 cmd->name = CopyString( cmd_name );
00567 cmd->function = function;
00568 cmd->next = cmd_functions;
00569 cmd_functions = cmd;
00570 }
|
Here is the call graph for this function:

|
|
|
Definition at line 365 of file cmd.c. References cmd_argc, cmd_argv, i, and strcat(). Referenced by CL_ForwardToServer_f(), Cmd_ArgsBuffer(), and SV_ConSay_f(). 00365 {
00366 static char cmd_args[MAX_STRING_CHARS];
00367 int i;
00368
00369 cmd_args[0] = 0;
00370 for ( i = 1 ; i < cmd_argc ; i++ ) {
00371 strcat( cmd_args, cmd_argv[i] );
00372 if ( i != cmd_argc-1 ) {
00373 strcat( cmd_args, " " );
00374 }
00375 }
00376
00377 return cmd_args;
00378 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 412 of file cmd.c. References buffer, Cmd_Args(), and Q_strncpyz(). Referenced by CL_CgameSystemCalls(). 00412 {
00413 Q_strncpyz( buffer, Cmd_Args(), bufferLength );
00414 }
|
Here is the call graph for this function:

|
|
Definition at line 387 of file cmd.c. References cmd_argc, cmd_argv, i, and strcat(). Referenced by CL_ConfigstringModified(). 00387 {
00388 static char cmd_args[BIG_INFO_STRING];
00389 int i;
00390
00391 cmd_args[0] = 0;
00392 if (arg < 0)
00393 arg = 0;
00394 for ( i = arg ; i < cmd_argc ; i++ ) {
00395 strcat( cmd_args, cmd_argv[i] );
00396 if ( i != cmd_argc-1 ) {
00397 strcat( cmd_args, " " );
00398 }
00399 }
00400
00401 return cmd_args;
00402 }
|
Here is the call graph for this function:

|
|
||||||||||||||||
|
Definition at line 353 of file cmd.c. References buffer, Cmd_Argv(), and Q_strncpyz(). Referenced by CL_CgameSystemCalls(), CL_UISystemCalls(), and SV_GameSystemCalls(). 00353 {
00354 Q_strncpyz( buffer, Cmd_Argv( arg ), bufferLength );
00355 }
|
Here is the call graph for this function:

|
|
Definition at line 425 of file cmd.c. Referenced by CL_Rcon_f(), and SVC_RemoteCommand(). 00426 {
00427 return cmd_cmd;
00428 }
|
|
|
Definition at line 605 of file cmd.c. References cmd_function_t, cmd_function_s::name, and cmd_function_s::next. Referenced by Field_CompleteCommand(). 00605 {
00606 cmd_function_t *cmd;
00607
00608 for (cmd=cmd_functions ; cmd ; cmd=cmd->next) {
00609 callback( cmd->name );
00610 }
00611 }
|
|
|
Definition at line 291 of file cmd.c. References Cmd_Argc(), Cmd_Argv(), Com_Printf(), and i. Referenced by Cmd_Init(). 00292 {
00293 int i;
00294
00295 for (i=1 ; i<Cmd_Argc() ; i++)
00296 Com_Printf ("%s ",Cmd_Argv(i));
00297 Com_Printf ("\n");
00298 }
|
Here is the call graph for this function:

|
|
Definition at line 239 of file cmd.c. References Cbuf_InsertText(), Cmd_Argc(), Cmd_Argv(), COM_DefaultExtension(), Com_Printf(), f, FS_FreeFile(), FS_ReadFile(), and Q_strncpyz(). Referenced by Cmd_Init(). 00239 {
00240 char *f;
00241 int len;
00242 char filename[MAX_QPATH];
00243
00244 if (Cmd_Argc () != 2) {
00245 Com_Printf ("exec <filename> : execute a script file\n");
00246 return;
00247 }
00248
00249 Q_strncpyz( filename, Cmd_Argv(1), sizeof( filename ) );
00250 COM_DefaultExtension( filename, sizeof( filename ), ".cfg" );
00251 len = FS_ReadFile( filename, (void **)&f);
00252 if (!f) {
00253 Com_Printf ("couldn't exec %s\n",Cmd_Argv(1));
00254 return;
00255 }
00256 Com_Printf ("execing %s\n",Cmd_Argv(1));
00257
00258 Cbuf_InsertText (f);
00259
00260 FS_FreeFile (f);
00261 }
|
Here is the call graph for this function:

|
|
Definition at line 621 of file cmd.c. References CL_ForwardCommandToServer(), CL_GameCommand(), Cmd_Argc(), cmd_argv, cmd_function_t, cmd_functions, Cmd_TokenizeString(), com_cl_running, com_sv_running, Cvar_Command(), cmd_function_s::function, cvar_s::integer, cmd_function_s::name, cmd_function_s::next, Q_stricmp(), SV_GameCommand(), and UI_GameCommand(). Referenced by Cbuf_Execute(), Cbuf_ExecuteText(), and SVC_RemoteCommand(). 00621 {
00622 cmd_function_t *cmd, **prev;
00623
00624 // execute the command line
00625 Cmd_TokenizeString( text );
00626 if ( !Cmd_Argc() ) {
00627 return; // no tokens
00628 }
00629
00630 // check registered command functions
00631 for ( prev = &cmd_functions ; *prev ; prev = &cmd->next ) {
00632 cmd = *prev;
00633 if ( !Q_stricmp( cmd_argv[0],cmd->name ) ) {
00634 // rearrange the links so that the command will be
00635 // near the head of the list next time it is used
00636 *prev = cmd->next;
00637 cmd->next = cmd_functions;
00638 cmd_functions = cmd;
00639
00640 // perform the action
00641 if ( !cmd->function ) {
00642 // let the cgame or game handle it
00643 break;
00644 } else {
00645 cmd->function ();
00646 }
00647 return;
00648 }
00649 }
00650
00651 // check cvars
00652 if ( Cvar_Command() ) {
00653 return;
00654 }
00655
00656 // check client game commands
00657 if ( com_cl_running && com_cl_running->integer && CL_GameCommand() ) {
00658 return;
00659 }
00660
00661 // check server game commands
00662 if ( com_sv_running && com_sv_running->integer && SV_GameCommand() ) {
00663 return;
00664 }
00665
00666 // check ui commands
00667 if ( com_cl_running && com_cl_running->integer && UI_GameCommand() ) {
00668 return;
00669 }
00670
00671 // send it as a server command if we are connected
00672 // this will usually result in a chat message
00673 CL_ForwardCommandToServer ( text );
00674 }
|
Here is the call graph for this function:

|
|
Definition at line 708 of file cmd.c. References Cmd_AddCommand(), Cmd_Echo_f(), Cmd_Exec_f(), Cmd_List_f(), Cmd_Vstr_f(), and Cmd_Wait_f(). Referenced by Com_Init(). 00708 {
00709 Cmd_AddCommand ("cmdlist",Cmd_List_f);
00710 Cmd_AddCommand ("exec",Cmd_Exec_f);
00711 Cmd_AddCommand ("vstr",Cmd_Vstr_f);
00712 Cmd_AddCommand ("echo",Cmd_Echo_f);
00713 Cmd_AddCommand ("wait", Cmd_Wait_f);
00714 }
|
Here is the call graph for this function:

|
|
Definition at line 681 of file cmd.c. References Cmd_Argc(), Cmd_Argv(), cmd_function_t, Com_Filter(), Com_Printf(), i, match(), cmd_function_s::name, cmd_function_s::next, and qfalse. Referenced by Cmd_Init(). 00682 {
00683 cmd_function_t *cmd;
00684 int i;
00685 char *match;
00686
00687 if ( Cmd_Argc() > 1 ) {
00688 match = Cmd_Argv( 1 );
00689 } else {
00690 match = NULL;
00691 }
00692
00693 i = 0;
00694 for (cmd=cmd_functions ; cmd ; cmd=cmd->next) {
00695 if (match && !Com_Filter(match, cmd->name, qfalse)) continue;
00696
00697 Com_Printf ("%s\n", cmd->name);
00698 i++;
00699 }
00700 Com_Printf ("%i commands\n", i);
00701 }
|
Here is the call graph for this function:

|
|
Definition at line 577 of file cmd.c. References cmd_function_t, cmd_function_s::name, cmd_function_s::next, strcmp(), and Z_Free(). Referenced by CL_CgameSystemCalls(), CL_Shutdown(), FS_Shutdown(), IN_Shutdown(), S_Shutdown(), and SV_RemoveOperatorCommands(). 00577 {
00578 cmd_function_t *cmd, **back;
00579
00580 back = &cmd_functions;
00581 while( 1 ) {
00582 cmd = *back;
00583 if ( !cmd ) {
00584 // command wasn't active
00585 return;
00586 }
00587 if ( !strcmp( cmd_name, cmd->name ) ) {
00588 *back = cmd->next;
00589 if (cmd->name) {
00590 Z_Free(cmd->name);
00591 }
00592 Z_Free (cmd);
00593 return;
00594 }
00595 back = &cmd->next;
00596 }
00597 }
|
Here is the call graph for this function:

|
|
Definition at line 442 of file cmd.c. References cmd_argc, cmd_argv, cmd_cmd, Com_DPrintf(), and Q_strncpyz(). Referenced by CL_ConnectionlessPacket(), CL_GetServerCommand(), Cmd_ExecuteString(), Com_SafeMode(), Com_StartupVariable(), Field_CompleteCommand(), FS_PureServerSetLoadedPaks(), FS_PureServerSetReferencedPaks(), SV_ConnectionlessPacket(), SV_ExecuteClientCommand(), and SV_VerifyPaks_f(). 00442 {
00443 const char *text;
00444 char *textOut;
00445
00446 #ifdef TKN_DBG
00447 // FIXME TTimo blunt hook to try to find the tokenization of userinfo
00448 Com_DPrintf("Cmd_TokenizeString: %s\n", text_in);
00449 #endif
00450
00451 // clear previous args
00452 cmd_argc = 0;
00453
00454 if ( !text_in ) {
00455 return;
00456 }
00457
00458 Q_strncpyz( cmd_cmd, text_in, sizeof(cmd_cmd) );
00459
00460 text = text_in;
00461 textOut = cmd_tokenized;
00462
00463 while ( 1 ) {
00464 if ( cmd_argc == MAX_STRING_TOKENS ) {
00465 return; // this is usually something malicious
00466 }
00467
00468 while ( 1 ) {
00469 // skip whitespace
00470 while ( *text && *text <= ' ' ) {
00471 text++;
00472 }
00473 if ( !*text ) {
00474 return; // all tokens parsed
00475 }
00476
00477 // skip // comments
00478 if ( text[0] == '/' && text[1] == '/' ) {
00479 return; // all tokens parsed
00480 }
00481
00482 // skip /* */ comments
00483 if ( text[0] == '/' && text[1] =='*' ) {
00484 while ( *text && ( text[0] != '*' || text[1] != '/' ) ) {
00485 text++;
00486 }
00487 if ( !*text ) {
00488 return; // all tokens parsed
00489 }
00490 text += 2;
00491 } else {
00492 break; // we are ready to parse a token
00493 }
00494 }
00495
00496 // handle quoted strings
00497 // NOTE TTimo this doesn't handle \" escaping
00498 if ( *text == '"' ) {
00499 cmd_argv[cmd_argc] = textOut;
00500 cmd_argc++;
00501 text++;
00502 while ( *text && *text != '"' ) {
00503 *textOut++ = *text++;
00504 }
00505 *textOut++ = 0;
00506 if ( !*text ) {
00507 return; // all tokens parsed
00508 }
00509 text++;
00510 continue;
00511 }
00512
00513 // regular token
00514 cmd_argv[cmd_argc] = textOut;
00515 cmd_argc++;
00516
00517 // skip until whitespace, quote, or command
00518 while ( *text > ' ' ) {
00519 if ( text[0] == '"' ) {
00520 break;
00521 }
00522
00523 if ( text[0] == '/' && text[1] == '/' ) {
00524 break;
00525 }
00526
00527 // skip /* */ comments
00528 if ( text[0] == '/' && text[1] =='*' ) {
00529 break;
00530 }
00531
00532 *textOut++ = *text++;
00533 }
00534
00535 *textOut++ = 0;
00536
00537 if ( !*text ) {
00538 return; // all tokens parsed
00539 }
00540 }
00541
00542 }
|
Here is the call graph for this function:

|
|
Definition at line 271 of file cmd.c. References Cbuf_InsertText(), Cmd_Argc(), Cmd_Argv(), Com_Printf(), Cvar_VariableString(), v, and va(). Referenced by Cmd_Init(). 00271 {
00272 char *v;
00273
00274 if (Cmd_Argc () != 2) {
00275 Com_Printf ("vstr <variablename> : execute a variable command\n");
00276 return;
00277 }
00278
00279 v = Cvar_VariableString( Cmd_Argv( 1 ) );
00280 Cbuf_InsertText( va("%s\n", v ) );
00281 }
|
Here is the call graph for this function:

|
|
Definition at line 52 of file cmd.c. References atoi, Cmd_Argc(), Cmd_Argv(), and cmd_wait. Referenced by Cmd_Init(). 00052 {
00053 if ( Cmd_Argc() == 2 ) {
00054 cmd_wait = atoi( Cmd_Argv( 1 ) );
00055 } else {
00056 cmd_wait = 1;
00057 }
00058 }
|
Here is the call graph for this function:

|
|
Definition at line 317 of file cmd.c. Referenced by Cmd_Args(), Cmd_ArgsFrom(), and Cmd_TokenizeString(). |
|
|
Definition at line 318 of file cmd.c. Referenced by Cmd_Args(), Cmd_ArgsFrom(), Cmd_Argv(), Cmd_ExecuteString(), and Cmd_TokenizeString(). |
|
|
Definition at line 320 of file cmd.c. Referenced by Cmd_TokenizeString(). |
|
|
Definition at line 322 of file cmd.c. Referenced by Cmd_AddCommand(), and Cmd_ExecuteString(). |
|
|
Definition at line 37 of file cmd.c. Referenced by Cbuf_AddText(), Cbuf_Execute(), Cbuf_Init(), and Cbuf_InsertText(). |
|
|
|
|
|
|
|
|
Definition at line 36 of file cmd.c. Referenced by Cbuf_Execute(), and Cmd_Wait_f(). |
1.3.9.1