cmd.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // cmd.h -- Command buffer and command execution
  16. //===========================================================================
  17. /*
  18. Any number of commands can be added in a frame, from several different sources.
  19. Most commands come from either keybindings or console line input, but remote
  20. servers can also send across commands and entire text files can be execed.
  21. The + command line options are also added to the command buffer.
  22. The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute ();
  23. */
  24. void Cbuf_Init (void);
  25. // allocates an initial text buffer that will grow as needed
  26. void Cbuf_AddText (char *text);
  27. // as new commands are generated from the console or keybindings,
  28. // the text is added to the end of the command buffer.
  29. void Cbuf_InsertText (char *text);
  30. // when a command wants to issue other commands immediately, the text is
  31. // inserted at the beginning of the buffer, before any remaining unexecuted
  32. // commands.
  33. void Cbuf_Execute (void);
  34. // Pulls off \n terminated lines of text from the command buffer and sends
  35. // them through Cmd_ExecuteString. Stops when the buffer is empty.
  36. // Normally called once per frame, but may be explicitly invoked.
  37. // Do not call inside a command function!
  38. //===========================================================================
  39. /*
  40. Command execution takes a null terminated string, breaks it into tokens,
  41. then searches for a command or variable that matches the first token.
  42. Commands can come from three sources, but the handler functions may choose
  43. to dissallow the action or forward it to a remote server if the source is
  44. not apropriate.
  45. */
  46. typedef void (*xcommand_t) (void);
  47. typedef enum
  48. {
  49. src_client, // came in over a net connection as a clc_stringcmd
  50. // host_client will be valid during this state.
  51. src_command // from the command buffer
  52. } cmd_source_t;
  53. extern cmd_source_t cmd_source;
  54. void Cmd_Init (void);
  55. void Cmd_AddCommand (char *cmd_name, xcommand_t function);
  56. // called by the init functions of other parts of the program to
  57. // register commands and functions to call for them.
  58. // The cmd_name is referenced later, so it should not be in temp memory
  59. qboolean Cmd_Exists (char *cmd_name);
  60. // used by the cvar code to check for cvar / command name overlap
  61. char *Cmd_CompleteCommand (char *partial);
  62. // attempts to match a partial command for automatic command line completion
  63. // returns NULL if nothing fits
  64. int Cmd_Argc (void);
  65. char *Cmd_Argv (int arg);
  66. char *Cmd_Args (void);
  67. // The functions that execute commands get their parameters with these
  68. // functions. Cmd_Argv () will return an empty string, not a NULL
  69. // if arg > argc, so string operations are allways safe.
  70. int Cmd_CheckParm (char *parm);
  71. // Returns the position (1 to argc-1) in the command's argument list
  72. // where the given parameter apears, or 0 if not present
  73. void Cmd_TokenizeString (char *text);
  74. // Takes a null terminated string. Does not need to be /n terminated.
  75. // breaks the string up into arg tokens.
  76. void Cmd_ExecuteString (char *text, cmd_source_t src);
  77. // Parses a single line of text into arguments and tries to execute it.
  78. // The text can come from the command buffer, a remote client, or stdin.
  79. void Cmd_ForwardToServer (void);
  80. // adds the current command line as a clc_stringcmd to the client message.
  81. // things like godmode, noclip, etc, are commands directed to the server,
  82. // so when they are typed in at the console, they will need to be forwarded.
  83. void Cmd_Print (char *text);
  84. // used by command functions to send output to either the graphics console or
  85. // passed as a print message to the client