diff options
author | Ron Yorston <rmy@pobox.com> | 2018-04-05 20:31:13 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-04-05 20:31:13 +0100 |
commit | f7c592f6d832602a628008d598a3aa130d89de4d (patch) | |
tree | 5b771c3f51bfb51e52f3736f89f7b4b195e13f82 | |
parent | 3f18c23c67ea8614f1901265d100d3e49bc7491e (diff) | |
download | busybox-w32-f7c592f6d832602a628008d598a3aa130d89de4d.tar.gz busybox-w32-f7c592f6d832602a628008d598a3aa130d89de4d.tar.bz2 busybox-w32-f7c592f6d832602a628008d598a3aa130d89de4d.zip |
win32: exclude termios code
The code to manipulate terminal settings serves no purpose in WIN32.
Use conditional compilation to exclude much of it.
-rw-r--r-- | editors/vi.c | 6 | ||||
-rw-r--r-- | libbb/lineedit.c | 19 | ||||
-rw-r--r-- | libbb/xfuncs.c | 2 | ||||
-rw-r--r-- | miscutils/less.c | 6 | ||||
-rw-r--r-- | win32/termios.c | 10 | ||||
-rw-r--r-- | win32/termios.h | 4 |
6 files changed, 26 insertions, 21 deletions
diff --git a/editors/vi.c b/editors/vi.c index b54dd98dc..26487bee6 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -353,7 +353,9 @@ struct globals { | |||
353 | #if ENABLE_FEATURE_VI_USE_SIGNALS | 353 | #if ENABLE_FEATURE_VI_USE_SIGNALS |
354 | sigjmp_buf restart; // catch_sig() | 354 | sigjmp_buf restart; // catch_sig() |
355 | #endif | 355 | #endif |
356 | #if !ENABLE_PLATFORM_MINGW32 | ||
356 | struct termios term_orig; // remember what the cooked mode was | 357 | struct termios term_orig; // remember what the cooked mode was |
358 | #endif | ||
357 | #if ENABLE_FEATURE_VI_COLON | 359 | #if ENABLE_FEATURE_VI_COLON |
358 | char *initial_cmds[3]; // currently 2 entries, NULL terminated | 360 | char *initial_cmds[3]; // currently 2 entries, NULL terminated |
359 | #endif | 361 | #endif |
@@ -2738,15 +2740,19 @@ static char *swap_context(char *p) // goto new context for '' command make this | |||
2738 | //----- Set terminal attributes -------------------------------- | 2740 | //----- Set terminal attributes -------------------------------- |
2739 | static void rawmode(void) | 2741 | static void rawmode(void) |
2740 | { | 2742 | { |
2743 | #if !ENABLE_PLATFORM_MINGW32 | ||
2741 | // no TERMIOS_CLEAR_ISIG: leave ISIG on - allow signals | 2744 | // no TERMIOS_CLEAR_ISIG: leave ISIG on - allow signals |
2742 | set_termios_to_raw(STDIN_FILENO, &term_orig, TERMIOS_RAW_CRNL); | 2745 | set_termios_to_raw(STDIN_FILENO, &term_orig, TERMIOS_RAW_CRNL); |
2743 | erase_char = term_orig.c_cc[VERASE]; | 2746 | erase_char = term_orig.c_cc[VERASE]; |
2747 | #endif | ||
2744 | } | 2748 | } |
2745 | 2749 | ||
2746 | static void cookmode(void) | 2750 | static void cookmode(void) |
2747 | { | 2751 | { |
2748 | fflush_all(); | 2752 | fflush_all(); |
2753 | #if !ENABLE_PLATFORM_MINGW32 | ||
2749 | tcsetattr_stdin_TCSANOW(&term_orig); | 2754 | tcsetattr_stdin_TCSANOW(&term_orig); |
2755 | #endif | ||
2750 | } | 2756 | } |
2751 | 2757 | ||
2752 | #if ENABLE_FEATURE_VI_USE_SIGNALS | 2758 | #if ENABLE_FEATURE_VI_USE_SIGNALS |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index b9ba71242..36b6abe2b 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -2379,7 +2379,7 @@ static int32_t reverse_i_search(int timeout) | |||
2379 | */ | 2379 | */ |
2380 | int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize) | 2380 | int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize) |
2381 | { | 2381 | { |
2382 | int len, n; | 2382 | int len IF_NOT_PLATFORM_MINGW32(, n); |
2383 | int timeout; | 2383 | int timeout; |
2384 | #if ENABLE_FEATURE_TAB_COMPLETION | 2384 | #if ENABLE_FEATURE_TAB_COMPLETION |
2385 | smallint lastWasTab = 0; | 2385 | smallint lastWasTab = 0; |
@@ -2389,21 +2389,18 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2389 | smallint vi_cmdmode = 0; | 2389 | smallint vi_cmdmode = 0; |
2390 | #endif | 2390 | #endif |
2391 | struct termios initial_settings; | 2391 | struct termios initial_settings; |
2392 | #if !ENABLE_PLATFORM_MINGW32 | ||
2392 | struct termios new_settings; | 2393 | struct termios new_settings; |
2394 | #endif | ||
2393 | char read_key_buffer[KEYCODE_BUFFER_SIZE]; | 2395 | char read_key_buffer[KEYCODE_BUFFER_SIZE]; |
2394 | 2396 | ||
2395 | INIT_S(); | 2397 | INIT_S(); |
2396 | 2398 | ||
2399 | #if !ENABLE_PLATFORM_MINGW32 | ||
2397 | n = get_termios_and_make_raw(STDIN_FILENO, &new_settings, &initial_settings, 0 | 2400 | n = get_termios_and_make_raw(STDIN_FILENO, &new_settings, &initial_settings, 0 |
2398 | | TERMIOS_CLEAR_ISIG /* turn off INTR (ctrl-C), QUIT, SUSP */ | 2401 | | TERMIOS_CLEAR_ISIG /* turn off INTR (ctrl-C), QUIT, SUSP */ |
2399 | ); | 2402 | ); |
2400 | #if ENABLE_PLATFORM_MINGW32 | ||
2401 | initial_settings.c_cc[VINTR] = CTRL('C'); | ||
2402 | initial_settings.c_cc[VEOF] = CTRL('D'); | ||
2403 | if (n > 0 || !isatty(0) || !isatty(1)) { | ||
2404 | #else | ||
2405 | if (n != 0 || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON) { | 2403 | if (n != 0 || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON) { |
2406 | #endif | ||
2407 | /* Happens when e.g. stty -echo was run before. | 2404 | /* Happens when e.g. stty -echo was run before. |
2408 | * But if ICANON is not set, we don't come here. | 2405 | * But if ICANON is not set, we don't come here. |
2409 | * (example: interactive python ^Z-backgrounded, | 2406 | * (example: interactive python ^Z-backgrounded, |
@@ -2418,6 +2415,10 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2418 | DEINIT_S(); | 2415 | DEINIT_S(); |
2419 | return len; | 2416 | return len; |
2420 | } | 2417 | } |
2418 | #else | ||
2419 | initial_settings.c_cc[VINTR] = CTRL('C'); | ||
2420 | initial_settings.c_cc[VEOF] = CTRL('D'); | ||
2421 | #endif | ||
2421 | 2422 | ||
2422 | init_unicode(); | 2423 | init_unicode(); |
2423 | 2424 | ||
@@ -2456,7 +2457,9 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2456 | #endif | 2457 | #endif |
2457 | #define command command_must_not_be_used | 2458 | #define command command_must_not_be_used |
2458 | 2459 | ||
2460 | #if !ENABLE_PLATFORM_MINGW32 | ||
2459 | tcsetattr_stdin_TCSANOW(&new_settings); | 2461 | tcsetattr_stdin_TCSANOW(&new_settings); |
2462 | #endif | ||
2460 | 2463 | ||
2461 | #if ENABLE_USERNAME_OR_HOMEDIR | 2464 | #if ENABLE_USERNAME_OR_HOMEDIR |
2462 | { | 2465 | { |
@@ -2947,8 +2950,10 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2947 | free_tab_completion_data(); | 2950 | free_tab_completion_data(); |
2948 | #endif | 2951 | #endif |
2949 | 2952 | ||
2953 | #if !ENABLE_PLATFORM_MINGW32 | ||
2950 | /* restore initial_settings */ | 2954 | /* restore initial_settings */ |
2951 | tcsetattr_stdin_TCSANOW(&initial_settings); | 2955 | tcsetattr_stdin_TCSANOW(&initial_settings); |
2956 | #endif | ||
2952 | #if ENABLE_FEATURE_EDITING_WINCH | 2957 | #if ENABLE_FEATURE_EDITING_WINCH |
2953 | /* restore SIGWINCH handler */ | 2958 | /* restore SIGWINCH handler */ |
2954 | sigaction_set(SIGWINCH, &S.SIGWINCH_handler); | 2959 | sigaction_set(SIGWINCH, &S.SIGWINCH_handler); |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index f2112aec9..6fa21ad00 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -305,6 +305,7 @@ int FAST_FUNC get_terminal_width(int fd) | |||
305 | return width; | 305 | return width; |
306 | } | 306 | } |
307 | 307 | ||
308 | #if !ENABLE_PLATFORM_MINGW32 | ||
308 | int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) | 309 | int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) |
309 | { | 310 | { |
310 | return tcsetattr(STDIN_FILENO, TCSANOW, tp); | 311 | return tcsetattr(STDIN_FILENO, TCSANOW, tp); |
@@ -380,6 +381,7 @@ int FAST_FUNC set_termios_to_raw(int fd, struct termios *oldterm, int flags) | |||
380 | get_termios_and_make_raw(fd, &newterm, oldterm, flags); | 381 | get_termios_and_make_raw(fd, &newterm, oldterm, flags); |
381 | return tcsetattr(fd, TCSANOW, &newterm); | 382 | return tcsetattr(fd, TCSANOW, &newterm); |
382 | } | 383 | } |
384 | #endif | ||
383 | 385 | ||
384 | pid_t FAST_FUNC safe_waitpid(pid_t pid, int *wstat, int options) | 386 | pid_t FAST_FUNC safe_waitpid(pid_t pid, int *wstat, int options) |
385 | { | 387 | { |
diff --git a/miscutils/less.c b/miscutils/less.c index e4885db77..9c75ae7ac 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -238,7 +238,9 @@ struct globals { | |||
238 | smallint winsize_err; | 238 | smallint winsize_err; |
239 | #endif | 239 | #endif |
240 | smallint terminated; | 240 | smallint terminated; |
241 | #if !ENABLE_PLATFORM_MINGW32 | ||
241 | struct termios term_orig, term_less; | 242 | struct termios term_orig, term_less; |
243 | #endif | ||
242 | char kbd_input[KEYCODE_BUFFER_SIZE]; | 244 | char kbd_input[KEYCODE_BUFFER_SIZE]; |
243 | }; | 245 | }; |
244 | #define G (*ptr_to_globals) | 246 | #define G (*ptr_to_globals) |
@@ -300,7 +302,9 @@ struct globals { | |||
300 | static void set_tty_cooked(void) | 302 | static void set_tty_cooked(void) |
301 | { | 303 | { |
302 | fflush_all(); | 304 | fflush_all(); |
305 | #if !ENABLE_PLATFORM_MINGW32 | ||
303 | tcsetattr(kbd_fd, TCSANOW, &term_orig); | 306 | tcsetattr(kbd_fd, TCSANOW, &term_orig); |
307 | #endif | ||
304 | } | 308 | } |
305 | 309 | ||
306 | /* Move the cursor to a position (x,y), where (0,0) is the | 310 | /* Move the cursor to a position (x,y), where (0,0) is the |
@@ -1966,7 +1970,9 @@ int less_main(int argc, char **argv) | |||
1966 | kbd_fd = tty_fd = 0; | 1970 | kbd_fd = tty_fd = 0; |
1967 | #endif | 1971 | #endif |
1968 | 1972 | ||
1973 | #if !ENABLE_PLATFORM_MINGW32 | ||
1969 | get_termios_and_make_raw(tty_fd, &term_less, &term_orig, TERMIOS_RAW_CRNL); | 1974 | get_termios_and_make_raw(tty_fd, &term_less, &term_orig, TERMIOS_RAW_CRNL); |
1975 | #endif | ||
1970 | 1976 | ||
1971 | IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(tty_fd, &width, &max_displayed_line); | 1977 | IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(tty_fd, &width, &max_displayed_line); |
1972 | /* 20: two tabstops + 4 */ | 1978 | /* 20: two tabstops + 4 */ |
diff --git a/win32/termios.c b/win32/termios.c index a1329ceba..7115bc0da 100644 --- a/win32/termios.c +++ b/win32/termios.c | |||
@@ -1,15 +1,5 @@ | |||
1 | #include "libbb.h" | 1 | #include "libbb.h" |
2 | 2 | ||
3 | int tcsetattr(int fd UNUSED_PARAM, int mode UNUSED_PARAM, const struct termios *t UNUSED_PARAM) | ||
4 | { | ||
5 | return -1; | ||
6 | } | ||
7 | |||
8 | int tcgetattr(int fd UNUSED_PARAM, struct termios *t UNUSED_PARAM) | ||
9 | { | ||
10 | return -1; | ||
11 | } | ||
12 | |||
13 | int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) | 3 | int64_t FAST_FUNC read_key(int fd, char *buf UNUSED_PARAM, int timeout) |
14 | { | 4 | { |
15 | HANDLE cin = GetStdHandle(STD_INPUT_HANDLE); | 5 | HANDLE cin = GetStdHandle(STD_INPUT_HANDLE); |
diff --git a/win32/termios.h b/win32/termios.h index 011a37eb9..c98d414f3 100644 --- a/win32/termios.h +++ b/win32/termios.h | |||
@@ -123,7 +123,3 @@ struct winsize { | |||
123 | unsigned short ws_row, ws_col; | 123 | unsigned short ws_row, ws_col; |
124 | unsigned short ws_xpixel, ws_ypixel; | 124 | unsigned short ws_xpixel, ws_ypixel; |
125 | }; | 125 | }; |
126 | |||
127 | int tcflush(int fd, int queue_selector); | ||
128 | int tcgetattr(int fd, struct termios *t); | ||
129 | int tcsetattr(int fd, int mode, const struct termios *t); | ||