2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-24 10:15:06 +00:00
|
|
|
/** @file console_internal.h Internally used functions for the console. */
|
2007-02-23 11:50:43 +00:00
|
|
|
|
2008-05-24 10:15:06 +00:00
|
|
|
#ifndef CONSOLE_INTERNAL_H
|
|
|
|
#define CONSOLE_INTERNAL_H
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2011-01-22 14:52:20 +00:00
|
|
|
#include "gfx_type.h"
|
2021-04-24 13:19:57 +00:00
|
|
|
#include <map>
|
2007-12-19 19:44:29 +00:00
|
|
|
|
2010-05-13 09:44:44 +00:00
|
|
|
static const uint ICON_CMDLN_SIZE = 1024; ///< maximum length of a typed in command
|
|
|
|
static const uint ICON_MAX_STREAMSIZE = 2048; ///< maximum length of a totally expanded command
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2010-03-24 20:43:31 +00:00
|
|
|
/** Return values of console hooks (#IConsoleHook). */
|
|
|
|
enum ConsoleHookResult {
|
|
|
|
CHR_ALLOW, ///< Allow command execution.
|
|
|
|
CHR_DISALLOW, ///< Disallow command execution.
|
2010-07-31 21:02:56 +00:00
|
|
|
CHR_HIDE, ///< Hide the existence of the command.
|
2010-03-24 20:43:31 +00:00
|
|
|
};
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* --Commands--
|
2005-05-02 15:52:19 +00:00
|
|
|
* Commands are commands, or functions. They get executed once and any
|
|
|
|
* effect they produce are carried out. The arguments to the commands
|
2013-01-08 22:46:42 +00:00
|
|
|
* are given to them, each input word separated by a double-quote (") is an argument
|
2005-05-02 15:52:19 +00:00
|
|
|
* If you want to handle multiple words as one, enclose them in double-quotes
|
2021-05-09 17:02:17 +00:00
|
|
|
* eg. 'say "hello everybody"'
|
2005-05-02 15:52:19 +00:00
|
|
|
*/
|
2010-02-10 18:18:08 +00:00
|
|
|
typedef bool IConsoleCmdProc(byte argc, char *argv[]);
|
2010-03-24 20:43:31 +00:00
|
|
|
typedef ConsoleHookResult IConsoleHook(bool echo);
|
2007-03-07 12:11:48 +00:00
|
|
|
struct IConsoleCmd {
|
2021-04-25 01:14:29 +00:00
|
|
|
IConsoleCmd(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook, bool unlisted) : name(name), proc(proc), hook(hook), unlisted(unlisted) {}
|
2005-05-02 15:52:19 +00:00
|
|
|
|
2021-04-24 13:19:57 +00:00
|
|
|
std::string name; ///< name of command
|
2007-02-23 11:50:43 +00:00
|
|
|
IConsoleCmdProc *proc; ///< process executed when command is typed
|
2010-02-10 18:18:08 +00:00
|
|
|
IConsoleHook *hook; ///< any special trigger action that needs executing
|
2017-02-21 20:47:38 +00:00
|
|
|
bool unlisted;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-05-02 15:52:19 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* --Aliases--
|
2005-05-02 15:52:19 +00:00
|
|
|
* Aliases are like shortcuts for complex functions, variable assignments,
|
2010-02-10 17:32:39 +00:00
|
|
|
* etc. You can use a simple alias to rename a longer command (eg 'set' for
|
|
|
|
* 'setting' for example), or concatenate more commands into one
|
2005-05-02 15:52:19 +00:00
|
|
|
* (eg. 'ng' for 'load %A; unpause; debug_level 5'). Aliases can parse the arguments
|
|
|
|
* given to them in the command line.
|
|
|
|
* - "%A - %Z" substitute arguments 1 t/m 26
|
2013-01-08 22:46:42 +00:00
|
|
|
* - "%+" lists all parameters keeping them separated
|
2005-05-02 15:52:19 +00:00
|
|
|
* - "%!" also lists all parameters but presenting them to the aliased command as one argument
|
|
|
|
* - ";" allows for combining commands (see example 'ng')
|
|
|
|
*/
|
2007-03-07 12:11:48 +00:00
|
|
|
struct IConsoleAlias {
|
2021-04-24 13:19:57 +00:00
|
|
|
IConsoleAlias(const std::string &name, const std::string &cmdline) : name(name), cmdline(cmdline) {}
|
2005-05-02 15:52:19 +00:00
|
|
|
|
2021-04-24 13:19:57 +00:00
|
|
|
std::string name; ///< name of the alias
|
|
|
|
std::string cmdline; ///< command(s) that is/are being aliased
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-12-13 22:13:02 +00:00
|
|
|
|
2021-04-24 13:19:57 +00:00
|
|
|
struct IConsole
|
|
|
|
{
|
|
|
|
typedef std::map<std::string, IConsoleCmd> CommandList;
|
|
|
|
typedef std::map<std::string, IConsoleAlias> AliasList;
|
|
|
|
|
|
|
|
/* console parser */
|
|
|
|
static CommandList &Commands();
|
|
|
|
static AliasList &Aliases();
|
|
|
|
|
|
|
|
/* Commands */
|
2021-04-25 01:14:29 +00:00
|
|
|
static void CmdRegister(const std::string &name, IConsoleCmdProc *proc, IConsoleHook *hook = nullptr, bool unlisted = false);
|
2021-04-24 13:19:57 +00:00
|
|
|
static IConsoleCmd *CmdGet(const std::string &name);
|
|
|
|
static void AliasRegister(const std::string &name, const std::string &cmd);
|
|
|
|
static IConsoleAlias *AliasGet(const std::string &name);
|
|
|
|
};
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2006-08-28 10:14:37 +00:00
|
|
|
/* console functions */
|
2007-03-07 11:47:46 +00:00
|
|
|
void IConsoleClearBuffer();
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2010-02-10 17:32:39 +00:00
|
|
|
/* console std lib (register ingame commands/aliases) */
|
2007-03-07 11:47:46 +00:00
|
|
|
void IConsoleStdLibRegister();
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2006-08-28 10:14:37 +00:00
|
|
|
/* Supporting functions */
|
2005-05-02 15:52:19 +00:00
|
|
|
bool GetArgumentInteger(uint32 *value, const char *arg);
|
2008-05-24 11:55:25 +00:00
|
|
|
|
|
|
|
void IConsoleGUIInit();
|
|
|
|
void IConsoleGUIFree();
|
2011-01-03 12:01:41 +00:00
|
|
|
void IConsoleGUIPrint(TextColour colour_code, char *string);
|
2008-05-24 11:55:25 +00:00
|
|
|
|
|
|
|
#endif /* CONSOLE_INTERNAL_H */
|