summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-03-27 17:20:27 +0000
committerDarkvater <darkvater@openttd.org>2005-03-27 17:20:27 +0000
commita494f96cfe9fa53b933eab8ded62f82e6bc06612 (patch)
treec8e1eeb70fe6107a77f36d37bfeb7cded43632e5
parentc4133f253547351734b4186b7a2d411553fde3a5 (diff)
downloadopenttd-a494f96cfe9fa53b933eab8ded62f82e6bc06612.tar.xz
(svn r2092) - Fix: old commands/lines in the console (history) did not show when they used 'special' characters like öä, etc. Diff approved by the code-police.
-rw-r--r--console.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/console.c b/console.c
index 338d3de79..b8320fa85 100644
--- a/console.c
+++ b/console.c
@@ -337,14 +337,18 @@ void IConsoleCmdBufferNavigate(signed char direction)
UpdateTextBufferSize(&_iconsole_cmdline);
}
+/**
+ * Handle the printing of text entered into the console or redirected there
+ * by any other means. Text can be redirected to other players in a network game
+ * as well as to a logfile. If the network server is a dedicated server, all activities
+ * are also logged. All lines to print are added to a temporary buffer which can be
+ * used as a history to print them onscreen
+ * @param color_code the colour of the command. Red in case of errors, etc.
+ * @param string the message entered or output on the console (notice, error, etc.)
+ */
void IConsolePrint(uint16 color_code, const char* string)
{
- char* _ex;
- char* _new;
- uint16 _exc;
- uint16 _newc;
- char* i;
- int j;
+ char *i;
#ifdef ENABLE_NETWORK
if (_redirect_console_to_client != 0) {
@@ -362,21 +366,18 @@ void IConsolePrint(uint16 color_code, const char* string)
if (!_iconsole_inited) return;
- _newc = color_code;
- _new = strdup(string);
+ /* move up all the strings in the buffer one place and do the same for colour
+ * to accomodate for the new command/message */
+ free(_iconsole_buffer[0]);
+ memmove(&_iconsole_buffer[0], &_iconsole_buffer[1], sizeof(_iconsole_buffer[0]) * ICON_BUFFER);
+ _iconsole_buffer[ICON_BUFFER] = strdup(string);
- for (i = _new; *i != '\0'; ++i)
- if (*i < ' ') *i = ' '; /* filter for ascii-function codes like BELL and so on [we need an special filter here later] */
+ // filter out unprintable characters
+ for (i = _iconsole_buffer[ICON_BUFFER]; *i != '\0'; i++)
+ if (!IsValidAsciiChar((byte)*i)) *i = ' ';
- for (j = ICON_BUFFER; j >= 0; --j) {
- _ex = _iconsole_buffer[j];
- _exc = _iconsole_cbuffer[j];
- _iconsole_buffer[j] = _new;
- _iconsole_cbuffer[j] = _newc;
- _new = _ex;
- _newc = _exc;
- }
- free(_ex);
+ memmove(&_iconsole_cbuffer[0], &_iconsole_cbuffer[1], sizeof(_iconsole_cbuffer[0]) * ICON_BUFFER);
+ _iconsole_cbuffer[ICON_BUFFER] = color_code;
IConsoleWriteToLogFile(string);