From f4e6f8d4a90571e6b9730541e37e43d353442426 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Sat, 9 May 2009 16:58:40 +1000 Subject: editors/vi: reimplement mysleep() because select() won't work on stdin on Windows This makes vi work on rxvt for Windows. There is work to do in winansi.c in order to make vim work on Windows console. --- editors/vi.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/editors/vi.c b/editors/vi.c index cd64aacc9..cda87220f 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -151,6 +151,9 @@ static char *modifying_cmds; // cmds that modify text[] static char *last_search_pattern; // last pattern from a '/' or '?' search #endif +#ifdef __MINGW32__ +#include "cygwin_termios.h" +#endif /* Moving biggest data to malloced space... */ struct globals { /* many references - keep near the top of globals */ @@ -2164,6 +2167,27 @@ static void catch_sig(int sig) } #endif /* FEATURE_VI_USE_SIGNALS */ +#ifdef __MINGW32__ +static int mysleep(int hund) // sleep for 'h' 1/100 seconds +{ + HANDLE h = GetStdHandle(STD_INPUT_HANDLE); + + fflush(stdout); + + /* In case of cygwin, it's a named pipe and won't work with WaitForSingleObject */ + if (is_cygwin_tty(0) || !h) { + if (hund) + Sleep(hund*10); + return 0; + } + else { + DWORD ret; + + ret = WaitForSingleObject(h, hund*10); + return ret != WAIT_TIMEOUT; + } +} +#else static int mysleep(int hund) // sleep for 'h' 1/100 seconds { fd_set rfds; @@ -2178,6 +2202,7 @@ static int mysleep(int hund) // sleep for 'h' 1/100 seconds select(1, &rfds, NULL, NULL, &tv); return FD_ISSET(0, &rfds); } +#endif #define readbuffer bb_common_bufsiz1 -- cgit v1.2.3-55-g6feb