cmd.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. */
  43. typedef void (*xcommand_t) (void);
  44. void Cmd_Init (void);
  45. void Cmd_AddCommand (char *cmd_name, xcommand_t function);
  46. // called by the init functions of other parts of the program to
  47. // register commands and functions to call for them.
  48. // The cmd_name is referenced later, so it should not be in temp memory
  49. // if function is NULL, the command will be forwarded to the server
  50. // as a clc_stringcmd instead of executed locally
  51. qboolean Cmd_Exists (char *cmd_name);
  52. // used by the cvar code to check for cvar / command name overlap
  53. char *Cmd_CompleteCommand (char *partial);
  54. // attempts to match a partial command for automatic command line completion
  55. // returns NULL if nothing fits
  56. int Cmd_Argc (void);
  57. char *Cmd_Argv (int arg);
  58. char *Cmd_Args (void);
  59. // The functions that execute commands get their parameters with these
  60. // functions. Cmd_Argv () will return an empty string, not a NULL
  61. // if arg > argc, so string operations are allways safe.
  62. int Cmd_CheckParm (char *parm);
  63. // Returns the position (1 to argc-1) in the command's argument list
  64. // where the given parameter apears, or 0 if not present
  65. void Cmd_TokenizeString (char *text);
  66. // Takes a null terminated string. Does not need to be /n terminated.
  67. // breaks the string up into arg tokens.
  68. void Cmd_ExecuteString (char *text);
  69. // Parses a single line of text into arguments and tries to execute it
  70. // as if it was typed at the console
  71. void Cmd_ForwardToServer (void);
  72. // adds the current command line as a clc_stringcmd to the client message.
  73. // things like godmode, noclip, etc, are commands directed to the server,
  74. // so when they are typed in at the console, they will need to be forwarded.
  75. void Cmd_StuffCmds_f (void);