# console.h

Go to the documentation of this file.

    00001 /* $Id: console.h 11832 2008-01-13 13:36:01Z rubidium $ */
    00002
    00005 #ifndef CONSOLE_H
    00006 #define CONSOLE_H
    00007
    00008 #include "window_type.h"
    00009
    00010 /* maximum length of a typed in command */
    00011 #define ICON_CMDLN_SIZE 255
    00012 /* maximum length of a totally expanded command */
    00013 #define ICON_MAX_STREAMSIZE 1024
    00014
    00015 enum IConsoleVarTypes {
    00016   ICONSOLE_VAR_BOOLEAN,
    00017   ICONSOLE_VAR_BYTE,
    00018   ICONSOLE_VAR_UINT16,
    00019   ICONSOLE_VAR_UINT32,
    00020   ICONSOLE_VAR_INT16,
    00021   ICONSOLE_VAR_INT32,
    00022   ICONSOLE_VAR_STRING
    00023 };
    00024
    00025 enum IConsoleModes {
    00026   ICONSOLE_FULL,
    00027   ICONSOLE_OPENED,
    00028   ICONSOLE_CLOSED
    00029 };
    00030
    00031 enum IConsoleHookTypes {
    00032   ICONSOLE_HOOK_ACCESS,
    00033   ICONSOLE_HOOK_PRE_ACTION,
    00034   ICONSOLE_HOOK_POST_ACTION
    00035 };
    00036
    00042 typedef bool IConsoleHook();
    00043 struct IConsoleHooks{
    00044   IConsoleHook *access;
    00045   IConsoleHook *pre;
    00046   IConsoleHook *post;
    00047 };
    00048
    00056 typedef bool (IConsoleCmdProc)(byte argc, char *argv[]);
    00057
    00058 struct IConsoleCmd {
    00059   char *name;
    00060   IConsoleCmd *next;
    00061
    00062   IConsoleCmdProc *proc;
    00063   IConsoleHooks hook;
    00064 };
    00065
    00075 struct IConsoleVar {
    00076   char *name;
    00077   IConsoleVar *next;
    00078
    00079   void *addr;
    00080   uint32 size;
    00081   char *help;
    00082   IConsoleVarTypes type;
    00083   IConsoleCmdProc *proc;
    00084   IConsoleHooks hook;
    00085 };
    00086
    00098 struct IConsoleAlias {
    00099   char *name;
    00100   IConsoleAlias *next;
    00101
    00102   char *cmdline;
    00103 };
    00104
    00105 /* console parser */
    00106 extern IConsoleCmd   *_iconsole_cmds;
    00107 extern IConsoleVar   *_iconsole_vars;
    00108 extern IConsoleAlias *_iconsole_aliases;
    00109
    00110 /* console colors/modes */
    00111 extern byte _icolour_def;
    00112 extern byte _icolour_err;
    00113 extern byte _icolour_warn;
    00114 extern byte _icolour_dbg;
    00115 extern byte _icolour_cmd;
    00116 extern IConsoleModes _iconsole_mode;
    00117
    00118 /* console functions */
    00119 void IConsoleInit();
    00120 void IConsoleFree();
    00121 void IConsoleClearBuffer();
    00122 void IConsoleResize(Window *w);
    00123 void IConsoleSwitch();
    00124 void IConsoleClose();
    00125 void IConsoleOpen();
    00126
    00127 /* console output */
    00128 void IConsolePrint(uint16 color_code, const char *string);
    00129 void CDECL IConsolePrintF(uint16 color_code, const char *s, ...);
    00130 void IConsoleDebug(const char *dbg, const char *string);
    00131 void IConsoleWarning(const char *string);
    00132 void IConsoleError(const char *string);
    00133
    00134 /* Commands */
    00135 void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc);
    00136 void IConsoleAliasRegister(const char *name, const char *cmd);
    00137 IConsoleCmd *IConsoleCmdGet(const char *name);
    00138 IConsoleAlias *IConsoleAliasGet(const char *name);
    00139
    00140 /* Variables */
    00141 void IConsoleVarRegister(const char *name, void *addr, IConsoleVarTypes type, const char *help);
    00142 void IConsoleVarStringRegister(const char *name, void *addr, uint32 size, const char *help);
    00143 IConsoleVar* IConsoleVarGet(const char *name);
    00144 void IConsoleVarPrintGetValue(const IConsoleVar *var);
    00145 void IConsoleVarPrintSetValue(const IConsoleVar *var);
    00146
    00147 /* Parser */
    00148 void IConsoleCmdExec(const char *cmdstr);
    00149 void IConsoleVarExec(const IConsoleVar *var, byte tokencount, char *token[]);
    00150
    00151 /* console std lib (register ingame commands/aliases/variables) */
    00152 void IConsoleStdLibRegister();
    00153
    00154 /* Hooking code */
    00155 void IConsoleCmdHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc);
    00156 void IConsoleVarHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *proc);
    00157 void IConsoleVarProcAdd(const char *name, IConsoleCmdProc *proc);
    00158
    00159 /* Supporting functions */
    00160 bool GetArgumentInteger(uint32 *value, const char *arg);
    00161 #endif /* CONSOLE_H */