diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2008-03-10 16:22:38 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2008-03-10 16:22:38 +0000 |
commit | 3e148838af0cd864ce60c7c16f884adfed698865 (patch) | |
tree | 500ab983832151fbac263d8303ab0c4c80e88c5f /winsup/cygwin/fhandler_console.cc | |
parent | 3461c83a0512529776a44990132a9e688c7d205f (diff) | |
download | cygnal-3e148838af0cd864ce60c7c16f884adfed698865.tar.gz cygnal-3e148838af0cd864ce60c7c16f884adfed698865.tar.bz2 cygnal-3e148838af0cd864ce60c7c16f884adfed698865.zip |
* 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.
Diffstat (limited to 'winsup/cygwin/fhandler_console.cc')
-rw-r--r-- | winsup/cygwin/fhandler_console.cc | 28 |
1 files changed, 15 insertions, 13 deletions
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 |