1 /* $Id: console_internal.h 24900 2013-01-08 22:46:42Z planetmaker $ */
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file console_internal.h Internally used functions for the console. */
12 #ifndef CONSOLE_INTERNAL_H
13 #define CONSOLE_INTERNAL_H
17 static const uint ICON_CMDLN_SIZE
= 1024; ///< maximum length of a typed in command
18 static const uint ICON_MAX_STREAMSIZE
= 2048; ///< maximum length of a totally expanded command
20 /** Return values of console hooks (#IConsoleHook). */
21 enum ConsoleHookResult
{
22 CHR_ALLOW
, ///< Allow command execution.
23 CHR_DISALLOW
, ///< Disallow command execution.
24 CHR_HIDE
, ///< Hide the existence of the command.
29 * Commands are commands, or functions. They get executed once and any
30 * effect they produce are carried out. The arguments to the commands
31 * are given to them, each input word separated by a double-quote (") is an argument
32 * If you want to handle multiple words as one, enclose them in double-quotes
33 * eg. 'say "hello sexy boy"'
35 typedef bool IConsoleCmdProc(byte argc
, char *argv
[]);
36 typedef ConsoleHookResult
IConsoleHook(bool echo
);
38 char *name
; ///< name of command
39 IConsoleCmd
*next
; ///< next command in list
41 IConsoleCmdProc
*proc
; ///< process executed when command is typed
42 IConsoleHook
*hook
; ///< any special trigger action that needs executing
47 * Aliases are like shortcuts for complex functions, variable assignments,
48 * etc. You can use a simple alias to rename a longer command (eg 'set' for
49 * 'setting' for example), or concatenate more commands into one
50 * (eg. 'ng' for 'load %A; unpause; debug_level 5'). Aliases can parse the arguments
51 * given to them in the command line.
52 * - "%A - %Z" substitute arguments 1 t/m 26
53 * - "%+" lists all parameters keeping them separated
54 * - "%!" also lists all parameters but presenting them to the aliased command as one argument
55 * - ";" allows for combining commands (see example 'ng')
57 struct IConsoleAlias
{
58 char *name
; ///< name of the alias
59 IConsoleAlias
*next
; ///< next alias in list
61 char *cmdline
; ///< command(s) that is/are being aliased
65 extern IConsoleCmd
*_iconsole_cmds
; ///< List of registered commands.
66 extern IConsoleAlias
*_iconsole_aliases
; ///< List of registered aliases.
68 /* console functions */
69 void IConsoleClearBuffer();
72 void IConsoleCmdRegister(const char *name
, IConsoleCmdProc
*proc
, IConsoleHook
*hook
= nullptr);
73 void IConsoleAliasRegister(const char *name
, const char *cmd
);
74 IConsoleCmd
*IConsoleCmdGet(const char *name
);
75 IConsoleAlias
*IConsoleAliasGet(const char *name
);
77 /* console std lib (register ingame commands/aliases) */
78 void IConsoleStdLibRegister();
80 /* Supporting functions */
81 bool GetArgumentInteger(uint32
*value
, const char *arg
);
83 void IConsoleGUIInit();
84 void IConsoleGUIFree();
85 void IConsoleGUIPrint(TextColour colour_code
, char *string
);
86 char *RemoveUnderscores(char *name
);
88 #endif /* CONSOLE_INTERNAL_H */