PATCH: Use getche on Win32

Mark Mitchell
2005-05-09T20:18:08Z

[This is the penultimate GDB-on-MinGW patch.]

Windows console semantics are different from UNIX. If we just use
"read" to read what the user's typing, we end up blocking until a
newline is available, and even then there are some oddities. The
easiest thing seems to be to use the special "getche" (short for "get
character with echo") routine which does the right thing.

Reviews?

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-05-09 Mark Mitchell <mark@codesourcery.com>

* readline/input.c (rl_getc): Use getche to read console input on
Windows.

Index: input.c
===================================================================
RCS file: /cvs/src/src/readline/input.c,v
retrieving revision 1.5
retrieving revision 1.5.60.1
diff -c -5 -p -r1.5 -r1.5.60.1
*** input.c 8 Dec 2002 22:31:37 -0000 1.5
--- input.c 5 Apr 2005 17:53:04 -0000 1.5.60.1
*************** rl_getc (stream)
*** 422,431 ****
--- 422,438 ----
int result;
unsigned char c;

while (1)
{
+ #ifdef __MINGW32__
+ /* On Windows, use a special routine to read a single character
+ from the console. (Otherwise, no characters are available
+ until the user hits the return key.) */
+ if (isatty (fileno (stream)))
+ return getche ();
+ #endif
result = read (fileno (stream), &c, sizeof (unsigned char));

if (result == sizeof (unsigned char))
return (c);