src/console_internal.h
changeset 9336 6baad5b3033d
child 9339 189117c9c937
equal deleted inserted replaced
9335:4f1e59a9aed4 9336:6baad5b3033d
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file console_internal.h Internally used functions for the console. */
       
     4 
       
     5 #ifndef CONSOLE_INTERNAL_H
       
     6 #define CONSOLE_INTERNAL_H
       
     7 
       
     8 #include "console_func.h"
       
     9 
       
    10 /* maximum length of a typed in command */
       
    11 #define ICON_CMDLN_SIZE 255
       
    12 /* maximum length of a totally expanded command */
       
    13 #define ICON_MAX_STREAMSIZE 1024
       
    14 
       
    15 enum IConsoleVarTypes {
       
    16 	ICONSOLE_VAR_BOOLEAN,
       
    17 	ICONSOLE_VAR_BYTE,
       
    18 	ICONSOLE_VAR_UINT16,
       
    19 	ICONSOLE_VAR_UINT32,
       
    20 	ICONSOLE_VAR_INT16,
       
    21 	ICONSOLE_VAR_INT32,
       
    22 	ICONSOLE_VAR_STRING
       
    23 };
       
    24 
       
    25 enum IConsoleHookTypes {
       
    26 	ICONSOLE_HOOK_ACCESS,
       
    27 	ICONSOLE_HOOK_PRE_ACTION,
       
    28 	ICONSOLE_HOOK_POST_ACTION
       
    29 };
       
    30 
       
    31 /** --Hooks--
       
    32  * Hooks are certain triggers get get accessed/executed on either
       
    33  * access, before execution/change or after execution/change. This allows
       
    34  * for general flow of permissions or special action needed in some cases
       
    35  */
       
    36 typedef bool IConsoleHook();
       
    37 struct IConsoleHooks{
       
    38 	IConsoleHook *access; ///< trigger when accessing the variable/command
       
    39 	IConsoleHook *pre;    ///< trigger before the variable/command is changed/executed
       
    40 	IConsoleHook *post;   ///< trigger after the variable/command is changed/executed
       
    41 };
       
    42 
       
    43 /** --Commands--
       
    44  * Commands are commands, or functions. They get executed once and any
       
    45  * effect they produce are carried out. The arguments to the commands
       
    46  * are given to them, each input word seperated by a double-quote (") is an argument
       
    47  * If you want to handle multiple words as one, enclose them in double-quotes
       
    48  * eg. 'say "hello sexy boy"'
       
    49  */
       
    50 typedef bool (IConsoleCmdProc)(byte argc, char *argv[]);
       
    51 
       
    52 struct IConsoleCmd {
       
    53 	char *name;               ///< name of command
       
    54 	IConsoleCmd *next;        ///< next command in list
       
    55 
       
    56 	IConsoleCmdProc *proc;    ///< process executed when command is typed
       
    57 	IConsoleHooks hook;       ///< any special trigger action that needs executing
       
    58 };
       
    59 
       
    60 /** --Variables--
       
    61  * Variables are pointers to real ingame variables which allow for
       
    62  * changing while ingame. After changing they keep their new value
       
    63  * and can be used for debugging, gameplay, etc. It accepts:
       
    64  * - no arguments; just print out current value
       
    65  * - '= <new value>' to assign a new value to the variable
       
    66  * - '++' to increase value by one
       
    67  * - '--' to decrease value by one
       
    68  */
       
    69 struct IConsoleVar {
       
    70 	char *name;               ///< name of the variable
       
    71 	IConsoleVar *next;        ///< next variable in list
       
    72 
       
    73 	void *addr;               ///< the address where the variable is pointing at
       
    74 	uint32 size;              ///< size of the variable, used for strings
       
    75 	char *help;               ///< the optional help string shown when requesting information
       
    76 	IConsoleVarTypes type;    ///< type of variable (for correct assignment/output)
       
    77 	IConsoleCmdProc *proc;    ///< some variables need really special handling, use a callback function for that
       
    78 	IConsoleHooks hook;       ///< any special trigger action that needs executing
       
    79 };
       
    80 
       
    81 /** --Aliases--
       
    82  * Aliases are like shortcuts for complex functions, variable assignments,
       
    83  * etc. You can use a simple alias to rename a longer command (eg 'lv' for
       
    84  * 'list_vars' for example), or concatenate more commands into one
       
    85  * (eg. 'ng' for 'load %A; unpause; debug_level 5'). Aliases can parse the arguments
       
    86  * given to them in the command line.
       
    87  * - "%A - %Z" substitute arguments 1 t/m 26
       
    88  * - "%+" lists all parameters keeping them seperated
       
    89  * - "%!" also lists all parameters but presenting them to the aliased command as one argument
       
    90  * - ";" allows for combining commands (see example 'ng')
       
    91  */
       
    92 struct IConsoleAlias {
       
    93 	char *name;                 ///< name of the alias
       
    94 	IConsoleAlias *next;        ///< next alias in list
       
    95 
       
    96 	char *cmdline;              ///< command(s) that is/are being aliased
       
    97 };
       
    98 
       
    99 /* console parser */
       
   100 extern IConsoleCmd   *_iconsole_cmds;    ///< list of registred commands
       
   101 extern IConsoleVar   *_iconsole_vars;    ///< list of registred vars
       
   102 extern IConsoleAlias *_iconsole_aliases; ///< list of registred aliases
       
   103 
       
   104 /* console functions */
       
   105 void IConsoleClearBuffer();
       
   106 void IConsoleOpen();
       
   107 
       
   108 /* console output */
       
   109 void IConsoleWarning(const char *string);
       
   110 void IConsoleError(const char *string);
       
   111 
       
   112 /* Commands */
       
   113 void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc);
       
   114 void IConsoleAliasRegister(const char *name, const char *cmd);
       
   115 IConsoleCmd *IConsoleCmdGet(const char *name);
       
   116 IConsoleAlias *IConsoleAliasGet(const char *name);
       
   117 
       
   118 /* Variables */
       
   119 void IConsoleVarRegister(const char *name, void *addr, IConsoleVarTypes type, const char *help);
       
   120 void IConsoleVarStringRegister(const char *name, void *addr, uint32 size, const char *help);
       
   121 IConsoleVar* IConsoleVarGet(const char *name);
       
   122 void IConsoleVarPrintGetValue(const IConsoleVar *var);
       
   123 void IConsoleVarPrintSetValue(const IConsoleVar *var);
       
   124 
       
   125 /* Parser */
       
   126 void IConsoleVarExec(const IConsoleVar *var, byte tokencount, char *token[]);
       
   127 
       
   128 /* console std lib (register ingame commands/aliases/variables) */
       
   129 void IConsoleStdLibRegister();
       
   130 
       
   131 /* Hooking code */
       
   132 void IConsoleCmdHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc);
       
   133 void IConsoleVarHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc);
       
   134 void IConsoleVarProcAdd(const char *name, IConsoleCmdProc *proc);
       
   135 
       
   136 /* Supporting functions */
       
   137 bool GetArgumentInteger(uint32 *value, const char *arg);
       
   138 #endif /* CONSOLE_H */