diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-05-09 16:58:40 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-05-10 18:37:42 +1000 |
commit | f4e6f8d4a90571e6b9730541e37e43d353442426 (patch) | |
tree | c20d78f91c9aeb474acee0edd71c05dc6fd94fdf | |
parent | e3448f1634fa986967b08f58752424480347217c (diff) | |
download | busybox-w32-f4e6f8d4a90571e6b9730541e37e43d353442426.tar.gz busybox-w32-f4e6f8d4a90571e6b9730541e37e43d353442426.tar.bz2 busybox-w32-f4e6f8d4a90571e6b9730541e37e43d353442426.zip |
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.
-rw-r--r-- | editors/vi.c | 25 |
1 files changed, 25 insertions, 0 deletions
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[] | |||
151 | static char *last_search_pattern; // last pattern from a '/' or '?' search | 151 | static char *last_search_pattern; // last pattern from a '/' or '?' search |
152 | #endif | 152 | #endif |
153 | 153 | ||
154 | #ifdef __MINGW32__ | ||
155 | #include "cygwin_termios.h" | ||
156 | #endif | ||
154 | /* Moving biggest data to malloced space... */ | 157 | /* Moving biggest data to malloced space... */ |
155 | struct globals { | 158 | struct globals { |
156 | /* many references - keep near the top of globals */ | 159 | /* many references - keep near the top of globals */ |
@@ -2164,6 +2167,27 @@ static void catch_sig(int sig) | |||
2164 | } | 2167 | } |
2165 | #endif /* FEATURE_VI_USE_SIGNALS */ | 2168 | #endif /* FEATURE_VI_USE_SIGNALS */ |
2166 | 2169 | ||
2170 | #ifdef __MINGW32__ | ||
2171 | static int mysleep(int hund) // sleep for 'h' 1/100 seconds | ||
2172 | { | ||
2173 | HANDLE h = GetStdHandle(STD_INPUT_HANDLE); | ||
2174 | |||
2175 | fflush(stdout); | ||
2176 | |||
2177 | /* In case of cygwin, it's a named pipe and won't work with WaitForSingleObject */ | ||
2178 | if (is_cygwin_tty(0) || !h) { | ||
2179 | if (hund) | ||
2180 | Sleep(hund*10); | ||
2181 | return 0; | ||
2182 | } | ||
2183 | else { | ||
2184 | DWORD ret; | ||
2185 | |||
2186 | ret = WaitForSingleObject(h, hund*10); | ||
2187 | return ret != WAIT_TIMEOUT; | ||
2188 | } | ||
2189 | } | ||
2190 | #else | ||
2167 | static int mysleep(int hund) // sleep for 'h' 1/100 seconds | 2191 | static int mysleep(int hund) // sleep for 'h' 1/100 seconds |
2168 | { | 2192 | { |
2169 | fd_set rfds; | 2193 | fd_set rfds; |
@@ -2178,6 +2202,7 @@ static int mysleep(int hund) // sleep for 'h' 1/100 seconds | |||
2178 | select(1, &rfds, NULL, NULL, &tv); | 2202 | select(1, &rfds, NULL, NULL, &tv); |
2179 | return FD_ISSET(0, &rfds); | 2203 | return FD_ISSET(0, &rfds); |
2180 | } | 2204 | } |
2205 | #endif | ||
2181 | 2206 | ||
2182 | #define readbuffer bb_common_bufsiz1 | 2207 | #define readbuffer bb_common_bufsiz1 |
2183 | 2208 | ||