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