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