2004-08-24 22:41:42 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "ttd.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-08-24 22:41:42 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "variables.h"
|
2005-02-21 18:59:54 +00:00
|
|
|
#include "string.h"
|
2004-08-24 22:41:42 +00:00
|
|
|
#include "hal.h"
|
|
|
|
#include <stdarg.h>
|
2004-09-19 15:24:45 +00:00
|
|
|
#include <string.h>
|
2004-09-17 09:51:44 +00:00
|
|
|
#include "console.h"
|
2004-12-04 17:54:56 +00:00
|
|
|
#include "network.h"
|
2005-01-15 20:09:16 +00:00
|
|
|
#include "network_data.h"
|
|
|
|
#include "network_server.h"
|
2004-09-17 09:51:44 +00:00
|
|
|
|
2004-09-21 21:40:59 +00:00
|
|
|
#define ICON_BUFFER 79
|
|
|
|
#define ICON_CMDBUF_SIZE 20
|
|
|
|
#define ICON_CMDLN_SIZE 255
|
|
|
|
#define ICON_LINE_HEIGHT 12
|
2004-12-04 17:54:56 +00:00
|
|
|
#define ICON_RIGHT_BORDERWIDTH 10
|
|
|
|
#define ICON_BOTTOM_BORDERWIDTH 12
|
2004-12-13 18:51:08 +00:00
|
|
|
#define ICON_MAX_ALIAS_LINES 40
|
2004-09-19 15:24:45 +00:00
|
|
|
|
2004-08-24 22:41:42 +00:00
|
|
|
// ** main console ** //
|
2005-02-22 14:52:20 +00:00
|
|
|
static Window *_iconsole_win; // Pointer to console window
|
2004-08-24 22:41:42 +00:00
|
|
|
static bool _iconsole_inited;
|
2004-09-21 21:40:59 +00:00
|
|
|
static char* _iconsole_buffer[ICON_BUFFER + 1];
|
2004-12-04 17:54:56 +00:00
|
|
|
static uint16 _iconsole_cbuffer[ICON_BUFFER + 1];
|
2005-02-21 18:59:54 +00:00
|
|
|
static Textbuf _iconsole_cmdline;
|
2004-08-24 22:41:42 +00:00
|
|
|
static byte _iconsole_scroll;
|
|
|
|
|
|
|
|
// ** console cursor ** //
|
|
|
|
static bool _icursor_state;
|
|
|
|
static byte _icursor_rate;
|
|
|
|
static byte _icursor_counter;
|
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
// ** stdlib ** //
|
2004-09-19 15:24:45 +00:00
|
|
|
byte _stdlib_developer = 1;
|
|
|
|
bool _stdlib_con_developer = false;
|
|
|
|
FILE* _iconsole_output_file;
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2004-09-21 21:40:59 +00:00
|
|
|
// ** main console cmd buffer
|
|
|
|
static char* _iconsole_cmdbuffer[ICON_CMDBUF_SIZE];
|
2004-09-12 20:15:18 +00:00
|
|
|
static byte _iconsole_cmdbufferpos;
|
|
|
|
|
2004-08-24 22:41:42 +00:00
|
|
|
/* *************** */
|
|
|
|
/* end of header */
|
2004-09-17 09:51:44 +00:00
|
|
|
/* *************** */
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
static void IConsoleClearCommand(void)
|
2004-08-24 22:41:42 +00:00
|
|
|
{
|
2005-02-21 18:59:54 +00:00
|
|
|
memset(_iconsole_cmdline.buf, 0, ICON_CMDLN_SIZE);
|
|
|
|
_iconsole_cmdline.length = 0;
|
|
|
|
_iconsole_cmdline.width = 0;
|
|
|
|
_iconsole_cmdline.caretpos = 0;
|
|
|
|
_iconsole_cmdline.caretxoffs = 0;
|
2004-09-19 15:24:45 +00:00
|
|
|
SetWindowDirty(_iconsole_win);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
// ** console window ** //
|
2004-09-19 15:24:45 +00:00
|
|
|
static void IConsoleWndProc(Window* w, WindowEvent* e)
|
2004-08-24 22:41:42 +00:00
|
|
|
{
|
|
|
|
switch(e->event) {
|
2005-02-21 18:59:54 +00:00
|
|
|
case WE_PAINT: {
|
2004-09-19 15:24:45 +00:00
|
|
|
int i = _iconsole_scroll;
|
2004-09-21 21:40:59 +00:00
|
|
|
int max = (w->height / ICON_LINE_HEIGHT) - 1;
|
2004-12-04 17:54:56 +00:00
|
|
|
int delta = 0;
|
2004-09-19 15:24:45 +00:00
|
|
|
GfxFillRect(w->left, w->top, w->width, w->height - 1, 0);
|
2005-01-11 23:39:21 +00:00
|
|
|
while ((i > 0) && (i > _iconsole_scroll - max) && (_iconsole_buffer[i] != NULL)) {
|
2004-09-19 15:24:45 +00:00
|
|
|
DoDrawString(_iconsole_buffer[i], 5,
|
2004-09-21 21:40:59 +00:00
|
|
|
w->height - (_iconsole_scroll + 2 - i) * ICON_LINE_HEIGHT, _iconsole_cbuffer[i]);
|
2004-09-19 15:24:45 +00:00
|
|
|
i--;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2005-02-21 18:59:54 +00:00
|
|
|
/* If the text is longer than the window, don't show the starting ']' */
|
|
|
|
delta = w->width - 10 - _iconsole_cmdline.width - ICON_RIGHT_BORDERWIDTH;
|
2004-12-04 17:54:56 +00:00
|
|
|
if (delta > 0) {
|
|
|
|
DoDrawString("]", 5, w->height - ICON_LINE_HEIGHT, _iconsole_color_commands);
|
|
|
|
delta = 0;
|
|
|
|
}
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
DoDrawString(_iconsole_cmdline.buf, 10 + delta, w->height - ICON_LINE_HEIGHT, _iconsole_color_commands);
|
|
|
|
|
|
|
|
if (_iconsole_cmdline.caret)
|
|
|
|
DoDrawString("_", 10 + delta + _iconsole_cmdline.caretxoffs, w->height - ICON_LINE_HEIGHT, 12);
|
2004-09-19 15:24:45 +00:00
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2005-02-21 18:59:54 +00:00
|
|
|
case WE_MOUSELOOP:
|
|
|
|
if (HandleCaret(&_iconsole_cmdline))
|
|
|
|
SetWindowDirty(w);
|
2004-09-19 15:24:45 +00:00
|
|
|
break;
|
|
|
|
case WE_DESTROY:
|
|
|
|
_iconsole_win = NULL;
|
|
|
|
_iconsole_mode = ICONSOLE_CLOSED;
|
|
|
|
break;
|
|
|
|
case WE_KEYPRESS:
|
|
|
|
e->keypress.cont = false;
|
|
|
|
switch (e->keypress.keycode) {
|
|
|
|
case WKC_UP:
|
|
|
|
IConsoleCmdBufferNavigate(+1);
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
case WKC_DOWN:
|
|
|
|
IConsoleCmdBufferNavigate(-1);
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
case WKC_SHIFT | WKC_PAGEUP:
|
2004-09-21 21:40:59 +00:00
|
|
|
if (_iconsole_scroll - (w->height / ICON_LINE_HEIGHT) - 1 < 0)
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_scroll = 0;
|
|
|
|
else
|
2004-09-21 21:40:59 +00:00
|
|
|
_iconsole_scroll -= (w->height / ICON_LINE_HEIGHT) - 1;
|
2004-09-19 15:24:45 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
case WKC_SHIFT | WKC_PAGEDOWN:
|
2004-09-21 21:40:59 +00:00
|
|
|
if (_iconsole_scroll + (w->height / ICON_LINE_HEIGHT) - 1 > ICON_BUFFER)
|
|
|
|
_iconsole_scroll = ICON_BUFFER;
|
2004-09-19 15:24:45 +00:00
|
|
|
else
|
2004-09-21 21:40:59 +00:00
|
|
|
_iconsole_scroll += (w->height / ICON_LINE_HEIGHT) - 1;
|
2004-09-19 15:24:45 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
case WKC_SHIFT | WKC_UP:
|
|
|
|
if (_iconsole_scroll <= 0)
|
|
|
|
_iconsole_scroll = 0;
|
|
|
|
else
|
|
|
|
--_iconsole_scroll;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
case WKC_SHIFT | WKC_DOWN:
|
2004-09-21 21:40:59 +00:00
|
|
|
if (_iconsole_scroll >= ICON_BUFFER)
|
|
|
|
_iconsole_scroll = ICON_BUFFER;
|
2004-09-19 15:24:45 +00:00
|
|
|
else
|
|
|
|
++_iconsole_scroll;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
case WKC_BACKQUOTE:
|
|
|
|
IConsoleSwitch();
|
|
|
|
break;
|
2005-02-21 18:59:54 +00:00
|
|
|
case WKC_RETURN: case WKC_NUM_ENTER:
|
|
|
|
IConsolePrintF(_iconsole_color_commands, "] %s", _iconsole_cmdline.buf);
|
|
|
|
_iconsole_cmdbufferpos = ICON_CMDBUF_SIZE - 1;
|
|
|
|
IConsoleCmdBufferAdd(_iconsole_cmdline.buf);
|
2004-12-15 21:30:20 +00:00
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
IConsoleCmdExec(_iconsole_cmdline.buf);
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsoleClearCommand();
|
|
|
|
break;
|
2004-12-04 17:54:56 +00:00
|
|
|
case WKC_CTRL | WKC_RETURN:
|
2005-02-21 18:59:54 +00:00
|
|
|
_iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL;
|
2004-12-04 17:54:56 +00:00
|
|
|
IConsoleResize();
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
break;
|
2005-02-21 18:59:54 +00:00
|
|
|
case (WKC_CTRL | 'V'):
|
|
|
|
if (InsertTextBufferClipboard(&_iconsole_cmdline))
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
case WKC_BACKSPACE: case WKC_DELETE:
|
|
|
|
if (DeleteTextBufferChar(&_iconsole_cmdline, e->keypress.keycode))
|
|
|
|
SetWindowDirty(w);
|
|
|
|
_iconsole_cmdbufferpos = ICON_CMDBUF_SIZE - 1;
|
|
|
|
break;
|
|
|
|
case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
|
|
|
|
if (MoveTextBufferPos(&_iconsole_cmdline, e->keypress.keycode))
|
|
|
|
SetWindowDirty(w);
|
2004-09-19 15:24:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
2005-02-21 18:59:54 +00:00
|
|
|
if (IsValidAsciiChar(e->keypress.ascii)) {
|
2004-09-21 21:40:59 +00:00
|
|
|
_iconsole_scroll = ICON_BUFFER;
|
2005-02-21 18:59:54 +00:00
|
|
|
InsertTextBufferChar(&_iconsole_cmdline, e->keypress.ascii);
|
2004-09-21 21:40:59 +00:00
|
|
|
_iconsole_cmdbufferpos = ICON_CMDBUF_SIZE - 1;
|
2005-02-21 18:59:54 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
} else
|
2004-09-19 15:24:45 +00:00
|
|
|
e->keypress.cont = true;
|
|
|
|
break;
|
|
|
|
}
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-21 18:59:54 +00:00
|
|
|
static const Widget _iconsole_window_widgets[] = {
|
|
|
|
{WIDGETS_END}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _iconsole_window_desc = {
|
|
|
|
0, 0, 2, 2,
|
|
|
|
WC_CONSOLE, 0,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
|
|
_iconsole_window_widgets,
|
|
|
|
IConsoleWndProc,
|
|
|
|
};
|
|
|
|
|
2004-12-15 00:31:08 +00:00
|
|
|
extern const char _openttd_revision[];
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleInit(void)
|
2004-08-24 22:41:42 +00:00
|
|
|
{
|
2004-09-14 16:10:20 +00:00
|
|
|
_iconsole_output_file = NULL;
|
2004-09-12 20:15:18 +00:00
|
|
|
_iconsole_color_default = 1;
|
2004-09-14 16:10:20 +00:00
|
|
|
_iconsole_color_error = 3;
|
2004-09-13 06:56:30 +00:00
|
|
|
_iconsole_color_warning = 13;
|
2004-09-12 20:15:18 +00:00
|
|
|
_iconsole_color_debug = 5;
|
|
|
|
_iconsole_color_commands = 2;
|
2004-09-21 21:40:59 +00:00
|
|
|
_iconsole_scroll = ICON_BUFFER;
|
|
|
|
_iconsole_cmdbufferpos = ICON_CMDBUF_SIZE - 1;
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_inited = true;
|
|
|
|
_iconsole_mode = ICONSOLE_CLOSED;
|
|
|
|
_iconsole_win = NULL;
|
|
|
|
_icursor_state = false;
|
|
|
|
_icursor_rate = 5;
|
|
|
|
_icursor_counter = 0;
|
2005-01-31 00:12:44 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_NETWORK /* Initialize network only variables */
|
|
|
|
_redirect_console_to_client = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(_iconsole_cmdbuffer, 0, sizeof(_iconsole_cmdbuffer));
|
|
|
|
memset(_iconsole_buffer, 0, sizeof(_iconsole_buffer));
|
|
|
|
memset(_iconsole_cbuffer, 0, sizeof(_iconsole_cbuffer));
|
2005-02-21 18:59:54 +00:00
|
|
|
_iconsole_cmdline.buf = calloc(ICON_CMDLN_SIZE, sizeof(*_iconsole_cmdline.buf)); // create buffer and zero it
|
|
|
|
_iconsole_cmdline.maxlength = ICON_CMDLN_SIZE - 1;
|
2005-01-31 00:12:44 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
IConsoleStdLibRegister();
|
2004-12-13 18:51:08 +00:00
|
|
|
IConsolePrintF(13, "OpenTTD Game Console Revision 6 - %s", _openttd_revision);
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsolePrint(12, "---------------------------------");
|
|
|
|
IConsolePrint(12, "use \"help\" for more info");
|
|
|
|
IConsolePrint(12, "");
|
2004-09-12 20:15:18 +00:00
|
|
|
IConsoleClearCommand();
|
|
|
|
IConsoleCmdBufferAdd("");
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleClear(void)
|
2004-08-24 22:41:42 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
uint i;
|
2004-09-21 21:40:59 +00:00
|
|
|
for (i = 0; i <= ICON_BUFFER; i++)
|
2004-09-12 20:15:18 +00:00
|
|
|
free(_iconsole_buffer[i]);
|
2005-02-21 18:59:54 +00:00
|
|
|
|
|
|
|
free(_iconsole_cmdline.buf);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2005-01-16 18:19:33 +00:00
|
|
|
static void IConsoleWriteToLogFile(const char* string)
|
|
|
|
{
|
|
|
|
if (_iconsole_output_file != NULL) {
|
|
|
|
// if there is an console output file ... also print it there
|
|
|
|
fwrite(string, strlen(string), 1, _iconsole_output_file);
|
|
|
|
fwrite("\n", 1, 1, _iconsole_output_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CloseConsoleLogIfActive(void)
|
|
|
|
{
|
|
|
|
if (_iconsole_output_file != NULL) {
|
|
|
|
IConsolePrintF(_iconsole_color_default, "file output complete");
|
|
|
|
fclose(_iconsole_output_file);
|
2005-01-23 21:42:29 +00:00
|
|
|
_iconsole_output_file = NULL;
|
2005-01-16 18:19:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleFree(void)
|
2004-08-24 22:41:42 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_inited = false;
|
2004-09-12 20:15:18 +00:00
|
|
|
IConsoleClear();
|
2005-01-16 18:19:33 +00:00
|
|
|
CloseConsoleLogIfActive();
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleResize(void)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2005-01-11 23:39:21 +00:00
|
|
|
|
|
|
|
_iconsole_win = FindWindowById(WC_CONSOLE, 0);
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
switch (_iconsole_mode) {
|
|
|
|
case ICONSOLE_OPENED:
|
|
|
|
_iconsole_win->height = _screen.height / 3;
|
|
|
|
_iconsole_win->width = _screen.width;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_FULL:
|
|
|
|
_iconsole_win->height = _screen.height - ICON_BOTTOM_BORDERWIDTH;
|
|
|
|
_iconsole_win->width = _screen.width;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2005-01-11 23:39:21 +00:00
|
|
|
|
|
|
|
MarkWholeScreenDirty();
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleSwitch(void)
|
2004-08-24 22:41:42 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
switch (_iconsole_mode) {
|
|
|
|
case ICONSOLE_CLOSED:
|
|
|
|
_iconsole_win = AllocateWindowDesc(&_iconsole_window_desc);
|
|
|
|
_iconsole_win->height = _screen.height / 3;
|
|
|
|
_iconsole_win->width = _screen.width;
|
|
|
|
_iconsole_mode = ICONSOLE_OPENED;
|
2005-02-22 14:52:20 +00:00
|
|
|
SETBIT(_no_scroll, SCROLL_CON);
|
2004-09-19 15:24:45 +00:00
|
|
|
break;
|
2005-02-22 14:52:20 +00:00
|
|
|
case ICONSOLE_OPENED: case ICONSOLE_FULL:
|
2004-12-04 17:54:56 +00:00
|
|
|
DeleteWindowById(WC_CONSOLE, 0);
|
|
|
|
_iconsole_win = NULL;
|
|
|
|
_iconsole_mode = ICONSOLE_CLOSED;
|
2005-02-22 14:52:20 +00:00
|
|
|
CLRBIT(_no_scroll, SCROLL_CON);
|
2004-12-04 17:54:56 +00:00
|
|
|
break;
|
2004-09-19 15:24:45 +00:00
|
|
|
}
|
2005-01-11 23:39:21 +00:00
|
|
|
|
|
|
|
MarkWholeScreenDirty();
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleClose(void)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch();
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleOpen(void)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (_iconsole_mode == ICONSOLE_CLOSED) IConsoleSwitch();
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleCmdBufferAdd(const char* cmd)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
|
|
|
int i;
|
2005-02-21 18:59:54 +00:00
|
|
|
if (_iconsole_cmdbufferpos != (ICON_CMDBUF_SIZE - 1)) return;
|
|
|
|
free(_iconsole_cmdbuffer[ICON_CMDBUF_SIZE - 2]);
|
|
|
|
for (i = (ICON_CMDBUF_SIZE - 2); i > 0; i--) _iconsole_cmdbuffer[i] = _iconsole_cmdbuffer[i - 1];
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_cmdbuffer[0] = strdup(cmd);
|
2004-08-25 22:11:41 +00:00
|
|
|
}
|
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
void IConsoleCmdBufferNavigate(signed char direction)
|
|
|
|
{
|
|
|
|
int i;
|
2004-09-19 15:24:45 +00:00
|
|
|
i = _iconsole_cmdbufferpos + direction;
|
2005-02-21 18:59:54 +00:00
|
|
|
if (i < 0) i = ICON_CMDBUF_SIZE - 1;
|
|
|
|
if (i >= ICON_CMDBUF_SIZE) i = 0;
|
2004-09-19 15:24:45 +00:00
|
|
|
if (direction > 0)
|
|
|
|
while (_iconsole_cmdbuffer[i] == NULL) {
|
2005-02-21 18:59:54 +00:00
|
|
|
i++;
|
|
|
|
if (i >= ICON_CMDBUF_SIZE) i = 0;
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
if (direction < 0)
|
|
|
|
while (_iconsole_cmdbuffer[i] == NULL) {
|
|
|
|
--i;
|
2005-02-21 18:59:54 +00:00
|
|
|
if (i < 0) i = ICON_CMDBUF_SIZE - 1;
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
|
|
|
_iconsole_cmdbufferpos = i;
|
|
|
|
IConsoleClearCommand();
|
2005-02-21 18:59:54 +00:00
|
|
|
ttd_strlcpy(_iconsole_cmdline.buf, _iconsole_cmdbuffer[i], _iconsole_cmdline.maxlength);
|
|
|
|
UpdateTextBufferSize(&_iconsole_cmdline);
|
2004-08-25 22:11:41 +00:00
|
|
|
}
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
void IConsolePrint(uint16 color_code, const char* string)
|
2004-08-24 22:41:42 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
char* _ex;
|
|
|
|
char* _new;
|
2004-12-04 17:54:56 +00:00
|
|
|
uint16 _exc;
|
|
|
|
uint16 _newc;
|
2004-09-19 15:24:45 +00:00
|
|
|
char* i;
|
|
|
|
int j;
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2005-01-31 00:12:44 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2005-01-15 20:09:16 +00:00
|
|
|
if (_redirect_console_to_client != 0) {
|
|
|
|
/* Redirect the string to the client */
|
|
|
|
SEND_COMMAND(PACKET_SERVER_RCON)(NetworkFindClientStateFromIndex(_redirect_console_to_client), color_code, string);
|
|
|
|
return;
|
|
|
|
}
|
2005-01-31 00:12:44 +00:00
|
|
|
#endif
|
2005-01-15 20:09:16 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
if (_network_dedicated) {
|
|
|
|
printf("%s\n", string);
|
2005-01-16 18:19:33 +00:00
|
|
|
IConsoleWriteToLogFile(string);
|
2004-12-04 17:54:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
if (!_iconsole_inited) return;
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
_newc = color_code;
|
|
|
|
_new = strdup(string);
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
for (i = _new; *i != '\0'; ++i)
|
2004-09-21 21:40:59 +00:00
|
|
|
if (*i < ' ') *i = ' '; /* filter for ascii-function codes like BELL and so on [we need an special filter here later] */
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2004-09-21 21:40:59 +00:00
|
|
|
for (j = ICON_BUFFER; j >= 0; --j) {
|
2004-09-19 15:24:45 +00:00
|
|
|
_ex = _iconsole_buffer[j];
|
|
|
|
_exc = _iconsole_cbuffer[j];
|
|
|
|
_iconsole_buffer[j] = _new;
|
|
|
|
_iconsole_cbuffer[j] = _newc;
|
|
|
|
_new = _ex;
|
|
|
|
_newc = _exc;
|
|
|
|
}
|
|
|
|
free(_ex);
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2005-01-16 18:19:33 +00:00
|
|
|
IConsoleWriteToLogFile(string);
|
2004-12-14 17:06:54 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
if (_iconsole_win != NULL) SetWindowDirty(_iconsole_win);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
void CDECL IConsolePrintF(uint16 color_code, const char* s, ...)
|
2004-08-24 22:41:42 +00:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
char buf[1024];
|
2004-09-14 16:10:20 +00:00
|
|
|
int len;
|
|
|
|
|
2004-08-24 22:41:42 +00:00
|
|
|
va_start(va, s);
|
2004-09-19 15:24:45 +00:00
|
|
|
len = vsnprintf(buf, sizeof(buf), s, va);
|
2004-08-24 22:41:42 +00:00
|
|
|
va_end(va);
|
2004-09-14 16:10:20 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsolePrint(color_code, buf);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleDebug(const char* string)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (_stdlib_developer > 1)
|
2004-12-04 17:54:56 +00:00
|
|
|
IConsolePrintF(_iconsole_color_debug, "dbg: %s", string);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleError(const char* string)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (_stdlib_developer > 0)
|
|
|
|
IConsolePrintF(_iconsole_color_error, "ERROR: %s", string);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-14 16:10:20 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleWarning(const char* string)
|
2004-09-14 16:10:20 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (_stdlib_developer > 0)
|
|
|
|
IConsolePrintF(_iconsole_color_warning, "WARNING: %s", string);
|
2004-09-14 16:10:20 +00:00
|
|
|
}
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleCmdRegister(const char* name, _iconsole_cmd_addr addr)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
char* _new;
|
|
|
|
_iconsole_cmd* item;
|
|
|
|
_iconsole_cmd* item_new;
|
2004-12-05 12:25:25 +00:00
|
|
|
_iconsole_cmd* item_before;
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
_new = strdup(name);
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
item_new = malloc(sizeof(_iconsole_cmd));
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
item_new->_next = NULL;
|
2004-09-19 15:24:45 +00:00
|
|
|
item_new->addr = addr;
|
|
|
|
item_new->name = _new;
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
item_new->hook_access = NULL;
|
|
|
|
item_new->hook_after_exec = NULL;
|
|
|
|
item_new->hook_before_exec = NULL;
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-12-05 12:25:25 +00:00
|
|
|
item_before = NULL;
|
2004-09-12 20:15:18 +00:00
|
|
|
item = _iconsole_cmds;
|
2004-12-05 12:25:25 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
if (item == NULL) {
|
|
|
|
_iconsole_cmds = item_new;
|
2004-09-19 15:24:45 +00:00
|
|
|
} else {
|
2004-12-05 12:25:25 +00:00
|
|
|
while ((item->_next != NULL) && (strcmp(item->name,item_new->name)<=0)) {
|
|
|
|
item_before = item;
|
|
|
|
item = item->_next;
|
|
|
|
}
|
|
|
|
// insertion sort
|
|
|
|
if (item_before==NULL) {
|
|
|
|
if (strcmp(item->name,item_new->name)<=0) {
|
|
|
|
// appending
|
|
|
|
item ->_next = item_new;
|
|
|
|
} else {
|
|
|
|
// inserting as startitem
|
|
|
|
_iconsole_cmds = item_new;
|
|
|
|
item_new ->_next = item;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (strcmp(item->name,item_new->name)<=0) {
|
|
|
|
// appending
|
|
|
|
item ->_next = item_new;
|
|
|
|
} else {
|
|
|
|
// inserting
|
|
|
|
item_new ->_next = item_before->_next;
|
|
|
|
item_before ->_next = item_new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// insertion sort end
|
2004-09-19 15:24:45 +00:00
|
|
|
}
|
2004-12-05 12:25:25 +00:00
|
|
|
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_cmd* IConsoleCmdGet(const char* name)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_cmd* item;
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
item = _iconsole_cmds;
|
|
|
|
while (item != NULL) {
|
2004-09-19 15:24:45 +00:00
|
|
|
if (strcmp(item->name, name) == 0) return item;
|
2004-09-12 20:15:18 +00:00
|
|
|
item = item->_next;
|
2004-09-19 15:24:45 +00:00
|
|
|
}
|
2004-09-12 20:15:18 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-12-13 18:51:08 +00:00
|
|
|
void IConsoleAliasRegister(const char* name, const char* cmdline)
|
|
|
|
{
|
|
|
|
char* _new;
|
|
|
|
char* _newcmd;
|
|
|
|
_iconsole_alias* item;
|
|
|
|
_iconsole_alias* item_new;
|
|
|
|
_iconsole_alias* item_before;
|
|
|
|
|
|
|
|
_new = strdup(name);
|
|
|
|
_newcmd = strdup(cmdline);
|
|
|
|
|
|
|
|
item_new = malloc(sizeof(_iconsole_alias));
|
|
|
|
|
|
|
|
item_new->_next = NULL;
|
|
|
|
item_new->cmdline = _newcmd;
|
|
|
|
item_new->name = _new;
|
|
|
|
|
|
|
|
item_before = NULL;
|
|
|
|
item = _iconsole_aliases;
|
|
|
|
|
|
|
|
if (item == NULL) {
|
|
|
|
_iconsole_aliases = item_new;
|
|
|
|
} else {
|
|
|
|
while ((item->_next != NULL) && (strcmp(item->name,item_new->name)<=0)) {
|
|
|
|
item_before = item;
|
|
|
|
item = item->_next;
|
|
|
|
}
|
|
|
|
// insertion sort
|
|
|
|
if (item_before==NULL) {
|
|
|
|
if (strcmp(item->name,item_new->name)<=0) {
|
|
|
|
// appending
|
|
|
|
item ->_next = item_new;
|
|
|
|
} else {
|
|
|
|
// inserting as startitem
|
|
|
|
_iconsole_aliases = item_new;
|
|
|
|
item_new ->_next = item;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (strcmp(item->name,item_new->name)<=0) {
|
|
|
|
// appending
|
|
|
|
item ->_next = item_new;
|
|
|
|
} else {
|
|
|
|
// inserting
|
|
|
|
item_new ->_next = item_before->_next;
|
|
|
|
item_before ->_next = item_new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// insertion sort end
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_iconsole_alias* IConsoleAliasGet(const char* name)
|
|
|
|
{
|
|
|
|
_iconsole_alias* item;
|
|
|
|
|
|
|
|
item = _iconsole_aliases;
|
|
|
|
while (item != NULL) {
|
|
|
|
if (strcmp(item->name, name) == 0) return item;
|
|
|
|
item = item->_next;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static void IConsoleAliasExec(const char* cmdline, char* tokens[20], byte tokentypes[20])
|
|
|
|
{
|
2004-12-13 18:51:08 +00:00
|
|
|
char* lines[ICON_MAX_ALIAS_LINES];
|
|
|
|
char* linestream;
|
|
|
|
char* linestream_s;
|
|
|
|
|
|
|
|
int c;
|
|
|
|
int i;
|
|
|
|
int l;
|
|
|
|
int x;
|
|
|
|
byte t;
|
|
|
|
|
|
|
|
//** clearing buffer **//
|
|
|
|
|
|
|
|
for (i = 0; i < 40; i++) {
|
|
|
|
lines[0] = NULL;
|
|
|
|
}
|
|
|
|
linestream_s = linestream = malloc(1024*ICON_MAX_ALIAS_LINES);
|
|
|
|
memset(linestream, 0, 1024*ICON_MAX_ALIAS_LINES);
|
|
|
|
|
|
|
|
//** parsing **//
|
|
|
|
|
|
|
|
l = strlen(cmdline);
|
|
|
|
i = 0;
|
|
|
|
c = 0;
|
|
|
|
x = 0;
|
|
|
|
t = 0;
|
|
|
|
lines[c] = linestream;
|
|
|
|
|
|
|
|
while (i < l && c < ICON_MAX_ALIAS_LINES - 1) {
|
|
|
|
if (cmdline[i] == '%') {
|
|
|
|
i++;
|
|
|
|
if (cmdline[i] == '+') {
|
2004-12-13 22:13:02 +00:00
|
|
|
// all params seperated: "[param 1]" "[param 2]"
|
2004-12-13 18:51:08 +00:00
|
|
|
t=1;
|
2004-12-14 20:27:00 +00:00
|
|
|
while ((tokens[t]!=NULL) && (t<20) &&
|
2004-12-13 20:45:55 +00:00
|
|
|
((tokentypes[t] == ICONSOLE_VAR_STRING) || (tokentypes[t] == ICONSOLE_VAR_UNKNOWN))) {
|
2004-12-13 18:51:08 +00:00
|
|
|
int l2 = strlen(tokens[t]);
|
|
|
|
*linestream = '"';
|
|
|
|
linestream++;
|
|
|
|
memcpy(linestream,tokens[t],l2);
|
|
|
|
linestream += l2;
|
|
|
|
*linestream = '"';
|
|
|
|
linestream++;
|
|
|
|
*linestream = ' ';
|
|
|
|
linestream++;
|
|
|
|
x += l2+3;
|
|
|
|
t++;
|
|
|
|
}
|
2004-12-13 22:13:02 +00:00
|
|
|
} else if (cmdline[i] == '!') {
|
|
|
|
// merge the params to one: "[param 1] [param 2] [param 3...]"
|
|
|
|
t=1;
|
|
|
|
*linestream = '"';
|
|
|
|
linestream++;
|
2004-12-14 20:27:00 +00:00
|
|
|
while ((tokens[t]!=NULL) && (t<20) &&
|
2004-12-13 22:13:02 +00:00
|
|
|
((tokentypes[t] == ICONSOLE_VAR_STRING) || (tokentypes[t] == ICONSOLE_VAR_UNKNOWN))) {
|
|
|
|
int l2 = strlen(tokens[t]);
|
|
|
|
memcpy(linestream,tokens[t],l2);
|
|
|
|
linestream += l2;
|
|
|
|
*linestream = ' ';
|
|
|
|
linestream++;
|
|
|
|
x += l2+1;
|
|
|
|
t++;
|
|
|
|
}
|
2005-01-08 00:48:10 +00:00
|
|
|
linestream--;
|
2004-12-13 22:13:02 +00:00
|
|
|
*linestream = '"';
|
|
|
|
linestream++;
|
2005-01-08 00:48:10 +00:00
|
|
|
x += 1;
|
2004-12-13 18:51:08 +00:00
|
|
|
} else {
|
2004-12-13 22:13:02 +00:00
|
|
|
// one specific parameter: %A = [param 1] %B = [param 2] ...
|
2004-12-13 18:51:08 +00:00
|
|
|
int l2;
|
|
|
|
t = ((byte)cmdline[i]) - 64;
|
2004-12-14 20:27:00 +00:00
|
|
|
if ((t<20) && (tokens[t]!=NULL) &&
|
2004-12-13 22:13:02 +00:00
|
|
|
((tokentypes[t] == ICONSOLE_VAR_STRING) || (tokentypes[t] == ICONSOLE_VAR_UNKNOWN))) {
|
2004-12-13 18:51:08 +00:00
|
|
|
l2 = strlen(tokens[t]);
|
2004-12-13 20:45:55 +00:00
|
|
|
*linestream = '"';
|
|
|
|
linestream++;
|
2004-12-13 18:51:08 +00:00
|
|
|
memcpy(linestream,tokens[t],l2);
|
|
|
|
linestream += l2;
|
2004-12-13 20:45:55 +00:00
|
|
|
*linestream = '"';
|
|
|
|
linestream++;
|
|
|
|
x += l2+2;
|
2004-12-13 18:51:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (cmdline[i] == '\\') {
|
2004-12-13 22:13:02 +00:00
|
|
|
// \\ = \ \' = ' \% = %
|
2004-12-13 18:51:08 +00:00
|
|
|
i++;
|
|
|
|
if (cmdline[i] == '\\') {
|
|
|
|
*linestream = '\\';
|
|
|
|
linestream++;
|
|
|
|
} else if (cmdline[i] == '\'') {
|
|
|
|
*linestream = '\'';
|
|
|
|
linestream++;
|
2004-12-13 22:13:02 +00:00
|
|
|
} else if (cmdline[i] == '%') {
|
|
|
|
*linestream = '%';
|
|
|
|
linestream++;
|
2004-12-13 18:51:08 +00:00
|
|
|
}
|
|
|
|
} else if (cmdline[i] == '\'') {
|
2004-12-13 22:13:02 +00:00
|
|
|
// ' = "
|
2004-12-13 18:51:08 +00:00
|
|
|
*linestream = '"';
|
|
|
|
linestream++;
|
|
|
|
} else if (cmdline[i] == ';') {
|
2004-12-13 22:13:02 +00:00
|
|
|
// ; = start a new line
|
2004-12-13 18:51:08 +00:00
|
|
|
c++;
|
|
|
|
*linestream = '\0';
|
|
|
|
linestream += 1024 - (x % 1024);
|
|
|
|
x += 1024 - (x % 1024);
|
|
|
|
lines[c] = linestream;
|
|
|
|
} else {
|
|
|
|
*linestream = cmdline[i];
|
|
|
|
linestream++;
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
linestream--;
|
|
|
|
if (*linestream != '\0') {
|
|
|
|
c++;
|
|
|
|
linestream++;
|
|
|
|
*linestream = '\0';
|
|
|
|
}
|
|
|
|
|
2004-12-13 20:45:55 +00:00
|
|
|
for (i=0; i<c; i++) {
|
|
|
|
IConsoleCmdExec(lines[i]);
|
|
|
|
}
|
2004-12-13 18:51:08 +00:00
|
|
|
|
2004-12-13 20:45:55 +00:00
|
|
|
free(linestream_s);
|
2004-12-13 18:51:08 +00:00
|
|
|
}
|
|
|
|
|
2004-12-05 12:25:25 +00:00
|
|
|
void IConsoleVarInsert(_iconsole_var* item_new, const char* name)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_var* item;
|
2004-12-05 12:25:25 +00:00
|
|
|
_iconsole_var* item_before;
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2004-12-05 12:25:25 +00:00
|
|
|
item_new->_next = NULL;
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
item_new->name = malloc(strlen(name) + 2); /* XXX unchecked malloc */
|
2004-12-04 17:54:56 +00:00
|
|
|
sprintf(item_new->name, "%s", name);
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2004-12-05 12:25:25 +00:00
|
|
|
item_before = NULL;
|
|
|
|
item = _iconsole_vars;
|
|
|
|
|
|
|
|
if (item == NULL) {
|
|
|
|
_iconsole_vars = item_new;
|
|
|
|
} else {
|
|
|
|
while ((item->_next != NULL) && (strcmp(item->name,item_new->name)<=0)) {
|
|
|
|
item_before = item;
|
|
|
|
item = item->_next;
|
|
|
|
}
|
|
|
|
// insertion sort
|
|
|
|
if (item_before==NULL) {
|
|
|
|
if (strcmp(item->name,item_new->name)<=0) {
|
|
|
|
// appending
|
|
|
|
item ->_next = item_new;
|
|
|
|
} else {
|
|
|
|
// inserting as startitem
|
|
|
|
_iconsole_vars = item_new;
|
|
|
|
item_new ->_next = item;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (strcmp(item->name,item_new->name)<=0) {
|
|
|
|
// appending
|
|
|
|
item ->_next = item_new;
|
|
|
|
} else {
|
|
|
|
// inserting
|
|
|
|
item_new ->_next = item_before->_next;
|
|
|
|
item_before ->_next = item_new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// insertion sort end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IConsoleVarRegister(const char* name, void* addr, _iconsole_var_types type)
|
|
|
|
{
|
|
|
|
_iconsole_var* item_new;
|
|
|
|
|
|
|
|
item_new = malloc(sizeof(_iconsole_var)); /* XXX unchecked malloc */
|
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
item_new->_next = NULL;
|
2004-12-05 12:25:25 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
switch (type) {
|
|
|
|
case ICONSOLE_VAR_BOOLEAN:
|
|
|
|
item_new->data.bool_ = addr;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_BYTE:
|
2004-12-04 17:54:56 +00:00
|
|
|
case ICONSOLE_VAR_UINT8:
|
2004-09-19 15:24:45 +00:00
|
|
|
item_new->data.byte_ = addr;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_UINT16:
|
|
|
|
item_new->data.uint16_ = addr;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_UINT32:
|
|
|
|
item_new->data.uint32_ = addr;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_INT16:
|
|
|
|
item_new->data.int16_ = addr;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_INT32:
|
|
|
|
item_new->data.int32_ = addr;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_STRING:
|
|
|
|
item_new->data.string_ = addr;
|
|
|
|
break;
|
|
|
|
default:
|
2004-09-21 21:40:59 +00:00
|
|
|
error("unknown console variable type");
|
2004-09-19 15:24:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-12-05 12:25:25 +00:00
|
|
|
|
|
|
|
IConsoleVarInsert(item_new, name);
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
item_new->type = type;
|
2004-09-12 20:15:18 +00:00
|
|
|
item_new->_malloc = false;
|
|
|
|
|
|
|
|
item_new->hook_access = NULL;
|
|
|
|
item_new->hook_after_change = NULL;
|
|
|
|
item_new->hook_before_change = NULL;
|
2004-12-13 09:01:24 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleVarMemRegister(const char* name, _iconsole_var_types type)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_var* item;
|
2004-09-12 20:15:18 +00:00
|
|
|
item = IConsoleVarAlloc(type);
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsoleVarInsert(item, name);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_var* IConsoleVarGet(const char* name)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_var* item;
|
|
|
|
for (item = _iconsole_vars; item != NULL; item = item->_next)
|
|
|
|
if (strcmp(item->name, name) == 0) return item;
|
2004-09-12 20:15:18 +00:00
|
|
|
return NULL;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_var* IConsoleVarAlloc(_iconsole_var_types type)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_var* item = malloc(sizeof(_iconsole_var)); /* XXX unchecked malloc */
|
2004-09-12 20:15:18 +00:00
|
|
|
item->_next = NULL;
|
2004-09-19 15:24:45 +00:00
|
|
|
item->name = NULL;
|
|
|
|
item->type = type;
|
2004-09-12 20:15:18 +00:00
|
|
|
switch (item->type) {
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_VAR_BOOLEAN:
|
|
|
|
item->data.bool_ = malloc(sizeof(*item->data.bool_));
|
|
|
|
*item->data.bool_ = false;
|
|
|
|
item->_malloc = true;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_BYTE:
|
2004-12-04 17:54:56 +00:00
|
|
|
case ICONSOLE_VAR_UINT8:
|
2004-09-19 15:24:45 +00:00
|
|
|
item->data.byte_ = malloc(sizeof(*item->data.byte_));
|
|
|
|
*item->data.byte_ = 0;
|
|
|
|
item->_malloc = true;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_UINT16:
|
|
|
|
item->data.uint16_ = malloc(sizeof(*item->data.uint16_));
|
|
|
|
*item->data.uint16_ = 0;
|
|
|
|
item->_malloc = true;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_UINT32:
|
|
|
|
item->data.uint32_ = malloc(sizeof(*item->data.uint32_));
|
|
|
|
*item->data.uint32_ = 0;
|
|
|
|
item->_malloc = true;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_INT16:
|
|
|
|
item->data.int16_ = malloc(sizeof(*item->data.int16_));
|
|
|
|
*item->data.int16_ = 0;
|
|
|
|
item->_malloc = true;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_INT32:
|
|
|
|
item->data.int32_ = malloc(sizeof(*item->data.int32_));
|
|
|
|
*item->data.int32_ = 0;
|
|
|
|
item->_malloc = true;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_POINTER:
|
2004-09-21 21:40:59 +00:00
|
|
|
case ICONSOLE_VAR_STRING:
|
|
|
|
// needs no memory ... it gets memory when it is set to an value
|
2004-09-19 15:24:45 +00:00
|
|
|
item->data.addr = NULL;
|
|
|
|
item->_malloc = false;
|
|
|
|
break;
|
|
|
|
default:
|
2004-09-21 21:40:59 +00:00
|
|
|
error("unknown console variable type");
|
2004-09-19 15:24:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
item->hook_access = NULL;
|
|
|
|
item->hook_after_change = NULL;
|
|
|
|
item->hook_before_change = NULL;
|
|
|
|
return item;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleVarFree(_iconsole_var* var)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-12 21:49:38 +00:00
|
|
|
if (var->_malloc)
|
2004-09-19 15:24:45 +00:00
|
|
|
free(var->data.addr);
|
|
|
|
free(var->name);
|
2004-09-12 20:15:18 +00:00
|
|
|
free(var);
|
|
|
|
}
|
2004-08-25 22:11:41 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleVarSetString(_iconsole_var* var, const char* string)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
|
|
|
if (string == NULL) return;
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
if (var->_malloc)
|
|
|
|
free(var->data.string_);
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
var->data.string_ = strdup(string);
|
|
|
|
var->_malloc = true;
|
2004-09-12 21:49:38 +00:00
|
|
|
}
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleVarSetValue(_iconsole_var* var, int value) {
|
2004-09-12 20:15:18 +00:00
|
|
|
switch (var->type) {
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_VAR_BOOLEAN:
|
|
|
|
*var->data.bool_ = (value != 0);
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_BYTE:
|
2004-12-04 17:54:56 +00:00
|
|
|
case ICONSOLE_VAR_UINT8:
|
2004-09-19 15:24:45 +00:00
|
|
|
*var->data.byte_ = value;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_UINT16:
|
|
|
|
*var->data.uint16_ = value;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_UINT32:
|
|
|
|
*var->data.uint32_ = value;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_INT16:
|
|
|
|
*var->data.int16_ = value;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_INT32:
|
|
|
|
*var->data.int32_ = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
2004-09-12 21:49:38 +00:00
|
|
|
}
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleVarDump(const _iconsole_var* var, const char* dump_desc)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-12-04 17:54:56 +00:00
|
|
|
if (var == NULL) return;
|
2004-09-19 15:24:45 +00:00
|
|
|
if (dump_desc == NULL) dump_desc = var->name;
|
2004-08-24 22:41:42 +00:00
|
|
|
|
|
|
|
switch (var->type) {
|
|
|
|
case ICONSOLE_VAR_BOOLEAN:
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsolePrintF(_iconsole_color_default, "%s = %s",
|
|
|
|
dump_desc, *var->data.bool_ ? "true" : "false");
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
case ICONSOLE_VAR_BYTE:
|
2004-12-04 17:54:56 +00:00
|
|
|
case ICONSOLE_VAR_UINT8:
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsolePrintF(_iconsole_color_default, "%s = %u",
|
|
|
|
dump_desc, *var->data.byte_);
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
case ICONSOLE_VAR_UINT16:
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsolePrintF(_iconsole_color_default, "%s = %u",
|
|
|
|
dump_desc, *var->data.uint16_);
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
case ICONSOLE_VAR_UINT32:
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsolePrintF(_iconsole_color_default, "%s = %u",
|
|
|
|
dump_desc, *var->data.uint32_);
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
case ICONSOLE_VAR_INT16:
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsolePrintF(_iconsole_color_default, "%s = %i",
|
|
|
|
dump_desc, *var->data.int16_);
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
case ICONSOLE_VAR_INT32:
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsolePrintF(_iconsole_color_default, "%s = %i",
|
|
|
|
dump_desc, *var->data.int32_);
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
case ICONSOLE_VAR_STRING:
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsolePrintF(_iconsole_color_default, "%s = %s",
|
|
|
|
dump_desc, var->data.string_);
|
|
|
|
break;
|
2004-08-25 22:11:41 +00:00
|
|
|
case ICONSOLE_VAR_REFERENCE:
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsolePrintF(_iconsole_color_default, "%s = @%s",
|
|
|
|
dump_desc, var->data.reference_);
|
2004-08-24 22:41:42 +00:00
|
|
|
case ICONSOLE_VAR_UNKNOWN:
|
|
|
|
case ICONSOLE_VAR_POINTER:
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsolePrintF(_iconsole_color_default, "%s = @%p",
|
|
|
|
dump_desc, var->data.addr);
|
|
|
|
break;
|
2004-09-21 21:40:59 +00:00
|
|
|
case ICONSOLE_VAR_NONE:
|
|
|
|
IConsolePrintF(_iconsole_color_default, "%s = [nothing]",
|
|
|
|
dump_desc);
|
2004-09-19 15:24:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
// * ************************* * //
|
|
|
|
// * hooking code * //
|
|
|
|
// * ************************* * //
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleVarHook(const char* name, _iconsole_hook_types type, iconsole_var_hook proc)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_var* hook_var = IConsoleVarGet(name);
|
2004-09-12 20:15:18 +00:00
|
|
|
if (hook_var == NULL) return;
|
|
|
|
switch (type) {
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_HOOK_BEFORE_CHANGE:
|
|
|
|
hook_var->hook_before_change = proc;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_AFTER_CHANGE:
|
|
|
|
hook_var->hook_after_change = proc;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_ACCESS:
|
|
|
|
hook_var->hook_access = proc;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_BEFORE_EXEC:
|
|
|
|
case ICONSOLE_HOOK_AFTER_EXEC:
|
|
|
|
assert(0);
|
|
|
|
break;
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
bool IConsoleVarHookHandle(_iconsole_var* hook_var, _iconsole_hook_types type)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-12-04 17:54:56 +00:00
|
|
|
iconsole_var_hook proc;
|
|
|
|
if (hook_var == NULL) return false;
|
|
|
|
|
|
|
|
proc = NULL;
|
2004-09-12 20:15:18 +00:00
|
|
|
switch (type) {
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_HOOK_BEFORE_CHANGE:
|
|
|
|
proc = hook_var->hook_before_change;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_AFTER_CHANGE:
|
|
|
|
proc = hook_var->hook_after_change;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_ACCESS:
|
|
|
|
proc = hook_var->hook_access;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_BEFORE_EXEC:
|
|
|
|
case ICONSOLE_HOOK_AFTER_EXEC:
|
|
|
|
assert(0);
|
|
|
|
break;
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
return proc == NULL ? true : proc(hook_var);
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleCmdHook(const char* name, _iconsole_hook_types type, iconsole_cmd_hook proc)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_cmd* hook_cmd = IConsoleCmdGet(name);
|
2004-09-12 20:15:18 +00:00
|
|
|
if (hook_cmd == NULL) return;
|
|
|
|
switch (type) {
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_HOOK_AFTER_EXEC:
|
|
|
|
hook_cmd->hook_after_exec = proc;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_BEFORE_EXEC:
|
|
|
|
hook_cmd->hook_before_exec = proc;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_ACCESS:
|
|
|
|
hook_cmd->hook_access = proc;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_BEFORE_CHANGE:
|
|
|
|
case ICONSOLE_HOOK_AFTER_CHANGE:
|
|
|
|
assert(0);
|
|
|
|
break;
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
bool IConsoleCmdHookHandle(_iconsole_cmd* hook_cmd, _iconsole_hook_types type)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
iconsole_cmd_hook proc = NULL;
|
2004-09-12 20:15:18 +00:00
|
|
|
switch (type) {
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_HOOK_AFTER_EXEC:
|
|
|
|
proc = hook_cmd->hook_after_exec;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_BEFORE_EXEC:
|
|
|
|
proc = hook_cmd->hook_before_exec;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_ACCESS:
|
|
|
|
proc = hook_cmd->hook_access;
|
|
|
|
break;
|
|
|
|
case ICONSOLE_HOOK_BEFORE_CHANGE:
|
|
|
|
case ICONSOLE_HOOK_AFTER_CHANGE:
|
|
|
|
assert(0);
|
|
|
|
break;
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
return proc == NULL ? true : proc(hook_cmd);
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
void IConsoleCmdExec(const char* cmdstr)
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
_iconsole_cmd_addr function;
|
|
|
|
char* tokens[20];
|
|
|
|
byte tokentypes[20];
|
|
|
|
char* tokenstream;
|
|
|
|
char* tokenstream_s;
|
|
|
|
byte execution_mode;
|
2004-12-13 18:51:08 +00:00
|
|
|
_iconsole_var* var = NULL;
|
|
|
|
_iconsole_var* result = NULL;
|
|
|
|
_iconsole_cmd* cmd = NULL;
|
|
|
|
_iconsole_alias* alias = NULL;
|
2004-09-12 20:15:18 +00:00
|
|
|
|
|
|
|
bool longtoken;
|
|
|
|
bool valid_token;
|
|
|
|
bool skip_lt_change;
|
|
|
|
|
2005-01-09 21:25:44 +00:00
|
|
|
uint c;
|
|
|
|
uint i;
|
|
|
|
uint l;
|
2005-01-23 13:09:35 +00:00
|
|
|
|
2005-02-17 17:38:17 +00:00
|
|
|
for (; strchr("\n\r \t", *cmdstr) != NULL; ++cmdstr) {
|
|
|
|
switch (*cmdstr) {
|
|
|
|
case '\0':
|
|
|
|
case '#':
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-09-12 20:15:18 +00:00
|
|
|
|
2004-12-13 20:45:55 +00:00
|
|
|
if (_stdlib_con_developer)
|
|
|
|
IConsolePrintF(_iconsole_color_debug, "CONDEBUG: execution_cmdline: %s", cmdstr);
|
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
//** clearing buffer **//
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
for (i = 0; i < 20; i++) {
|
|
|
|
tokens[i] = NULL;
|
|
|
|
tokentypes[i] = ICONSOLE_VAR_NONE;
|
|
|
|
}
|
|
|
|
tokenstream_s = tokenstream = malloc(1024);
|
|
|
|
memset(tokenstream, 0, 1024);
|
2004-09-12 20:15:18 +00:00
|
|
|
|
|
|
|
//** parsing **//
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
longtoken = false;
|
|
|
|
valid_token = false;
|
|
|
|
skip_lt_change = false;
|
|
|
|
l = strlen(cmdstr);
|
|
|
|
i = 0;
|
|
|
|
c = 0;
|
2004-09-12 20:15:18 +00:00
|
|
|
tokens[c] = tokenstream;
|
2004-12-04 17:54:56 +00:00
|
|
|
tokentypes[c] = ICONSOLE_VAR_UNKNOWN;
|
2004-09-21 21:40:59 +00:00
|
|
|
while (i < l && c < lengthof(tokens) - 1) {
|
2004-09-19 15:24:45 +00:00
|
|
|
if (cmdstr[i] == '"') {
|
2004-09-12 20:15:18 +00:00
|
|
|
if (longtoken) {
|
2004-09-19 15:24:45 +00:00
|
|
|
if (cmdstr[i + 1] == '"') {
|
2004-09-12 20:15:18 +00:00
|
|
|
i++;
|
|
|
|
*tokenstream = '"';
|
|
|
|
tokenstream++;
|
2004-09-19 15:24:45 +00:00
|
|
|
skip_lt_change = true;
|
2004-08-24 22:41:42 +00:00
|
|
|
} else {
|
2004-09-19 15:24:45 +00:00
|
|
|
longtoken = !longtoken;
|
2004-12-04 17:54:56 +00:00
|
|
|
tokentypes[c] = ICONSOLE_VAR_STRING;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
} else {
|
2004-09-19 15:24:45 +00:00
|
|
|
longtoken = !longtoken;
|
2004-12-04 17:54:56 +00:00
|
|
|
tokentypes[c] = ICONSOLE_VAR_STRING;
|
|
|
|
}
|
2004-09-12 20:15:18 +00:00
|
|
|
if (!skip_lt_change) {
|
|
|
|
if (!longtoken) {
|
|
|
|
if (valid_token) {
|
|
|
|
c++;
|
2004-09-19 15:24:45 +00:00
|
|
|
*tokenstream = '\0';
|
2004-09-12 20:15:18 +00:00
|
|
|
tokenstream++;
|
|
|
|
tokens[c] = tokenstream;
|
2004-12-04 17:54:56 +00:00
|
|
|
tokentypes[c] = ICONSOLE_VAR_UNKNOWN;
|
2004-09-12 20:15:18 +00:00
|
|
|
valid_token = false;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
skip_lt_change=false;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
} else if (!longtoken && cmdstr[i] == ' ') {
|
2004-09-12 20:15:18 +00:00
|
|
|
if (valid_token) {
|
|
|
|
c++;
|
2004-09-19 15:24:45 +00:00
|
|
|
*tokenstream = '\0';
|
2004-09-12 20:15:18 +00:00
|
|
|
tokenstream++;
|
|
|
|
tokens[c] = tokenstream;
|
2004-12-04 17:54:56 +00:00
|
|
|
tokentypes[c] = ICONSOLE_VAR_UNKNOWN;
|
2004-09-12 20:15:18 +00:00
|
|
|
valid_token = false;
|
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
} else {
|
|
|
|
valid_token = true;
|
2004-09-12 20:15:18 +00:00
|
|
|
*tokenstream = cmdstr[i];
|
2004-08-24 22:41:42 +00:00
|
|
|
tokenstream++;
|
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
i++;
|
|
|
|
}
|
2004-09-12 20:15:18 +00:00
|
|
|
|
|
|
|
tokenstream--;
|
2004-09-19 15:24:45 +00:00
|
|
|
if (*tokenstream != '\0') {
|
2004-09-12 20:15:18 +00:00
|
|
|
c++;
|
2004-08-24 22:41:42 +00:00
|
|
|
tokenstream++;
|
2004-09-19 15:24:45 +00:00
|
|
|
*tokenstream = '\0';
|
|
|
|
}
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
//** interpreting **//
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
if (tokens[i] != NULL && i > 0 && strlen(tokens[i]) > 0) {
|
2004-12-04 17:54:56 +00:00
|
|
|
if (IConsoleVarGet((char *)tokens[i]) != NULL) {
|
2004-09-21 21:40:59 +00:00
|
|
|
// change the variable to an pointer if execution_mode != 4 is
|
2004-12-04 17:54:56 +00:00
|
|
|
// being prepared. execution_mode 4 is used to assign
|
2004-09-21 21:40:59 +00:00
|
|
|
// one variables data to another one
|
|
|
|
// [token 0 and 2]
|
|
|
|
if (!((i == 2) && (tokentypes[1] == ICONSOLE_VAR_UNKNOWN) &&
|
|
|
|
(strcmp(tokens[1], "<<") == 0))) {
|
2004-12-04 17:54:56 +00:00
|
|
|
// only look for another variable if it isnt an longtoken == string with ""
|
|
|
|
var = NULL;
|
|
|
|
if (tokentypes[i]!=ICONSOLE_VAR_STRING) var = IConsoleVarGet(tokens[i]);
|
2004-09-19 15:24:45 +00:00
|
|
|
if (var != NULL) {
|
2004-09-21 21:40:59 +00:00
|
|
|
// pointer to the data --> token
|
2004-12-04 17:54:56 +00:00
|
|
|
tokens[i] = (char *) var->data.addr; /* XXX: maybe someone finds an cleaner way to do this */
|
2004-09-19 15:24:45 +00:00
|
|
|
tokentypes[i] = var->type;
|
2004-08-25 22:11:41 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
if (tokens[i] != NULL && tokens[i][0] == '@' && (IConsoleVarGet(tokens[i]+1) != NULL)) {
|
|
|
|
var = IConsoleVarGet(tokens[i]+1);
|
2004-09-19 15:24:45 +00:00
|
|
|
if (var != NULL) {
|
2004-09-21 21:40:59 +00:00
|
|
|
// pointer to the _iconsole_var struct --> token
|
2004-12-04 17:54:56 +00:00
|
|
|
tokens[i] = (char *) var; /* XXX: maybe someone finds an cleaner way to do this */
|
2004-09-19 15:24:45 +00:00
|
|
|
tokentypes[i] = ICONSOLE_VAR_REFERENCE;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
}
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
execution_mode=0;
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
function = NULL;
|
|
|
|
cmd = IConsoleCmdGet(tokens[0]);
|
2004-12-13 18:51:08 +00:00
|
|
|
if (cmd != NULL) {
|
|
|
|
function = cmd->addr;
|
|
|
|
} else {
|
|
|
|
alias = IConsoleAliasGet(tokens[0]);
|
|
|
|
if (alias != NULL) execution_mode = 5; // alias handling
|
|
|
|
}
|
2004-09-12 20:15:18 +00:00
|
|
|
|
|
|
|
if (function != NULL) {
|
2004-09-19 15:24:45 +00:00
|
|
|
execution_mode = 1; // this is a command
|
|
|
|
} else {
|
2004-09-12 20:15:18 +00:00
|
|
|
var = IConsoleVarGet(tokens[0]);
|
|
|
|
if (var != NULL) {
|
2004-09-19 15:24:45 +00:00
|
|
|
execution_mode = 2; // this is a variable
|
|
|
|
if (c > 2 && strcmp(tokens[1], "<<") == 0) {
|
2004-09-12 20:15:18 +00:00
|
|
|
// this is command to variable mode [normal]
|
2004-09-12 21:49:38 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
function = NULL;
|
|
|
|
cmd = IConsoleCmdGet(tokens[2]);
|
|
|
|
if (cmd != NULL) function = cmd->addr;
|
|
|
|
|
|
|
|
if (function != NULL) {
|
2004-09-19 15:24:45 +00:00
|
|
|
execution_mode = 3;
|
|
|
|
} else {
|
2004-09-12 20:15:18 +00:00
|
|
|
result = IConsoleVarGet(tokens[2]);
|
2004-09-19 15:24:45 +00:00
|
|
|
if (result != NULL)
|
2004-12-13 18:51:08 +00:00
|
|
|
execution_mode = 4;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
}
|
2004-08-24 22:41:42 +00:00
|
|
|
|
2004-09-12 20:15:18 +00:00
|
|
|
//** executing **//
|
2004-09-19 15:24:45 +00:00
|
|
|
if (_stdlib_con_developer)
|
|
|
|
IConsolePrintF(_iconsole_color_debug, "CONDEBUG: execution_mode: %i",
|
|
|
|
execution_mode);
|
2004-09-12 20:15:18 +00:00
|
|
|
switch (execution_mode) {
|
2004-09-19 15:24:45 +00:00
|
|
|
case 0:
|
|
|
|
// not found
|
|
|
|
IConsoleError("command or variable not found");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (IConsoleCmdHookHandle(cmd, ICONSOLE_HOOK_ACCESS)) {
|
|
|
|
// execution with command syntax
|
|
|
|
IConsoleCmdHookHandle(cmd, ICONSOLE_HOOK_BEFORE_EXEC);
|
|
|
|
result = function(c, tokens, tokentypes);
|
|
|
|
if (result != NULL) {
|
|
|
|
IConsoleVarDump(result, "result");
|
|
|
|
IConsoleVarFree(result);
|
|
|
|
}
|
|
|
|
IConsoleCmdHookHandle(cmd, ICONSOLE_HOOK_AFTER_EXEC);
|
|
|
|
break;
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
case 2:
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
// execution with variable syntax
|
|
|
|
if (IConsoleVarHookHandle(var, ICONSOLE_HOOK_ACCESS) && (c == 2 || c == 3)) {
|
|
|
|
// ** variable modifications ** //
|
|
|
|
IConsoleVarHookHandle(var, ICONSOLE_HOOK_BEFORE_CHANGE);
|
|
|
|
switch (var->type) {
|
|
|
|
case ICONSOLE_VAR_BOOLEAN:
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (strcmp(tokens[1], "=") == 0) {
|
|
|
|
if (c == 3) {
|
|
|
|
*var->data.bool_ = (atoi(tokens[2]) != 0);
|
2004-09-12 20:15:18 +00:00
|
|
|
} else {
|
2004-09-19 15:24:45 +00:00
|
|
|
*var->data.bool_ = false;
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "++") == 0) {
|
2004-09-21 21:40:59 +00:00
|
|
|
*var->data.bool_ = true;
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "--") == 0) {
|
2004-09-21 21:40:59 +00:00
|
|
|
*var->data.bool_ = false;
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsoleVarDump(var, NULL);
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
else
|
|
|
|
IConsoleError("operation not supported");
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_VAR_BYTE:
|
2004-12-04 17:54:56 +00:00
|
|
|
case ICONSOLE_VAR_UINT8:
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (strcmp(tokens[1], "=") == 0) {
|
|
|
|
if (c == 3)
|
|
|
|
*var->data.byte_ = atoi(tokens[2]);
|
|
|
|
else
|
|
|
|
*var->data.byte_ = 0;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "++") == 0) {
|
|
|
|
++*var->data.byte_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "--")==0) {
|
|
|
|
--*var->data.byte_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
else
|
|
|
|
IConsoleError("operation not supported");
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_VAR_UINT16:
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (strcmp(tokens[1], "=") == 0) {
|
|
|
|
if (c == 3)
|
|
|
|
*var->data.uint16_ = atoi(tokens[2]);
|
|
|
|
else
|
|
|
|
*var->data.uint16_ = 0;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "++") == 0) {
|
|
|
|
++*var->data.uint16_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "--") == 0) {
|
|
|
|
--*var->data.uint16_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
else
|
|
|
|
IConsoleError("operation not supported");
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_VAR_UINT32:
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (strcmp(tokens[1], "=") == 0) {
|
|
|
|
if (c == 3)
|
|
|
|
*var->data.uint32_ = atoi(tokens[2]);
|
|
|
|
else
|
|
|
|
*var->data.uint32_ = 0;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "++") == 0) {
|
|
|
|
++*var->data.uint32_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "--") == 0) {
|
|
|
|
--*var->data.uint32_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
else
|
|
|
|
IConsoleError("operation not supported");
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_VAR_INT16:
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (strcmp(tokens[1], "=") == 0) {
|
|
|
|
if (c == 3)
|
|
|
|
*var->data.int16_ = atoi(tokens[2]);
|
|
|
|
else
|
|
|
|
*var->data.int16_ = 0;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "++") == 0) {
|
|
|
|
++*var->data.int16_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "--") == 0) {
|
|
|
|
--*var->data.int16_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
else
|
|
|
|
IConsoleError("operation not supported");
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_VAR_INT32:
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (strcmp(tokens[1], "=") == 0) {
|
|
|
|
if (c == 3)
|
|
|
|
*var->data.int32_ = atoi(tokens[2]);
|
|
|
|
else
|
|
|
|
*var->data.int32_ = 0;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "++") == 0) {
|
|
|
|
++*var->data.int32_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "--") == 0) {
|
|
|
|
--*var->data.int32_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
else { IConsoleError("operation not supported"); }
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_VAR_STRING:
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (strcmp(tokens[1], "=") == 0) {
|
|
|
|
if (c == 3)
|
|
|
|
IConsoleVarSetString(var, tokens[2]);
|
|
|
|
else
|
|
|
|
IConsoleVarSetString(var, "");
|
|
|
|
IConsoleVarDump(var, NULL);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
else
|
|
|
|
IConsoleError("operation not supported");
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
case ICONSOLE_VAR_POINTER:
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
if (strcmp(tokens[1], "=") == 0) {
|
|
|
|
if (c == 3) {
|
|
|
|
if (tokentypes[2] == ICONSOLE_VAR_UNKNOWN)
|
2004-09-21 21:40:59 +00:00
|
|
|
var->data.addr = (void*)atoi(tokens[2]); /* direct access on memory [by address] */
|
2004-09-19 15:24:45 +00:00
|
|
|
else
|
2004-09-21 21:40:59 +00:00
|
|
|
var->data.addr = (void*)tokens[2]; /* direct acces on memory [by variable] */
|
2004-09-19 15:24:45 +00:00
|
|
|
} else
|
|
|
|
var->data.addr = NULL;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "++") == 0) {
|
2004-09-21 21:40:59 +00:00
|
|
|
++*(char*)&var->data.addr; /* change the address + 1 */
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
} else if (strcmp(tokens[1], "--") == 0) {
|
2004-09-21 21:40:59 +00:00
|
|
|
--*(char*)&var->data.addr; /* change the address - 1 */
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsoleVarDump(var, NULL);
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
else
|
|
|
|
IConsoleError("operation not supported");
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
case ICONSOLE_VAR_NONE:
|
|
|
|
case ICONSOLE_VAR_REFERENCE:
|
|
|
|
case ICONSOLE_VAR_UNKNOWN:
|
2004-09-21 21:40:59 +00:00
|
|
|
IConsoleError("operation not supported");
|
2004-09-19 15:24:45 +00:00
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsoleVarHookHandle(var, ICONSOLE_HOOK_AFTER_CHANGE);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
if (c == 1) // ** variable output ** //
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
case 3:
|
|
|
|
case 4:
|
2004-09-12 20:15:18 +00:00
|
|
|
{
|
2004-09-19 15:24:45 +00:00
|
|
|
// execute command with result or assign a variable
|
|
|
|
if (execution_mode == 3) {
|
|
|
|
if (IConsoleCmdHookHandle(cmd, ICONSOLE_HOOK_ACCESS)) {
|
2004-09-12 21:49:38 +00:00
|
|
|
int i;
|
|
|
|
int diff;
|
2004-09-19 15:24:45 +00:00
|
|
|
void* temp;
|
2004-09-12 21:49:38 +00:00
|
|
|
byte temp2;
|
|
|
|
|
|
|
|
// tokenshifting
|
2004-09-19 15:24:45 +00:00
|
|
|
for (diff = 0; diff < 2; diff++) {
|
|
|
|
temp = tokens[0];
|
|
|
|
temp2 = tokentypes[0];
|
|
|
|
for (i = 0; i < 19; i++) {
|
|
|
|
tokens[i] = tokens[i + 1];
|
|
|
|
tokentypes[i] = tokentypes[i + 1];
|
2004-09-12 21:49:38 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
tokens[19] = temp;
|
|
|
|
tokentypes[19] = temp2;
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsoleCmdHookHandle(cmd, ICONSOLE_HOOK_BEFORE_EXEC);
|
|
|
|
result = function(c, tokens, tokentypes);
|
|
|
|
IConsoleCmdHookHandle(cmd, ICONSOLE_HOOK_AFTER_EXEC);
|
2004-09-12 21:49:38 +00:00
|
|
|
} else
|
2004-09-19 15:24:45 +00:00
|
|
|
execution_mode = 255;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-08-25 22:11:41 +00:00
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
if (IConsoleVarHookHandle(var, ICONSOLE_HOOK_ACCESS) && result != NULL) {
|
|
|
|
if (result->type != var->type) {
|
2004-09-12 20:15:18 +00:00
|
|
|
IConsoleError("variable type missmatch");
|
2004-09-19 15:24:45 +00:00
|
|
|
} else {
|
|
|
|
IConsoleVarHookHandle(var, ICONSOLE_HOOK_BEFORE_CHANGE);
|
|
|
|
switch (result->type) {
|
|
|
|
case ICONSOLE_VAR_BOOLEAN:
|
|
|
|
*var->data.bool_ = *result->data.bool_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_BYTE:
|
2004-12-04 17:54:56 +00:00
|
|
|
case ICONSOLE_VAR_UINT8:
|
2004-09-19 15:24:45 +00:00
|
|
|
*var->data.byte_ = *result->data.byte_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_UINT16:
|
|
|
|
*var->data.uint16_ = *result->data.uint16_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_UINT32:
|
|
|
|
*var->data.uint32_ = *result->data.uint32_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_INT16:
|
|
|
|
*var->data.int16_ = *result->data.int16_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_INT32:
|
|
|
|
*var->data.int32_ = *result->data.int32_;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_POINTER:
|
|
|
|
var->data.addr = result->data.addr;
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
break;
|
|
|
|
case ICONSOLE_VAR_STRING:
|
|
|
|
IConsoleVarSetString(var, result->data.string_);
|
|
|
|
IConsoleVarDump(var, NULL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
IConsoleError("variable type missmatch");
|
|
|
|
break;
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
IConsoleVarHookHandle(var, ICONSOLE_HOOK_AFTER_CHANGE);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-19 15:24:45 +00:00
|
|
|
if (execution_mode == 3) {
|
|
|
|
IConsoleVarFree(result);
|
2004-09-12 20:15:18 +00:00
|
|
|
}
|
2004-08-25 22:11:41 +00:00
|
|
|
}
|
2004-09-19 15:24:45 +00:00
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
2004-12-13 18:51:08 +00:00
|
|
|
case 5: {
|
|
|
|
// execute an alias
|
|
|
|
IConsoleAliasExec(alias->cmdline, tokens,tokentypes);
|
|
|
|
}
|
|
|
|
break;
|
2004-09-19 15:24:45 +00:00
|
|
|
default:
|
|
|
|
// execution mode invalid
|
|
|
|
IConsoleError("invalid execution mode");
|
|
|
|
break;
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
2004-09-21 21:40:59 +00:00
|
|
|
//** freeing the tokenstream **//
|
2004-09-12 20:15:18 +00:00
|
|
|
free(tokenstream_s);
|
2004-08-24 22:41:42 +00:00
|
|
|
}
|