Fix console input on Windows to permit the debugger to function.

Previously, on Win32 with MSVC, the non-blocking input function didn't work correctly and prevented use of the debugger.  Instead, use native console I/O to implement non-blocking input, which both works and avoids CRT (i.e. MSVC vs. Cygwin) dependency.
This commit is contained in:
Peter 2013-12-04 01:55:22 +00:00
parent 4db94cb6ff
commit bb085287d8
2 changed files with 23 additions and 12 deletions

View File

@ -392,6 +392,7 @@ do_debug_intfc()
show_regs();
break;
case '\n':
case '\r':
*line_ptr = 0;
if(old_mode == 's') {
do_blank();
@ -720,7 +721,7 @@ read_line(char *buf, int len)
break;
}
space_left -= ret;
if(buf[ret-1] == 0x0a) {
if(buf[ret-1] == '\r' || buf[ret-1] == '\n') {
break;
}
buf = &buf[ret];

View File

@ -41,18 +41,20 @@ extern int g_win_fullscreen_state;
int
win_nonblock_read_stdin(int fd, char *bufptr, int len)
{
HANDLE oshandle;
DWORD dwret;
int ret;
errno = EAGAIN;
oshandle = (HANDLE)_get_osfhandle(fd); // get stdin handle
dwret = WaitForSingleObject(oshandle, 1); // wait 1msec for data
ret = -1;
if(dwret == WAIT_OBJECT_0) {
ret = read(fd, bufptr, len);
DWORD charsRead = 0;
ReadConsole(GetStdHandle(STD_INPUT_HANDLE), bufptr, len, &charsRead, NULL);
if (charsRead == 0)
{
errno = EAGAIN;
return -1;
}
else
{
DWORD charsWritten = 0;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), bufptr, charsRead, &charsWritten, NULL);
return charsRead;
}
return ret;
}
void get_cwd(LPTSTR buffer, int size)
@ -166,6 +168,14 @@ main(int argc, char **argv)
printf("...rect is: %ld, %ld, %ld, %ld\n", rect.left, rect.top,
rect.right, rect.bottom);
// Enable non-blocking, character-at-a-time console I/O.
// win_nonblock_read_stdin() expects this behavior.
DWORD mode;
GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode);
mode &= ~ENABLE_LINE_INPUT;
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), mode);
gsportinit(hwnd);
int ret = gsportmain(argc, argv);