tron@2186: /* $Id$ */ tron@2186: darkvater@205: #ifndef CONSOLE_H darkvater@205: #define CONSOLE_H signde@220: Darkvater@1739: // maximum length of a typed in command Darkvater@1739: #define ICON_CMDLN_SIZE 255 Darkvater@1739: // maximum length of a totally expanded command Darkvater@1739: #define ICON_MAX_STREAMSIZE 1024 darkvater@135: Darkvater@1739: typedef enum IConsoleVarTypes { darkvater@135: ICONSOLE_VAR_BOOLEAN, darkvater@135: ICONSOLE_VAR_BYTE, darkvater@135: ICONSOLE_VAR_UINT16, darkvater@135: ICONSOLE_VAR_UINT32, darkvater@135: ICONSOLE_VAR_INT16, darkvater@135: ICONSOLE_VAR_INT32, Darkvater@1739: ICONSOLE_VAR_STRING Darkvater@1739: } IConsoleVarTypes; darkvater@135: Darkvater@1739: typedef enum IConsoleModes { truelight@543: ICONSOLE_FULL, truelight@543: ICONSOLE_OPENED, truelight@543: ICONSOLE_CLOSED Darkvater@1739: } IConsoleModes; darkvater@135: Darkvater@1739: typedef enum IConsoleHookTypes { Darkvater@1739: ICONSOLE_HOOK_ACCESS, Darkvater@1739: ICONSOLE_HOOK_PRE_ACTION, Darkvater@1739: ICONSOLE_HOOK_POST_ACTION Darkvater@1739: } IConsoleHookTypes; darkvater@289: Darkvater@1739: /** --Hooks-- Darkvater@1739: * Hooks are certain triggers get get accessed/executed on either Darkvater@1739: * access, before execution/change or after execution/change. This allows Darkvater@1739: * for general flow of permissions or special action needed in some cases Darkvater@1739: */ Darkvater@1739: typedef bool IConsoleHook(void); Darkvater@1739: typedef struct IConsoleHooks{ Darkvater@1739: IConsoleHook *access; // trigger when accessing the variable/command Darkvater@1739: IConsoleHook *pre; // trigger before the variable/command is changed/executed Darkvater@1739: IConsoleHook *post; // trigger after the variable/command is changed/executed Darkvater@1739: } IConsoleHooks; darkvater@289: Darkvater@1739: /** --Commands-- Darkvater@1739: * Commands are commands, or functions. They get executed once and any Darkvater@1739: * effect they produce are carried out. The arguments to the commands Darkvater@1739: * are given to them, each input word seperated by a double-quote (") is an argument Darkvater@1739: * If you want to handle multiple words as one, enclose them in double-quotes Darkvater@1739: * eg. 'say "hello sexy boy"' Darkvater@1739: */ Darkvater@1739: typedef bool (IConsoleCmdProc)(byte argc, char *argv[]); darkvater@135: Darkvater@1739: struct IConsoleCmd; Darkvater@1739: typedef struct IConsoleCmd { Darkvater@1739: char *name; // name of command Darkvater@1739: struct IConsoleCmd *next; // next command in list truelight@634: Darkvater@1739: IConsoleCmdProc *proc; // process executed when command is typed Darkvater@1739: IConsoleHooks hook; // any special trigger action that needs executing Darkvater@1739: } IConsoleCmd; truelight@634: Darkvater@1739: /** --Variables-- Darkvater@1739: * Variables are pointers to real ingame variables which allow for Darkvater@1739: * changing while ingame. After changing they keep their new value Darkvater@1739: * and can be used for debugging, gameplay, etc. It accepts: Darkvater@1739: * - no arguments; just print out current value Darkvater@1739: * - '= ' to assign a new value to the variable Darkvater@1739: * - '++' to increase value by one Darkvater@1739: * - '--' to decrease value by one Darkvater@1739: */ Darkvater@1739: struct IConsoleVar; Darkvater@1739: typedef struct IConsoleVar { Darkvater@1739: char *name; // name of the variable Darkvater@1739: struct IConsoleVar *next; // next variable in list Darkvater@1739: Darkvater@1739: void *addr; // the address where the variable is pointing at Darkvater@1739: uint32 size; // size of the variable, used for strings Darkvater@1739: char *help; // the optional help string shown when requesting information Darkvater@1739: IConsoleVarTypes type; // type of variable (for correct assignment/output) Darkvater@1739: IConsoleCmdProc *proc; // some variables need really special handling, use a callback function for that Darkvater@1739: IConsoleHooks hook; // any special trigger action that needs executing Darkvater@1739: } IConsoleVar; Darkvater@1739: Darkvater@1739: /** --Aliases-- Darkvater@1739: * Aliases are like shortcuts for complex functions, variable assignments, Darkvater@1739: * etc. You can use a simple alias to rename a longer command (eg 'lv' for Darkvater@1739: * 'list_vars' for example), or concatenate more commands into one Darkvater@1739: * (eg. 'ng' for 'load %A; unpause; debug_level 5'). Aliases can parse the arguments Darkvater@1739: * given to them in the command line. Darkvater@1739: * - "%A - %Z" substitute arguments 1 t/m 26 Darkvater@1739: * - "%+" lists all parameters keeping them seperated Darkvater@1739: * - "%!" also lists all parameters but presenting them to the aliased command as one argument Darkvater@1739: * - ";" allows for combining commands (see example 'ng') Darkvater@1739: */ Darkvater@1739: struct IConsoleAlias; Darkvater@1739: typedef struct IConsoleAlias { Darkvater@1739: char *name; // name of the alias Darkvater@1739: struct IConsoleAlias *next; // next alias in list Darkvater@1739: Darkvater@1739: char *cmdline; // command(s) that is/are being aliased Darkvater@1739: } IConsoleAlias; dominik@644: signde@220: // ** console parser ** // Darkvater@1739: IConsoleCmd *_iconsole_cmds; // list of registred commands Darkvater@1739: IConsoleVar *_iconsole_vars; // list of registred vars Darkvater@1739: IConsoleAlias *_iconsole_aliases; // list of registred aliases signde@220: Darkvater@1739: // ** console colors/modes ** // Darkvater@1805: VARDEF byte _icolour_def; Darkvater@1805: VARDEF byte _icolour_err; Darkvater@1805: VARDEF byte _icolour_warn; Darkvater@1805: VARDEF byte _icolour_dbg; Darkvater@1805: VARDEF byte _icolour_cmd; Darkvater@1739: VARDEF IConsoleModes _iconsole_mode; darkvater@141: darkvater@135: // ** console functions ** // darkvater@289: void IConsoleInit(void); darkvater@289: void IConsoleFree(void); Darkvater@1827: void IConsoleClearBuffer(void); darkvater@289: void IConsoleResize(void); darkvater@289: void IConsoleSwitch(void); darkvater@289: void IConsoleClose(void); darkvater@289: void IConsoleOpen(void); darkvater@135: darkvater@135: // ** console output ** // Darkvater@1739: void IConsolePrint(uint16 color_code, const char *string); Darkvater@1739: void CDECL IConsolePrintF(uint16 color_code, const char *s, ...); Darkvater@1739: void IConsoleDebug(const char *string); Darkvater@1739: void IConsoleWarning(const char *string); Darkvater@1739: void IConsoleError(const char *string); darkvater@135: darkvater@135: // *** Commands *** // Darkvater@1739: void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc); Darkvater@1739: void IConsoleAliasRegister(const char *name, const char *cmd); Darkvater@1739: IConsoleCmd *IConsoleCmdGet(const char *name); Darkvater@1739: IConsoleAlias *IConsoleAliasGet(const char *name); darkvater@135: darkvater@135: // *** Variables *** // Darkvater@1739: void IConsoleVarRegister(const char *name, void *addr, IConsoleVarTypes type, const char *help); Darkvater@1739: void IConsoleVarStringRegister(const char *name, void *addr, uint32 size, const char *help); Darkvater@1739: IConsoleVar* IConsoleVarGet(const char *name); Darkvater@1739: void IConsoleVarPrintGetValue(const IConsoleVar *var); Darkvater@1739: void IConsoleVarPrintSetValue(const IConsoleVar *var); darkvater@135: darkvater@135: // *** Parser *** // Darkvater@1739: void IConsoleCmdExec(const char *cmdstr); Darkvater@1739: void IConsoleVarExec(const IConsoleVar *var, byte tokencount, char *token[]); darkvater@135: Darkvater@1739: // ** console std lib (register ingame commands/aliases/variables) ** // darkvater@289: void IConsoleStdLibRegister(void); signde@220: Darkvater@1739: // ** Hooking code ** // Darkvater@1739: void IConsoleCmdHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc); Darkvater@1739: void IConsoleVarHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc); Darkvater@1739: void IConsoleVarProcAdd(const char *name, IConsoleCmdProc *proc); signde@220: Darkvater@1739: // ** Supporting functions **// Darkvater@1739: bool GetArgumentInteger(uint32 *value, const char *arg); darkvater@205: #endif /* CONSOLE_H */