summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/libunix.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-06-08 18:48:41 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-06-08 18:48:41 +0000
commit859a5ab42d2c9922f5ddc0b73961bb4231e379b7 (patch)
tree3fbd5e9d68ebe65470346bf7676ca92143452e21 /crawl-ref/source/libunix.cc
parente2b75cbb2ad69c4cfd62eca04a82ee3fa04e3d6b (diff)
downloadcrawl-ref-859a5ab42d2c9922f5ddc0b73961bb4231e379b7.tar.gz
crawl-ref-859a5ab42d2c9922f5ddc0b73961bb4231e379b7.zip
When showing glyphs in messages (as in the tutorial), use stringize_glyph() to
convert Unicode glyphs to multibyte sequences. Added multibyte_strlen to calculate string lengths correctly when dealing with multibyte strings. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1560 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/libunix.cc')
-rw-r--r--crawl-ref/source/libunix.cc30
1 files changed, 27 insertions, 3 deletions
diff --git a/crawl-ref/source/libunix.cc b/crawl-ref/source/libunix.cc
index b92e33241b..b26397113a 100644
--- a/crawl-ref/source/libunix.cc
+++ b/crawl-ref/source/libunix.cc
@@ -48,6 +48,7 @@
#include "files.h"
#ifdef UNICODE_GLYPHS
+#include <wchar.h>
#include <locale.h>
#endif
@@ -167,6 +168,26 @@ static void setup_colour_pairs( void )
init_pair(63, COLOR_BLACK, Options.background);
} // end setup_colour_pairs()
+#ifdef UNICODE_GLYPHS
+static std::string unix_glyph2string(unsigned gly)
+{
+ char buf[50]; // Overkill, I know.
+ wchar_t wcbuf[2];
+ wcbuf[0] = gly;
+ wcbuf[1] = 0;
+ if (wcstombs(buf, wcbuf, sizeof buf) != (size_t) -1)
+ return (buf);
+
+ return std::string(1, gly);
+}
+
+static int unix_multibyte_strlen(const std::string &s)
+{
+ const char *cs = s.c_str();
+ size_t len = mbsrtowcs(NULL, &cs, 0, NULL);
+ return (len == (size_t) -1? s.length() : len);
+}
+#endif
static void termio_init()
{
@@ -187,7 +208,11 @@ static void termio_init()
tcsetattr(0, TCSAFLUSH, &game_term);
#ifdef UNICODE_GLYPHS
- crawl_state.unicode_ok = !!setlocale(LC_ALL, "");
+ if ((crawl_state.unicode_ok = !!setlocale(LC_ALL, "")))
+ {
+ crawl_state.glyph2strfn = unix_glyph2string;
+ crawl_state.multibyte_strlen = unix_multibyte_strlen;
+ }
#endif
}
@@ -271,7 +296,7 @@ void message_out(int which_line, int color, const char *s, int firstcol,
firstcol = Options.delay_message_clear? 1 : 0;
else
firstcol--;
-
+
mvwaddstr(Message_Window, which_line, firstcol, s);
if (newline && which_line == crawl_view.msgsz.y - 1)
@@ -394,7 +419,6 @@ int itoa(int value, char *strptr, int radix)
return (OK); /* Me? Fail? Nah. */
}
-
int cprintf(const char *format,...)
{
int i;