summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-11-16 17:41:24 +0000
committerDarkvater <Darkvater@openttd.org>2006-11-16 17:41:24 +0000
commit22bfbc8a7aa396d48ff0319ab9ea4919dba5eb3f (patch)
tree7c2185201a93f3c8c674dabd72895508d9d7290a
parent55506a902ac5bf51c8f771e932dbb10be46242d7 (diff)
downloadopenttd-22bfbc8a7aa396d48ff0319ab9ea4919dba5eb3f.tar.xz
(svn r7172) -Fix [r6931]: The console showed '?' characters instead of colours. Now strip all
colours for the console. It's a bit magicky (magic numbers) but UTF8 fixes that soon.
-rw-r--r--console.c1
-rw-r--r--string.c13
-rw-r--r--string.h3
3 files changed, 17 insertions, 0 deletions
diff --git a/console.c b/console.c
index 005c31428..1b5ef1c64 100644
--- a/console.c
+++ b/console.c
@@ -400,6 +400,7 @@ void IConsolePrint(uint16 color_code, const char *string)
memmove(&_iconsole_buffer[0], &_iconsole_buffer[1], sizeof(_iconsole_buffer[0]) * ICON_BUFFER);
_iconsole_buffer[ICON_BUFFER] = strdup(string);
+ str_strip_colours(_iconsole_buffer[ICON_BUFFER]);
str_validate(_iconsole_buffer[ICON_BUFFER]);
memmove(&_iconsole_cbuffer[0], &_iconsole_cbuffer[1], sizeof(_iconsole_cbuffer[0]) * ICON_BUFFER);
diff --git a/string.c b/string.c
index 297e931fb..f6f10de13 100644
--- a/string.c
+++ b/string.c
@@ -72,6 +72,19 @@ void str_validate(char *str)
if (!IsValidAsciiChar(*str, CS_ALPHANUMERAL)) *str = '?';
}
+void str_strip_colours(char *str)
+{
+ char *dst = str;
+ for (; *str != '\0';) {
+ if (*str >= 15 && *str <= 31) { // magic colour codes
+ str++;
+ } else {
+ *dst++ = *str++;
+ }
+ }
+ *dst = '\0';
+}
+
/**
* Only allow certain keys. You can define the filter to be used. This makes
* sure no invalid keys can get into an editbox, like BELL.
diff --git a/string.h b/string.h
index 781586515..f86854a88 100644
--- a/string.h
+++ b/string.h
@@ -29,6 +29,9 @@ char* CDECL str_fmt(const char* str, ...);
* replaces them with a question mark '?' */
void str_validate(char *str);
+/** Scans the string for colour codes and strips them */
+void str_strip_colours(char *str);
+
/**
* Valid filter types for IsValidAsciiChar.
*/