Based on code by Rolf Siegrist Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Unified · Split
| @@ -1101,6 +1101,7 @@ HAVE_LIST=" · 1100 unmodified lines | ||
| 1101 | 1101 | memalign |
| 1102 | 1102 | mkstemp |
| 1103 | 1103 | mmap |
| 1104 | + PeekNamedPipe | |
| 1104 | 1105 | posix_memalign |
| 1105 | 1106 | round |
| 1106 | 1107 | roundf |
| @@ -2842,6 +2843,7 @@ check_func strerror_r · 1735 unmodified lines | ||
| 2842 | 2843 | check_func strptime |
| 2843 | 2844 | check_func strtok_r |
| 2844 | 2845 | check_func_headers conio.h kbhit |
| 2846 | +check_func_headers windows.h PeekNamedPipe | |
| 2845 | 2847 | check_func_headers io.h setmode |
| 2846 | 2848 | check_func_headers lzo/lzo1x.h lzo1x_999_compress |
| 2847 | 2849 | check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi |
| @@ -487,9 +487,9 @@ static void term_init(void) · 486 unmodified lines | ||
| 487 | 487 | /* read a key without blocking */ |
| 488 | 488 | static int read_key(void) |
| 489 | 489 | { |
| 490 | + unsigned char ch; | |
| 490 | 491 | #if HAVE_TERMIOS_H |
| 491 | 492 | int n = 1; |
| 492 | − unsigned char ch; | |
| 493 | 493 | struct timeval tv; |
| 494 | 494 | fd_set rfds; |
| 495 | 495 | |
| @@ -509,6 +509,32 @@ static int read_key(void) · 13 unmodified lines | ||
| 509 | 509 | return n; |
| 510 | 510 | } |
| 511 | 511 | #elif HAVE_KBHIT |
| 512 | +# if HAVE_PEEKNAMEDPIPE | |
| 513 | + static int is_pipe; | |
| 514 | + static HANDLE input_handle; | |
| 515 | + DWORD dw, nchars; | |
| 516 | + if(!input_handle){ | |
| 517 | + input_handle = GetStdHandle(STD_INPUT_HANDLE); | |
| 518 | + is_pipe = !GetConsoleMode(input_handle, &dw); | |
| 519 | + } | |
| 520 | + | |
| 521 | + if (stdin->_cnt > 0) { | |
| 522 | + read(0, &ch, 1); | |
| 523 | + return ch; | |
| 524 | + } | |
| 525 | + if (is_pipe) { | |
| 526 | + /* When running under a GUI, you will end here. */ | |
| 527 | + if (!PeekNamedPipe(input_handle, NULL, 0, NULL, &nchars, NULL)) | |
| 528 | + return -1; | |
| 529 | + //Read it | |
| 530 | + if(nchars != 0) { | |
| 531 | + read(0, &ch, 1); | |
| 532 | + return ch; | |
| 533 | + }else{ | |
| 534 | + return -1; | |
| 535 | + } | |
| 536 | + } | |
| 537 | +# endif | |
| 512 | 538 | if(kbhit()) |
| 513 | 539 | return(getch()); |
| 514 | 540 | #endif |