diff options
Diffstat (limited to 'util-linux/more.c')
-rw-r--r-- | util-linux/more.c | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/util-linux/more.c b/util-linux/more.c index b0f20c441..9ac4dd8e3 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | #include "libbb.h" | 17 | #include "libbb.h" |
18 | 18 | ||
19 | #if ENABLE_FEATURE_USE_TERMIOS | 19 | /* Support for FEATURE_USE_TERMIOS */ |
20 | 20 | ||
21 | struct globals { | 21 | struct globals { |
22 | int cin_fileno; | 22 | int cin_fileno; |
@@ -29,7 +29,9 @@ struct globals { | |||
29 | #define new_settings (G.new_settings ) | 29 | #define new_settings (G.new_settings ) |
30 | #define cin_fileno (G.cin_fileno ) | 30 | #define cin_fileno (G.cin_fileno ) |
31 | 31 | ||
32 | #define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp) | 32 | #define setTermSettings(fd, argp) do { \ |
33 | if (ENABLE_FEATURE_USE_TERMIOS) tcsetattr(fd, TCSANOW, argp); \ | ||
34 | } while(0) | ||
33 | #define getTermSettings(fd, argp) tcgetattr(fd, argp) | 35 | #define getTermSettings(fd, argp) tcgetattr(fd, argp) |
34 | 36 | ||
35 | static void gotsig(int sig UNUSED_PARAM) | 37 | static void gotsig(int sig UNUSED_PARAM) |
@@ -39,11 +41,6 @@ static void gotsig(int sig UNUSED_PARAM) | |||
39 | exit(EXIT_FAILURE); | 41 | exit(EXIT_FAILURE); |
40 | } | 42 | } |
41 | 43 | ||
42 | #else /* !FEATURE_USE_TERMIOS */ | ||
43 | #define INIT_G() ((void)0) | ||
44 | #define setTermSettings(fd, argp) ((void)0) | ||
45 | #endif /* FEATURE_USE_TERMIOS */ | ||
46 | |||
47 | #define CONVERTED_TAB_SIZE 8 | 44 | #define CONVERTED_TAB_SIZE 8 |
48 | 45 | ||
49 | int more_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 46 | int more_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -72,21 +69,21 @@ int more_main(int argc UNUSED_PARAM, char **argv) | |||
72 | if (!cin) | 69 | if (!cin) |
73 | return bb_cat(argv); | 70 | return bb_cat(argv); |
74 | 71 | ||
75 | #if ENABLE_FEATURE_USE_TERMIOS | 72 | if (ENABLE_FEATURE_USE_TERMIOS) { |
76 | cin_fileno = fileno(cin); | 73 | cin_fileno = fileno(cin); |
77 | getTermSettings(cin_fileno, &initial_settings); | 74 | getTermSettings(cin_fileno, &initial_settings); |
78 | new_settings = initial_settings; | 75 | new_settings = initial_settings; |
79 | new_settings.c_lflag &= ~ICANON; | 76 | new_settings.c_lflag &= ~ICANON; |
80 | new_settings.c_lflag &= ~ECHO; | 77 | new_settings.c_lflag &= ~ECHO; |
81 | new_settings.c_cc[VMIN] = 1; | 78 | new_settings.c_cc[VMIN] = 1; |
82 | new_settings.c_cc[VTIME] = 0; | 79 | new_settings.c_cc[VTIME] = 0; |
83 | setTermSettings(cin_fileno, &new_settings); | 80 | setTermSettings(cin_fileno, &new_settings); |
84 | bb_signals(0 | 81 | bb_signals(0 |
85 | + (1 << SIGINT) | 82 | + (1 << SIGINT) |
86 | + (1 << SIGQUIT) | 83 | + (1 << SIGQUIT) |
87 | + (1 << SIGTERM) | 84 | + (1 << SIGTERM) |
88 | , gotsig); | 85 | , gotsig); |
89 | #endif | 86 | } |
90 | 87 | ||
91 | do { | 88 | do { |
92 | file = stdin; | 89 | file = stdin; |
@@ -126,9 +123,8 @@ int more_main(int argc UNUSED_PARAM, char **argv) | |||
126 | for (;;) { | 123 | for (;;) { |
127 | input = getc(cin); | 124 | input = getc(cin); |
128 | input = tolower(input); | 125 | input = tolower(input); |
129 | #if !ENABLE_FEATURE_USE_TERMIOS | 126 | if (!ENABLE_FEATURE_USE_TERMIOS) |
130 | printf("\033[A"); /* up cursor */ | 127 | printf("\033[A"); /* cursor up */ |
131 | #endif | ||
132 | /* Erase the last message */ | 128 | /* Erase the last message */ |
133 | printf("\r%*s\r", len, ""); | 129 | printf("\r%*s\r", len, ""); |
134 | 130 | ||
@@ -150,10 +146,10 @@ int more_main(int argc UNUSED_PARAM, char **argv) | |||
150 | 146 | ||
151 | /* The user may have resized the terminal. | 147 | /* The user may have resized the terminal. |
152 | * Re-read the dimensions. */ | 148 | * Re-read the dimensions. */ |
153 | #if ENABLE_FEATURE_USE_TERMIOS | 149 | if (ENABLE_FEATURE_USE_TERMIOS) { |
154 | get_terminal_width_height(cin_fileno, &terminal_width, &terminal_height); | 150 | get_terminal_width_height(cin_fileno, &terminal_width, &terminal_height); |
155 | terminal_height -= 1; | 151 | terminal_height -= 1; |
156 | #endif | 152 | } |
157 | } | 153 | } |
158 | 154 | ||
159 | /* Crudely convert tabs into spaces, which are | 155 | /* Crudely convert tabs into spaces, which are |