* 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.
This commit is contained in:
Corinna Vinschen 2008-03-10 16:22:38 +00:00
parent 3461c83a05
commit 3e148838af
2 changed files with 26 additions and 13 deletions

View File

@ -1,3 +1,14 @@
2008-03-10 Corinna Vinschen <corinna@vinschen.de>
* 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 <corinna@vinschen.de> 2008-03-08 Corinna Vinschen <corinna@vinschen.de>
* fhandler_disk_file.cc (DIR_BUF_SIZE): Define required space for file * fhandler_disk_file.cc (DIR_BUF_SIZE): Define required space for file

View File

@ -152,10 +152,10 @@ set_console_state_for_spawn (bool iscyg)
/* The results of GetConsoleCP() and GetConsoleOutputCP() cannot be /* The results of GetConsoleCP() and GetConsoleOutputCP() cannot be
cached, because a program or the user can change these values at cached, because a program or the user can change these values at
any time. */ any time. */
inline bool inline DWORD
dev_console::con_to_str (char *d, int dlen, WCHAR w) 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 inline UINT
@ -354,7 +354,7 @@ fhandler_console::read (void *pv, size_t& buflen)
} }
else 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 /* Determine if the keystroke is modified by META. The tricky
part is to distinguish whether the right Alt key should be part is to distinguish whether the right Alt key should be
recognized as Alt, or as AltGr. */ 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); memcpy (trunc_buf.buf + trunc_buf.len, src, cp_len);
nfound = next_char (cp, trunc_buf.buf, nfound = next_char (cp, trunc_buf.buf,
trunc_buf.buf + trunc_buf.len + cp_len); trunc_buf.buf + trunc_buf.len + cp_len);
if (!nfound) /* Invalid multibyte sequence. */ /* Still truncated multibyte sequence? Keep in trunc_buf. */
{ /* Give up and print replacement chars. */ if (nfound == trunc_buf.buf)
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. */
trunc_buf.len += cp_len; trunc_buf.len += cp_len;
return end; return end;
} }
else /* Valid multibyte sequence? Process. */
if (nfound)
{ {
/* Valid multibyte sequence. Process. */
WCHAR buf[2]; WCHAR buf[2];
buf_len = dev_state->str_to_con (buf, (const char *) trunc_buf.buf, buf_len = dev_state->str_to_con (buf, (const char *) trunc_buf.buf,
nfound - trunc_buf.buf); nfound - trunc_buf.buf);
WriteConsoleW (get_output_handle (), buf, buf_len, &done, 0); WriteConsoleW (get_output_handle (), buf, buf_len, &done, 0);
found = src + (nfound - trunc_buf.buf - trunc_buf.len); 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; trunc_buf.len = 0;
/* ... and proceed. */
} }
while (found < end while (found < end