tron@2186: /* $Id$ */ tron@2186: belugas@6449: /** @file console.h */ belugas@6449: darkvater@205: #ifndef CONSOLE_H darkvater@205: #define CONSOLE_H signde@220: rubidium@8602: #include "window_type.h" rubidium@8602: belugas@6449: /* maximum length of a typed in command */ Darkvater@1739: #define ICON_CMDLN_SIZE 255 belugas@6449: /* maximum length of a totally expanded command */ Darkvater@1739: #define ICON_MAX_STREAMSIZE 1024 darkvater@135: rubidium@6574: 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 rubidium@6574: }; darkvater@135: rubidium@6574: enum IConsoleModes { truelight@543: ICONSOLE_FULL, truelight@543: ICONSOLE_OPENED, truelight@543: ICONSOLE_CLOSED rubidium@6574: }; darkvater@135: rubidium@6574: enum IConsoleHookTypes { Darkvater@1739: ICONSOLE_HOOK_ACCESS, Darkvater@1739: ICONSOLE_HOOK_PRE_ACTION, Darkvater@1739: ICONSOLE_HOOK_POST_ACTION rubidium@6574: }; 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: */ rubidium@6573: typedef bool IConsoleHook(); rubidium@6574: struct IConsoleHooks{ belugas@6449: IConsoleHook *access; ///< trigger when accessing the variable/command belugas@6449: IConsoleHook *pre; ///< trigger before the variable/command is changed/executed belugas@6449: IConsoleHook *post; ///< trigger after the variable/command is changed/executed rubidium@6574: }; 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: rubidium@6574: struct IConsoleCmd { belugas@6449: char *name; ///< name of command rubidium@6574: IConsoleCmd *next; ///< next command in list truelight@634: belugas@6449: IConsoleCmdProc *proc; ///< process executed when command is typed belugas@6449: IConsoleHooks hook; ///< any special trigger action that needs executing rubidium@6574: }; 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: */ rubidium@6574: struct IConsoleVar { belugas@6449: char *name; ///< name of the variable rubidium@6574: IConsoleVar *next; ///< next variable in list Darkvater@1739: belugas@6449: void *addr; ///< the address where the variable is pointing at belugas@6449: uint32 size; ///< size of the variable, used for strings belugas@6449: char *help; ///< the optional help string shown when requesting information belugas@6449: IConsoleVarTypes type; ///< type of variable (for correct assignment/output) belugas@6449: IConsoleCmdProc *proc; ///< some variables need really special handling, use a callback function for that belugas@6449: IConsoleHooks hook; ///< any special trigger action that needs executing rubidium@6574: }; 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: */ rubidium@6574: struct IConsoleAlias { belugas@6449: char *name; ///< name of the alias rubidium@6574: IConsoleAlias *next; ///< next alias in list Darkvater@1739: belugas@6449: char *cmdline; ///< command(s) that is/are being aliased rubidium@6574: }; dominik@644: rubidium@4432: /* console parser */ rubidium@8764: extern IConsoleCmd *_iconsole_cmds; ///< list of registred commands rubidium@8764: extern IConsoleVar *_iconsole_vars; ///< list of registred vars rubidium@8764: extern IConsoleAlias *_iconsole_aliases; ///< list of registred aliases signde@220: rubidium@4432: /* console colors/modes */ rubidium@8764: extern byte _icolour_def; rubidium@8764: extern byte _icolour_err; rubidium@8764: extern byte _icolour_warn; rubidium@8764: extern byte _icolour_dbg; rubidium@8764: extern byte _icolour_cmd; rubidium@8764: extern IConsoleModes _iconsole_mode; darkvater@141: rubidium@4432: /* console functions */ rubidium@6573: void IConsoleInit(); rubidium@6573: void IConsoleFree(); rubidium@6573: void IConsoleClearBuffer(); Darkvater@5143: void IConsoleResize(Window *w); rubidium@6573: void IConsoleSwitch(); rubidium@6573: void IConsoleClose(); rubidium@6573: void IConsoleOpen(); darkvater@135: rubidium@4432: /* console output */ Darkvater@1739: void IConsolePrint(uint16 color_code, const char *string); Darkvater@1739: void CDECL IConsolePrintF(uint16 color_code, const char *s, ...); Darkvater@5568: void IConsoleDebug(const char *dbg, const char *string); Darkvater@1739: void IConsoleWarning(const char *string); Darkvater@1739: void IConsoleError(const char *string); darkvater@135: rubidium@4432: /* 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: rubidium@4432: /* 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: rubidium@4432: /* Parser */ Darkvater@1739: void IConsoleCmdExec(const char *cmdstr); Darkvater@1739: void IConsoleVarExec(const IConsoleVar *var, byte tokencount, char *token[]); darkvater@135: rubidium@4432: /* console std lib (register ingame commands/aliases/variables) */ rubidium@6573: void IConsoleStdLibRegister(); signde@220: rubidium@4432: /* 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: rubidium@4432: /* Supporting functions */ Darkvater@1739: bool GetArgumentInteger(uint32 *value, const char *arg); darkvater@205: #endif /* CONSOLE_H */