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