cmd.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. Copyright (C) 2004 Michael Liebscher <johnnycanuck@users.sourceforge.net>
  3. Copyright (C) 1997-2001 Id Software, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /*
  17. * cmd.h: Command text buffering and command execution.
  18. *
  19. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  20. *
  21. * Acknowledgement:
  22. * This code was derived from Quake II, and was originally
  23. * written by Id Software, Inc.
  24. *
  25. */
  26. /*
  27. Notes:
  28. Any number of commands can be added in a frame, from several different sources.
  29. Most commands come from either keybindings or console line input, but remote
  30. servers can also send across commands and entire text files can be execed.
  31. The + command line options are also added to the command buffer.
  32. The game starts with a Cbuf_AddText( "exec DEFAULT.CFG\n" ); Cbuf_Execute();
  33. */
  34. #ifndef __CMD_H__
  35. #define __CMD_H__
  36. #include "arch.h"
  37. typedef enum {
  38. EXEC_NOW, // don't return until completed
  39. EXEC_INSERT, // insert at current position, but don't run yet
  40. EXEC_APPEND // add to end of the command buffer
  41. } execwhen_t;
  42. extern void Cbuf_AddText( const char *text );
  43. // as new commands are generated from the console or keybindings,
  44. // the text is added to the end of the command buffer.
  45. extern void Cbuf_InsertText( char *text );
  46. // when a command wants to issue other commands immediately, the text is
  47. // inserted at the beginning of the buffer, before any remaining unexecuted
  48. // commands.
  49. extern void Cbuf_ExecuteText( execwhen_t exec_when, char *text );
  50. // this can be used in place of either Cbuf_AddText or Cbuf_InsertText
  51. extern void Cbuf_AddEarlyCommands( _boolean clear );
  52. // adds all the +set commands from the command line
  53. extern _boolean Cbuf_AddLateCommands( void );
  54. // adds all the remaining + commands from the command line
  55. // Returns true if any late commands were added, which
  56. // will keep the demoloop from immediately starting
  57. extern void Cbuf_Execute( void );
  58. // Pulls off \n terminated lines of text from the command buffer and sends
  59. // them through Cmd_ExecuteString. Stops when the buffer is empty.
  60. // Normally called once per frame, but may be explicitly invoked.
  61. // Do not call inside a command function!
  62. extern void Cbuf_CopyToDefer( void );
  63. extern void Cbuf_InsertFromDefer( void );
  64. // These two functions are used to defer any pending commands while a map
  65. // is being loaded
  66. //===========================================================================
  67. #define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString
  68. #define MAX_STRING_TOKENS 80 // max tokens resulting from Cmd_TokenizeString
  69. #define MAX_TOKEN_CHARS 128 // max length of an individual token
  70. /*
  71. Command execution takes a NUL-terminated string, breaks it into tokens,
  72. then searches for a command or variable that matches the first token.
  73. */
  74. typedef void (*xcommand_t) (void);
  75. extern void Cmd_Init( void );
  76. extern void Cmd_AddCommand( char *cmd_name, xcommand_t function );
  77. // called by the init functions of other parts of the program to
  78. // register commands and functions to call for them.
  79. // The cmd_name is referenced later, so it should not be in temp memory
  80. // if function is NULL, the command will be forwarded to the server
  81. // as a clc_stringcmd instead of executed locally
  82. extern void Cmd_RemoveCommand( char *cmd_name );
  83. extern _boolean Cmd_Exists( char *cmd_name );
  84. // used by the cvar code to check for cvar / command name overlap
  85. extern char *Cmd_CompleteCommand( char *partial );
  86. // attempts to match a partial command for automatic command line completion
  87. // returns NULL if nothing fits
  88. extern int Cmd_Argc( void );
  89. extern char *Cmd_Argv( int arg );
  90. extern char *Cmd_Args( void );
  91. // The functions that execute commands get their parameters with these
  92. // functions. Cmd_Argv () will return an empty string, not a NULL
  93. // if arg > argc, so string operations are always safe.
  94. extern void Cmd_TokenizeString( char *text, _boolean macroExpand );
  95. // Takes a NUL-terminated string. Does not need to be /n terminated.
  96. // breaks the string up into arg tokens.
  97. extern void Cmd_ExecuteString( char *text );
  98. // Parses a single line of text into arguments and tries to execute it
  99. // as if it was typed at the console
  100. //extern void Cmd_ForwardToServer( void );
  101. // adds the current command line as a clc_stringcmd to the client message.
  102. // things like godmode, noclip, etc, are commands directed to the server,
  103. // so when they are typed in at the console, they will need to be forwarded.
  104. #endif /* __CMD_H__ */