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

View File

@ -41,18 +41,20 @@ extern int g_win_fullscreen_state;
int int
win_nonblock_read_stdin(int fd, char *bufptr, int len) win_nonblock_read_stdin(int fd, char *bufptr, int len)
{ {
HANDLE oshandle; DWORD charsRead = 0;
DWORD dwret; ReadConsole(GetStdHandle(STD_INPUT_HANDLE), bufptr, len, &charsRead, NULL);
int ret;
if (charsRead == 0)
errno = EAGAIN; {
oshandle = (HANDLE)_get_osfhandle(fd); // get stdin handle errno = EAGAIN;
dwret = WaitForSingleObject(oshandle, 1); // wait 1msec for data return -1;
ret = -1; }
if(dwret == WAIT_OBJECT_0) { else
ret = read(fd, bufptr, len); {
DWORD charsWritten = 0;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), bufptr, charsRead, &charsWritten, NULL);
return charsRead;
} }
return ret;
} }
void get_cwd(LPTSTR buffer, int size) 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, printf("...rect is: %ld, %ld, %ld, %ld\n", rect.left, rect.top,
rect.right, rect.bottom); 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); gsportinit(hwnd);
int ret = gsportmain(argc, argv); int ret = gsportmain(argc, argv);