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