2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
/** @file console.h */
|
|
|
|
|
2004-09-11 19:18:30 +00:00
|
|
|
#ifndef CONSOLE_H
|
|
|
|
#define CONSOLE_H
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2007-12-19 19:44:29 +00:00
|
|
|
#include "window_type.h"
|
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
/* maximum length of a typed in command */
|
2005-05-02 15:52:19 +00:00
|
|
|
#define ICON_CMDLN_SIZE 255
|
2007-02-23 11:50:43 +00:00
|
|
|
/* maximum length of a totally expanded command */
|
2005-05-02 15:52:19 +00:00
|
|
|
#define ICON_MAX_STREAMSIZE 1024
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum IConsoleVarTypes {
|
2004-08-24 22:41:42 +00:00
|
|
|
ICONSOLE_VAR_BOOLEAN,
|
|
|
|
ICONSOLE_VAR_BYTE,
|
|
|
|
ICONSOLE_VAR_UINT16,
|
|
|
|
ICONSOLE_VAR_UINT32,
|
|
|
|
ICONSOLE_VAR_INT16,
|
|
|
|
ICONSOLE_VAR_INT32,
|
2005-05-02 15:52:19 +00:00
|
|
|
ICONSOLE_VAR_STRING
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum IConsoleModes {
|
2004-12-04 17:54:56 +00:00
|
|
|
ICONSOLE_FULL,
|
|
|
|
ICONSOLE_OPENED,
|
|
|
|
ICONSOLE_CLOSED
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum IConsoleHookTypes {
|
2004-09-12 20:15:18 +00:00
|
|
|
ICONSOLE_HOOK_ACCESS,
|
2005-05-02 15:52:19 +00:00
|
|
|
ICONSOLE_HOOK_PRE_ACTION,
|
|
|
|
ICONSOLE_HOOK_POST_ACTION
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-05-02 15:52:19 +00:00
|
|
|
|
|
|
|
/** --Hooks--
|
|
|
|
* Hooks are certain triggers get get accessed/executed on either
|
|
|
|
* access, before execution/change or after execution/change. This allows
|
|
|
|
* for general flow of permissions or special action needed in some cases
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
typedef bool IConsoleHook();
|
2007-03-07 12:11:48 +00:00
|
|
|
struct IConsoleHooks{
|
2007-02-23 11:50:43 +00:00
|
|
|
IConsoleHook *access; ///< trigger when accessing the variable/command
|
|
|
|
IConsoleHook *pre; ///< trigger before the variable/command is changed/executed
|
|
|
|
IConsoleHook *post; ///< trigger after the variable/command is changed/executed
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-05-02 15:52:19 +00:00
|
|
|
|
|
|
|
/** --Commands--
|
|
|
|
* Commands are commands, or functions. They get executed once and any
|
|
|
|
* effect they produce are carried out. The arguments to the commands
|
|
|
|
* are given to them, each input word seperated by a double-quote (") is an argument
|
|
|
|
* If you want to handle multiple words as one, enclose them in double-quotes
|
|
|
|
* eg. 'say "hello sexy boy"'
|
|
|
|
*/
|
|
|
|
typedef bool (IConsoleCmdProc)(byte argc, char *argv[]);
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct IConsoleCmd {
|
2007-02-23 11:50:43 +00:00
|
|
|
char *name; ///< name of command
|
2007-03-07 12:11:48 +00:00
|
|
|
IConsoleCmd *next; ///< next command in list
|
2005-05-02 15:52:19 +00:00
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
IConsoleCmdProc *proc; ///< process executed when command is typed
|
|
|
|
IConsoleHooks hook; ///< any special trigger action that needs executing
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-05-02 15:52:19 +00:00
|
|
|
|
|
|
|
/** --Variables--
|
|
|
|
* Variables are pointers to real ingame variables which allow for
|
|
|
|
* changing while ingame. After changing they keep their new value
|
|
|
|
* and can be used for debugging, gameplay, etc. It accepts:
|
|
|
|
* - no arguments; just print out current value
|
|
|
|
* - '= <new value>' to assign a new value to the variable
|
|
|
|
* - '++' to increase value by one
|
|
|
|
* - '--' to decrease value by one
|
|
|
|
*/
|
2007-03-07 12:11:48 +00:00
|
|
|
struct IConsoleVar {
|
2007-02-23 11:50:43 +00:00
|
|
|
char *name; ///< name of the variable
|
2007-03-07 12:11:48 +00:00
|
|
|
IConsoleVar *next; ///< next variable in list
|
2007-02-23 11:50:43 +00:00
|
|
|
|
|
|
|
void *addr; ///< the address where the variable is pointing at
|
|
|
|
uint32 size; ///< size of the variable, used for strings
|
|
|
|
char *help; ///< the optional help string shown when requesting information
|
|
|
|
IConsoleVarTypes type; ///< type of variable (for correct assignment/output)
|
|
|
|
IConsoleCmdProc *proc; ///< some variables need really special handling, use a callback function for that
|
|
|
|
IConsoleHooks hook; ///< any special trigger action that needs executing
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-05-02 15:52:19 +00:00
|
|
|
|
|
|
|
/** --Aliases--
|
|
|
|
* Aliases are like shortcuts for complex functions, variable assignments,
|
|
|
|
* etc. You can use a simple alias to rename a longer command (eg 'lv' for
|
|
|
|
* 'list_vars' for example), or concatenate more commands into one
|
|
|
|
* (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
|
|
|
|
* - "%+" lists all parameters keeping them seperated
|
|
|
|
* - "%!" 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 {
|
2007-02-23 11:50:43 +00:00
|
|
|
char *name; ///< name of the alias
|
2007-03-07 12:11:48 +00:00
|
|
|
IConsoleAlias *next; ///< next alias in list
|
2005-05-02 15:52:19 +00:00
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
char *cmdline; ///< command(s) that is/are being aliased
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-12-13 22:13:02 +00:00
|
|
|
|
2006-08-28 10:14:37 +00:00
|
|
|
/* console parser */
|
2007-02-23 11:50:43 +00:00
|
|
|
VARDEF IConsoleCmd *_iconsole_cmds; ///< list of registred commands
|
|
|
|
VARDEF IConsoleVar *_iconsole_vars; ///< list of registred vars
|
|
|
|
VARDEF IConsoleAlias *_iconsole_aliases; ///< list of registred aliases
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2006-08-28 10:14:37 +00:00
|
|
|
/* console colors/modes */
|
2005-05-14 19:34:59 +00:00
|
|
|
VARDEF byte _icolour_def;
|
|
|
|
VARDEF byte _icolour_err;
|
|
|
|
VARDEF byte _icolour_warn;
|
|
|
|
VARDEF byte _icolour_dbg;
|
|
|
|
VARDEF byte _icolour_cmd;
|
2005-05-02 15:52:19 +00:00
|
|
|
VARDEF IConsoleModes _iconsole_mode;
|
2004-08-25 22:11:41 +00:00
|
|
|
|
2006-08-28 10:14:37 +00:00
|
|
|
/* console functions */
|
2007-03-07 11:47:46 +00:00
|
|
|
void IConsoleInit();
|
|
|
|
void IConsoleFree();
|
|
|
|
void IConsoleClearBuffer();
|
2006-11-21 22:10:52 +00:00
|
|
|
void IConsoleResize(Window *w);
|
2007-03-07 11:47:46 +00:00
|
|
|
void IConsoleSwitch();
|
|
|
|
void IConsoleClose();
|
|
|
|
void IConsoleOpen();
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2006-08-28 10:14:37 +00:00
|
|
|
/* console output */
|
2005-05-02 15:52:19 +00:00
|
|
|
void IConsolePrint(uint16 color_code, const char *string);
|
|
|
|
void CDECL IConsolePrintF(uint16 color_code, const char *s, ...);
|
2006-12-26 17:36:18 +00:00
|
|
|
void IConsoleDebug(const char *dbg, const char *string);
|
2005-05-02 15:52:19 +00:00
|
|
|
void IConsoleWarning(const char *string);
|
|
|
|
void IConsoleError(const char *string);
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2006-08-28 10:14:37 +00:00
|
|
|
/* Commands */
|
2005-05-02 15:52:19 +00:00
|
|
|
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc);
|
|
|
|
void IConsoleAliasRegister(const char *name, const char *cmd);
|
|
|
|
IConsoleCmd *IConsoleCmdGet(const char *name);
|
|
|
|
IConsoleAlias *IConsoleAliasGet(const char *name);
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2006-08-28 10:14:37 +00:00
|
|
|
/* Variables */
|
2005-05-02 15:52:19 +00:00
|
|
|
void IConsoleVarRegister(const char *name, void *addr, IConsoleVarTypes type, const char *help);
|
|
|
|
void IConsoleVarStringRegister(const char *name, void *addr, uint32 size, const char *help);
|
|
|
|
IConsoleVar* IConsoleVarGet(const char *name);
|
|
|
|
void IConsoleVarPrintGetValue(const IConsoleVar *var);
|
|
|
|
void IConsoleVarPrintSetValue(const IConsoleVar *var);
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2006-08-28 10:14:37 +00:00
|
|
|
/* Parser */
|
2005-05-02 15:52:19 +00:00
|
|
|
void IConsoleCmdExec(const char *cmdstr);
|
|
|
|
void IConsoleVarExec(const IConsoleVar *var, byte tokencount, char *token[]);
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2006-08-28 10:14:37 +00:00
|
|
|
/* console std lib (register ingame commands/aliases/variables) */
|
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
|
|
|
/* Hooking code */
|
2005-05-02 15:52:19 +00:00
|
|
|
void IConsoleCmdHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc);
|
|
|
|
void IConsoleVarHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc);
|
|
|
|
void IConsoleVarProcAdd(const char *name, IConsoleCmdProc *proc);
|
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);
|
2004-09-11 19:18:30 +00:00
|
|
|
#endif /* CONSOLE_H */
|