From 3e148838af0cd864ce60c7c16f884adfed698865 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 10 Mar 2008 16:22:38 +0000 Subject: [PATCH] * fhandler.h (dev_console::con_to_str): Declare returning DWORD. * fhandler_console.cc (dev_console::con_to_str): Return number of multibyte char bytes. (fhandler_console::read): Set nread to number of multibyte char bytes returned from con_to_str. (fhandler_console::write_normal): Reorder trunc buffer preocessing. Return after writing valid multibyte sequence out of trunc buffer. Change comments slightly. --- winsup/cygwin/ChangeLog | 11 +++++++++++ winsup/cygwin/fhandler_console.cc | 28 +++++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 83aadcfde..a28d22efe 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +2008-03-10 Corinna Vinschen + + * fhandler.h (dev_console::con_to_str): Declare returning DWORD. + * fhandler_console.cc (dev_console::con_to_str): Return number of + multibyte char bytes. + (fhandler_console::read): Set nread to number of multibyte char bytes + returned from con_to_str. + (fhandler_console::write_normal): Reorder trunc buffer preocessing. + Return after writing valid multibyte sequence out of trunc buffer. + Change comments slightly. + 2008-03-08 Corinna Vinschen * fhandler_disk_file.cc (DIR_BUF_SIZE): Define required space for file diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 0a445aa2e..c83b3915b 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -152,10 +152,10 @@ set_console_state_for_spawn (bool iscyg) /* The results of GetConsoleCP() and GetConsoleOutputCP() cannot be cached, because a program or the user can change these values at any time. */ -inline bool +inline DWORD dev_console::con_to_str (char *d, int dlen, WCHAR w) { - return !!sys_wcstombs (d, dlen, &w, 1); + return sys_wcstombs (d, dlen, &w, 1); } inline UINT @@ -354,7 +354,7 @@ fhandler_console::read (void *pv, size_t& buflen) } else { - dev_state->con_to_str (tmp + 1, 59, wch); + nread = dev_state->con_to_str (tmp + 1, 59, wch); /* Determine if the keystroke is modified by META. The tricky part is to distinguish whether the right Alt key should be recognized as Alt, or as AltGr. */ @@ -1464,27 +1464,29 @@ fhandler_console::write_normal (const unsigned char *src, memcpy (trunc_buf.buf + trunc_buf.len, src, cp_len); nfound = next_char (cp, trunc_buf.buf, trunc_buf.buf + trunc_buf.len + cp_len); - if (!nfound) /* Invalid multibyte sequence. */ - { /* Give up and print replacement chars. */ - for (int i = 0; i < trunc_buf.len; ++i) - write_replacement_char (trunc_buf.buf + i); - } - else if (nfound == trunc_buf.buf) - { /* Still truncated multibyte sequence. */ + /* Still truncated multibyte sequence? Keep in trunc_buf. */ + if (nfound == trunc_buf.buf) + { trunc_buf.len += cp_len; return end; } - else + /* Valid multibyte sequence? Process. */ + if (nfound) { - /* Valid multibyte sequence. Process. */ WCHAR buf[2]; buf_len = dev_state->str_to_con (buf, (const char *) trunc_buf.buf, nfound - trunc_buf.buf); WriteConsoleW (get_output_handle (), buf, buf_len, &done, 0); found = src + (nfound - trunc_buf.buf - trunc_buf.len); + trunc_buf.len = 0; + return found; } - /* Mark trunc_buf as unused. */ + /* Give up, print replacement chars for trunc_buf... */ + for (int i = 0; i < trunc_buf.len; ++i) + write_replacement_char (trunc_buf.buf + i); + /* ... mark trunc_buf as unused... */ trunc_buf.len = 0; + /* ... and proceed. */ } while (found < end